bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add _Static_assert when compiling server and user stubs.


From: Samuel Thibault
Subject: Re: [PATCH] Add _Static_assert when compiling server and user stubs.
Date: Fri, 21 Jan 2022 00:09:24 +0100
User-agent: NeoMutt/20170609 (1.8.3)

Flavio Cruz, le mer. 19 janv. 2022 22:59:13 -0800, a ecrit:
> 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.

Applied, thanks!

> ---
>  server.c               |  4 ++--
>  tests/good/case.defs   |  6 ++++--
>  tests/includes/types.h |  2 +-
>  user.c                 |  2 +-
>  utils.c                | 39 ++++++++++++++++++++++++++++++++-------
>  utils.h                |  9 ++++++---
>  6 files changed, 46 insertions(+), 16 deletions(-)
> 
> diff --git a/server.c b/server.c
> index 6d089c1..0b78990 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");
> @@ -1327,7 +1327,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 505f434..0e1e2e3 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -190,19 +190,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
> @@ -323,7 +339,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",
> @@ -337,16 +354,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 3a4c832..91666ae 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);
> @@ -63,7 +65,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, ...);
> -- 
> 2.32.0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]