summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Cruz <flaviocruz@gmail.com>2022-01-19 22:59:13 -0800
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-01-21 00:09:10 +0100
commit983b56e9f7ef1fdfcf82ad82cc70f939318e599f (patch)
tree1d7fd8e704ffd8436842c014df703c7a9070e186
parentcf4bcc3f1435eafa3ed8b5fadfa9698033d1e2df (diff)
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: <YekIQaxvs+4FrHyw@viriathus>
-rw-r--r--server.c4
-rw-r--r--tests/good/case.defs6
-rw-r--r--tests/includes/types.h2
-rw-r--r--user.c2
-rw-r--r--utils.c39
-rw-r--r--utils.h9
6 files changed, 46 insertions, 16 deletions
diff --git a/server.c b/server.c
index 1dd10c8..0b6d93d 100644
--- a/server.c
+++ b/server.c
@@ -184,7 +184,7 @@ WriteEpilog(FILE *file, const statement_t *stats)
WriteStaticDecl(file, itRetCodeType,
itRetCodeType->itDeallocate, itRetCodeType->itLongForm,
- !IsKernelServer, "RetCodeType");
+ /*is_server=*/ TRUE, !IsKernelServer, "RetCodeType");
fprintf(file, "\n");
fprintf(file, "\tmig_routine_t routine;\n");
@@ -1328,7 +1328,7 @@ WriteRoutine(FILE *file, const routine_t *rt)
WriteList(file, rt->rtArgs, WriteCheckDecl, akbRequestQC, "\n", "\n");
WriteList(file, rt->rtArgs,
- IsKernelServer ? WriteTypeDeclOut : WriteTypeDeclIn,
+ IsKernelServer ? WriteTypeDeclOutServer : WriteTypeDeclInServer,
akbReplyInit, "\n", "\n");
WriteList(file, rt->rtArgs, WriteLocalVarDecl,
diff --git a/tests/good/case.defs b/tests/good/case.defs
index 25ba510..479f733 100644
--- a/tests/good/case.defs
+++ b/tests/good/case.defs
@@ -19,9 +19,11 @@
/* Tests some keywords with different casing. */
SUBSYSTEM myroutine 100;
-TyPe int = MACH_MSG_TYPE_INTEGER_64;
+import <stdint.h>;
+
+TyPe uint64_t = MACH_MSG_TYPE_INTEGER_64;
typE mach_port_t = MACH_MSG_TYPE_COPY_SEND;
RouTine factorial(port : mach_port_t;
n : int;
- out result : int);
+ out result : uint64_t);
diff --git a/tests/includes/types.h b/tests/includes/types.h
index c8c3afd..fe70e69 100644
--- a/tests/includes/types.h
+++ b/tests/includes/types.h
@@ -28,7 +28,7 @@ typedef struct char_struct {
char c4;
} char_struct_t;
-typedef char* string_t;
+typedef char string_t[256];
typedef const char* const_string_t;
static inline int8_t int_to_int8(int n) {
diff --git a/user.c b/user.c
index 7f355ed..9aff07c 100644
--- a/user.c
+++ b/user.c
@@ -1164,7 +1164,7 @@ WriteRoutine(FILE *file, const routine_t *rt)
/* declarations and initializations of the mach_msg_type_t variables
for each argument */
- WriteList(file, rt->rtArgs, WriteTypeDeclIn, akbRequest, "\n", "\n");
+ WriteList(file, rt->rtArgs, WriteTypeDeclInUser, akbRequest, "\n", "\n");
if (!rt->rtOneWay)
WriteList(file, rt->rtArgs, WriteCheckDecl, akbReplyQC, "\n", "\n");
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);
}
/*
diff --git a/utils.h b/utils.h
index 0524f0c..a5673b0 100644
--- a/utils.h
+++ b/utils.h
@@ -46,8 +46,10 @@ extern void WriteReverseList(FILE *file, const argument_t *args,
extern write_list_fn_t WriteNameDecl;
extern write_list_fn_t WriteUserVarDecl;
extern write_list_fn_t WriteServerVarDecl;
-extern write_list_fn_t WriteTypeDeclIn;
-extern write_list_fn_t WriteTypeDeclOut;
+extern write_list_fn_t WriteTypeDeclInServer;
+extern write_list_fn_t WriteTypeDeclOutServer;
+extern write_list_fn_t WriteTypeDeclInUser;
+extern write_list_fn_t WriteTypeDeclOutUser;
extern write_list_fn_t WriteCheckDecl;
extern const char *ReturnTypeStr(const routine_t *rt);
@@ -65,7 +67,8 @@ extern void WriteStructDecl(FILE *file, const argument_t *args,
extern void WriteStaticDecl(FILE *file, const ipc_type_t *it,
dealloc_t dealloc, boolean_t longform,
- boolean_t inname, identifier_t name);
+ boolean_t is_server, boolean_t inname,
+ identifier_t name);
extern void WriteCopyType(FILE *file, const ipc_type_t *it,
const char *left, const char *right, ...);