--- Gnu-Mach/kern/ipc_tt.c 2020/09/02 04:42:46 1.1.1.3 +++ Gnu-Mach/kern/ipc_tt.c 2020/09/02 04:49:54 1.1.1.6 @@ -29,14 +29,14 @@ * Task and thread related IPC functions. */ -#include - #include #include #include #include #include #include +#include +#include #include #include #include @@ -72,7 +72,7 @@ ipc_task_init( int i; - kr = ipc_space_create(&ipc_table_entries[0], &space); + kr = ipc_space_create(&space); if (kr != KERN_SUCCESS) panic("ipc_task_init"); @@ -213,8 +213,7 @@ ipc_task_terminate( */ void -ipc_thread_init(thread) - thread_t thread; +ipc_thread_init(thread_t thread) { ipc_port_t kport; @@ -232,39 +231,6 @@ ipc_thread_init(thread) thread->ith_mig_reply = MACH_PORT_NULL; thread->ith_rpc_reply = IP_NULL; - -#if MACH_IPC_COMPAT - { - ipc_space_t space = thread->task->itk_space; - ipc_port_t port; - mach_port_t name; - kern_return_t kr; - - kr = ipc_port_alloc_compat(space, &name, &port); - if (kr != KERN_SUCCESS) - panic("ipc_thread_init"); - /* port is locked and active */ - - /* - * Now we have a reply port. We need to make a naked - * send right to stash in ith_reply. We can't use - * ipc_port_make_send, because we can't unlock the port - * before making the right. Also we don't want to - * increment ip_mscount. The net effect of all this - * is the same as doing - * ipc_port_alloc_kernel get the port - * ipc_port_make_send make the send right - * ipc_object_copyin_from_kernel grab receive right - * ipc_object_copyout_compat and give to user - */ - - port->ip_srights++; - ip_reference(port); - ip_unlock(port); - - thread->ith_reply = port; - } -#endif /* MACH_IPC_COMPAT */ } /* @@ -276,8 +242,7 @@ ipc_thread_init(thread) */ void -ipc_thread_enable(thread) - thread_t thread; +ipc_thread_enable(thread_t thread) { ipc_port_t kport; @@ -297,8 +262,7 @@ ipc_thread_enable(thread) */ void -ipc_thread_disable(thread) - thread_t thread; +ipc_thread_disable(thread_t thread) { ipc_port_t kport; @@ -319,8 +283,7 @@ ipc_thread_disable(thread) */ void -ipc_thread_terminate(thread) - thread_t thread; +ipc_thread_terminate(thread_t thread) { ipc_port_t kport; @@ -345,43 +308,6 @@ ipc_thread_terminate(thread) if (IP_VALID(thread->ith_exception)) ipc_port_release_send(thread->ith_exception); -#if MACH_IPC_COMPAT - if (IP_VALID(thread->ith_reply)) { - ipc_space_t space = thread->task->itk_space; - ipc_port_t port = thread->ith_reply; - ipc_entry_t entry; - mach_port_t name; - - /* destroy any rights the task may have for the port */ - - is_write_lock(space); - if (space->is_active && - ipc_right_reverse(space, (ipc_object_t) port, - &name, &entry)) { - /* reply port is locked and active */ - ip_unlock(port); - - (void) ipc_right_destroy(space, name, entry); - /* space is unlocked */ - } else - is_write_unlock(space); - - ipc_port_release_send(port); - } - - /* - * Note we do *not* destroy any rights the space may have - * for the thread's kernel port. The old IPC code did this, - * to avoid generating a notification when the port is - * destroyed. However, this isn't a good idea when - * the kernel port is interposed, because then it doesn't - * happen, exposing the interposition to the task. - * Because we don't need the efficiency hack, I flushed - * this behaviour, introducing a small incompatibility - * with the old IPC code. - */ -#endif /* MACH_IPC_COMPAT */ - /* destroy the kernel port */ ipc_port_dealloc_kernel(kport); @@ -457,9 +383,9 @@ retrieve_thread_self(thread) ipc_port_t retrieve_task_self_fast( - register task_t task) + task_t task) { - register ipc_port_t port; + ipc_port_t port; assert(task == current_task()); @@ -494,10 +420,9 @@ retrieve_task_self_fast( */ ipc_port_t -retrieve_thread_self_fast(thread) - register thread_t thread; +retrieve_thread_self_fast(thread_t thread) { - register ipc_port_t port; + ipc_port_t port; assert(thread == current_thread()); @@ -608,7 +533,7 @@ mach_task_self(void) */ mach_port_t -mach_thread_self() +mach_thread_self(void) { thread_t thread = current_thread(); task_t task = thread->task; @@ -645,163 +570,6 @@ mach_reply_port(void) return name; } -#if MACH_IPC_COMPAT - -/* - * Routine: retrieve_task_notify - * Purpose: - * Return a reference (or null) for - * the task's notify port. - * Conditions: - * Nothing locked. - */ - -ipc_port_t -retrieve_task_notify(task) - task_t task; -{ - ipc_space_t space = task->itk_space; - ipc_port_t port; - - is_read_lock(space); - if (space->is_active) { - port = space->is_notify; - if (IP_VALID(port)) - ipc_port_reference(port); - } else - port = IP_NULL; - is_read_unlock(space); - - return port; -} - -/* - * Routine: retrieve_thread_reply - * Purpose: - * Return a reference (or null) for - * the thread's reply port. - * Conditions: - * Nothing locked. - */ - -ipc_port_t -retrieve_thread_reply(thread) - thread_t thread; -{ - ipc_port_t port; - - ith_lock(thread); - if (thread->ith_self != IP_NULL) { - port = thread->ith_reply; - if (IP_VALID(port)) - ipc_port_reference(port); - } else - port = IP_NULL; - ith_unlock(thread); - - return port; -} - -/* - * Routine: task_self [mach trap] - * Purpose: - * Give the caller send rights for his task port. - * If new, the send right is marked with IE_BITS_COMPAT. - * Conditions: - * Nothing locked. - * Returns: - * MACH_PORT_NULL if there are any resource failures - * or other errors. - */ - -port_name_t -task_self() -{ - task_t task = current_task(); - ipc_port_t sright; - mach_port_t name; - - sright = retrieve_task_self_fast(task); - name = ipc_port_copyout_send_compat(sright, task->itk_space); - return (port_name_t) name; -} - -/* - * Routine: task_notify [mach trap] - * Purpose: - * Give the caller the name of his own notify port. - * Conditions: - * Nothing locked. - * Returns: - * MACH_PORT_NULL if there isn't a notify port, - * if it is dead, or if the caller doesn't hold - * receive rights for it. - */ - -port_name_t -task_notify() -{ - task_t task = current_task(); - ipc_port_t notify; - mach_port_t name; - - notify = retrieve_task_notify(task); - name = ipc_port_copyout_receiver(notify, task->itk_space); - return (port_name_t) name; -} - -/* - * Routine: thread_self [mach trap] - * Purpose: - * Give the caller send rights for his own thread port. - * If new, the send right is marked with IE_BITS_COMPAT. - * Conditions: - * Nothing locked. - * Returns: - * MACH_PORT_NULL if there are any resource failures - * or other errors. - */ - -port_name_t -thread_self() -{ - thread_t thread = current_thread(); - task_t task = thread->task; - ipc_port_t sright; - mach_port_t name; - - sright = retrieve_thread_self_fast(thread); - name = ipc_port_copyout_send_compat(sright, task->itk_space); - return (port_name_t) name; -} - -/* - * Routine: thread_reply [mach trap] - * Purpose: - * Give the caller the name of his own reply port. - * Conditions: - * Nothing locked. - * Returns: - * MACH_PORT_NULL if there isn't a reply port, - * if it is dead, or if the caller doesn't hold - * receive rights for it. - */ - -port_name_t -thread_reply() -{ - task_t task = current_task(); - thread_t thread = current_thread(); - ipc_port_t reply; - mach_port_t name; - - reply = retrieve_thread_reply(thread); - name = ipc_port_copyout_receiver(reply, task->itk_space); - return (port_name_t) name; -} - -#endif /* MACH_IPC_COMPAT */ - /* * Routine: task_get_special_port [kernel call] * Purpose: @@ -829,24 +597,6 @@ task_get_special_port( return KERN_INVALID_ARGUMENT; switch (which) { -#if MACH_IPC_COMPAT - case TASK_NOTIFY_PORT: { - ipc_space_t space = task->itk_space; - - is_read_lock(space); - if (!space->is_active) { - is_read_unlock(space); - return KERN_FAILURE; - } - - port = ipc_port_copy_send(space->is_notify); - is_read_unlock(space); - - *portp = port; - return KERN_SUCCESS; - } -#endif /* MACH_IPC_COMPAT */ - case TASK_KERNEL_PORT: whichp = &task->itk_sself; break; @@ -893,9 +643,9 @@ task_get_special_port( kern_return_t task_set_special_port( - task_t task, - int which, - ipc_port_t port) + task_t task, + int which, + const ipc_port_t port) { ipc_port_t *whichp; ipc_port_t old; @@ -904,26 +654,6 @@ task_set_special_port( return KERN_INVALID_ARGUMENT; switch (which) { -#if MACH_IPC_COMPAT - case TASK_NOTIFY_PORT: { - ipc_space_t space = task->itk_space; - - is_write_lock(space); - if (!space->is_active) { - is_write_unlock(space); - return KERN_FAILURE; - } - - old = space->is_notify; - space->is_notify = port; - is_write_unlock(space); - - if (IP_VALID(old)) - ipc_port_release_send(old); - return KERN_SUCCESS; - } -#endif /* MACH_IPC_COMPAT */ - case TASK_KERNEL_PORT: whichp = &task->itk_sself; break; @@ -970,10 +700,10 @@ task_set_special_port( */ kern_return_t -thread_get_special_port(thread, which, portp) - thread_t thread; - int which; - ipc_port_t *portp; +thread_get_special_port( + thread_t thread, + int which, + ipc_port_t *portp) { ipc_port_t *whichp; ipc_port_t port; @@ -982,12 +712,6 @@ thread_get_special_port(thread, which, p return KERN_INVALID_ARGUMENT; switch (which) { -#if MACH_IPC_COMPAT - case THREAD_REPLY_PORT: - whichp = &thread->ith_reply; - break; -#endif /* MACH_IPC_COMPAT */ - case THREAD_KERNEL_PORT: whichp = &thread->ith_sself; break; @@ -1029,10 +753,10 @@ thread_get_special_port(thread, which, p */ kern_return_t -thread_set_special_port(thread, which, port) - thread_t thread; - int which; - ipc_port_t port; +thread_set_special_port( + thread_t thread, + int which, + ipc_port_t port) { ipc_port_t *whichp; ipc_port_t old; @@ -1041,12 +765,6 @@ thread_set_special_port(thread, which, p return KERN_INVALID_ARGUMENT; switch (which) { -#if MACH_IPC_COMPAT - case THREAD_REPLY_PORT: - whichp = &thread->ith_reply; - break; -#endif /* MACH_IPC_COMPAT */ - case THREAD_KERNEL_PORT: whichp = &thread->ith_sself; break; @@ -1111,7 +829,7 @@ mach_ports_register( */ for (i = 0; i < portsCnt; i++) - ports[i] = memory[i]; + ports[i] = (ipc_port_t)memory[i]; for (; i < TASK_PORT_REGISTER_MAX; i++) ports[i] = IP_NULL; @@ -1167,10 +885,10 @@ mach_ports_register( */ kern_return_t -mach_ports_lookup(task, portsp, portsCnt) - task_t task; - ipc_port_t **portsp; - mach_msg_type_number_t *portsCnt; +mach_ports_lookup( + task_t task, + ipc_port_t **portsp, + mach_msg_type_number_t *portsCnt) { vm_offset_t memory; vm_size_t size; @@ -1280,8 +998,7 @@ convert_port_to_space( */ vm_map_t -convert_port_to_map(port) - ipc_port_t port; +convert_port_to_map(ipc_port_t port) { vm_map_t map = VM_MAP_NULL; @@ -1309,8 +1026,7 @@ convert_port_to_map(port) */ thread_t -convert_port_to_thread(port) - ipc_port_t port; +convert_port_to_thread(ipc_port_t port) { thread_t thread = THREAD_NULL; @@ -1338,8 +1054,7 @@ convert_port_to_thread(port) */ ipc_port_t -convert_task_to_port(task) - task_t task; +convert_task_to_port(task_t task) { ipc_port_t port; @@ -1365,8 +1080,7 @@ convert_task_to_port(task) */ ipc_port_t -convert_thread_to_port(thread) - thread_t thread; +convert_thread_to_port(thread_t thread) { ipc_port_t port; @@ -1390,8 +1104,7 @@ convert_thread_to_port(thread) */ void -space_deallocate(space) - ipc_space_t space; +space_deallocate(ipc_space_t space) { if (space != IS_NULL) is_release(space);