bug-hurd
[Top][All Lists]
Advanced

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

[PATCH 1/7] add msg_user_header_t for user-side msg structure


From: Luca Dariz
Subject: [PATCH 1/7] add msg_user_header_t for user-side msg structure
Date: Mon, 16 Jan 2023 11:58:51 +0100

* include/mach/message.h: use mach_msg_user_header_t only in KERNEL,
  and define it as mach_msh_header_t for user space
* ipc/ipc_kmsg.c: use mach_msg_user_header_t where appropriate
* ipc/ipc_kmsg.h: Likewise
* ipc/mach_msg.c: Likewise
* ipc/mach_msg.h: Likewise
* kern/thread.h: Likewise
---
 include/mach/message.h | 17 ++++++++++++++++-
 ipc/ipc_kmsg.c         |  6 +++---
 ipc/ipc_kmsg.h         |  4 ++--
 ipc/mach_msg.c         | 10 +++++-----
 ipc/mach_msg.h         |  4 ++--
 kern/thread.h          |  2 +-
 6 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/include/mach/message.h b/include/mach/message.h
index 798b47b4..c3081e66 100644
--- a/include/mach/message.h
+++ b/include/mach/message.h
@@ -132,6 +132,7 @@ typedef     unsigned int mach_msg_size_t;
 typedef natural_t mach_msg_seqno_t;
 typedef integer_t mach_msg_id_t;
 
+/* full header structure, may have different size in user/kernel spaces */
 typedef        struct mach_msg_header {
     mach_msg_bits_t    msgh_bits;
     mach_msg_size_t    msgh_size;
@@ -144,6 +145,20 @@ typedef    struct mach_msg_header {
     mach_msg_id_t      msgh_id;
 } mach_msg_header_t;
 
+#ifdef KERNEL
+/* user-side header format, needed in the kernel */
+typedef        struct {
+    mach_msg_bits_t    msgh_bits;
+    mach_msg_size_t    msgh_size;
+    mach_port_name_t   msgh_remote_port;
+    mach_port_name_t   msgh_local_port;
+    mach_port_seqno_t  msgh_seqno;
+    mach_msg_id_t      msgh_id;
+} mach_msg_user_header_t;
+#else
+typedef mach_msg_header_t mach_msg_user_header_t;
+#endif
+
 /*
  *  There is no fixed upper bound to the size of Mach messages.
  */
@@ -389,7 +404,7 @@ typedef kern_return_t mach_msg_return_t;
 
 extern mach_msg_return_t
 mach_msg_trap
-   (mach_msg_header_t *msg,
+   (mach_msg_user_header_t *msg,
     mach_msg_option_t option,
     mach_msg_size_t send_size,
     mach_msg_size_t rcv_size,
diff --git a/ipc/ipc_kmsg.c b/ipc/ipc_kmsg.c
index 62e138c7..d00c67d4 100644
--- a/ipc/ipc_kmsg.c
+++ b/ipc/ipc_kmsg.c
@@ -499,13 +499,13 @@ ipc_kmsg_free(ipc_kmsg_t kmsg)
 
 mach_msg_return_t
 ipc_kmsg_get(
-       mach_msg_header_t       *msg,
+       mach_msg_user_header_t  *msg,
        mach_msg_size_t         size,
        ipc_kmsg_t              *kmsgp)
 {
        ipc_kmsg_t kmsg;
 
-       if ((size < sizeof(mach_msg_header_t)) || (size & 3))
+       if ((size < sizeof(mach_msg_user_header_t)) || (size & 3))
                return MACH_SEND_MSG_TOO_SMALL;
 
        if (size <= IKM_SAVED_MSG_SIZE) {
@@ -587,7 +587,7 @@ ipc_kmsg_get_from_kernel(
 
 mach_msg_return_t
 ipc_kmsg_put(
-       mach_msg_header_t       *msg,
+       mach_msg_user_header_t  *msg,
        ipc_kmsg_t              kmsg,
        mach_msg_size_t         size)
 {
diff --git a/ipc/ipc_kmsg.h b/ipc/ipc_kmsg.h
index ffda9b5e..16df31f5 100644
--- a/ipc/ipc_kmsg.h
+++ b/ipc/ipc_kmsg.h
@@ -242,13 +242,13 @@ extern void
 ipc_kmsg_free(ipc_kmsg_t);
 
 extern mach_msg_return_t
-ipc_kmsg_get(mach_msg_header_t *, mach_msg_size_t, ipc_kmsg_t *);
+ipc_kmsg_get(mach_msg_user_header_t *, mach_msg_size_t, ipc_kmsg_t *);
 
 extern mach_msg_return_t
 ipc_kmsg_get_from_kernel(mach_msg_header_t *, mach_msg_size_t, ipc_kmsg_t *);
 
 extern mach_msg_return_t
-ipc_kmsg_put(mach_msg_header_t *, ipc_kmsg_t, mach_msg_size_t);
+ipc_kmsg_put(mach_msg_user_header_t *, ipc_kmsg_t, mach_msg_size_t);
 
 extern void
 ipc_kmsg_put_to_kernel(mach_msg_header_t *, ipc_kmsg_t, mach_msg_size_t);
diff --git a/ipc/mach_msg.c b/ipc/mach_msg.c
index f15164a3..221ea975 100644
--- a/ipc/mach_msg.c
+++ b/ipc/mach_msg.c
@@ -89,7 +89,7 @@
 
 mach_msg_return_t
 mach_msg_send(
-       mach_msg_header_t       *msg,
+       mach_msg_user_header_t  *msg,
        mach_msg_option_t       option,
        mach_msg_size_t         send_size,
        mach_msg_timeout_t      time_out,
@@ -171,7 +171,7 @@ mach_msg_send(
 
 mach_msg_return_t
 mach_msg_receive(
-       mach_msg_header_t       *msg,
+       mach_msg_user_header_t  *msg,
        mach_msg_option_t       option,
        mach_msg_size_t         rcv_size,
        mach_port_name_t        rcv_name,
@@ -286,7 +286,7 @@ mach_msg_receive_continue(void)
        ipc_thread_t self = current_thread();
        ipc_space_t space = current_space();
        vm_map_t map = current_map();
-       mach_msg_header_t *msg = self->ith_msg;
+       mach_msg_user_header_t *msg = self->ith_msg;
        mach_msg_option_t option = self->ith_option;
        mach_msg_size_t rcv_size = self->ith_rcv_size;
        mach_msg_timeout_t time_out = self->ith_timeout;
@@ -380,7 +380,7 @@ mach_msg_receive_continue(void)
 
 mach_msg_return_t
 mach_msg_trap(
-       mach_msg_header_t       *msg,
+       mach_msg_user_header_t  *msg,
        mach_msg_option_t       option,
        mach_msg_size_t         send_size,
        mach_msg_size_t         rcv_size,
@@ -1609,7 +1609,7 @@ mach_msg_continue(void)
        task_t task = thread->task;
        ipc_space_t space = task->itk_space;
        vm_map_t map = task->map;
-       mach_msg_header_t *msg = thread->ith_msg;
+       mach_msg_user_header_t *msg = thread->ith_msg;
        mach_msg_size_t rcv_size = thread->ith_rcv_size;
        ipc_object_t object = thread->ith_object;
        ipc_mqueue_t mqueue = thread->ith_mqueue;
diff --git a/ipc/mach_msg.h b/ipc/mach_msg.h
index ee093f8d..2951bcea 100644
--- a/ipc/mach_msg.h
+++ b/ipc/mach_msg.h
@@ -40,11 +40,11 @@
 #include <mach/message.h>
 
 extern mach_msg_return_t
-mach_msg_send(mach_msg_header_t *, mach_msg_option_t,
+mach_msg_send(mach_msg_user_header_t *, mach_msg_option_t,
              mach_msg_size_t, mach_msg_timeout_t, mach_port_name_t);
 
 extern mach_msg_return_t
-mach_msg_receive(mach_msg_header_t *, mach_msg_option_t,
+mach_msg_receive(mach_msg_user_header_t *, mach_msg_option_t,
                 mach_msg_size_t, mach_port_name_t,
                 mach_msg_timeout_t, mach_port_name_t);
 
diff --git a/kern/thread.h b/kern/thread.h
index da8bd2ed..ebbbd11c 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -178,7 +178,7 @@ struct thread {
        /* State saved when thread's stack is discarded */
        union {
                struct {
-                       mach_msg_header_t *msg;
+                       mach_msg_user_header_t *msg;
                        mach_msg_option_t option;
                        mach_msg_size_t rcv_size;
                        mach_msg_timeout_t timeout;
-- 
2.30.2




reply via email to

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