Skip to content

Commit 9795593

Browse files
thierryredingtorvalds
authored andcommitted
asm/sections: add helpers to check for section data
Add a helper to check if an object (given an address and a size) is part of a section (given beginning and end addresses). For convenience, also provide a helper that performs this check for __init data using the __init_begin and __init_end limits. Signed-off-by: Thierry Reding <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Joe Perches <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b493c34 commit 9795593

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

include/asm-generic/sections.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/* References to section boundaries */
55

66
#include <linux/compiler.h>
7+
#include <linux/types.h>
78

89
/*
910
* Usage guidelines:
@@ -63,4 +64,68 @@ static inline int arch_is_kernel_data(unsigned long addr)
6364
}
6465
#endif
6566

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+
66131
#endif /* _ASM_GENERIC_SECTIONS_H_ */

0 commit comments

Comments
 (0)