From dad5ccf4808854af8f6af32ab4f15dca00dae42b Mon Sep 17 00:00:00 2001 From: kib Date: Thu, 11 May 2017 09:36:51 +0000 Subject: MFC r317523: Add asserts to verify stability of struct proc and struct thread layouts. --- sys/kern/kern_thread.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'sys/kern') diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index df33821..6a42950 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -64,6 +64,57 @@ __FBSDID("$FreeBSD$"); #include #include +/* + * Asserts below verify the stability of struct thread and struct proc + * layout, as exposed by KBI to modules. On head, the KBI is allowed + * to drift, change to the structures must be accompanied by the + * assert update. + * + * On the stable branches after KBI freeze, conditions must not be + * violated. Typically new fields are moved to the end of the + * structures. + */ +#ifdef __amd64__ +_Static_assert(offsetof(struct thread, td_flags) == 0xe4, + "struct thread KBI td_flags"); +_Static_assert(offsetof(struct thread, td_pflags) == 0xec, + "struct thread KBI td_pflags"); +_Static_assert(offsetof(struct thread, td_frame) == 0x418, + "struct thread KBI td_frame"); +_Static_assert(offsetof(struct thread, td_emuldata) == 0x4c0, + "struct thread KBI td_emuldata"); +_Static_assert(offsetof(struct proc, p_flag) == 0xb0, + "struct proc KBI p_flag"); +_Static_assert(offsetof(struct proc, p_pid) == 0xbc, + "struct proc KBI p_pid"); +_Static_assert(offsetof(struct proc, p_filemon) == 0x3d0, + "struct proc KBI p_filemon"); +_Static_assert(offsetof(struct proc, p_comm) == 0x3e0, + "struct proc KBI p_comm"); +_Static_assert(offsetof(struct proc, p_emuldata) == 0x4b0, + "struct proc KBI p_emuldata"); +#endif +#ifdef __i386__ +_Static_assert(offsetof(struct thread, td_flags) == 0x8c, + "struct thread KBI td_flags"); +_Static_assert(offsetof(struct thread, td_pflags) == 0x94, + "struct thread KBI td_pflags"); +_Static_assert(offsetof(struct thread, td_frame) == 0x2c0, + "struct thread KBI td_frame"); +_Static_assert(offsetof(struct thread, td_emuldata) == 0x30c, + "struct thread KBI td_emuldata"); +_Static_assert(offsetof(struct proc, p_flag) == 0x68, + "struct proc KBI p_flag"); +_Static_assert(offsetof(struct proc, p_pid) == 0x74, + "struct proc KBI p_pid"); +_Static_assert(offsetof(struct proc, p_filemon) == 0x278, + "struct proc KBI p_filemon"); +_Static_assert(offsetof(struct proc, p_comm) == 0x284, + "struct proc KBI p_comm"); +_Static_assert(offsetof(struct proc, p_emuldata) == 0x304, + "struct proc KBI p_emuldata"); +#endif + SDT_PROVIDER_DECLARE(proc); SDT_PROBE_DEFINE(proc, , , lwp__exit); -- cgit v1.1