unw_create_addr_space.tex 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. \documentclass{article}
  2. \usepackage[fancyhdr,pdf]{latex2man}
  3. \input{common.tex}
  4. \begin{document}
  5. \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
  6. \end{Name}
  7. \section{Synopsis}
  8. \File{\#include $<$libunwind.h$>$}\\
  9. \Type{unw\_addr\_space\_t} \Func{unw\_create\_addr\_space}(\Type{unw\_accessors\_t~*}\Var{ap}, \Type{int} \Var{byteorder});\\
  10. \section{Description}
  11. The \Func{unw\_create\_addr\_space}() routine creates a new unwind
  12. address-space and initializes it based on the call-back routines
  13. passed via the \Var{ap} pointer and the specified \Var{byteorder}.
  14. The call-back routines are described in detail below. The
  15. \Var{byteorder} can be set to 0 to request the default byte-order of
  16. the unwind target. To request a particular byte-order,
  17. \Var{byteorder} can be set to any constant defined by
  18. \File{$<$endian.h$>$}. In particular, \Const{\_\_LITTLE\_ENDIAN} would
  19. request little-endian byte-order and \Const{\_\_BIG\_ENDIAN} would
  20. request big-endian byte-order. Whether or not a particular byte-order
  21. is supported depends on the target platform.
  22. \section{Call-back Routines}
  23. \Prog{Libunwind} uses a set of call-back routines to access the
  24. information it needs to unwind a chain of stack-frames. These
  25. routines are specified via the \Var{ap} argument, which points to a
  26. variable of type \Type{unw\_accessors\_t}. The contents of this
  27. variable is copied into the newly-created address space, so the
  28. variable must remain valid only for the duration of the call to
  29. \Func{unw\_create\_addr\_space}().
  30. The first argument to every call-back routine is an address-space
  31. identifier (\Var{as}) and the last argument is an arbitrary,
  32. application-specified void-pointer (\Var{arg}). When invoking a
  33. call-back routine, \Prog{libunwind} sets the \Var{as} argument to the
  34. address-space on whose behalf the invocation is made and the \Var{arg}
  35. argument to the value that was specified when
  36. \Func{unw\_init\_remote}(3) was called.
  37. The synopsis and a detailed description of every call-back routine
  38. follows below.
  39. \subsection{Call-back Routine Synopsis}
  40. \Type{int} \Func{find\_proc\_info}(\Type{unw\_addr\_space\_t} \Var{as},\\
  41. \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},\\
  42. \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);\\
  43. \Type{void} \Func{put\_unwind\_info}(\Type{unw\_addr\_space\_t} \Var{as},\\
  44. \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});\\
  45. \Type{int} \Func{get\_dyn\_info\_list\_addr}(\Type{unw\_addr\_space\_t} \Var{as},\\
  46. \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});\\
  47. \Type{int} \Func{access\_mem}(\Var{unw\_addr\_space\_t} \Var{as},\\
  48. \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},\\
  49. \SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{int} \Var{write}, \Type{void~*}\Var{arg});\\
  50. \Type{int} \Func{access\_reg}(\Var{unw\_addr\_space\_t} \Var{as},\\
  51. \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},\\
  52. \SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{int} \Var{write}, \Type{void~*}\Var{arg});\\
  53. \Type{int} \Func{access\_fpreg}(\Var{unw\_addr\_space\_t} \Var{as},\\
  54. \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},\\
  55. \SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{int} \Var{write}, \Type{void~*}\Var{arg});\\
  56. \Type{int} \Func{resume}(\Var{unw\_addr\_space\_t} \Var{as},\\
  57. \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});\\
  58. \Type{int} \Func{get\_proc\_name}(\Type{unw\_addr\_space\_t} \Var{as},\\
  59. \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},\\
  60. \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},\\
  61. \SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\SP\Type{void~*}\Var{arg});\\
  62. \subsection{find\_proc\_info}
  63. \Prog{Libunwind} invokes the \Func{find\_proc\_info}() call-back to
  64. locate the information need to unwind a particular procedure. The
  65. \Var{ip} argument is an instruction-address inside the procedure whose
  66. information is needed. The \Var{pip} argument is a pointer to the
  67. variable used to return the desired information. The type of this
  68. variable is \Type{unw\_proc\_info\_t}. See
  69. \Func{unw\_get\_proc\_info(3)} for details. Argument
  70. \Var{need\_unwind\_info} is zero if the call-back does not need to
  71. provide values for the following members in the
  72. \Type{unw\_proc\_info\_t} structure: \Var{format},
  73. \Var{unwind\_info\_size}, and \Var{unwind\_info}. If
  74. \Var{need\_unwind\_info} is non-zero, valid values need to be returned
  75. in these members. Furthermore, the contents of the memory addressed
  76. by the \Var{unwind\_info} member must remain valid until the info is
  77. released via the \Func{put\_unwind\_info} call-back (see below).
  78. On successful completion, the \Func{find\_proc\_info}() call-back must
  79. return zero. Otherwise, the negative value of one of the
  80. \Type{unw\_error\_t} error-codes may be returned. In particular, this
  81. call-back may return -\Const{UNW\_ESTOPUNWIND} to signal the end of
  82. the frame-chain.
  83. \subsection{put\_unwind\_info}
  84. \Prog{Libunwind} invokes the \Func{put\_unwind\_info}() call-back to
  85. release the resources (such as memory) allocated by a previous call to
  86. \Func{find\_proc\_info}() with the \Var{need\_unwind\_info} argument
  87. set to a non-zero value. The \Var{pip} argument has the same value as
  88. the argument of the same name in the previous matching call to
  89. \Func{find\_proc\_info}(). Note that \Prog{libunwind} does \emph{not}
  90. invoke \Func{put\_unwind\_info} for calls to \Func{find\_proc\_info}()
  91. with a zero \Var{need\_unwind\_info} argument.
  92. \subsection{get\_dyn\_info\_list\_addr}
  93. \Prog{Libunwind} invokes the \Func{get\_dyn\_info\_list\_addr}()
  94. call-back to obtain the address of the head of the dynamic unwind-info
  95. registration list. The variable stored at the returned address must
  96. have a type of \Type{unw\_dyn\_info\_list\_t} (see
  97. \Func{\_U\_dyn\_register}(3)). The \Var{dliap} argument is a pointer
  98. to a variable of type \Type{unw\_word\_t} which is used to return the
  99. address of the dynamic unwind-info registration list. If no dynamic
  100. unwind-info registration list exist, the value pointed to by
  101. \Var{dliap} must be cleared to zero. \Prog{Libunwind} will cache the
  102. value returned by \Func{get\_dyn\_info\_list\_addr}() if caching is
  103. enabled for the given address-space. The cache can be cleared with a
  104. call to \Func{unw\_flush\_cache}().
  105. On successful completion, the \Func{get\_dyn\_info\_list\_addr}()
  106. call-back must return zero. Otherwise, the negative value of one of
  107. the \Type{unw\_error\_t} error-codes may be returned.
  108. \subsection{access\_mem}
  109. \Prog{Libunwind} invokes the \Func{access\_mem}() call-back to read
  110. from or write to a word of memory in the target address-space. The
  111. address of the word to be accessed is passed in argument \Var{addr}.
  112. To read memory, \Prog{libunwind} sets argument \Var{write} to zero and
  113. \Var{valp} to point to the word that receives the read value. To
  114. write memory, \Prog{libunwind} sets argument \Var{write} to a non-zero
  115. value and \Var{valp} to point to the word that contains the value to
  116. be written. The word that \Var{valp} points to is always in the
  117. byte-order of the host-platform, regardless of the byte-order of the
  118. target. In other words, it is the responsibility of the call-back
  119. routine to convert between the target's and the host's byte-order, if
  120. necessary.
  121. On successful completion, the \Func{access\_mem}()
  122. call-back must return zero. Otherwise, the negative value of one of
  123. the \Type{unw\_error\_t} error-codes may be returned.
  124. \subsection{access\_reg}
  125. \Prog{Libunwind} invokes the \Func{access\_reg}() call-back to read
  126. from or write to a scalar (non-floating-point) CPU register. The
  127. index of the register to be accessed is passed in argument
  128. \Var{regnum}. To read a register, \Prog{libunwind} sets argument
  129. \Var{write} to zero and \Var{valp} to point to the word that receives
  130. the read value. To write a register, \Prog{libunwind} sets argument
  131. \Var{write} to a non-zero value and \Var{valp} to point to the word
  132. that contains the value to be written. The word that \Var{valp}
  133. points to is always in the byte-order of the host-platform, regardless
  134. of the byte-order of the target. In other words, it is the
  135. responsibility of the call-back routine to convert between the
  136. target's and the host's byte-order, if necessary.
  137. On successful completion, the \Func{access\_reg}() call-back must
  138. return zero. Otherwise, the negative value of one of the
  139. \Type{unw\_error\_t} error-codes may be returned.
  140. \subsection{access\_fpreg}
  141. \Prog{Libunwind} invokes the \Func{access\_fpreg}() call-back to read
  142. from or write to a floating-point CPU register. The index of the
  143. register to be accessed is passed in argument \Var{regnum}. To read a
  144. register, \Prog{libunwind} sets argument \Var{write} to zero and
  145. \Var{fpvalp} to point to a variable of type \Type{unw\_fpreg\_t} that
  146. receives the read value. To write a register, \Prog{libunwind} sets
  147. argument \Var{write} to a non-zero value and \Var{fpvalp} to point to
  148. the variable of type \Type{unw\_fpreg\_t} that contains the value to
  149. be written. The word that \Var{fpvalp} points to is always in the
  150. byte-order of the host-platform, regardless of the byte-order of the
  151. target. In other words, it is the responsibility of the call-back
  152. routine to convert between the target's and the host's byte-order, if
  153. necessary.
  154. On successful completion, the \Func{access\_fpreg}() call-back must
  155. return zero. Otherwise, the negative value of one of the
  156. \Type{unw\_error\_t} error-codes may be returned.
  157. \subsection{resume}
  158. \Prog{Libunwind} invokes the \Func{resume}() call-back to resume
  159. execution in the target address space. Argument \Var{cp} is the
  160. unwind-cursor that identifies the stack-frame in which execution
  161. should resume. By the time \Prog{libunwind} invokes the \Func{resume}
  162. call-back, it has already established the desired machine- and
  163. memory-state via calls to the \Func{access\_reg}(),
  164. \Func{access\_fpreg}, and \Func{access\_mem}() call-backs. Thus, all
  165. the call-back needs to do is perform whatever action is needed to
  166. actually resume execution.
  167. The \Func{resume} call-back is invoked only in response to a call to
  168. \Func{unw\_resume}(3), so applications which never invoke
  169. \Func{unw\_resume}(3) need not define the \Func{resume} callback.
  170. On successful completion, the \Func{resume}() call-back must return
  171. zero. Otherwise, the negative value of one of the
  172. \Type{unw\_error\_t} error-codes may be returned. As a special case,
  173. when resuming execution in the local address space, the call-back will
  174. not return on success.
  175. \subsection{get\_proc\_name}
  176. \Prog{Libunwind} invokes the \Func{get\_proc\_name}() call-back to
  177. obtain the procedure-name of a static (not dynamically generated)
  178. procedure. Argument \Var{addr} is an instruction-address within the
  179. procedure whose name is to be obtained. The \Var{bufp} argument is a
  180. pointer to a character-buffer used to return the procedure name. The
  181. size of this buffer is specified in argument \Var{buf\_len}. The
  182. returned name must be terminated by a NUL character. If the
  183. procedure's name is longer than \Var{buf\_len} bytes, it must be
  184. truncated to \Var{buf\_len}\Prog{-1} bytes, with the last byte in the
  185. buffer set to the NUL character and -\Const{UNW\_ENOMEM} must be
  186. returned. Argument \Var{offp} is a pointer to a word which is used to
  187. return the byte-offset relative to the start of the procedure whose
  188. name is being returned. For example, if procedure \Func{foo}() starts
  189. at address 0x40003000, then invoking \Func{get\_proc\_name}() with
  190. \Var{addr} set to 0x40003080 should return a value of 0x80 in the word
  191. pointed to by \Var{offp} (assuming the procedure is at least 0x80
  192. bytes long).
  193. On successful completion, the \Func{get\_proc\_name}() call-back must
  194. return zero. Otherwise, the negative value of one of the
  195. \Type{unw\_error\_t} error-codes may be returned.
  196. \section{Return Value}
  197. On successful completion, \Func{unw\_create\_addr\_space}() returns a
  198. non-\Const{NULL} value that represents the newly created
  199. address-space. Otherwise, \Const{NULL} is returned.
  200. \section{Thread and Signal Safety}
  201. \Func{unw\_create\_addr\_space}() is thread-safe but \emph{not}
  202. safe to use from a signal handler.
  203. \section{See Also}
  204. \SeeAlso{\_U\_dyn\_register(3)},
  205. \SeeAlso{libunwind(3)},
  206. \SeeAlso{unw\_destroy\_addr\_space(3)},
  207. \SeeAlso{unw\_get\_proc\_info(3)},
  208. \SeeAlso{unw\_init\_remote(3)},
  209. \SeeAlso{unw\_resume(3)}
  210. \section{Author}
  211. \noindent
  212. David Mosberger-Tang\\
  213. Email: \Email{dmosberger@gmail.com}\\
  214. WWW: \URL{http://www.nongnu.org/libunwind/}.
  215. \LatexManEnd
  216. \end{document}