bug-hurd
[Top][All Lists]
Advanced

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

[PATCH] Cast kernel server call arguments to the correct type when mach_


From: Flavio Cruz
Subject: [PATCH] Cast kernel server call arguments to the correct type when mach_port_t and ipc_port_t are used interchangeably
Date: Wed, 30 Dec 2015 18:03:58 +0100
User-agent: Mutt/1.5.24 (2015-08-30)

This fixes a warning when compiling the mig generated file
gnumach/kern/mach4.server.c. Here, an ipc_port_t* is passed to a
function that expects a mach_port_t* (In0P->object). Since mig uses
mach_port_t and ipc_port_t interchangeably in kernel interfaces, we need
to use casts to make GCC happy.

---
diff --git a/server.c b/server.c
index a08795b..7dcd5cf 100644
--- a/server.c
+++ b/server.c
@@ -749,6 +749,18 @@ WriteServerCallArg(FILE *file, const argument_t *arg)
     const ipc_type_t *it = arg->argType;
     boolean_t NeedClose = FALSE;
 
+    if (IsKernelServer) {
+        /* If the type (incl. array) is handled differently, then we need to
+           cast it to the real argument type.  */
+        if (it->itSpecial ||
+            it->itInLine && it->itVarArray && it->itElement->itSpecial) {
+            /* Some arguments are transformed into the correct type already.  
*/
+            if (!akCheckAll(arg->argKind, akbSendRcv|akbVarNeeded))
+              fprintf(file, "(%s%s)", it->itTransType,
+                      arg->argByReferenceServer ? "*" : "");
+        }
+    }
+
     if (arg->argByReferenceServer)
        fprintf(file, "&");
 
diff --git a/type.c b/type.c
index 7565f34..cae3781 100644
--- a/type.c
+++ b/type.c
@@ -219,16 +219,21 @@ itCalculateNameInfo(ipc_type_t *it)
        (((it->itInName == MACH_MSG_TYPE_POLYMORPHIC) &&
          (it->itOutName == MACH_MSG_TYPE_POLYMORPHIC)) ||
         MACH_MSG_TYPE_PORT_ANY(it->itInName) ||
-        MACH_MSG_TYPE_PORT_ANY(it->itOutName)))
+        MACH_MSG_TYPE_PORT_ANY(it->itOutName))) {
        it->itServerType = "ipc_port_t";
-
-    if (IsKernelUser &&
+        it->itSpecial = TRUE;
+    }
+    else if (IsKernelUser &&
        streql(it->itUserType, "mach_port_t") &&
        (((it->itInName == MACH_MSG_TYPE_POLYMORPHIC) &&
          (it->itOutName == MACH_MSG_TYPE_POLYMORPHIC)) ||
         MACH_MSG_TYPE_PORT_ANY(it->itInName) ||
-        MACH_MSG_TYPE_PORT_ANY(it->itOutName)))
+        MACH_MSG_TYPE_PORT_ANY(it->itOutName))) {
        it->itUserType = "ipc_port_t";
+        it->itSpecial = TRUE;
+    } else {
+        it->itSpecial = FALSE;
+    }
 
     if (it->itTransType == strNULL)
        it->itTransType = it->itServerType;
diff --git a/type.h b/type.h
index 50de063..56f1baf 100644
--- a/type.h
+++ b/type.h
@@ -129,6 +129,10 @@ typedef enum dealloc {
  *
  * itElement points to any substructure that the type may have.
  * It is only used with variable-sized array types.
+ *
+ * itSpecial is used only on kernel interfaces and is set to TRUE when
+ * the initial type is mach_port_t, which in turn is actually translated to
+ * internal port pointers (ipc_port_t).
  */
 
 typedef struct ipc_type
@@ -169,6 +173,10 @@ typedef struct ipc_type
     identifier_t itInTransPayload;     /* may be NULL */
     identifier_t itOutTrans;   /* may be NULL */
     identifier_t itDestructor; /* may be NULL */
+
+    /* TRUE for kernel interfaces if the type gets special treatment.
+       Read comments on itCalculateNameInfo for details.  */
+    boolean_t itSpecial;
 } ipc_type_t;
 
 #define        itNULL          ((ipc_type_t *) 0)



reply via email to

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