From 96ade86f9f410cee6377f60530bcc3aa89b20402 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sat, 23 May 2015 18:23:45 +0200 Subject: kern: avoid breaking the strict-aliasing rules * kern/exception.c (exception_parse_reply): Use `BAD_TYPECHECK'. --- kern/exception.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kern/exception.c b/kern/exception.c index 6e84c0a5..6cb3bfbf 100644 --- a/kern/exception.c +++ b/kern/exception.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #if MACH_KDB @@ -754,6 +755,12 @@ exception_raise( } } +/* Macro used by MIG to cleanly check the type. */ +#define BAD_TYPECHECK(type, check) unlikely (({\ + union { mach_msg_type_t t; unsigned32_t w; } _t, _c;\ + _t.t = *(type); _c.t = *(check);_t.w != _c.w; })) + +/* Type descriptor for the return code. */ mach_msg_type_t exc_RetCode_proto = { /* msgt_name = */ MACH_MSG_TYPE_INTEGER_32, /* msgt_size = */ 32, @@ -786,7 +793,7 @@ exception_parse_reply(ipc_kmsg_t kmsg) MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0)) || (msg->Head.msgh_size != sizeof *msg) || (msg->Head.msgh_id != MACH_EXCEPTION_REPLY_ID) || - (* (int *) &msg->RetCodeType != * (int *) &exc_RetCode_proto)) { + (BAD_TYPECHECK(&msg->RetCodeType, &exc_RetCode_proto))) { /* * Bozo user sent us a misformatted reply. */ -- cgit v1.2.3