From 983b56e9f7ef1fdfcf82ad82cc70f939318e599f Mon Sep 17 00:00:00 2001 From: Flavio Cruz Date: Wed, 19 Jan 2022 22:59:13 -0800 Subject: Add _Static_assert when compiling server and user stubs. This is only done when data is inlined with a concrete size. It ensures the C and Mig types have the same size in the target arch. Tested by building the hurd package. No assertions were triggered. Message-Id: --- utils.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'utils.c') diff --git a/utils.c b/utils.c index 48c4420..bdc39b7 100644 --- a/utils.c +++ b/utils.c @@ -221,19 +221,35 @@ WriteServerVarDecl(FILE *file, const argument_t *arg) } void -WriteTypeDeclIn(FILE *file, const argument_t *arg) +WriteTypeDeclInServer(FILE *file, const argument_t *arg) { WriteStaticDecl(file, arg->argType, arg->argType->itIndefinite ? d_NO : arg->argDeallocate, - arg->argLongForm, TRUE, arg->argTTName); + arg->argLongForm, /*is_server=*/TRUE, TRUE, arg->argTTName); } void -WriteTypeDeclOut(FILE *file, const argument_t *arg) +WriteTypeDeclOutServer(FILE *file, const argument_t *arg) { WriteStaticDecl(file, arg->argType, arg->argType->itIndefinite ? d_NO : arg->argDeallocate, - arg->argLongForm, FALSE, arg->argTTName); + arg->argLongForm, /*is_server=*/TRUE, FALSE, arg->argTTName); +} + +void +WriteTypeDeclInUser(FILE *file, const argument_t *arg) +{ + WriteStaticDecl(file, arg->argType, + arg->argType->itIndefinite ? d_NO : arg->argDeallocate, + arg->argLongForm, /*is_server=*/FALSE, TRUE, arg->argTTName); +} + +void +WriteTypeDeclOutUser(FILE *file, const argument_t *arg) +{ + WriteStaticDecl(file, arg->argType, + arg->argType->itIndefinite ? d_NO : arg->argDeallocate, + arg->argLongForm, /*is_server=*/FALSE, FALSE, arg->argTTName); } void @@ -354,7 +370,8 @@ WriteStaticLongDecl(FILE *file, const ipc_type_t *it, static void WriteStaticShortDecl(FILE *file, const ipc_type_t *it, - dealloc_t dealloc, boolean_t inname, identifier_t name) + dealloc_t dealloc, boolean_t is_server, boolean_t inname, + identifier_t name) { fprintf(file, "\tconst mach_msg_type_t %s = {\n", name); fprintf(file, "\t\t/* msgt_name = */\t\t(unsigned char) %s,\n", @@ -368,16 +385,24 @@ WriteStaticShortDecl(FILE *file, const ipc_type_t *it, strdealloc(dealloc)); fprintf(file, "\t\t/* msgt_unused = */\t\t0\n"); fprintf(file, "\t};\n"); + if (it->itInLine && !it->itVarArray) { + identifier_t type = is_server ? FetchServerType(it) : FetchUserType(it); + const u_int size_bytes = it->itSize >> 3; + fprintf(file, "\t_Static_assert(sizeof(%s) == %d * %d, \"expected %s to be size %d * %d\");\n", + type, size_bytes, it->itNumber, + type, size_bytes, it->itNumber); + } } void WriteStaticDecl(FILE *file, const ipc_type_t *it, dealloc_t dealloc, - boolean_t longform, boolean_t inname, identifier_t name) + boolean_t longform, boolean_t is_server, boolean_t inname, + identifier_t name) { if (longform) WriteStaticLongDecl(file, it, dealloc, inname, name); else - WriteStaticShortDecl(file, it, dealloc, inname, name); + WriteStaticShortDecl(file, it, dealloc, is_server, inname, name); } /* -- cgit v1.2.3