X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/39236c6e673c41db228275375ab7fdb0f837b292..7e41aa883dd258f888d0470250eead40a53ef1f5:/osfmk/ipc/mach_debug.c diff --git a/osfmk/ipc/mach_debug.c b/osfmk/ipc/mach_debug.c index c97e27bcf..25c472e15 100644 --- a/osfmk/ipc/mach_debug.c +++ b/osfmk/ipc/mach_debug.c @@ -84,6 +84,8 @@ #include #include #include + +#include #endif /* @@ -186,6 +188,12 @@ mach_port_space_info( 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; @@ -213,7 +221,7 @@ mach_port_space_info( 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; } @@ -243,7 +251,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) { - 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); @@ -252,7 +260,7 @@ mach_port_space_info( } 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; } @@ -261,9 +269,12 @@ mach_port_space_info( /* 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, @@ -274,7 +285,7 @@ mach_port_space_info( 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; @@ -290,6 +301,56 @@ mach_port_space_info( } #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: @@ -415,7 +476,7 @@ mach_port_kobject( 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); @@ -430,9 +491,11 @@ mach_port_kobject( 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;