extable.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Rewritten by Rusty Russell, on the backs of many others...
  2. Copyright (C) 2001 Rusty Russell, 2002 Rusty Russell IBM.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/ftrace.h>
  18. #include <asm/uaccess.h>
  19. #include <asm/sections.h>
  20. extern struct exception_table_entry __start___ex_table[];
  21. extern struct exception_table_entry __stop___ex_table[];
  22. /* Sort the kernel's built-in exception table */
  23. void __init sort_main_extable(void)
  24. {
  25. sort_extable(__start___ex_table, __stop___ex_table);
  26. }
  27. /* Given an address, look for it in the exception tables. */
  28. const struct exception_table_entry *search_exception_tables(unsigned long addr)
  29. {
  30. const struct exception_table_entry *e;
  31. e = search_extable(__start___ex_table, __stop___ex_table-1, addr);
  32. if (!e)
  33. e = search_module_extables(addr);
  34. return e;
  35. }
  36. static inline int init_kernel_text(unsigned long addr)
  37. {
  38. if (addr >= (unsigned long)_sinittext &&
  39. addr <= (unsigned long)_einittext)
  40. return 1;
  41. return 0;
  42. }
  43. __notrace_funcgraph int core_kernel_text(unsigned long addr)
  44. {
  45. if (addr >= (unsigned long)_stext &&
  46. addr <= (unsigned long)_etext)
  47. return 1;
  48. if (system_state == SYSTEM_BOOTING &&
  49. init_kernel_text(addr))
  50. return 1;
  51. return 0;
  52. }
  53. __notrace_funcgraph int __kernel_text_address(unsigned long addr)
  54. {
  55. if (core_kernel_text(addr))
  56. return 1;
  57. if (__module_text_address(addr))
  58. return 1;
  59. /*
  60. * There might be init symbols in saved stacktraces.
  61. * Give those symbols a chance to be printed in
  62. * backtraces (such as lockdep traces).
  63. *
  64. * Since we are after the module-symbols check, there's
  65. * no danger of address overlap:
  66. */
  67. if (init_kernel_text(addr))
  68. return 1;
  69. return 0;
  70. }
  71. int kernel_text_address(unsigned long addr)
  72. {
  73. if (core_kernel_text(addr))
  74. return 1;
  75. return module_text_address(addr) != NULL;
  76. }
  77. /*
  78. * On some architectures (PPC64, IA64) function pointers
  79. * are actually only tokens to some data that then holds the
  80. * real function address. As a result, to find if a function
  81. * pointer is part of the kernel text, we need to do some
  82. * special dereferencing first.
  83. */
  84. int func_ptr_is_kernel_text(void *ptr)
  85. {
  86. unsigned long addr;
  87. addr = (unsigned long) dereference_function_descriptor(ptr);
  88. if (core_kernel_text(addr))
  89. return 1;
  90. return module_text_address(addr) != NULL;
  91. }