modlib_symtab.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /****************************************************************************
  2. * libs/libc/modlib/modlib_symtab.c
  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. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <assert.h>
  25. #include <nuttx/symtab.h>
  26. #include <nuttx/lib/modlib.h>
  27. /****************************************************************************
  28. * Pre-processor Definitions
  29. ****************************************************************************/
  30. #ifdef CONFIG_MODLIB_HAVE_SYMTAB
  31. /* Symbol table used by dlsym */
  32. # ifndef CONFIG_MODLIB_SYMTAB_ARRAY
  33. # error "CONFIG_MODLIB_SYMTAB_ARRAY must be defined"
  34. # endif
  35. /* Number of Symbols in the Table */
  36. # ifndef CONFIG_MODLIB_NSYMBOLS_VAR
  37. # error "CONFIG_MODLIB_NSYMBOLS_VAR must be defined"
  38. # endif
  39. #endif
  40. /****************************************************************************
  41. * Public Data
  42. ****************************************************************************/
  43. #ifdef CONFIG_MODLIB_HAVE_SYMTAB
  44. extern const struct symtab_s CONFIG_MODLIB_SYMTAB_ARRAY[];
  45. extern int CONFIG_MODLIB_NSYMBOLS_VAR;
  46. #endif
  47. /****************************************************************************
  48. * Private Data
  49. ****************************************************************************/
  50. static FAR const struct symtab_s *g_modlib_symtab;
  51. static FAR int g_modlib_nsymbols;
  52. /****************************************************************************
  53. * Public Functions
  54. ****************************************************************************/
  55. /****************************************************************************
  56. * Name: modlib_getsymtab
  57. *
  58. * Description:
  59. * Get the current kernel symbol table selection as an atomic operation.
  60. *
  61. * Input Parameters:
  62. * symtab - The location to store the symbol table.
  63. * nsymbols - The location to store the number of symbols in the symbol
  64. * table.
  65. *
  66. * Returned Value:
  67. * None
  68. *
  69. ****************************************************************************/
  70. void modlib_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
  71. {
  72. DEBUGASSERT(symtab != NULL && nsymbols != NULL);
  73. /* Borrow the registry lock to assure atomic access */
  74. modlib_registry_lock();
  75. #ifdef CONFIG_MODLIB_HAVE_SYMTAB
  76. if (g_modlib_symtab == NULL)
  77. {
  78. g_modlib_symtab = CONFIG_MODLIB_SYMTAB_ARRAY;
  79. g_modlib_nsymbols = CONFIG_MODLIB_NSYMBOLS_VAR;
  80. }
  81. #endif
  82. *symtab = g_modlib_symtab;
  83. *nsymbols = g_modlib_nsymbols;
  84. modlib_registry_unlock();
  85. }
  86. /****************************************************************************
  87. * Name: modlib_setsymtab
  88. *
  89. * Description:
  90. * Select a new kernel symbol table selection as an atomic operation.
  91. *
  92. * Input Parameters:
  93. * symtab - The new symbol table.
  94. * nsymbols - The number of symbols in the symbol table.
  95. *
  96. * Returned Value:
  97. * None
  98. *
  99. ****************************************************************************/
  100. void modlib_setsymtab(FAR const struct symtab_s *symtab, int nsymbols)
  101. {
  102. /* Borrow the registry lock to assure atomic access */
  103. modlib_registry_lock();
  104. g_modlib_symtab = symtab;
  105. g_modlib_nsymbols = nsymbols;
  106. modlib_registry_unlock();
  107. }