module.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /****************************************************************************
  2. * include/nuttx/module.h
  3. *
  4. * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __INCLUDE_NUTTX_MODULE_H
  36. #define __INCLUDE_NUTTX_MODULE_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <sys/types.h>
  42. /****************************************************************************
  43. * Public Function Prototypes
  44. ****************************************************************************/
  45. #undef EXTERN
  46. #if defined(__cplusplus)
  47. #define EXTERN extern "C"
  48. extern "C"
  49. {
  50. #else
  51. #define EXTERN extern
  52. #endif
  53. /****************************************************************************
  54. * Name: insmod
  55. *
  56. * Description:
  57. * Verify that the file is an ELF module binary and, if so, load the
  58. * module into kernel memory and initialize it for use.
  59. *
  60. * NOTE: modlib_setsymtab had to have been called in board-specific OS logic
  61. * prior to calling this function from application logic (perhaps via
  62. * boardctl(BOARDIOC_OS_SYMTAB). Otherwise, insmod will be unable to
  63. * resolve symbols in the OS module.
  64. *
  65. * Input Parameters:
  66. *
  67. * filename - Full path to the module binary to be loaded
  68. * modname - The name that can be used to refer to the module after
  69. * it has been loaded.
  70. *
  71. * Returned Value:
  72. * A non-NULL module handle that can be used on subsequent calls to other
  73. * module interfaces is returned on success. If insmod() was unable to
  74. * load the module insmod() will return a NULL handle and the errno
  75. * variable will be set appropriately.
  76. *
  77. ****************************************************************************/
  78. FAR void *insmod(FAR const char *filename, FAR const char *modname);
  79. /****************************************************************************
  80. * Name: rmmod
  81. *
  82. * Description:
  83. * Remove a previously installed module from memory.
  84. *
  85. * Input Parameters:
  86. * handle - The module handler previously returned by insmod().
  87. *
  88. * Returned Value:
  89. * Zero (OK) on success. On any failure, -1 (ERROR) is returned the
  90. * errno value is set appropriately.
  91. *
  92. ****************************************************************************/
  93. int rmmod(FAR void *handle);
  94. /****************************************************************************
  95. * Name: modsym
  96. *
  97. * Description:
  98. * modsym() returns the address of a symbol defined within the object that
  99. * was previously made accessible through a insmod() call. handle is the
  100. * value returned from a call to insmod() (and which has not since been
  101. * released via a call to rmmod()), name is the symbol's name as a
  102. * character string.
  103. *
  104. * The returned symbol address will remain valid until rmmod() is called.
  105. *
  106. * Input Parameters:
  107. * handle - The opaque, non-NULL value returned by a previous successful
  108. * call to insmod().
  109. * name - A pointer to the symbol name string.
  110. *
  111. * Returned Value:
  112. * The address associated with the symbol is returned on success.
  113. * If handle does not refer to a valid module opened by insmod(), or if
  114. * the named symbol cannot be found within any of the objects associated
  115. * with handle, modsym() will return NULL and the errno variable will be
  116. * set appropriately.
  117. *
  118. ****************************************************************************/
  119. FAR const void *modsym(FAR void *handle, FAR const char *name);
  120. /****************************************************************************
  121. * Name: modhandle
  122. *
  123. * Description:
  124. * modhandle() returns the module handle for the installed module with the
  125. * provided name. A secondary use of this function is to determine if a
  126. * module has been loaded or not.
  127. *
  128. * Input Parameters:
  129. * name - A pointer to the module name string.
  130. *
  131. * Returned Value:
  132. * The non-NULL module handle previously returned by insmod() is returned
  133. * on success. If no module with that name is installed, modhandle() will
  134. * return a NULL handle and the errno variable will be set appropriately.
  135. *
  136. ****************************************************************************/
  137. FAR void *modhandle(FAR const char *name);
  138. #undef EXTERN
  139. #if defined(__cplusplus)
  140. }
  141. #endif
  142. #endif /* __INCLUDE_NUTTX_MODULE_H */