---
name: "unw_set_caching_policy"
section: "3libunwind"
platform: "linux"
package: "libunwind-dev"
version: "1.8.1-0.1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/unw_set_caching_policy/3libunwind"
---

# unw\_set\_caching\_policy(3libunwind)

## NAME

unw\_set\_caching\_policy -- set unwind caching policy

## SYNOPSIS

\#include \<libunwind.h\>\

int unw\_set\_caching\_policy(unw\_addr\_space\_t as, unw\_caching\_policy\_t policy);\

## DESCRIPTION

The unw\_set\_caching\_policy() routine sets the caching policy  of address space as to the policy specified by argument  policy. The policy argument can take one of three  possible values:

- UNW\_CACHE\_NONE

   Turns off caching completely. This  also implicitly flushes the contents of all caches as if  unw\_flush\_cache() had been called.

- UNW\_CACHE\_GLOBAL

   Enables caching using a global cache  that is shared by all threads. If global caching is unavailable or  unsupported, libunwind may fall back on using a per-thread  cache, as if UNW\_CACHE\_PER\_THREAD had been specified.

- UNW\_CACHE\_PER\_THREAD

   Enables caching using  thread-local caches. If a thread-local caching are unavailable or  unsupported, libunwind may fall back on using a global cache,  as if UNW\_CACHE\_GLOBAL had been specified.

If caching is enabled, an application must be prepared to make  appropriate calls to unw\_flush\_cache() whenever the target  changes in a way that could affect the validity of cached information.  For example, after unloading (removing) a shared library,  unw\_flush\_cache() would have to be called (at least) for the  address-range that was covered by the shared library.

For address spaces created via unw\_create\_addr\_space(3libunwind), caching is turned off by default. For the local address space  unw\_local\_addr\_space, caching is turned on by default.

## RETURN VALUE

On successful completion, unw\_set\_caching\_policy() returns 0.  Otherwise the negative value of one of the error-codes below is  returned.

## THREAD AND SIGNAL SAFETY

unw\_set\_caching\_policy() is thread-safe but *not* safe  to use from a signal handler.

## ERRORS

- UNW\_ENOMEM

   The desired caching policy could not be  established because the application is out of memory.

## SEE ALSO

libunwind(3libunwind), unw\_create\_addr\_space(3libunwind), unw\_set\_cache\_size(3libunwind), unw\_flush\_cache(3libunwind)

## AUTHOR

David Mosberger-Tang\
 Email: **dmosberger@gmail.com**\
 WWW: **http://www.nongnu.org/libunwind/**.
