---
name: "unw_init_local"
section: "3"
platform: "linux"
package: "libunwind"
version: "1.8.3-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/unw_init_local"
---

# unw\_init\_local(3)

## NAME

unw\_init\_local -- initialize cursor for local unwinding

## SYNOPSIS

\#include \<libunwind.h\>\

int unw\_init\_local(unw\_cursor\_t \*c, unw\_context\_t \*ctxt);\
 int unw\_init\_local2(unw\_cursor\_t \*c, unw\_context\_t \*ctxt, int flag);\

## DESCRIPTION

The unw\_init\_local() routine initializes the unwind cursor  pointed to by c with the machine state in the context structure  pointed to by ctxt. As such, the machine state pointed to by  ctxt identifies the initial stack frame at which unwinding  starts. The machine state is expected to be one provided by a call to  unw\_getcontext(); as such, the instruction pointer may point to  the instruction after the last instruction of a function, and  libunwind will back-up the instruction pointer before beginning  a walk up the call stack. The machine state must remain valid for the  duration for which the cursor c is in use.

The unw\_init\_local() routine can be used only for unwinding in  the address space of the current process (i.e., for local unwinding).  For all other cases, unw\_init\_remote() must be used instead.  However, unwind performance may be better when using  unw\_init\_local(). Also, unw\_init\_local() is  available even when UNW\_LOCAL\_ONLY has been defined before  including \<libunwind.h\>, whereas unw\_init\_remote() is not.

If the unw\_context\_t is known to be a signal frame (i.e.,  from the third argument in a sigaction handler on linux),  unw\_init\_local2() should be used for correct initialization  on some platforms, passing the UNW\_INIT\_SIGNAL\_FRAME flag.

## RETURN VALUE

On successful completion, unw\_init\_local() returns 0.  Otherwise the negative value of one of the error codes below is  returned.

## THREAD AND SIGNAL SAFETY

unw\_init\_local() is thread safe as well as safe to use from a  signal handler.

## ERRORS

- UNW\_EINVAL

   unw\_init\_local() was called in a  version of libunwind which supports remote unwinding only  (this normally happens when calling unw\_init\_local() for a  cross-platform version of libunwind).

- UNW\_EUNSPEC

   An unspecified error occurred.

- UNW\_EBADREG

   A register needed by unw\_init\_local() wasn't accessible.

## SEE ALSO

libunwind(3libunwind), unw\_init\_remote(3libunwind)

## AUTHOR

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