From d76280e4fc71265b88bce2bdaf25b3be846fc6b2 Mon Sep 17 00:00:00 2001
From: Flavio Cruz <flaviocruz@gmail.com>
Date: Thu, 2 Feb 2023 02:41:52 -0500
Subject: Do not generate the server routine for kernel servers.

The kernel does not use these functions so we can avoid a few compiler
warnings. I think we could make the hurd servers not use these also but
currently these are still needed.
Message-Id: <Y9tpQNDG/mx84kV+@jupiter.tail36e24.ts.net>
---
 server.c | 94 +++++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 48 insertions(+), 46 deletions(-)

diff --git a/server.c b/server.c
index 69c3678..95b0056 100644
--- a/server.c
+++ b/server.c
@@ -170,53 +170,55 @@ WriteEpilog(FILE *file, const statement_t *stats)
      fprintf(file, "\n");
 
      /*
-      * Then, the server routine
+      * Then, the server routine. Only write them if it's a user server since the kernel
+      * relies only on the routines above.
       */
-    fprintf(file, "mig_external boolean_t %s\n", ServerDemux);
-    fprintf(file, "\t(mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)\n");
-
-    fprintf(file, "{\n");
-    fprintf(file, "\tmach_msg_header_t *InP =  InHeadP;\n");
-
-    fprintf(file, "\tmig_reply_header_t *OutP = (mig_reply_header_t *) OutHeadP;\n");
-
-    fprintf(file, "\n");
-
-    WriteStaticDecl(file, itRetCodeType,
-		    itRetCodeType->itDeallocate, itRetCodeType->itLongForm,
-		    /*is_server=*/ true, !IsKernelServer, "RetCodeType");
-    fprintf(file, "\n");
-
-    fprintf(file, "\tmig_routine_t routine;\n");
-    fprintf(file, "\n");
-
-    fprintf(file, "\tOutP->Head.msgh_bits = ");
-    fprintf(file, "MACH_MSGH_BITS(MACH_MSGH_BITS_REPLY(InP->msgh_bits), 0);\n");
-    fprintf(file, "\tOutP->Head.msgh_size = sizeof *OutP;\n");
-    fprintf(file, "\tOutP->Head.msgh_remote_port = InP->msgh_reply_port;\n");
-    fprintf(file, "\tOutP->Head.msgh_local_port = MACH_PORT_NULL;\n");
-    fprintf(file, "\tOutP->Head.msgh_seqno = 0;\n");
-    fprintf(file, "\tOutP->Head.msgh_id = InP->msgh_id + 100;\n");
-    fprintf(file, "\n");
-    WritePackMsgType(file, itRetCodeType,
-		     itRetCodeType->itDeallocate, itRetCodeType->itLongForm,
-		     !IsKernelServer, "OutP->RetCodeType", "RetCodeType");
-    fprintf(file, "\n");
-
-    fprintf(file, "\tif ((InP->msgh_id > %d) || (InP->msgh_id < %d) ||\n",
-	    SubsystemBase + rtNumber - 1, SubsystemBase);
-    fprintf(file, "\t    ((routine = %s_routines[InP->msgh_id - %d]) == 0)) {\n",
-	    ServerDemux, SubsystemBase);
-    fprintf(file, "\t\tOutP->RetCode = MIG_BAD_ID;\n");
-    fprintf(file, "\t\treturn FALSE;\n");
-    fprintf(file, "\t}\n");
-
-    /* Call appropriate routine */
-    fprintf(file, "\t(*routine) (InP, &OutP->Head);\n");
-    fprintf(file, "\treturn TRUE;\n");
-    fprintf(file, "}\n");
-    fprintf(file, "\n");
-
+    if (!IsKernelServer) {
+        fprintf(file, "mig_external boolean_t %s\n", ServerDemux);
+        fprintf(file, "\t(mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)\n");
+
+        fprintf(file, "{\n");
+        fprintf(file, "\tmach_msg_header_t *InP =  InHeadP;\n");
+
+        fprintf(file, "\tmig_reply_header_t *OutP = (mig_reply_header_t *) OutHeadP;\n");
+
+        fprintf(file, "\n");
+
+        WriteStaticDecl(file, itRetCodeType,
+                itRetCodeType->itDeallocate, itRetCodeType->itLongForm,
+                /*is_server=*/ true, !IsKernelServer, "RetCodeType");
+        fprintf(file, "\n");
+
+        fprintf(file, "\tmig_routine_t routine;\n");
+        fprintf(file, "\n");
+
+        fprintf(file, "\tOutP->Head.msgh_bits = ");
+        fprintf(file, "MACH_MSGH_BITS(MACH_MSGH_BITS_REPLY(InP->msgh_bits), 0);\n");
+        fprintf(file, "\tOutP->Head.msgh_size = sizeof *OutP;\n");
+        fprintf(file, "\tOutP->Head.msgh_remote_port = InP->msgh_reply_port;\n");
+        fprintf(file, "\tOutP->Head.msgh_local_port = MACH_PORT_NULL;\n");
+        fprintf(file, "\tOutP->Head.msgh_seqno = 0;\n");
+        fprintf(file, "\tOutP->Head.msgh_id = InP->msgh_id + 100;\n");
+        fprintf(file, "\n");
+        WritePackMsgType(file, itRetCodeType,
+                itRetCodeType->itDeallocate, itRetCodeType->itLongForm,
+                !IsKernelServer, "OutP->RetCodeType", "RetCodeType");
+        fprintf(file, "\n");
+
+        fprintf(file, "\tif ((InP->msgh_id > %d) || (InP->msgh_id < %d) ||\n",
+                SubsystemBase + rtNumber - 1, SubsystemBase);
+        fprintf(file, "\t    ((routine = %s_routines[InP->msgh_id - %d]) == 0)) {\n",
+                ServerDemux, SubsystemBase);
+        fprintf(file, "\t\tOutP->RetCode = MIG_BAD_ID;\n");
+        fprintf(file, "\t\treturn FALSE;\n");
+        fprintf(file, "\t}\n");
+
+        /* Call appropriate routine */
+        fprintf(file, "\t(*routine) (InP, &OutP->Head);\n");
+        fprintf(file, "\treturn TRUE;\n");
+        fprintf(file, "}\n");
+        fprintf(file, "\n");
+	}
     /* symtab */
 
     if (GenSymTab) {
-- 
cgit v1.2.3