-upl_t
-convert_port_to_upl(
- ipc_port_t port)
-{
- upl_t upl;
-
- ip_lock(port);
- if (!ip_active(port) || (ip_kotype(port) != IKOT_UPL)) {
- ip_unlock(port);
- return (upl_t)NULL;
- }
- upl = (upl_t) port->ip_kobject;
- ip_unlock(port);
- upl_lock(upl);
- upl->ref_count+=1;
- upl_unlock(upl);
- return upl;
-}
-
-/*
- * Routine: convert_port_entry_to_map
- * Purpose:
- * Convert from a port specifying an entry or a task
- * to a map. Doesn't consume the port ref; produces a map ref,
- * which may be null. Unlike convert_port_to_map, the
- * port may be task or a named entry backed.
- * Conditions:
- * Nothing locked.
- */
-
-
-vm_map_t
-convert_port_entry_to_map(
- ipc_port_t port)
-{
- task_t task;
- vm_map_t map;
- vm_named_entry_t named_entry;
-
- if(IP_VALID(port) && (ip_kotype(port) == IKOT_NAMED_ENTRY)) {
- while(TRUE) {
- ip_lock(port);
- if(ip_active(port) && (ip_kotype(port)
- == IKOT_NAMED_ENTRY)) {
- named_entry =
- (vm_named_entry_t)port->ip_kobject;
- if (!(mutex_try(&(named_entry)->Lock))) {
- ip_unlock(port);
- mutex_pause();
- continue;
- }
- named_entry->ref_count++;
- mutex_unlock(&(named_entry)->Lock);
- ip_unlock(port);
- if ((named_entry->is_sub_map) &&
- (named_entry->protection
- & VM_PROT_WRITE)) {
- map = named_entry->backing.map;
- } else {
- mach_destroy_memory_entry(port);
- return VM_MAP_NULL;
- }
- vm_map_reference_swap(map);
- mach_destroy_memory_entry(port);
- break;
- }
- else
- return VM_MAP_NULL;
- }
- } else {
- task_t task;
-
- task = convert_port_to_locked_task(port);
-
- if (task == TASK_NULL)
- return VM_MAP_NULL;
-
- if (!task->active) {
- task_unlock(task);
- return VM_MAP_NULL;
- }
-
- map = task->map;
- vm_map_reference_swap(map);
- task_unlock(task);
- }
-
- return map;
-}
-
-/*
- * Routine: convert_port_entry_to_object
- * Purpose:
- * Convert from a port specifying a named entry to an
- * object. Doesn't consume the port ref; produces a map ref,
- * which may be null.
- * Conditions:
- * Nothing locked.
- */
-
-
-vm_object_t
-convert_port_entry_to_object(
- ipc_port_t port)
-{
- vm_object_t object;
- vm_named_entry_t named_entry;
-
- if(IP_VALID(port) && (ip_kotype(port) == IKOT_NAMED_ENTRY)) {
- while(TRUE) {
- ip_lock(port);
- if(ip_active(port) && (ip_kotype(port)
- == IKOT_NAMED_ENTRY)) {
- named_entry =
- (vm_named_entry_t)port->ip_kobject;
- if (!(mutex_try(&(named_entry)->Lock))) {
- ip_unlock(port);
- mutex_pause();
- continue;
- }
- named_entry->ref_count++;
- mutex_unlock(&(named_entry)->Lock);
- ip_unlock(port);
- if ((!named_entry->is_sub_map) &&
- (named_entry->protection
- & VM_PROT_WRITE)) {
- object = named_entry->object;
- } else {
- mach_destroy_memory_entry(port);
- return (vm_object_t)NULL;
- }
- vm_object_reference(named_entry->object);
- mach_destroy_memory_entry(port);
- break;
- }
- else
- return (vm_object_t)NULL;
- }
- } else {
- return (vm_object_t)NULL;
- }
-
- return object;
-}
-