|
4 | 4 | /* References to section boundaries */
|
5 | 5 |
|
6 | 6 | #include <linux/compiler.h>
|
| 7 | +#include <linux/types.h> |
7 | 8 |
|
8 | 9 | /*
|
9 | 10 | * Usage guidelines:
|
@@ -63,4 +64,68 @@ static inline int arch_is_kernel_data(unsigned long addr)
|
63 | 64 | }
|
64 | 65 | #endif
|
65 | 66 |
|
| 67 | +/** |
| 68 | + * memory_contains - checks if an object is contained within a memory region |
| 69 | + * @begin: virtual address of the beginning of the memory region |
| 70 | + * @end: virtual address of the end of the memory region |
| 71 | + * @virt: virtual address of the memory object |
| 72 | + * @size: size of the memory object |
| 73 | + * |
| 74 | + * Returns: true if the object specified by @virt and @size is entirely |
| 75 | + * contained within the memory region defined by @begin and @end, false |
| 76 | + * otherwise. |
| 77 | + */ |
| 78 | +static inline bool memory_contains(void *begin, void *end, void *virt, |
| 79 | + size_t size) |
| 80 | +{ |
| 81 | + return virt >= begin && virt + size <= end; |
| 82 | +} |
| 83 | + |
| 84 | +/** |
| 85 | + * memory_intersects - checks if the region occupied by an object intersects |
| 86 | + * with another memory region |
| 87 | + * @begin: virtual address of the beginning of the memory regien |
| 88 | + * @end: virtual address of the end of the memory region |
| 89 | + * @virt: virtual address of the memory object |
| 90 | + * @size: size of the memory object |
| 91 | + * |
| 92 | + * Returns: true if an object's memory region, specified by @virt and @size, |
| 93 | + * intersects with the region specified by @begin and @end, false otherwise. |
| 94 | + */ |
| 95 | +static inline bool memory_intersects(void *begin, void *end, void *virt, |
| 96 | + size_t size) |
| 97 | +{ |
| 98 | + void *vend = virt + size; |
| 99 | + |
| 100 | + return (virt >= begin && virt < end) || (vend >= begin && vend < end); |
| 101 | +} |
| 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 | +/** |
| 118 | + * init_section_intersects - checks if the region occupied by an object |
| 119 | + * intersects with the init section |
| 120 | + * @virt: virtual address of the memory object |
| 121 | + * @size: size of the memory object |
| 122 | + * |
| 123 | + * Returns: true if an object's memory region, specified by @virt and @size, |
| 124 | + * intersects with the init section, false otherwise. |
| 125 | + */ |
| 126 | +static inline bool init_section_intersects(void *virt, size_t size) |
| 127 | +{ |
| 128 | + return memory_intersects(__init_begin, __init_end, virt, size); |
| 129 | +} |
| 130 | + |
66 | 131 | #endif /* _ASM_GENERIC_SECTIONS_H_ */
|
0 commit comments