#include <ipc/ipc_hash.h>
#include <ipc/ipc_table.h>
#include <ipc/ipc_right.h>
+
+#include <security/mac_mach_internal.h>
#endif
/*
if (space == IS_NULL)
return KERN_INVALID_TASK;
+#if !(DEVELOPMENT | DEBUG)
+ const boolean_t dbg_ok = (mac_task_check_expose_task(kernel_task) == 0);
+#else
+ const boolean_t dbg_ok = TRUE;
+#endif
+
/* start with in-line memory */
table_size = 0;
if (table_size != table_size_needed) {
if (table_size != 0)
kmem_free(ipc_kernel_map, table_addr, table_size);
- kr = kmem_alloc(ipc_kernel_map, &table_addr, table_size_needed);
+ kr = kmem_alloc(ipc_kernel_map, &table_addr, table_size_needed, VM_KERN_MEMORY_IPC);
if (kr != KERN_SUCCESS) {
return KERN_RESOURCE_SHORTAGE;
}
iin->iin_type = IE_BITS_TYPE(bits);
if ((entry->ie_bits & MACH_PORT_TYPE_PORT_RIGHTS) != MACH_PORT_TYPE_NONE &&
entry->ie_request != IE_REQ_NONE) {
- ipc_port_t port = (ipc_port_t) entry->ie_object;
+ __IGNORE_WCASTALIGN(ipc_port_t port = (ipc_port_t) entry->ie_object);
assert(IP_VALID(port));
ip_lock(port);
}
iin->iin_urefs = IE_BITS_UREFS(bits);
- iin->iin_object = (natural_t)VM_KERNEL_ADDRPERM((uintptr_t)entry->ie_object);
+ iin->iin_object = (dbg_ok) ? (natural_t)VM_KERNEL_ADDRPERM((uintptr_t)entry->ie_object) : 0;
iin->iin_next = entry->ie_next;
iin->iin_hash = entry->ie_index;
}
/* prepare the table out-of-line data for return */
if (table_size > 0) {
- if (table_size > infop->iis_table_size * sizeof(ipc_info_name_t))
+ vm_size_t used_table_size;
+
+ used_table_size = infop->iis_table_size * sizeof(ipc_info_name_t);
+ if (table_size > used_table_size)
bzero((char *)&table_info[infop->iis_table_size],
- table_size - infop->iis_table_size * sizeof(ipc_info_name_t));
+ table_size - used_table_size);
kr = vm_map_unwire(
ipc_kernel_map,
FALSE);
assert(kr == KERN_SUCCESS);
kr = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)table_addr,
- (vm_map_size_t)table_size, TRUE, ©);
+ (vm_map_size_t)used_table_size, TRUE, ©);
assert(kr == KERN_SUCCESS);
*tablep = (ipc_info_name_t *)copy;
*tableCntp = infop->iis_table_size;
}
#endif /* MACH_IPC_DEBUG */
+/*
+ * Routine: mach_port_space_basic_info
+ * Purpose:
+ * Returns basic information about an IPC space.
+ * Conditions:
+ * Nothing locked.
+ * Returns:
+ * KERN_SUCCESS Returned information.
+ * KERN_FAILURE The call is not supported.
+ * KERN_INVALID_TASK The space is dead.
+ */
+
+#if !MACH_IPC_DEBUG
+kern_return_t
+mach_port_space_basic_info(
+ __unused ipc_space_t space,
+ __unused ipc_info_space_basic_t *infop)
+{
+ return KERN_FAILURE;
+}
+#else
+kern_return_t
+mach_port_space_basic_info(
+ ipc_space_t space,
+ ipc_info_space_basic_t *infop)
+{
+ if (space == IS_NULL)
+ return KERN_INVALID_TASK;
+
+
+ is_read_lock(space);
+ if (!is_active(space)) {
+ is_read_unlock(space);
+ return KERN_INVALID_TASK;
+ }
+
+ /* get the basic space info */
+ infop->iisb_genno_mask = MACH_PORT_NGEN(MACH_PORT_DEAD);
+ infop->iisb_table_size = space->is_table_size;
+ infop->iisb_table_next = space->is_table_next->its_size;
+ infop->iisb_table_inuse = space->is_table_size - space->is_table_free - 1;
+ infop->iisb_reserved[0] = 0;
+ infop->iisb_reserved[1] = 0;
+
+ is_read_unlock(space);
+
+ return KERN_SUCCESS;
+}
+#endif /* MACH_IPC_DEBUG */
+
/*
* Routine: mach_port_dnrequest_info
* Purpose:
return KERN_INVALID_RIGHT;
}
- port = (ipc_port_t) entry->ie_object;
+ __IGNORE_WCASTALIGN(port = (ipc_port_t) entry->ie_object);
assert(port != IP_NULL);
ip_lock(port);
kaddr = (mach_vm_address_t)port->ip_kobject;
ip_unlock(port);
+#if (DEVELOPMENT || DEBUG)
if (0 != kaddr && is_ipc_kobject(*typep))
- *addrp = VM_KERNEL_ADDRPERM(VM_KERNEL_UNSLIDE(kaddr));
+ *addrp = VM_KERNEL_UNSLIDE_OR_PERM(kaddr);
else
+#endif
*addrp = 0;
return KERN_SUCCESS;