simple-object.txh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. @c -*- mode: texinfo -*-
  2. @deftypefn Extension {simple_object_read *} simple_object_open_read @
  3. (int @var{descriptor}, off_t @var{offset}, const char *{segment_name}, @
  4. const char **@var{errmsg}, int *@var{err})
  5. Opens an object file for reading. Creates and returns an
  6. @code{simple_object_read} pointer which may be passed to other
  7. functions to extract data from the object file.
  8. @var{descriptor} holds a file descriptor which permits reading.
  9. @var{offset} is the offset into the file; this will be @code{0} in the
  10. normal case, but may be a different value when reading an object file
  11. in an archive file.
  12. @var{segment_name} is only used with the Mach-O file format used on
  13. Darwin aka Mac OS X. It is required on that platform, and means to
  14. only look at sections within the segment with that name. The
  15. parameter is ignored on other systems.
  16. If an error occurs, this functions returns @code{NULL} and sets
  17. @code{*@var{errmsg}} to an error string and sets @code{*@var{err}} to
  18. an errno value or @code{0} if there is no relevant errno.
  19. @end deftypefn
  20. @deftypefn Extension {const char *} simple_object_find_sections @
  21. (simple_object_read *@var{simple_object}, int (*@var{pfn}) (void *@var{data}, @
  22. const char *@var{name}, off_t @var{offset}, off_t @var{length}), @
  23. void *@var{data}, int *@var{err})
  24. This function calls @var{pfn} for each section in @var{simple_object}.
  25. It calls @var{pfn} with the section name, the offset within the file
  26. of the section contents, and the length of the section contents. The
  27. offset within the file is relative to the offset passed to
  28. @code{simple_object_open_read}. The @var{data} argument to this
  29. function is passed along to @var{pfn}.
  30. If @var{pfn} returns @code{0}, the loop over the sections stops and
  31. @code{simple_object_find_sections} returns. If @var{pfn} returns some
  32. other value, the loop continues.
  33. On success @code{simple_object_find_sections} returns. On error it
  34. returns an error string, and sets @code{*@var{err}} to an errno value
  35. or @code{0} if there is no relevant errno.
  36. @end deftypefn
  37. @deftypefn Extension {int} simple_object_find_section @
  38. (simple_object_read *@var{simple_object} off_t *@var{offset}, @
  39. off_t *@var{length}, const char **@var{errmsg}, int *@var{err})
  40. Look for the section @var{name} in @var{simple_object}. This returns
  41. information for the first section with that name.
  42. If found, return 1 and set @code{*@var{offset}} to the offset in the
  43. file of the section contents and set @code{*@var{length}} to the
  44. length of the section contents. The value in @code{*@var{offset}}
  45. will be relative to the offset passed to
  46. @code{simple_object_open_read}.
  47. If the section is not found, and no error occurs,
  48. @code{simple_object_find_section} returns @code{0} and set
  49. @code{*@var{errmsg}} to @code{NULL}.
  50. If an error occurs, @code{simple_object_find_section} returns
  51. @code{0}, sets @code{*@var{errmsg}} to an error message, and sets
  52. @code{*@var{err}} to an errno value or @code{0} if there is no
  53. relevant errno.
  54. @end deftypefn
  55. @deftypefn Extension {void} simple_object_release_read @
  56. (simple_object_read *@var{simple_object})
  57. Release all resources associated with @var{simple_object}. This does
  58. not close the file descriptor.
  59. @end deftypefn
  60. @deftypefn Extension {simple_object_attributes *} simple_object_fetch_attributes @
  61. (simple_object_read *@var{simple_object}, const char **@var{errmsg}, int *@var{err})
  62. Fetch the attributes of @var{simple_object}. The attributes are
  63. internal information such as the format of the object file, or the
  64. architecture it was compiled for. This information will persist until
  65. @code{simple_object_attributes_release} is called, even if
  66. @var{simple_object} itself is released.
  67. On error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
  68. error message, and sets @code{*@var{err}} to an errno value or
  69. @code{0} if there is no relevant errno.
  70. @end deftypefn
  71. @deftypefn Extension {const char *} simple_object_attributes_compare @
  72. (simple_object_attributes *@var{attrs1}, simple_object_attributes *@var{attrs2}, @
  73. int *@var{err})
  74. Compare @var{attrs1} and @var{attrs2}. If they could be linked
  75. together without error, return @code{NULL}. Otherwise, return an
  76. error message and set @code{*@var{err}} to an errno value or @code{0}
  77. if there is no relevant errno.
  78. @end deftypefn
  79. @deftypefn Extension {void} simple_object_release_attributes @
  80. (simple_object_attributes *@var{attrs})
  81. Release all resources associated with @var{attrs}.
  82. @end deftypefn
  83. @deftypefn Extension {simple_object_write *} simple_object_start_write @
  84. (simple_object_attributes @var{attrs}, const char *@var{segment_name}, @
  85. const char **@var{errmsg}, int *@var{err})
  86. Start creating a new object file using the object file format
  87. described in @var{attrs}. You must fetch attribute information from
  88. an existing object file before you can create a new one. There is
  89. currently no support for creating an object file de novo.
  90. @var{segment_name} is only used with Mach-O as found on Darwin aka Mac
  91. OS X. The parameter is required on that target. It means that all
  92. sections are created within the named segment. It is ignored for
  93. other object file formats.
  94. On error @code{simple_object_start_write} returns @code{NULL}, sets
  95. @code{*@var{ERRMSG}} to an error message, and sets @code{*@var{err}}
  96. to an errno value or @code{0} if there is no relevant errno.
  97. @end deftypefn
  98. @deftypefn Extension {simple_object_write_section *} simple_object_write_create_section @
  99. (simple_object_write *@var{simple_object}, const char *@var{name}, @
  100. unsigned int @var{align}, const char **@var{errmsg}, int *@var{err})
  101. Add a section to @var{simple_object}. @var{name} is the name of the
  102. new section. @var{align} is the required alignment expressed as the
  103. number of required low-order 0 bits (e.g., 2 for alignment to a 32-bit
  104. boundary).
  105. The section is created as containing data, readable, not writable, not
  106. executable, not loaded at runtime. The section is not written to the
  107. file until @code{simple_object_write_to_file} is called.
  108. On error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
  109. error message, and sets @code{*@var{err}} to an errno value or
  110. @code{0} if there is no relevant errno.
  111. @end deftypefn
  112. @deftypefn Extension {const char *} simple_object_write_add_data @
  113. (simple_object_write *@var{simple_object}, @
  114. simple_object_write_section *@var{section}, const void *@var{buffer}, @
  115. size_t @var{size}, int @var{copy}, int *@var{err})
  116. Add data @var{buffer}/@var{size} to @var{section} in
  117. @var{simple_object}. If @var{copy} is non-zero, the data will be
  118. copied into memory if necessary. If @var{copy} is zero, @var{buffer}
  119. must persist until @code{simple_object_write_to_file} is called. is
  120. released.
  121. On success this returns @code{NULL}. On error this returns an error
  122. message, and sets @code{*@var{err}} to an errno value or 0 if there is
  123. no relevant erro.
  124. @end deftypefn
  125. @deftypefn Extension {const char *} simple_object_write_to_file @
  126. (simple_object_write *@var{simple_object}, int @var{descriptor}, int *@var{err})
  127. Write the complete object file to @var{descriptor}, an open file
  128. descriptor. This writes out all the data accumulated by calls to
  129. @code{simple_object_write_create_section} and
  130. @var{simple_object_write_add_data}.
  131. This returns @code{NULL} on success. On error this returns an error
  132. message and sets @code{*@var{err}} to an errno value or @code{0} if
  133. there is no relevant errno.
  134. @end deftypefn
  135. @deftypefn Extension {void} simple_object_release_write @
  136. (simple_object_write *@var{simple_object})
  137. Release all resources associated with @var{simple_object}.
  138. @end deftypefn