sections.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * __irqentry_text_start, __irqentry_text_end
  28. * __softirqentry_text_start, __softirqentry_text_end
  29. */
  30. extern char _text[], _stext[], _etext[];
  31. extern char _data[], _sdata[], _edata[];
  32. extern char __bss_start[], __bss_stop[];
  33. extern char __init_begin[], __init_end[];
  34. extern char _sinittext[], _einittext[];
  35. extern char __start_data_ro_after_init[], __end_data_ro_after_init[];
  36. extern char _end[];
  37. extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[];
  38. extern char __kprobes_text_start[], __kprobes_text_end[];
  39. extern char __entry_text_start[], __entry_text_end[];
  40. extern char __start_rodata[], __end_rodata[];
  41. extern char __irqentry_text_start[], __irqentry_text_end[];
  42. extern char __softirqentry_text_start[], __softirqentry_text_end[];
  43. /* Start and end of .ctors section - used for constructor calls. */
  44. extern char __ctors_start[], __ctors_end[];
  45. extern __visible const void __nosave_begin, __nosave_end;
  46. /* function descriptor handling (if any). Override
  47. * in asm/sections.h */
  48. #ifndef dereference_function_descriptor
  49. #define dereference_function_descriptor(p) (p)
  50. #endif
  51. /* random extra sections (if any). Override
  52. * in asm/sections.h */
  53. #ifndef arch_is_kernel_text
  54. static inline int arch_is_kernel_text(unsigned long addr)
  55. {
  56. return 0;
  57. }
  58. #endif
  59. #ifndef arch_is_kernel_data
  60. static inline int arch_is_kernel_data(unsigned long addr)
  61. {
  62. return 0;
  63. }
  64. #endif
  65. /**
  66. * memory_contains - checks if an object is contained within a memory region
  67. * @begin: virtual address of the beginning of the memory region
  68. * @end: virtual address of the end of the memory region
  69. * @virt: virtual address of the memory object
  70. * @size: size of the memory object
  71. *
  72. * Returns: true if the object specified by @virt and @size is entirely
  73. * contained within the memory region defined by @begin and @end, false
  74. * otherwise.
  75. */
  76. static inline bool memory_contains(void *begin, void *end, void *virt,
  77. size_t size)
  78. {
  79. return virt >= begin && virt + size <= end;
  80. }
  81. /**
  82. * memory_intersects - checks if the region occupied by an object intersects
  83. * with another memory region
  84. * @begin: virtual address of the beginning of the memory regien
  85. * @end: virtual address of the end of the memory region
  86. * @virt: virtual address of the memory object
  87. * @size: size of the memory object
  88. *
  89. * Returns: true if an object's memory region, specified by @virt and @size,
  90. * intersects with the region specified by @begin and @end, false otherwise.
  91. */
  92. static inline bool memory_intersects(void *begin, void *end, void *virt,
  93. size_t size)
  94. {
  95. void *vend = virt + size;
  96. return (virt >= begin && virt < end) || (vend >= begin && vend < end);
  97. }
  98. /**
  99. * init_section_contains - checks if an object is contained within the init
  100. * section
  101. * @virt: virtual address of the memory object
  102. * @size: size of the memory object
  103. *
  104. * Returns: true if the object specified by @virt and @size is entirely
  105. * contained within the init section, false otherwise.
  106. */
  107. static inline bool init_section_contains(void *virt, size_t size)
  108. {
  109. return memory_contains(__init_begin, __init_end, virt, size);
  110. }
  111. /**
  112. * init_section_intersects - checks if the region occupied by an object
  113. * intersects with the init section
  114. * @virt: virtual address of the memory object
  115. * @size: size of the memory object
  116. *
  117. * Returns: true if an object's memory region, specified by @virt and @size,
  118. * intersects with the init section, false otherwise.
  119. */
  120. static inline bool init_section_intersects(void *virt, size_t size)
  121. {
  122. return memory_intersects(__init_begin, __init_end, virt, size);
  123. }
  124. #endif /* _ASM_GENERIC_SECTIONS_H_ */