summaryrefslogtreecommitdiff
path: root/ipc/ipc_kmsg.c
diff options
context:
space:
mode:
Diffstat (limited to 'ipc/ipc_kmsg.c')
-rw-r--r--ipc/ipc_kmsg.c107
1 files changed, 26 insertions, 81 deletions
diff --git a/ipc/ipc_kmsg.c b/ipc/ipc_kmsg.c
index c0f07dd8..cae700f5 100644
--- a/ipc/ipc_kmsg.c
+++ b/ipc/ipc_kmsg.c
@@ -698,24 +698,14 @@ ipc_kmsg_copyin_header(
if (!space->is_active)
goto abort_async;
- /* optimized ipc_entry_lookup */
-
- {
- mach_port_index_t index = MACH_PORT_INDEX(dest_name);
- mach_port_gen_t gen = MACH_PORT_GEN(dest_name);
-
- if (index >= space->is_table_size)
+ entry = ipc_entry_lookup (space, dest_name);
+ if (entry == IE_NULL)
goto abort_async;
-
- entry = &space->is_table[index];
bits = entry->ie_bits;
- /* check generation number and type bit */
-
- if ((bits & (IE_BITS_GEN_MASK|MACH_PORT_TYPE_SEND)) !=
- (gen | MACH_PORT_TYPE_SEND))
+ /* check type bits */
+ if (IE_BITS_TYPE (bits) != MACH_PORT_TYPE_SEND)
goto abort_async;
- }
/* optimized ipc_right_copyin */
@@ -750,8 +740,6 @@ ipc_kmsg_copyin_header(
case MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND,
MACH_MSG_TYPE_MAKE_SEND_ONCE): {
- ipc_entry_num_t size;
- ipc_entry_t table;
ipc_entry_t entry;
ipc_entry_bits_t bits;
ipc_port_t dest_port, reply_port;
@@ -762,51 +750,28 @@ ipc_kmsg_copyin_header(
if (!space->is_active)
goto abort_request;
- size = space->is_table_size;
- table = space->is_table;
-
- /* optimized ipc_entry_lookup of dest_name */
-
- {
- mach_port_index_t index = MACH_PORT_INDEX(dest_name);
- mach_port_gen_t gen = MACH_PORT_GEN(dest_name);
-
- if (index >= size)
+ entry = ipc_entry_lookup (space, dest_name);
+ if (entry == IE_NULL)
goto abort_request;
-
- entry = &table[index];
bits = entry->ie_bits;
- /* check generation number and type bit */
-
- if ((bits & (IE_BITS_GEN_MASK|MACH_PORT_TYPE_SEND)) !=
- (gen | MACH_PORT_TYPE_SEND))
+ /* check type bits */
+ if (IE_BITS_TYPE (bits) != MACH_PORT_TYPE_SEND)
goto abort_request;
- }
assert(IE_BITS_UREFS(bits) > 0);
dest_port = (ipc_port_t) entry->ie_object;
assert(dest_port != IP_NULL);
- /* optimized ipc_entry_lookup of reply_name */
-
- {
- mach_port_index_t index = MACH_PORT_INDEX(reply_name);
- mach_port_gen_t gen = MACH_PORT_GEN(reply_name);
-
- if (index >= size)
+ entry = ipc_entry_lookup (space, reply_name);
+ if (entry == IE_NULL)
goto abort_request;
-
- entry = &table[index];
bits = entry->ie_bits;
- /* check generation number and type bit */
-
- if ((bits & (IE_BITS_GEN_MASK|MACH_PORT_TYPE_RECEIVE)) !=
- (gen | MACH_PORT_TYPE_RECEIVE))
+ /* check type bits */
+ if (IE_BITS_TYPE (bits) != MACH_PORT_TYPE_RECEIVE)
goto abort_request;
- }
reply_port = (ipc_port_t) entry->ie_object;
assert(reply_port != IP_NULL);
@@ -853,9 +818,6 @@ ipc_kmsg_copyin_header(
}
case MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE, 0): {
- mach_port_index_t index;
- mach_port_gen_t gen;
- ipc_entry_t table;
ipc_entry_t entry;
ipc_entry_bits_t bits;
ipc_port_t dest_port;
@@ -869,24 +831,13 @@ ipc_kmsg_copyin_header(
if (!space->is_active)
goto abort_reply;
- /* optimized ipc_entry_lookup */
-
- table = space->is_table;
-
- index = MACH_PORT_INDEX(dest_name);
- gen = MACH_PORT_GEN(dest_name);
-
- if (index >= space->is_table_size)
+ entry = ipc_entry_lookup (space, dest_name);
+ if (entry == IE_NULL)
goto abort_reply;
-
- entry = &table[index];
bits = entry->ie_bits;
- /* check generation number, collision bit, and type bit */
-
- if ((bits & (IE_BITS_GEN_MASK|IE_BITS_COLLISION|
- MACH_PORT_TYPE_SEND_ONCE)) !=
- (gen | MACH_PORT_TYPE_SEND_ONCE))
+ /* check and type bits */
+ if (IE_BITS_TYPE (bits) != MACH_PORT_TYPE_SEND_ONCE)
goto abort_reply;
/* optimized ipc_right_copyin */
@@ -910,12 +861,8 @@ ipc_kmsg_copyin_header(
assert(dest_port->ip_sorights > 0);
ip_unlock(dest_port);
- /* optimized ipc_entry_dealloc */
-
- entry->ie_next = table->ie_next;
- table->ie_next = index;
- entry->ie_bits = gen;
entry->ie_object = IO_NULL;
+ ipc_entry_dealloc (space, dest_name, entry);
is_write_unlock(space);
msg->msgh_bits = (MACH_MSGH_BITS_OTHER(mbits) |
@@ -1815,8 +1762,6 @@ ipc_kmsg_copyout_header(
case MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND,
MACH_MSG_TYPE_PORT_SEND_ONCE): {
- ipc_entry_t table;
- mach_port_index_t index;
ipc_entry_t entry;
ipc_port_t reply = (ipc_port_t) msg->msgh_local_port;
mach_port_t dest_name, reply_name;
@@ -1829,8 +1774,7 @@ ipc_kmsg_copyout_header(
break;
is_write_lock(space);
- if (!space->is_active ||
- ((index = (table = space->is_table)->ie_next) == 0)) {
+ if (!space->is_active || space->is_table->ie_next == 0) {
is_write_unlock(space);
break;
}
@@ -1860,11 +1804,14 @@ ipc_kmsg_copyout_header(
assert(reply->ip_sorights > 0);
ip_unlock(reply);
- /* optimized ipc_entry_get */
-
- entry = &table[index];
- table->ie_next = entry->ie_next;
- entry->ie_request = 0;
+ kern_return_t kr;
+ kr = ipc_entry_get (space, &reply_name, &entry);
+ if (kr) {
+ ip_unlock(reply);
+ ip_unlock(dest);
+ is_write_unlock(space);
+ break;
+ }
{
mach_port_gen_t gen;
@@ -1872,8 +1819,6 @@ ipc_kmsg_copyout_header(
assert((entry->ie_bits &~ IE_BITS_GEN_MASK) == 0);
gen = entry->ie_bits + IE_BITS_GEN_ONE;
- reply_name = MACH_PORT_MAKE(index, gen);
-
/* optimized ipc_right_copyout */
entry->ie_bits = gen | (MACH_PORT_TYPE_SEND_ONCE | 1);