modlib.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /****************************************************************************
  2. * libs/libc/modlib/modlib.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __LIBC_MODLIB_MODLIB_H
  21. #define __LIBC_MODLIB_MODLIB_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <sys/types.h>
  27. #include <nuttx/arch.h>
  28. #include <nuttx/lib/modlib.h>
  29. /****************************************************************************
  30. * Public Function Prototypes
  31. ****************************************************************************/
  32. /****************************************************************************
  33. * Name: modlib_verifyheader
  34. *
  35. * Description:
  36. * Given the header from a possible ELF executable, verify that it is
  37. * an ELF executable.
  38. *
  39. * Returned Value:
  40. * 0 (OK) is returned on success and a negated errno is returned on
  41. * failure.
  42. *
  43. ****************************************************************************/
  44. int modlib_verifyheader(FAR const Elf_Ehdr *header);
  45. /****************************************************************************
  46. * Name: modlib_findsymtab
  47. *
  48. * Description:
  49. * Find the symbol table section.
  50. *
  51. * Returned Value:
  52. * 0 (OK) is returned on success and a negated errno is returned on
  53. * failure.
  54. *
  55. ****************************************************************************/
  56. int modlib_findsymtab(FAR struct mod_loadinfo_s *loadinfo);
  57. /****************************************************************************
  58. * Name: modlib_readsym
  59. *
  60. * Description:
  61. * Read the ELF symbol structure at the specified index into memory.
  62. *
  63. * Input Parameters:
  64. * loadinfo - Load state information
  65. * index - Symbol table index
  66. * sym - Location to return the table entry
  67. *
  68. * Returned Value:
  69. * 0 (OK) is returned on success and a negated errno is returned on
  70. * failure.
  71. *
  72. ****************************************************************************/
  73. int modlib_readsym(FAR struct mod_loadinfo_s *loadinfo, int index,
  74. FAR Elf_Sym *sym);
  75. /****************************************************************************
  76. * Name: modlib_symvalue
  77. *
  78. * Description:
  79. * Get the value of a symbol. The updated value of the symbol is returned
  80. * in the st_value field of the symbol table entry.
  81. *
  82. * Input Parameters:
  83. * modp - Module state information
  84. * loadinfo - Load state information
  85. * sym - Symbol table entry (value might be undefined)
  86. *
  87. * Returned Value:
  88. * 0 (OK) is returned on success and a negated errno is returned on
  89. * failure.
  90. *
  91. * EINVAL - There is something inconsistent in the symbol table (should
  92. * only happen if the file is corrupted)
  93. * ENOSYS - Symbol lies in common
  94. * ESRCH - Symbol has no name
  95. * ENOENT - Symbol undefined and not provided via a symbol table
  96. *
  97. ****************************************************************************/
  98. int modlib_symvalue(FAR struct module_s *modp,
  99. FAR struct mod_loadinfo_s *loadinfo, FAR Elf_Sym *sym);
  100. /****************************************************************************
  101. * Name: modlib_loadshdrs
  102. *
  103. * Description:
  104. * Loads section headers into memory.
  105. *
  106. * Returned Value:
  107. * 0 (OK) is returned on success and a negated errno is returned on
  108. * failure.
  109. *
  110. ****************************************************************************/
  111. int modlib_loadshdrs(FAR struct mod_loadinfo_s *loadinfo);
  112. /****************************************************************************
  113. * Name: modlib_findsection
  114. *
  115. * Description:
  116. * A section by its name.
  117. *
  118. * Input Parameters:
  119. * loadinfo - Load state information
  120. * sectname - Name of the section to find
  121. *
  122. * Returned Value:
  123. * On success, the index to the section is returned; A negated errno value
  124. * is returned on failure.
  125. *
  126. ****************************************************************************/
  127. int modlib_findsection(FAR struct mod_loadinfo_s *loadinfo,
  128. FAR const char *sectname);
  129. /****************************************************************************
  130. * Name: modlib_allocbuffer
  131. *
  132. * Description:
  133. * Perform the initial allocation of the I/O buffer, if it has not already
  134. * been allocated.
  135. *
  136. * Returned Value:
  137. * 0 (OK) is returned on success and a negated errno is returned on
  138. * failure.
  139. *
  140. ****************************************************************************/
  141. int modlib_allocbuffer(FAR struct mod_loadinfo_s *loadinfo);
  142. /****************************************************************************
  143. * Name: modlib_reallocbuffer
  144. *
  145. * Description:
  146. * Increase the size of I/O buffer by the specified buffer increment.
  147. *
  148. * Returned Value:
  149. * 0 (OK) is returned on success and a negated errno is returned on
  150. * failure.
  151. *
  152. ****************************************************************************/
  153. int modlib_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo,
  154. size_t increment);
  155. /****************************************************************************
  156. * Name: modlib_freebuffers
  157. *
  158. * Description:
  159. * Release all working buffers.
  160. *
  161. * Returned Value:
  162. * 0 (OK) is returned on success and a negated errno is returned on
  163. * failure.
  164. *
  165. ****************************************************************************/
  166. int modlib_freebuffers(FAR struct mod_loadinfo_s *loadinfo);
  167. #endif /* __LIBC_MODLIB_MODLIB_H */