#include <ipc/ipc_right.h>
#include <security/mac_mach_internal.h>
+#include <device/device_types.h>
#endif
/*
#if !MACH_IPC_DEBUG
kern_return_t
-mach_port_space_info(
- __unused ipc_space_t space,
+mach_port_space_info_from_user(
+ __unused mach_port_t port,
__unused ipc_info_space_t *infop,
__unused ipc_info_name_array_t *tablep,
__unused mach_msg_type_number_t *tableCntp,
{
return KERN_FAILURE;
}
+
#else
+kern_return_t
+mach_port_space_info(
+ ipc_space_t space,
+ ipc_info_space_t *infop,
+ ipc_info_name_array_t *tablep,
+ mach_msg_type_number_t *tableCntp,
+ __unused ipc_info_tree_name_array_t *treep,
+ __unused mach_msg_type_number_t *treeCntp);
+
kern_return_t
mach_port_space_info(
ipc_space_t space,
}
#if !(DEVELOPMENT || DEBUG) && CONFIG_MACF
- const boolean_t dbg_ok = (mac_task_check_expose_task(kernel_task) == 0);
+ const boolean_t dbg_ok = (mac_task_check_expose_task(kernel_task, TASK_FLAVOR_CONTROL) == 0);
#else
const boolean_t dbg_ok = TRUE;
#endif
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) {
- __IGNORE_WCASTALIGN(ipc_port_t port = (ipc_port_t) entry->ie_object);
+ ipc_port_t port = ip_object_to_port(entry->ie_object);
assert(IP_VALID(port));
ip_lock(port);
*treeCntp = 0;
return KERN_SUCCESS;
}
+
+kern_return_t
+mach_port_space_info_from_user(
+ mach_port_t port,
+ ipc_info_space_t *infop,
+ ipc_info_name_array_t *tablep,
+ mach_msg_type_number_t *tableCntp,
+ __unused ipc_info_tree_name_array_t *treep,
+ __unused mach_msg_type_number_t *treeCntp)
+{
+ kern_return_t kr;
+
+ ipc_space_t space = convert_port_to_space_check_type(port, NULL, TASK_FLAVOR_READ, FALSE);
+
+ if (space == IPC_SPACE_NULL) {
+ return KERN_INVALID_ARGUMENT;
+ }
+
+ kr = mach_port_space_info(space, infop, tablep, tableCntp, treep, treeCntp);
+
+ ipc_space_release(space);
+ return kr;
+}
#endif /* MACH_IPC_DEBUG */
/*
#if !MACH_IPC_DEBUG
kern_return_t
-mach_port_kobject(
- __unused ipc_space_t space,
+mach_port_kobject_from_user(
+ __unused mach_port_t port,
__unused mach_port_name_t name,
__unused natural_t *typep,
__unused mach_vm_address_t *addrp)
{
return KERN_FAILURE;
}
+
+kern_return_t
+mach_port_kobject_description_from_user(
+ __unused mach_port_t port,
+ __unused mach_port_name_t name,
+ __unused natural_t *typep,
+ __unused mach_vm_address_t *addrp,
+ __unused kobject_description_t des)
+{
+ return KERN_FAILURE;
+}
#else
kern_return_t
-mach_port_kobject(
+mach_port_kobject_description(
ipc_space_t space,
mach_port_name_t name,
natural_t *typep,
- mach_vm_address_t *addrp)
+ mach_vm_address_t *addrp,
+ kobject_description_t desc);
+
+kern_return_t
+mach_port_kobject_description(
+ ipc_space_t space,
+ mach_port_name_t name,
+ natural_t *typep,
+ mach_vm_address_t *addrp,
+ kobject_description_t desc)
{
ipc_entry_t entry;
ipc_port_t port;
kern_return_t kr;
mach_vm_address_t kaddr;
+ io_object_t obj = NULL;
if (space == IS_NULL) {
return KERN_INVALID_TASK;
return KERN_INVALID_RIGHT;
}
- __IGNORE_WCASTALIGN(port = (ipc_port_t) entry->ie_object);
+ port = ip_object_to_port(entry->ie_object);
assert(port != IP_NULL);
ip_lock(port);
}
*typep = (unsigned int) ip_kotype(port);
- kaddr = (mach_vm_address_t)port->ip_kobject;
- ip_unlock(port);
+ kaddr = (mach_vm_address_t)ip_get_kobject(port);
+ *addrp = 0;
+
+ if (desc) {
+ *desc = '\0';
+ switch (ip_kotype(port)) {
+ case IKOT_IOKIT_OBJECT:
+ case IKOT_IOKIT_CONNECT:
+ case IKOT_IOKIT_IDENT:
+ case IKOT_UEXT_OBJECT:
+ obj = (io_object_t) kaddr;
+ iokit_add_reference(obj, IKOT_IOKIT_OBJECT);
+ break;
+ default:
+ break;
+ }
+ }
#if (DEVELOPMENT || DEBUG)
- if (0 != kaddr && is_ipc_kobject(*typep)) {
- *addrp = VM_KERNEL_UNSLIDE_OR_PERM(kaddr);
- } else
+ *addrp = VM_KERNEL_UNSLIDE_OR_PERM(kaddr);
#endif
- *addrp = 0;
+
+ ip_unlock(port);
+
+ if (obj) {
+ iokit_port_object_description(obj, desc);
+ iokit_remove_reference(obj);
+ }
return KERN_SUCCESS;
}
+
+kern_return_t
+mach_port_kobject(
+ ipc_space_t space,
+ mach_port_name_t name,
+ natural_t *typep,
+ mach_vm_address_t *addrp);
+
+kern_return_t
+mach_port_kobject(
+ ipc_space_t space,
+ mach_port_name_t name,
+ natural_t *typep,
+ mach_vm_address_t *addrp)
+{
+ return mach_port_kobject_description(space, name, typep, addrp, NULL);
+}
+
+kern_return_t
+mach_port_kobject_description_from_user(
+ mach_port_t port,
+ mach_port_name_t name,
+ natural_t *typep,
+ mach_vm_address_t *addrp,
+ kobject_description_t desc)
+{
+ kern_return_t kr;
+
+ ipc_space_t space = convert_port_to_space_check_type(port, NULL, TASK_FLAVOR_READ, FALSE);
+
+ if (space == IPC_SPACE_NULL) {
+ return KERN_INVALID_ARGUMENT;
+ }
+
+ kr = mach_port_kobject_description(space, name, typep, addrp, desc);
+
+ ipc_space_release(space);
+ return kr;
+}
+
+kern_return_t
+mach_port_kobject_from_user(
+ mach_port_t port,
+ mach_port_name_t name,
+ natural_t *typep,
+ mach_vm_address_t *addrp)
+{
+ return mach_port_kobject_description_from_user(port, name, typep, addrp, NULL);
+}
+
#endif /* MACH_IPC_DEBUG */
+
/*
* Routine: mach_port_kernel_object [Legacy kernel call]
* Purpose:
#if !MACH_IPC_DEBUG
kern_return_t
-mach_port_kernel_object(
- __unused ipc_space_t space,
+mach_port_kernel_object_from_user(
+ __unused mach_port_t port,
__unused mach_port_name_t name,
__unused unsigned int *typep,
__unused unsigned int *addrp)
return KERN_FAILURE;
}
#else
+kern_return_t
+mach_port_kernel_object(
+ ipc_space_t space,
+ mach_port_name_t name,
+ unsigned int *typep,
+ unsigned int *addrp);
+
kern_return_t
mach_port_kernel_object(
ipc_space_t space,
*addrp = (unsigned int) addr;
return kr;
}
+
+kern_return_t
+mach_port_kernel_object_from_user(
+ mach_port_t port,
+ mach_port_name_t name,
+ unsigned int *typep,
+ unsigned int *addrp)
+{
+ kern_return_t kr;
+
+ ipc_space_t space = convert_port_to_space_check_type(port, NULL, TASK_FLAVOR_READ, FALSE);
+
+ if (space == IPC_SPACE_NULL) {
+ return KERN_INVALID_ARGUMENT;
+ }
+
+ kr = mach_port_kernel_object(space, name, typep, addrp);
+
+ ipc_space_release(space);
+ return kr;
+}
#endif /* MACH_IPC_DEBUG */
#if (DEVELOPMENT || DEBUG)