From d4ed2ed7fa36a2637f6f3b352ee2875abaf27092 Mon Sep 17 00:00:00 2001 From: Luca Dariz Date: Mon, 6 Jan 2025 14:46:49 +0100 Subject: header: add definitions for RPC presence and IDs This allows to check at compilation time for some rpc (as done for example in glibc for thread_set/get_name() and host_page_size()). Also the IDs can be useful for testing purposes, or when assembling messages manually. Message-ID: <20250106134649.391487-1-luca@orpolo.org> --- header.c | 14 ++++++++++++++ mig_string.h | 1 + string.c | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/header.c b/header.c index 8190376..4781e86 100644 --- a/header.c +++ b/header.c @@ -82,13 +82,20 @@ WriteEpilog(FILE *file, const char *protect) static void WriteUserRoutine(FILE *file, const routine_t *rt) { + char *defName = strupper(rt->rtUserName); fprintf(file, "\n"); fprintf(file, "/* %s %s */\n", rtRoutineKindToStr(rt->rtKind), rt->rtName); + fprintf(file, "#define MIG_RPC_HAVE_%s\n", defName); + fprintf(file, "#define MIG_RPC_REQUEST_ID_%s %d\n", + defName, rt->rtNumber + SubsystemBase); + fprintf(file, "#define MIG_RPC_REPLY_ID_%s %d\n", + defName, rt->rtNumber + SubsystemBase + 100); WriteMigExternal(file); fprintf(file, "%s %s\n", ReturnTypeStr(rt), rt->rtUserName); fprintf(file, "(\n"); WriteList(file, rt->rtArgs, WriteUserVarDecl, akbUserArg, ",\n", "\n"); fprintf(file, ");\n"); + strfree(defName); } void @@ -137,14 +144,21 @@ WriteRoutineList(FILE *file, const statement_t *stats) static void WriteServerRoutine(FILE *file, const routine_t *rt) { + char *defName = strupper(rt->rtServerName); fprintf(file, "\n"); fprintf(file, "/* %s %s */\n", rtRoutineKindToStr(rt->rtKind), rt->rtName); + fprintf(file, "#define MIG_RPC_HAVE_%s\n", defName); + fprintf(file, "#define MIG_RPC_REQUEST_ID_%s %d\n", + defName, rt->rtNumber + SubsystemBase); + fprintf(file, "#define MIG_RPC_REPLY_ID_%s %d\n", + defName, rt->rtNumber + SubsystemBase + 100); WriteMigExternal(file); fprintf(file, "%s %s\n", ReturnTypeStr(rt), rt->rtServerName); fprintf(file, "(\n"); WriteList(file, rt->rtArgs, WriteServerVarDecl, akbServerArg, ",\n", "\n"); fprintf(file, ");\n"); + strfree(defName); } void diff --git a/mig_string.h b/mig_string.h index 920171c..fc1dd72 100644 --- a/mig_string.h +++ b/mig_string.h @@ -44,5 +44,6 @@ extern void strfree(string_t string); extern const char *strbool(bool v); extern const char *strstring(const_string_t string); +extern char *strupper(const_string_t string); #endif /* _MIG_STRING_H */ diff --git a/string.c b/string.c index e182948..eeaaba2 100644 --- a/string.c +++ b/string.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "error.h" #include "mig_string.h" @@ -77,3 +78,13 @@ strstring(const_string_t string) else return string; } + +char * +strupper(const_string_t string) +{ + string_t upper = strmake(string); + + for (int i=0; i