X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/0a7de7458d150b5d4dffc935ba399be265ef0a1a..refs/heads/master:/osfmk/ipc/mach_debug.c diff --git a/osfmk/ipc/mach_debug.c b/osfmk/ipc/mach_debug.c index 19df67bf7..6ad851ac5 100644 --- a/osfmk/ipc/mach_debug.c +++ b/osfmk/ipc/mach_debug.c @@ -86,6 +86,7 @@ #include #include +#include #endif /* @@ -157,8 +158,8 @@ mach_port_get_srights( #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, @@ -167,7 +168,17 @@ mach_port_space_info( { 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, @@ -192,7 +203,7 @@ mach_port_space_info( } #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 @@ -256,7 +267,7 @@ mach_port_space_info( 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); @@ -305,6 +316,29 @@ mach_port_space_info( *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 */ /* @@ -452,26 +486,47 @@ mach_port_dnrequest_info( #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; @@ -488,7 +543,7 @@ mach_port_kobject( 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); @@ -500,19 +555,89 @@ mach_port_kobject( } *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: @@ -533,8 +658,8 @@ mach_port_kobject( #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) @@ -542,6 +667,13 @@ mach_port_kernel_object( 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, @@ -556,6 +688,27 @@ mach_port_kernel_object( *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)