lib/tests/randstruct_kunit.c
Source file repositories/reference/linux-study-clean/lib/tests/randstruct_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/tests/randstruct_kunit.c- Extension
.c- Size
- 9157 bytes
- Lines
- 335
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/init.hlinux/kernel.hlinux/module.hlinux/string.h
Detected Declarations
struct randstruct_untouchedstruct randstruct_shuffledstruct randstruct_funcs_untouchedstruct randstruct_funcs_shuffledstruct randstruct_mixed_untouchedstruct randstruct_mixed_shuffledstruct contains_randstruct_untouchedstruct contains_randstruct_shuffledstruct contains_func_untouchedstruct contains_func_shuffledenum randstruct_member_namesfunction randstruct_layout_samefunction check_pairfunction check_pairfunction check_pairfunction test_check_initfunction test_check_contained_initfunction test_check_funcs_initfunction randstruct_test_init
Annotated Snippet
struct randstruct_untouched {
DO_MANY_MEMBERS(unsigned_long_member)
};
/* Struct explicitly marked with __randomize_layout. */
struct randstruct_shuffled {
DO_MANY_MEMBERS(unsigned_long_member)
} __randomize_layout;
#undef unsigned_long_member
/* Struct implicitly randomized from being all func ptrs. */
#define func_member(x, ignored) size_t (*x)(int);
struct randstruct_funcs_untouched {
DO_MANY_MEMBERS(func_member)
} __no_randomize_layout;
struct randstruct_funcs_shuffled {
DO_MANY_MEMBERS(func_member)
};
#define func_body(x, ignored) \
static noinline size_t func_##x(int arg) \
{ \
return offsetof(struct randstruct_funcs_untouched, x); \
}
DO_MANY_MEMBERS(func_body)
/* Various mixed types. */
#define mixed_members \
bool a; \
short b; \
unsigned int c __aligned(16); \
size_t d; \
char e; \
u64 f; \
union { \
struct randstruct_shuffled shuffled; \
uintptr_t g; \
}; \
union { \
void *ptr; \
char h; \
};
struct randstruct_mixed_untouched {
mixed_members
};
struct randstruct_mixed_shuffled {
mixed_members
} __randomize_layout;
#undef mixed_members
struct contains_randstruct_untouched {
int before;
struct randstruct_untouched untouched;
int after;
};
struct contains_randstruct_shuffled {
int before;
struct randstruct_shuffled shuffled;
int after;
};
struct contains_func_untouched {
struct randstruct_funcs_shuffled inner;
DO_MANY_MEMBERS(func_member)
} __no_randomize_layout;
struct contains_func_shuffled {
struct randstruct_funcs_shuffled inner;
DO_MANY_MEMBERS(func_member)
};
#undef func_member
#define check_mismatch(x, untouched, shuffled) \
if (offsetof(untouched, x) != offsetof(shuffled, x)) \
mismatches++; \
kunit_info(test, #shuffled "::" #x " @ %zu (vs %zu)\n", \
offsetof(shuffled, x), \
offsetof(untouched, x)); \
#define check_pair(outcome, untouched, shuffled, checker...) \
mismatches = 0; \
DO_MANY_MEMBERS(checker, untouched, shuffled) \
kunit_info(test, "Differing " #untouched " vs " #shuffled " member positions: %d\n", \
mismatches); \
KUNIT_##outcome##_MSG(test, mismatches, 0, \
#untouched " vs " #shuffled " layouts: unlucky or broken?\n");
Annotation
- Immediate include surface: `kunit/test.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/string.h`.
- Detected declarations: `struct randstruct_untouched`, `struct randstruct_shuffled`, `struct randstruct_funcs_untouched`, `struct randstruct_funcs_shuffled`, `struct randstruct_mixed_untouched`, `struct randstruct_mixed_shuffled`, `struct contains_randstruct_untouched`, `struct contains_randstruct_shuffled`, `struct contains_func_untouched`, `struct contains_func_shuffled`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.