sections.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef _ASM_GENERIC_SECTIONS_H_
  2. #define _ASM_GENERIC_SECTIONS_H_
  3. /* References to section boundaries */
  4. #include <linux/compiler.h>
  5. #include <linux/types.h>
  6. /*
  7. * Usage guidelines:
  8. * _text, _data: architecture specific, don't use them in arch-independent code
  9. * [_stext, _etext]: contains .text.* sections, may also contain .rodata.*
  10. * and/or .init.* sections
  11. * [_sdata, _edata]: contains .data.* sections, may also contain .rodata.*
  12. * and/or .init.* sections.
  13. * [__start_rodata, __end_rodata]: contains .rodata.* sections
  14. * [__start_data_ro_after_init, __end_data_ro_after_init]:
  15. * contains data.ro_after_init section
  16. * [__init_begin, __init_end]: contains .init.* sections, but .init.text.*
  17. * may be out of this range on some architectures.
  18. * [_sinittext, _einittext]: contains .init.text.* sections
  19. * [__bss_start, __bss_stop]: contains BSS sections
  20. *
  21. * Following global variables are optional and may be unavailable on some
  22. * architectures and/or kernel configurations.
  23. * _text, _data
  24. * __kprobes_text_start, __kprobes_text_end
  25. * __entry_text_start, __entry_text_end
  26. * __ctors_start, __ctors_end
  27. */
  28. extern char _text[], _stext[], _etext[];
  29. extern char _data[], _sdata[], _edata[];
  30. extern char __bss_start[], __bss_stop[];
  31. extern char __init_begin[], __init_end[];
  32. extern char _sinittext[], _einittext[];
  33. extern char __start_data_ro_after_init[], __end_data_ro_after_init[];
  34. extern char _end[];
  35. extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[];
  36. extern char __kprobes_text_start[], __kprobes_text_end[];
  37. extern char __entry_text_start[], __entry_text_end[];
  38. extern char __start_rodata[], __end_rodata[];
  39. /* Start and end of .ctors section - used for constructor calls. */
  40. extern char __ctors_start[], __ctors_end[];
  41. extern __visible const void __nosave_begin, __nosave_end;
  42. /* function descriptor handling (if any). Override
  43. * in asm/sections.h */
  44. #ifndef dereference_function_descriptor
  45. #define dereference_function_descriptor(p) (p)
  46. #endif
  47. /* random extra sections (if any). Override
  48. * in asm/sections.h */
  49. #ifndef arch_is_kernel_text
  50. static inline int arch_is_kernel_text(unsigned long addr)
  51. {
  52. return 0;
  53. }
  54. #endif
  55. #ifndef arch_is_kernel_data
  56. static inline int arch_is_kernel_data(unsigned long addr)
  57. {
  58. return 0;
  59. }
  60. #endif
  61. /**
  62. * memory_contains - checks if an object is contained within a memory region
  63. * @begin: virtual address of the beginning of the memory region
  64. * @end: virtual address of the end of the memory region
  65. * @virt: virtual address of the memory object
  66. * @size: size of the memory object
  67. *
  68. * Returns: true if the object specified by @virt and @size is entirely
  69. * contained within the memory region defined by @begin and @end, false
  70. * otherwise.
  71. */
  72. static inline bool memory_contains(void *begin, void *end, void *virt,
  73. size_t size)
  74. {
  75. return virt >= begin && virt + size <= end;
  76. }
  77. /**
  78. * memory_intersects - checks if the region occupied by an object intersects
  79. * with another memory region
  80. * @begin: virtual address of the beginning of the memory regien
  81. * @end: virtual address of the end of the memory region
  82. * @virt: virtual address of the memory object
  83. * @size: size of the memory object
  84. *
  85. * Returns: true if an object's memory region, specified by @virt and @size,
  86. * intersects with the region specified by @begin and @end, false otherwise.
  87. */
  88. static inline bool memory_intersects(void *begin, void *end, void *virt,
  89. size_t size)
  90. {
  91. void *vend = virt + size;
  92. return (virt >= begin && virt < end) || (vend >= begin && vend < end);
  93. }
  94. /**
  95. * init_section_contains - checks if an object is contained within the init
  96. * section
  97. * @virt: virtual address of the memory object
  98. * @size: size of the memory object
  99. *
  100. * Returns: true if the object specified by @virt and @size is entirely
  101. * contained within the init section, false otherwise.
  102. */
  103. static inline bool init_section_contains(void *virt, size_t size)
  104. {
  105. return memory_contains(__init_begin, __init_end, virt, size);
  106. }
  107. /**
  108. * init_section_intersects - checks if the region occupied by an object
  109. * intersects with the init section
  110. * @virt: virtual address of the memory object
  111. * @size: size of the memory object
  112. *
  113. * Returns: true if an object's memory region, specified by @virt and @size,
  114. * intersects with the init section, false otherwise.
  115. */
  116. static inline bool init_section_intersects(void *virt, size_t size)
  117. {
  118. return memory_intersects(__init_begin, __init_end, virt, size);
  119. }
  120. #endif /* _ASM_GENERIC_SECTIONS_H_ */