2003-03-13 03:15:01 +01:00
\documentclass { article}
\usepackage [fancyhdr,pdf] { latex2man}
\input { common.tex}
\begin { document}
2003-03-31 21:57:09 +02:00
\begin { Name} { 3} { unw\_ create\_ addr\_ space} { David Mosberger-Tang} { Programming Library} { unw\_ create\_ addr\_ space} unw\_ create\_ addr\_ space -- create address space for remote unwinding
2003-03-13 03:15:01 +01:00
\end { Name}
\section { Synopsis}
\File { \# include $ < $ libunwind.h$ > $ } \\
2005-04-20 23:02:21 +02:00
\Type { unw\_ addr\_ space\_ t} \Func { unw\_ create\_ addr\_ space} (\Type { unw\_ accessors\_ t~*} \Var { ap} , \Type { int} \Var { byteorder} );\\
2003-03-13 03:15:01 +01:00
\section { Description}
The \Func { unw\_ create\_ addr\_ space} () routine creates a new unwind
address-space and initializes it based on the call-back routines
passed via the \Var { ap} pointer and the specified \Var { byteorder} .
The call-back routines are described in detail below. The
\Var { byteorder} can be set to 0 to request the default byte-order of
the unwind target. To request a particular byte-order,
\Var { byteorder} can be set to any constant defined by
2004-08-05 10:59:57 +02:00
\File { $ < $ endian.h$ > $ } . In particular, \Const { \_ \_ LITTLE\_ ENDIAN} would
2003-03-13 03:15:01 +01:00
request little-endian byte-order and \Const { \_ \_ BIG\_ ENDIAN} would
request big-endian byte-order. Whether or not a particular byte-order
is supported depends on the target platform.
\section { Call-back Routines}
\Prog { Libunwind} uses a set of call-back routines to access the
information it needs to unwind a chain of stack-frames. These
routines are specified via the \Var { ap} argument, which points to a
variable of type \Type { unw\_ accessors\_ t} . The contents of this
variable is copied into the newly-created address space, so the
variable must remain valid only for the duration of the call to
\Func { unw\_ create\_ addr\_ space} ().
The first argument to every call-back routine is an address-space
identifier (\Var { as} ) and the last argument is an arbitrary,
application-specified void-pointer (\Var { arg} ). When invoking a
call-back routine, \Prog { libunwind} sets the \Var { as} argument to the
address-space on whose behalf the invocation is made and the \Var { arg}
argument to the value that was specified when
\Func { unw\_ init\_ remote} (3) was called.
The synopsis and a detailed description of every call-back routine
follows below.
\subsection { Call-back Routine Synopsis}
\Type { int} \Func { find\_ proc\_ info} (\Type { unw\_ addr\_ space\_ t} \Var { as} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { unw\_ word\_ t} \Var { ip} , \Type { unw\_ proc\_ info\_ t~*} \Var { pip} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { int} \Var { need\_ unwind\_ info} , \Type { void~*} arg);\\
\Type { void} \Func { put\_ unwind\_ info} (\Type { unw\_ addr\_ space\_ t} \Var { as} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { unw\_ proc\_ info\_ t~*} pip, \Type { void~*} \Var { arg} );\\
\Type { int} \Func { get\_ dyn\_ info\_ list\_ addr} (\Type { unw\_ addr\_ space\_ t} \Var { as} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { unw\_ word\_ t~*} \Var { dilap} , \Type { void~*} \Var { arg} );\\
\Type { int} \Func { access\_ mem} (\Var { unw\_ addr\_ space\_ t} \Var { as} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { unw\_ word\_ t} \Var { addr} , \Type { unw\_ word\_ t~*} \Var { valp} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { int} \Var { write} , \Type { void~*} \Var { arg} );\\
\Type { int} \Func { access\_ reg} (\Var { unw\_ addr\_ space\_ t} \Var { as} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { unw\_ regnum\_ t} \Var { regnum} , \Type { unw\_ word\_ t~*} \Var { valp} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { int} \Var { write} , \Type { void~*} \Var { arg} );\\
\Type { int} \Func { access\_ fpreg} (\Var { unw\_ addr\_ space\_ t} \Var { as} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { unw\_ regnum\_ t} \Var { regnum} , \Type { unw\_ fpreg\_ t~*} \Var { fpvalp} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { int} \Var { write} , \Type { void~*} \Var { arg} );\\
\Type { int} \Func { resume} (\Var { unw\_ addr\_ space\_ t} \Var { as} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { unw\_ cursor\_ t~*} \Var { cp} , \Type { void~*} \Var { arg} );\\
\Type { int} \Func { get\_ proc\_ name} (\Type { unw\_ addr\_ space\_ t} \Var { as} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { unw\_ word\_ t} \Var { addr} , \Type { char~*} \Var { bufp} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { size\_ t} \Var { buf\_ len} , \Type { unw\_ word\_ t~*} \Var { offp} ,\\
\SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \SP \Type { void~*} \Var { arg} );\\
\subsection { find\_ proc\_ info}
\Prog { Libunwind} invokes the \Func { find\_ proc\_ info} () call-back to
locate the information need to unwind a particular procedure. The
\Var { ip} argument is an instruction-address inside the procedure whose
information is needed. The \Var { pip} argument is a pointer to the
variable used to return the desired information. The type of this
variable is \Type { unw\_ proc\_ info\_ t} . See
\Func { unw\_ get\_ proc\_ info(3)} for details. Argument
\Var { need\_ unwind\_ info} is zero if the call-back does not need to
provide values for the following members in the
\Type { unw\_ proc\_ info\_ t} structure: \Var { format} ,
\Var { unwind\_ info\_ size} , and \Var { unwind\_ info} . If
\Var { need\_ unwind\_ info} is non-zero, valid values need to be returned
in these members. Furthermore, the contents of the memory addressed
by the \Var { unwind\_ info} member must remain valid until the info is
released via the \Func { put\_ unwind\_ info} call-back (see below).
On successful completion, the \Func { find\_ proc\_ info} () call-back must
return zero. Otherwise, the negative value of one of the
2003-03-20 08:51:37 +01:00
\Type { unw\_ error\_ t} error-codes may be returned. In particular, this
call-back may return -\Const { UNW\_ ESTOPUNWIND} to signal the end of
the frame-chain.
2003-03-13 03:15:01 +01:00
\subsection { put\_ unwind\_ info}
\Prog { Libunwind} invokes the \Func { put\_ unwind\_ info} () call-back to
release the resources (such as memory) allocated by a previous call to
\Func { find\_ proc\_ info} () with the \Var { need\_ unwind\_ info} argument
set to a non-zero value. The \Var { pip} argument has the same value as
the argument of the same name in the previous matching call to
\Func { find\_ proc\_ info} (). Note that \Prog { libunwind} does \emph { not}
invoke \Func { put\_ unwind\_ info} for calls to \Func { find\_ proc\_ info} ()
with a zero \Var { need\_ unwind\_ info} argument.
\subsection { get\_ dyn\_ info\_ list\_ addr}
\Prog { Libunwind} invokes the \Func { get\_ dyn\_ info\_ list\_ addr} ()
call-back to obtain the address of the head of the dynamic unwind-info
registration list. The variable stored at the returned address must
have a type of \Type { unw\_ dyn\_ info\_ list\_ t} (see
\Func { \_ U\_ dyn\_ register} (3)). The \Var { dliap} argument is a pointer
to a variable of type \Type { unw\_ word\_ t} which is used to return the
address of the dynamic unwind-info registration list. If no dynamic
unwind-info registration list exist, the value pointed to by
\Var { dliap} must be cleared to zero. \Prog { Libunwind} will cache the
value returned by \Func { get\_ dyn\_ info\_ list\_ addr} () if caching is
enabled for the given address-space. The cache can be cleared with a
call to \Func { unw\_ flush\_ cache} ().
On successful completion, the \Func { get\_ dyn\_ info\_ list\_ addr} ()
call-back must return zero. Otherwise, the negative value of one of
the \Type { unw\_ error\_ t} error-codes may be returned.
\subsection { access\_ mem}
\Prog { Libunwind} invokes the \Func { access\_ mem} () call-back to read
from or write to a word of memory in the target address-space. The
address of the word to be accessed is passed in argument \Var { addr} .
To read memory, \Prog { libunwind} sets argument \Var { write} to zero and
\Var { valp} to point to the word that receives the read value. To
write memory, \Prog { libunwind} sets argument \Var { write} to a non-zero
value and \Var { valp} to point to the word that contains the value to
be written. The word that \Var { valp} points to is always in the
byte-order of the host-platform, regardless of the byte-order of the
target. In other words, it is the responsibility of the call-back
routine to convert between the target's and the host's byte-order, if
necessary.
On successful completion, the \Func { access\_ mem} ()
call-back must return zero. Otherwise, the negative value of one of
the \Type { unw\_ error\_ t} error-codes may be returned.
\subsection { access\_ reg}
\Prog { Libunwind} invokes the \Func { access\_ reg} () call-back to read
from or write to a scalar (non-floating-point) CPU register. The
index of the register to be accessed is passed in argument
\Var { regnum} . To read a register, \Prog { libunwind} sets argument
\Var { write} to zero and \Var { valp} to point to the word that receives
the read value. To write a register, \Prog { libunwind} sets argument
\Var { write} to a non-zero value and \Var { valp} to point to the word
that contains the value to be written. The word that \Var { valp}
points to is always in the byte-order of the host-platform, regardless
of the byte-order of the target. In other words, it is the
responsibility of the call-back routine to convert between the
target's and the host's byte-order, if necessary.
On successful completion, the \Func { access\_ reg} () call-back must
return zero. Otherwise, the negative value of one of the
\Type { unw\_ error\_ t} error-codes may be returned.
\subsection { access\_ fpreg}
\Prog { Libunwind} invokes the \Func { access\_ fpreg} () call-back to read
from or write to a floating-point CPU register. The index of the
register to be accessed is passed in argument \Var { regnum} . To read a
register, \Prog { libunwind} sets argument \Var { write} to zero and
\Var { fpvalp} to point to a variable of type \Type { unw\_ fpreg\_ t} that
receives the read value. To write a register, \Prog { libunwind} sets
argument \Var { write} to a non-zero value and \Var { fpvalp} to point to
the variable of type \Type { unw\_ fpreg\_ t} that contains the value to
be written. The word that \Var { fpvalp} points to is always in the
byte-order of the host-platform, regardless of the byte-order of the
target. In other words, it is the responsibility of the call-back
routine to convert between the target's and the host's byte-order, if
necessary.
On successful completion, the \Func { access\_ fpreg} () call-back must
return zero. Otherwise, the negative value of one of the
\Type { unw\_ error\_ t} error-codes may be returned.
\subsection { resume}
\Prog { Libunwind} invokes the \Func { resume} () call-back to resume
execution in the target address space. Argument \Var { cp} is the
unwind-cursor that identifies the stack-frame in which execution
should resume. By the time \Prog { libunwind} invokes the \Func { resume}
call-back, it has already established the desired machine- and
2004-08-05 10:59:57 +02:00
memory-state via calls to the \Func { access\_ reg} (),
2003-03-13 03:15:01 +01:00
\Func { access\_ fpreg} , and \Func { access\_ mem} () call-backs. Thus, all
the call-back needs to do is perform whatever action is needed to
actually resume execution.
The \Func { resume} call-back is invoked only in response to a call to
\Func { unw\_ resume} (3), so applications which never invoke
\Func { unw\_ resume} (3) need not define the \Func { resume} callback.
On successful completion, the \Func { resume} () call-back must return
zero. Otherwise, the negative value of one of the
\Type { unw\_ error\_ t} error-codes may be returned. As a special case,
when resuming execution in the local address space, the call-back will
not return on success.
\subsection { get\_ proc\_ name}
\Prog { Libunwind} invokes the \Func { get\_ proc\_ name} () call-back to
obtain the procedure-name of a static (not dynamically generated)
procedure. Argument \Var { addr} is an instruction-address within the
procedure whose name is to be obtained. The \Var { bufp} argument is a
pointer to a character-buffer used to return the procedure name. The
2004-08-05 10:59:57 +02:00
size of this buffer is specified in argument \Var { buf\_ len} . The
2003-03-13 03:15:01 +01:00
returned name must be terminated by a NUL character. If the
2004-08-05 10:59:57 +02:00
procedure's name is longer than \Var { buf\_ len} bytes, it must be
2003-03-13 03:15:01 +01:00
truncated to \Var { buf\_ len} \Prog { -1} bytes, with the last byte in the
buffer set to the NUL character and -\Const { UNW\_ ENOMEM} must be
returned. Argument \Var { offp} is a pointer to a word which is used to
return the byte-offset relative to the start of the procedure whose
name is being returned. For example, if procedure \Func { foo} () starts
at address 0x40003000, then invoking \Func { get\_ proc\_ name} () with
\Var { addr} set to 0x40003080 should return a value of 0x80 in the word
pointed to by \Var { offp} (assuming the procedure is at least 0x80
bytes long).
On successful completion, the \Func { get\_ proc\_ name} () call-back must
return zero. Otherwise, the negative value of one of the
\Type { unw\_ error\_ t} error-codes may be returned.
\section { Return Value}
On successful completion, \Func { unw\_ create\_ addr\_ space} () returns a
non-\Const { NULL} value that represents the newly created
address-space. Otherwise, \Const { NULL} is returned.
\section { Thread and Signal Safety}
\Func { unw\_ create\_ addr\_ space} () is thread-safe but \emph { not}
safe to use from a signal handler.
\section { See Also}
\SeeAlso { \_ U\_ dyn\_ register(3)} ,
\SeeAlso { libunwind(3)} ,
\SeeAlso { unw\_ destroy\_ addr\_ space(3)} ,
\SeeAlso { unw\_ get\_ proc\_ info(3)} ,
\SeeAlso { unw\_ init\_ remote(3)} ,
\SeeAlso { unw\_ resume(3)}
\section { Author}
\noindent
David Mosberger-Tang\\
Hewlett-Packard Labs\\
Palo-Alto, CA 94304\\
Email: \Email { davidm@hpl.hp.com} \\
WWW: \URL { http://www.hpl.hp.com/research/linux/libunwind/} .
\LatexManEnd
\end { document}