symbol.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2018 Agustina Arzille.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef KERN_SYMBOL_H
  18. #define KERN_SYMBOL_H
  19. #include <stdbool.h>
  20. #include <stdint.h>
  21. #include <kern/macros.h>
  22. #define __symbol_table __section (".symbol")
  23. /*
  24. * Symbol structure.
  25. *
  26. * This structure is public.
  27. */
  28. struct symbol
  29. {
  30. uintptr_t addr;
  31. uintptr_t size;
  32. const char *name;
  33. };
  34. // Symbol table iterator.
  35. struct symbol_iter
  36. {
  37. size_t idx;
  38. const struct symbol *symbol;
  39. };
  40. /*
  41. * Look up a symbol from an address.
  42. *
  43. * NULL is returned if no symbol was found for the given address.
  44. */
  45. const struct symbol* symbol_lookup (uintptr_t addr);
  46. // Initialize a symbol table iterator.
  47. void symbol_iter_init (struct symbol_iter *iter);
  48. // Move the symbol table iterator. Returns true if there are still entries.
  49. bool symbol_iter_next (struct symbol_iter *iter);
  50. // Test if an iterator is valid.
  51. static inline bool
  52. symbol_iter_valid (const struct symbol_iter *iter)
  53. {
  54. return (iter->symbol != NULL);
  55. }
  56. #endif