summaryrefslogtreecommitdiff
path: root/ipc
diff options
context:
space:
mode:
authorLuca Dariz <luca@orpolo.org>2023-01-16 11:58:57 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-01-18 02:31:51 +0100
commitfc6bcf785b702e7e8a675ea0fe9856cc1b24b8f6 (patch)
tree23e99832f6ea6dc52bf7f6fdb137d58218410773 /ipc
parentf056fcda8bf9a5c375b20ef3803718187d9d4211 (diff)
replace mach_port_t with mach_port_name_t
This is a cleanup following the introduction of mach_port_name_t. The same set of changes is applied to all files: - rename mach_port_t to mach_port_name_t where a port name is used, - use MACH_PORT_NAME_NULL and MACH_PORT_NAME_DEAD where appropriate, - use invalid_port_to_name() and invalid_name_to_port() for conversion where appropriate, - use regular copyout() insted of copyout_port() when we deal with mach_port_name_t already before copyout, - use the new helper ipc_kmsg_copyout_object_to_port() when we really want to place a port name in the space of a mach_port_t. * include/mach/notify.h: Likewise * ipc/ipc_entry.c: Likewise * ipc/ipc_kmsg.c: Likewise * ipc/ipc_kmsg.h: Likewise, and add ipc_kmsg_copyout_object_to_port() * ipc/ipc_marequest.c: Likewise * ipc/ipc_object.c: Likewise * ipc/ipc_port.c: Likewise * ipc/ipc_space.h: Likewise * ipc/mach_msg.c: Likewise * ipc/mach_port.c: Likewise * kern/exception.c: Likewise * kern/ipc_mig.c: Likewise Message-Id: <20230116105857.240210-8-luca@orpolo.org>
Diffstat (limited to 'ipc')
-rw-r--r--ipc/ipc_entry.c2
-rw-r--r--ipc/ipc_kmsg.c40
-rw-r--r--ipc/ipc_kmsg.h11
-rw-r--r--ipc/ipc_marequest.c4
-rw-r--r--ipc/ipc_object.c4
-rw-r--r--ipc/ipc_port.c6
-rw-r--r--ipc/ipc_space.h2
-rw-r--r--ipc/mach_msg.c2
-rw-r--r--ipc/mach_port.c14
9 files changed, 47 insertions, 38 deletions
diff --git a/ipc/ipc_entry.c b/ipc/ipc_entry.c
index c24ea46c..f13c442f 100644
--- a/ipc/ipc_entry.c
+++ b/ipc/ipc_entry.c
@@ -127,7 +127,7 @@ ipc_entry_alloc_name(
kern_return_t kr;
ipc_entry_t entry, e, *prevp;
void **slot;
- assert(MACH_PORT_VALID(name));
+ assert(MACH_PORT_NAME_VALID(name));
if (!space->is_active) {
return KERN_INVALID_TASK;
diff --git a/ipc/ipc_kmsg.c b/ipc/ipc_kmsg.c
index 45070b7a..8bb20a18 100644
--- a/ipc/ipc_kmsg.c
+++ b/ipc/ipc_kmsg.c
@@ -44,6 +44,7 @@
#include <machine/locore.h>
#include <machine/copy_user.h>
#include <kern/assert.h>
+#include <kern/debug.h>
#include <kern/kalloc.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
@@ -1078,7 +1079,7 @@ ipc_kmsg_copyin_header(
reply_soright = soright;
}
}
- } else if (!MACH_PORT_VALID(reply_name)) {
+ } else if (!MACH_PORT_NAME_VALID(reply_name)) {
ipc_entry_t entry;
/*
@@ -1101,7 +1102,7 @@ ipc_kmsg_copyin_header(
if (IE_BITS_TYPE(entry->ie_bits) == MACH_PORT_TYPE_NONE)
ipc_entry_dealloc(space, dest_name, entry);
- reply_port = (ipc_object_t) reply_name;
+ reply_port = (ipc_object_t) invalid_name_to_port(reply_name);
reply_soright = IP_NULL;
} else {
ipc_entry_t dest_entry, reply_entry;
@@ -1461,10 +1462,10 @@ ipc_kmsg_copyin_body(
((mach_msg_type_t*)type)->msgt_name = newname;
for (i = 0; i < number; i++) {
- mach_port_name_t port = (mach_port_name_t) objects[i];
+ mach_port_name_t port = ((mach_port_t*)data)[i];
ipc_object_t object;
- if (!MACH_PORT_VALID(port))
+ if (!MACH_PORT_NAME_VALID(port))
continue;
kr = ipc_object_copyin(space, port,
@@ -1846,7 +1847,7 @@ ipc_kmsg_copyout_header(
entry->ie_bits = gen | (MACH_PORT_TYPE_SEND_ONCE | 1);
}
- assert(MACH_PORT_VALID(reply_name));
+ assert(MACH_PORT_NAME_VALID(reply_name));
entry->ie_object = (ipc_object_t) reply;
is_write_unlock(space);
@@ -2021,7 +2022,7 @@ ipc_kmsg_copyout_header(
is_write_unlock(space);
reply = IP_DEAD;
- reply_name = MACH_PORT_DEAD;
+ reply_name = MACH_PORT_NAME_DEAD;
goto copyout_dest;
}
@@ -2132,7 +2133,7 @@ ipc_kmsg_copyout_header(
ip_lock(dest);
is_read_unlock(space);
- reply_name = (mach_port_name_t) reply;
+ reply_name = invalid_port_to_name(msg->msgh_local_port);
}
/*
@@ -2201,12 +2202,12 @@ ipc_kmsg_copyout_header(
if (ip_active(reply) ||
IP_TIMESTAMP_ORDER(timestamp,
reply->ip_timestamp))
- dest_name = MACH_PORT_DEAD;
+ dest_name = MACH_PORT_NAME_DEAD;
else
- dest_name = MACH_PORT_NULL;
+ dest_name = MACH_PORT_NAME_NULL;
ip_unlock(reply);
} else
- dest_name = MACH_PORT_DEAD;
+ dest_name = MACH_PORT_NAME_DEAD;
}
if (IP_VALID(reply))
@@ -2254,7 +2255,7 @@ ipc_kmsg_copyout_object(
mach_port_name_t *namep)
{
if (!IO_VALID(object)) {
- *namep = (mach_port_name_t) object;
+ *namep = invalid_port_to_name((mach_port_t)object);
return MACH_MSG_SUCCESS;
}
@@ -2324,9 +2325,9 @@ ipc_kmsg_copyout_object(
ipc_object_destroy(object, msgt_name);
if (kr == KERN_INVALID_CAPABILITY)
- *namep = MACH_PORT_DEAD;
+ *namep = MACH_PORT_NAME_DEAD;
else {
- *namep = MACH_PORT_NULL;
+ *namep = MACH_PORT_NAME_NULL;
if (kr == KERN_RESOURCE_SHORTAGE)
return MACH_MSG_IPC_KERNEL;
@@ -2435,11 +2436,8 @@ ipc_kmsg_copyout_body(
for (i = 0; i < number; i++) {
ipc_object_t object = objects[i];
- /* TODO: revisit this for 64 bits since the size of
- * mach_port_name_t is not the same as a pointer size.
- */
- mr |= ipc_kmsg_copyout_object(space, object,
- name, (mach_port_name_t *)&objects[i]);
+ mr |= ipc_kmsg_copyout_object_to_port(space, object,
+ name, (mach_port_t *)&objects[i]);
}
}
@@ -2628,14 +2626,14 @@ ipc_kmsg_copyout_dest(
} else {
io_release(dest);
io_check_unlock(dest);
- dest_name = MACH_PORT_DEAD;
+ dest_name = MACH_PORT_NAME_DEAD;
}
if (IO_VALID(reply)) {
ipc_object_destroy(reply, reply_type);
- reply_name = MACH_PORT_NULL;
+ reply_name = MACH_PORT_NAME_NULL;
} else
- reply_name = (mach_port_name_t) reply;
+ reply_name = invalid_port_to_name((mach_port_t)reply);
kmsg->ikm_header.msgh_bits = (MACH_MSGH_BITS_OTHER(mbits) |
MACH_MSGH_BITS(reply_type, dest_type));
diff --git a/ipc/ipc_kmsg.h b/ipc/ipc_kmsg.h
index 16df31f5..b1eb06c7 100644
--- a/ipc/ipc_kmsg.h
+++ b/ipc/ipc_kmsg.h
@@ -269,6 +269,17 @@ extern mach_msg_return_t
ipc_kmsg_copyout_object(ipc_space_t, ipc_object_t,
mach_msg_type_name_t, mach_port_name_t *);
+static inline mach_msg_return_t
+ipc_kmsg_copyout_object_to_port(ipc_space_t space, ipc_object_t object,
+ mach_msg_type_name_t msgt_name, mach_port_t *portp)
+{
+ mach_port_name_t name;;
+ mach_msg_return_t mr;
+ mr = ipc_kmsg_copyout_object(space, object, msgt_name, &name);
+ *portp = (mach_port_t)name;
+ return mr;
+}
+
extern mach_msg_return_t
ipc_kmsg_copyout_body(ipc_kmsg_t, ipc_space_t, vm_map_t);
diff --git a/ipc/ipc_marequest.c b/ipc/ipc_marequest.c
index 526e4722..c096fe24 100644
--- a/ipc/ipc_marequest.c
+++ b/ipc/ipc_marequest.c
@@ -279,7 +279,7 @@ ipc_marequest_cancel(
*last = marequest->imar_next;
imarb_unlock(bucket);
- marequest->imar_name = MACH_PORT_NULL;
+ marequest->imar_name = MACH_PORT_NAME_NULL;
}
/*
@@ -377,7 +377,7 @@ ipc_marequest_destroy(ipc_marequest_t marequest)
entry->ie_bits &= ~IE_BITS_MAREQUEST;
} else
- name = MACH_PORT_NULL;
+ name = MACH_PORT_NAME_NULL;
}
is_write_unlock(space);
diff --git a/ipc/ipc_object.c b/ipc/ipc_object.c
index 3fd7f92b..1074fb2c 100644
--- a/ipc/ipc_object.c
+++ b/ipc/ipc_object.c
@@ -804,7 +804,7 @@ ipc_object_copyout_dest(
if (port->ip_receiver == space)
name = port->ip_receiver_name;
else
- name = MACH_PORT_NULL;
+ name = MACH_PORT_NAME_NULL;
ip_unlock(port);
@@ -839,7 +839,7 @@ ipc_object_copyout_dest(
ip_unlock(port);
ipc_notify_send_once(port);
- name = MACH_PORT_NULL;
+ name = MACH_PORT_NAME_NULL;
}
break;
diff --git a/ipc/ipc_port.c b/ipc/ipc_port.c
index c8bc0fb9..f9ccc290 100644
--- a/ipc/ipc_port.c
+++ b/ipc/ipc_port.c
@@ -1024,12 +1024,12 @@ ipc_port_copyout_send(
ipc_port_release_send(sright);
if (kr == KERN_INVALID_CAPABILITY)
- name = MACH_PORT_DEAD;
+ name = MACH_PORT_NAME_DEAD;
else
- name = MACH_PORT_NULL;
+ name = MACH_PORT_NAME_NULL;
}
} else
- name = (mach_port_name_t) sright;
+ name = invalid_port_to_name((mach_port_t)sright);
return name;
}
diff --git a/ipc/ipc_space.h b/ipc/ipc_space.h
index 84923e7a..b4eb5ba6 100644
--- a/ipc/ipc_space.h
+++ b/ipc/ipc_space.h
@@ -208,7 +208,7 @@ ipc_entry_get(
* (See comment in ipc/ipc_table.h.)
*/
- assert(MACH_PORT_VALID(new_name));
+ assert(MACH_PORT_NAME_VALID(new_name));
assert(free_entry->ie_object == IO_NULL);
space->is_size += 1;
diff --git a/ipc/mach_msg.c b/ipc/mach_msg.c
index 1a6d67d0..46218bb6 100644
--- a/ipc/mach_msg.c
+++ b/ipc/mach_msg.c
@@ -1002,7 +1002,7 @@ mach_msg_trap(
entry->ie_bits = gen | (MACH_PORT_TYPE_SEND_ONCE | 1);
}
- assert(MACH_PORT_VALID(reply_name));
+ assert(MACH_PORT_NAME_VALID(reply_name));
entry->ie_object = (ipc_object_t) reply_port;
is_write_unlock(space);
}
diff --git a/ipc/mach_port.c b/ipc/mach_port.c
index 6edf9f88..67713a50 100644
--- a/ipc/mach_port.c
+++ b/ipc/mach_port.c
@@ -374,7 +374,7 @@ mach_port_rename(
if (space == IS_NULL)
return KERN_INVALID_TASK;
- if (!MACH_PORT_VALID(nname))
+ if (!MACH_PORT_NAME_VALID(nname))
return KERN_INVALID_VALUE;
return ipc_object_rename(space, oname, nname);
@@ -422,7 +422,7 @@ mach_port_allocate_name(
if (space == IS_NULL)
return KERN_INVALID_TASK;
- if (!MACH_PORT_VALID(name))
+ if (!MACH_PORT_NAME_VALID(name))
return KERN_INVALID_VALUE;
switch (right) {
@@ -548,7 +548,7 @@ mach_port_destroy(
kr = ipc_right_lookup_write(space, name, &entry);
if (kr != KERN_SUCCESS) {
- if (MACH_PORT_VALID (name) && space == current_space()) {
+ if (MACH_PORT_NAME_VALID (name) && space == current_space()) {
printf("task %.*s destroying a bogus port %lu, most probably a bug.\n", (int) sizeof current_task()->name, current_task()->name, (unsigned long) name);
if (mach_port_deallocate_debug)
SoftDebugger("mach_port_deallocate");
@@ -592,7 +592,7 @@ mach_port_deallocate(
kr = ipc_right_lookup_write(space, name, &entry);
if (kr != KERN_SUCCESS) {
- if (MACH_PORT_VALID (name) && space == current_space()) {
+ if (MACH_PORT_NAME_VALID (name) && space == current_space()) {
printf("task %.*s deallocating a bogus port %lu, most probably a bug.\n", (int) sizeof current_task()->name, current_task()->name, (unsigned long) name);
if (mach_port_deallocate_debug)
SoftDebugger("mach_port_deallocate");
@@ -714,7 +714,7 @@ mach_port_mod_refs(
kr = ipc_right_lookup_write(space, name, &entry);
if (kr != KERN_SUCCESS) {
- if (MACH_PORT_VALID (name) && space == current_space()) {
+ if (MACH_PORT_NAME_VALID (name) && space == current_space()) {
printf("task %.*s %screasing a bogus port "
"%u by %d, most probably a bug.\n",
(int) (sizeof current_task()->name),
@@ -1228,7 +1228,7 @@ mach_port_insert_right(
if (space == IS_NULL)
return KERN_INVALID_TASK;
- if (!MACH_PORT_VALID(name) ||
+ if (!MACH_PORT_NAME_VALID(name) ||
!MACH_MSG_TYPE_PORT_ANY_RIGHT(polyPoly))
return KERN_INVALID_VALUE;
@@ -1323,7 +1323,7 @@ mach_port_get_receive_status(
statusp->mps_seqno = port->ip_seqno;
imq_unlock(&pset->ips_messages);
ips_unlock(pset);
- assert(MACH_PORT_VALID(statusp->mps_pset));
+ assert(MACH_PORT_NAME_VALID(statusp->mps_pset));
}
} else {
no_port_set: