--- Gnu-Mach/kern/ipc_mig.c 2020/09/02 04:42:50 1.1.1.2 +++ Gnu-Mach/kern/ipc_mig.c 2020/09/02 04:49:59 1.1.1.5 @@ -24,17 +24,20 @@ * the rights to redistribute these changes. */ -#include - #include #include #include #include +#include #include +#include #include +#include #include #include #include +#include +#include #include #include #include @@ -46,8 +49,10 @@ #include #include #include +#include +#include #include - +#include /* * Routine: mach_msg_send_from_kernel @@ -87,129 +92,13 @@ mach_msg_send_from_kernel( mach_msg_return_t mach_msg_rpc_from_kernel(msg, send_size, reply_size) - mach_msg_header_t *msg; + const mach_msg_header_t *msg; mach_msg_size_t send_size; mach_msg_size_t reply_size; { panic("mach_msg_rpc_from_kernel"); /*XXX*/ } -#if NORMA_VM -/* - * Routine: mach_msg_rpc_from_kernel - * Purpose: - * Send a message from the kernel and receive a reply. - * Uses ith_rpc_reply for the reply port. - * - * This is used by the client side of KernelUser interfaces - * to implement Routines. - * Conditions: - * Nothing locked. - * Returns: - * MACH_MSG_SUCCESS Sent the message. - * MACH_RCV_PORT_DIED The reply port was deallocated. - */ - -mach_msg_return_t -mach_msg_rpc_from_kernel( - mach_msg_header_t *msg, - mach_msg_size_t send_size, - mach_msg_size_t rcv_size) -{ - ipc_thread_t self = current_thread(); - ipc_port_t reply; - ipc_kmsg_t kmsg; - mach_port_seqno_t seqno; - mach_msg_return_t mr; - - assert(MACH_PORT_VALID(msg->msgh_remote_port)); - assert(msg->msgh_local_port == MACH_PORT_NULL); - - mr = ipc_kmsg_get_from_kernel(msg, send_size, &kmsg); - if (mr != MACH_MSG_SUCCESS) - panic("mach_msg_rpc_from_kernel"); - - ipc_kmsg_copyin_from_kernel(kmsg); - - ith_lock(self); - assert(self->ith_self != IP_NULL); - - reply = self->ith_rpc_reply; - if (reply == IP_NULL) { - ith_unlock(self); - reply = ipc_port_alloc_reply(); - ith_lock(self); - if ((reply == IP_NULL) || - (self->ith_rpc_reply != IP_NULL)) - panic("mach_msg_rpc_from_kernel"); - self->ith_rpc_reply = reply; - } - - /* insert send-once right for the reply port */ - kmsg->ikm_header.msgh_local_port = - (mach_port_t) ipc_port_make_sonce(reply); - - ipc_port_reference(reply); - ith_unlock(self); - - ipc_mqueue_send_always(kmsg); - - for (;;) { - ipc_mqueue_t mqueue; - - ip_lock(reply); - if (!ip_active(reply)) { - ip_unlock(reply); - ipc_port_release(reply); - return MACH_RCV_PORT_DIED; - } - - assert(reply->ip_pset == IPS_NULL); - mqueue = &reply->ip_messages; - imq_lock(mqueue); - ip_unlock(reply); - - mr = ipc_mqueue_receive(mqueue, MACH_MSG_OPTION_NONE, - MACH_MSG_SIZE_MAX, - MACH_MSG_TIMEOUT_NONE, - FALSE, IMQ_NULL_CONTINUE, - &kmsg, &seqno); - /* mqueue is unlocked */ - if (mr == MACH_MSG_SUCCESS) - break; - - assert((mr == MACH_RCV_INTERRUPTED) || - (mr == MACH_RCV_PORT_DIED)); - - while (thread_should_halt(self)) { - /* don't terminate while holding a reference */ - if (self->ast & AST_TERMINATE) - ipc_port_release(reply); - thread_halt_self(); - } - } - ipc_port_release(reply); - - kmsg->ikm_header.msgh_seqno = seqno; - - if (rcv_size < kmsg->ikm_header.msgh_size) { - ipc_kmsg_copyout_dest(kmsg, ipc_space_reply); - ipc_kmsg_put_to_kernel(msg, kmsg, kmsg->ikm_header.msgh_size); - return MACH_RCV_TOO_LARGE; - } - - /* - * We want to preserve rights and memory in reply! - * We don't have to put them anywhere; just leave them - * as they are. - */ - - ipc_kmsg_copyout_to_kernel(kmsg, ipc_space_reply); - ipc_kmsg_put_to_kernel(msg, kmsg, kmsg->ikm_header.msgh_size); - return MACH_MSG_SUCCESS; -} -#endif /* NORMA_VM */ - /* * Routine: mach_msg_abort_rpc * Purpose: @@ -221,8 +110,7 @@ mach_msg_rpc_from_kernel( */ void -mach_msg_abort_rpc(thread) - ipc_thread_t thread; +mach_msg_abort_rpc(ipc_thread_t thread) { ipc_port_t reply = IP_NULL; @@ -252,14 +140,14 @@ mach_msg_abort_rpc(thread) */ mach_msg_return_t -mach_msg(msg, option, send_size, rcv_size, rcv_name, time_out, notify) - mach_msg_header_t *msg; - mach_msg_option_t option; - mach_msg_size_t send_size; - mach_msg_size_t rcv_size; - mach_port_t rcv_name; - mach_msg_timeout_t time_out; - mach_port_t notify; +mach_msg( + mach_msg_header_t *msg, + mach_msg_option_t option, + mach_msg_size_t send_size, + mach_msg_size_t rcv_size, + mach_port_t rcv_name, + mach_msg_timeout_t time_out, + mach_port_t notify) { ipc_space_t space = current_space(); vm_map_t map = current_map(); @@ -383,10 +271,10 @@ mig_put_reply_port( /* * mig_strncpy.c - by Joshua Block * - * mig_strncp -- Bounded string copy. Does what the library routine strncpy - * OUGHT to do: Copies the (null terminated) string in src into dest, a - * buffer of length len. Assures that the copy is still null terminated - * and doesn't overflow the buffer, truncating the copy if necessary. + * mig_strncpy -- Bounded string copy. Does what the library routine + * strncpy does: Copies the (null terminated) string in src into dest, + * a buffer of length len. Returns the length of the destination + * string excluding the terminating null. * * Parameters: * @@ -396,37 +284,44 @@ mig_put_reply_port( * * len - Length of destination buffer. */ -void mig_strncpy(dest, src, len) -char *dest, *src; -int len; +vm_size_t +mig_strncpy(dest, src, len) + char *dest; + const char *src; + int len; { - int i; + char *dest_ = dest; + int i; - if (len <= 0) - return; + if (len <= 0) + return 0; - for (i=1; iis_active); \ \ - if ((index >= space->is_table_size) || \ - (((entry = &space->is_table[index])->ie_bits & \ - (IE_BITS_GEN_MASK|MACH_PORT_TYPE_SEND)) != \ - (MACH_PORT_GEN(name) | MACH_PORT_TYPE_SEND))) { \ - is_read_unlock(space); \ + entry = ipc_entry_lookup (space, name); \ + if (entry == IE_NULL) { \ + is_read_unlock (space); \ + abort; \ + } \ + \ + if (IE_BITS_TYPE (entry->ie_bits) != MACH_PORT_TYPE_SEND) { \ + is_read_unlock (space); \ abort; \ } \ \ @@ -439,11 +334,10 @@ MACRO_BEGIN \ MACRO_END device_t -port_name_to_device(name) - mach_port_t name; +port_name_to_device(mach_port_t name) { - register ipc_port_t port; - register device_t device; + ipc_port_t port; + device_t device; fast_send_right_lookup(name, port, goto abort); /* port is locked */ @@ -483,17 +377,16 @@ port_name_to_device(name) } thread_t -port_name_to_thread(name) - mach_port_t name; +port_name_to_thread(mach_port_t name) { - register ipc_port_t port; + ipc_port_t port; fast_send_right_lookup(name, port, goto abort); /* port is locked */ if (ip_active(port) && (ip_kotype(port) == IKOT_THREAD)) { - register thread_t thread; + thread_t thread; thread = (thread_t) port->ip_kobject; assert(thread != THREAD_NULL); @@ -529,17 +422,16 @@ port_name_to_thread(name) } task_t -port_name_to_task(name) - mach_port_t name; +port_name_to_task(mach_port_t name) { - register ipc_port_t port; + ipc_port_t port; fast_send_right_lookup(name, port, goto abort); /* port is locked */ if (ip_active(port) && (ip_kotype(port) == IKOT_TASK)) { - register task_t task; + task_t task; task = (task_t) port->ip_kobject; assert(task != TASK_NULL); @@ -580,14 +472,14 @@ vm_map_t port_name_to_map( mach_port_t name) { - register ipc_port_t port; + ipc_port_t port; fast_send_right_lookup(name, port, goto abort); /* port is locked */ if (ip_active(port) && (ip_kotype(port) == IKOT_TASK)) { - register vm_map_t map; + vm_map_t map; map = ((task_t) port->ip_kobject)->map; assert(map != VM_MAP_NULL); @@ -625,17 +517,16 @@ port_name_to_map( } ipc_space_t -port_name_to_space(name) - mach_port_t name; +port_name_to_space(mach_port_t name) { - register ipc_port_t port; + ipc_port_t port; fast_send_right_lookup(name, port, goto abort); /* port is locked */ if (ip_active(port) && (ip_kotype(port) == IKOT_TASK)) { - register ipc_space_t space; + ipc_space_t space; space = ((task_t) port->ip_kobject)->itk_space; assert(space != IS_NULL); @@ -681,12 +572,11 @@ port_name_to_space(name) * AARGH! */ -kern_return_t thread_get_state_KERNEL(thread_port, flavor, - old_state, old_state_count) - mach_port_t thread_port; /* port right for thread */ - int flavor; - thread_state_t old_state; /* pointer to OUT array */ - natural_t *old_state_count; /* IN/OUT */ +kern_return_t thread_get_state_KERNEL( + mach_port_t thread_port, /* port right for thread */ + int flavor, + thread_state_t old_state, /* pointer to OUT array */ + natural_t *old_state_count) /* IN/OUT */ { thread_t thread; kern_return_t result; @@ -698,12 +588,11 @@ kern_return_t thread_get_state_KERNEL(th return result; } -kern_return_t thread_set_state_KERNEL(thread_port, flavor, - new_state, new_state_count) - mach_port_t thread_port; /* port right for thread */ - int flavor; - thread_state_t new_state; - natural_t new_state_count; +kern_return_t thread_set_state_KERNEL( + mach_port_t thread_port, /* port right for thread */ + int flavor, + thread_state_t new_state, + natural_t new_state_count) { thread_t thread; kern_return_t result; @@ -725,7 +614,7 @@ kern_return_t thread_set_state_KERNEL(th * knows to fall back on an RPC. For other return values, it won't * retry with an RPC. The retry might get a different (incorrect) rc. * Return values are only set (and should only be set, with copyout) - * on successfull calls. + * on successful calls. */ kern_return_t @@ -762,12 +651,12 @@ syscall_vm_map( } else port = (ipc_port_t) memory_object; - copyin((char *)address, (char *)&addr, sizeof(vm_offset_t)); + copyin(address, &addr, sizeof(vm_offset_t)); result = vm_map(map, &addr, size, mask, anywhere, port, offset, copy, cur_protection, max_protection, inheritance); if (result == KERN_SUCCESS) - copyout((char *)&addr, (char *)address, sizeof(vm_offset_t)); + copyout(&addr, address, sizeof(vm_offset_t)); if (IP_VALID(port)) ipc_port_release_send(port); vm_map_deallocate(map); @@ -775,11 +664,11 @@ syscall_vm_map( return result; } -kern_return_t syscall_vm_allocate(target_map, address, size, anywhere) - mach_port_t target_map; - vm_offset_t *address; - vm_size_t size; - boolean_t anywhere; +kern_return_t syscall_vm_allocate( + mach_port_t target_map, + vm_offset_t *address, + vm_size_t size, + boolean_t anywhere) { vm_map_t map; vm_offset_t addr; @@ -789,19 +678,19 @@ kern_return_t syscall_vm_allocate(target if (map == VM_MAP_NULL) return MACH_SEND_INTERRUPTED; - copyin((char *)address, (char *)&addr, sizeof(vm_offset_t)); + copyin(address, &addr, sizeof(vm_offset_t)); result = vm_allocate(map, &addr, size, anywhere); if (result == KERN_SUCCESS) - copyout((char *)&addr, (char *)address, sizeof(vm_offset_t)); + copyout(&addr, address, sizeof(vm_offset_t)); vm_map_deallocate(map); return result; } -kern_return_t syscall_vm_deallocate(target_map, start, size) - mach_port_t target_map; - vm_offset_t start; - vm_size_t size; +kern_return_t syscall_vm_deallocate( + mach_port_t target_map, + vm_offset_t start, + vm_size_t size) { vm_map_t map; kern_return_t result; @@ -816,10 +705,10 @@ kern_return_t syscall_vm_deallocate(targ return result; } -kern_return_t syscall_task_create(parent_task, inherit_memory, child_task) - mach_port_t parent_task; - boolean_t inherit_memory; - mach_port_t *child_task; /* OUT */ +kern_return_t syscall_task_create( + mach_port_t parent_task, + boolean_t inherit_memory, + mach_port_t *child_task) /* OUT */ { task_t t, c; ipc_port_t port; @@ -837,7 +726,7 @@ kern_return_t syscall_task_create(parent (void) ipc_kmsg_copyout_object(current_space(), (ipc_object_t) port, MACH_MSG_TYPE_PORT_SEND, &name); - copyout((char *)&name, (char *)child_task, + copyout(&name, child_task, sizeof(mach_port_t)); } task_deallocate(t); @@ -845,8 +734,7 @@ kern_return_t syscall_task_create(parent return result; } -kern_return_t syscall_task_terminate(task) - mach_port_t task; +kern_return_t syscall_task_terminate(mach_port_t task) { task_t t; kern_return_t result; @@ -861,8 +749,7 @@ kern_return_t syscall_task_terminate(tas return result; } -kern_return_t syscall_task_suspend(task) - mach_port_t task; +kern_return_t syscall_task_suspend(mach_port_t task) { task_t t; kern_return_t result; @@ -877,10 +764,10 @@ kern_return_t syscall_task_suspend(task) return result; } -kern_return_t syscall_task_set_special_port(task, which_port, port_name) - mach_port_t task; - int which_port; - mach_port_t port_name; +kern_return_t syscall_task_set_special_port( + mach_port_t task, + int which_port, + mach_port_t port_name) { task_t t; ipc_port_t port; @@ -910,10 +797,10 @@ kern_return_t syscall_task_set_special_p } kern_return_t -syscall_mach_port_allocate(task, right, namep) - mach_port_t task; - mach_port_right_t right; - mach_port_t *namep; +syscall_mach_port_allocate( + mach_port_t task, + mach_port_right_t right, + mach_port_t *namep) { ipc_space_t space; mach_port_t name; @@ -925,17 +812,17 @@ syscall_mach_port_allocate(task, right, kr = mach_port_allocate(space, right, &name); if (kr == KERN_SUCCESS) - copyout((char *)&name, (char *)namep, sizeof(mach_port_t)); + copyout(&name, namep, sizeof(mach_port_t)); is_release(space); return kr; } kern_return_t -syscall_mach_port_allocate_name(task, right, name) - mach_port_t task; - mach_port_right_t right; - mach_port_t name; +syscall_mach_port_allocate_name( + mach_port_t task, + mach_port_right_t right, + mach_port_t name) { ipc_space_t space; kern_return_t kr; @@ -951,9 +838,9 @@ syscall_mach_port_allocate_name(task, ri } kern_return_t -syscall_mach_port_deallocate(task, name) - mach_port_t task; - mach_port_t name; +syscall_mach_port_deallocate( + mach_port_t task, + mach_port_t name) { ipc_space_t space; kern_return_t kr; @@ -969,11 +856,11 @@ syscall_mach_port_deallocate(task, name) } kern_return_t -syscall_mach_port_insert_right(task, name, right, rightType) - mach_port_t task; - mach_port_t name; - mach_port_t right; - mach_msg_type_name_t rightType; +syscall_mach_port_insert_right( + mach_port_t task, + mach_port_t name, + mach_port_t right, + mach_msg_type_name_t rightType) { ipc_space_t space; ipc_object_t object; @@ -1008,8 +895,7 @@ syscall_mach_port_insert_right(task, nam return kr; } -kern_return_t syscall_thread_depress_abort(thread) - mach_port_t thread; +kern_return_t syscall_thread_depress_abort(mach_port_t thread) { thread_t t; kern_return_t result; @@ -1027,10 +913,6 @@ kern_return_t syscall_thread_depress_abo /* * Device traps -- these are way experimental. */ - -extern io_return_t ds_device_write_trap(); -extern io_return_t ds_device_writev_trap(); - io_return_t syscall_device_write_request(mach_port_t device_name, mach_port_t reply_name, @@ -1040,7 +922,7 @@ syscall_device_write_request(mach_port_t vm_size_t data_count) { device_t dev; - ipc_port_t reply_port; + /*ipc_port_t reply_port;*/ io_return_t res; /* @@ -1061,9 +943,10 @@ syscall_device_write_request(mach_port_t /* * Translate reply port. */ - if (reply_name == MACH_PORT_NULL) + /*if (reply_name == MACH_PORT_NULL) reply_port = IP_NULL; - else { + */ + if (reply_name != MACH_PORT_NULL) { /* Homey don't play that. */ device_deallocate(dev); return KERN_INVALID_RIGHT; @@ -1090,7 +973,7 @@ syscall_device_writev_request(mach_port_ vm_size_t iocount) { device_t dev; - ipc_port_t reply_port; + /*ipc_port_t reply_port;*/ io_return_t res; /* @@ -1111,9 +994,10 @@ syscall_device_writev_request(mach_port_ /* * Translate reply port. */ - if (reply_name == MACH_PORT_NULL) + /*if (reply_name == MACH_PORT_NULL) reply_port = IP_NULL; - else { + */ + if (reply_name != MACH_PORT_NULL) { /* Homey don't play that. */ device_deallocate(dev); return KERN_INVALID_RIGHT;