sections.h 5.0 KB

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