From 93e9d420554ed60cb3fa9fa47d3e97b33556b276 Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Mon, 3 Sep 2012 14:01:12 +0200 Subject: Add control page offset checks Make sure the kernel and userspace compilers have the same idea of the layout of the control page. --- include/internal.h | 2 ++ src/kernel_iface.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/internal.h b/include/internal.h index 747f095..035440b 100644 --- a/include/internal.h +++ b/include/internal.h @@ -23,6 +23,8 @@ int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, #define likely(x) __builtin_expect((x), 1) #define unlikely(x) __builtin_expect((x), 0) +#define offsetof(s, x) __builtin_offsetof(s, x) + #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) diff --git a/src/kernel_iface.c b/src/kernel_iface.c index b9c8f59..4cc1af5 100644 --- a/src/kernel_iface.c +++ b/src/kernel_iface.c @@ -82,7 +82,16 @@ int init_kernel_iface(void) int err = 0; long page_size = sysconf(_SC_PAGESIZE); - BUILD_BUG_ON(sizeof(union np_flag) != sizeof(uint32_t)); + BUILD_BUG_ON(sizeof(union np_flag) != sizeof(uint64_t)); + + BUILD_BUG_ON(offsetof(struct control_page, sched.raw) + != LITMUS_CP_OFFSET_SCHED); + BUILD_BUG_ON(offsetof(struct control_page, irq_count) + != LITMUS_CP_OFFSET_IRQ_COUNT); + BUILD_BUG_ON(offsetof(struct control_page, ts_syscall_start) + != LITMUS_CP_OFFSET_TS_SC_START); + BUILD_BUG_ON(offsetof(struct control_page, irq_syscall_start) + != LITMUS_CP_OFFSET_IRQ_SC_START); err = map_file(LITMUS_CTRL_DEVICE, (void**) &ctrl_page, CTRL_PAGES * page_size); if (err) { -- cgit v1.2.2