binfmt_execsymtab.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /****************************************************************************
  2. * binfmt/binfmt_execsymtab.c
  3. *
  4. * Copyright (C) 2013, 2016, 2018 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. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <nuttx/config.h>
  39. #include <assert.h>
  40. #include <nuttx/irq.h>
  41. #include <nuttx/arch.h>
  42. #include <nuttx/binfmt/symtab.h>
  43. #ifdef CONFIG_LIBC_EXECFUNCS
  44. /****************************************************************************
  45. * Pre-processor Definitions
  46. ****************************************************************************/
  47. /* If CONFIG_LIBC_EXECFUNCS is defined in the configuration, then the
  48. * following must also be defined:
  49. */
  50. #ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
  51. /* Symbol table used by exec[l|v] */
  52. # ifndef CONFIG_EXECFUNCS_SYMTAB_ARRAY
  53. # error "CONFIG_EXECFUNCS_SYMTAB_ARRAY must be defined"
  54. # endif
  55. /* Number of Symbols in the Table */
  56. # ifndef CONFIG_EXECFUNCS_NSYMBOLS_VAR
  57. # error "CONFIG_EXECFUNCS_NSYMBOLS_VAR must be defined"
  58. # endif
  59. #endif
  60. /****************************************************************************
  61. * Public Data
  62. ****************************************************************************/
  63. #ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
  64. extern const struct symtab_s CONFIG_EXECFUNCS_SYMTAB_ARRAY[];
  65. extern int CONFIG_EXECFUNCS_NSYMBOLS_VAR;
  66. #endif
  67. /****************************************************************************
  68. * Private Data
  69. ****************************************************************************/
  70. static FAR const struct symtab_s *g_exec_symtab;
  71. static int g_exec_nsymbols;
  72. /****************************************************************************
  73. * Public Functions
  74. ****************************************************************************/
  75. /****************************************************************************
  76. * Name: exec_getsymtab
  77. *
  78. * Description:
  79. * Get the current symbol table selection as an atomic operation.
  80. *
  81. * Input Parameters:
  82. * symtab - The location to store the symbol table.
  83. * nsymbols - The location to store the number of symbols in the symbol table.
  84. *
  85. * Returned Value:
  86. * None
  87. *
  88. ****************************************************************************/
  89. void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
  90. {
  91. irqstate_t flags;
  92. DEBUGASSERT(symtab != NULL && nsymbols != NULL);
  93. /* Disable interrupts very briefly so that both the symbol table and its
  94. * size are returned as a single atomic operation.
  95. */
  96. flags = enter_critical_section();
  97. #ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
  98. /* If a bring-up symbol table has been provided and if the exec symbol
  99. * table has not yet been initialized, then use the provided start-up
  100. * symbol table.
  101. */
  102. if (g_exec_symtab == NULL)
  103. {
  104. g_exec_symtab = CONFIG_EXECFUNCS_SYMTAB_ARRAY;
  105. g_exec_nsymbols = CONFIG_EXECFUNCS_NSYMBOLS_VAR;
  106. }
  107. #endif
  108. /* Return the symbol table and its size */
  109. *symtab = g_exec_symtab;
  110. *nsymbols = g_exec_nsymbols;
  111. leave_critical_section(flags);
  112. }
  113. /****************************************************************************
  114. * Name: exec_setsymtab
  115. *
  116. * Description:
  117. * Select a new symbol table selection as an atomic operation.
  118. *
  119. * Input Parameters:
  120. * symtab - The new symbol table.
  121. * nsymbols - The number of symbols in the symbol table.
  122. *
  123. * Returned Value:
  124. * None
  125. *
  126. ****************************************************************************/
  127. void exec_setsymtab(FAR const struct symtab_s *symtab, int nsymbols)
  128. {
  129. irqstate_t flags;
  130. DEBUGASSERT(symtab != NULL);
  131. /* Disable interrupts very briefly so that both the symbol table and its
  132. * size are set as a single atomic operation.
  133. */
  134. flags = enter_critical_section();
  135. g_exec_symtab = symtab;
  136. g_exec_nsymbols = nsymbols;
  137. leave_critical_section(flags);
  138. }
  139. #endif /* CONFIG_LIBC_EXECFUNCS */