--- Gnu-Mach/kern/ipc_mig.c 2020/09/02 04:36:57 1.1.1.1 +++ Gnu-Mach/kern/ipc_mig.c 2020/09/02 04:45:22 1.1.1.3 @@ -1,40 +1,42 @@ -/* +/* * Mach Operating System * Copyright (c) 1991,1990 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ -#include - #include #include #include #include +#include #include +#include #include +#include #include #include #include +#include #include #include #include @@ -46,8 +48,10 @@ #include #include #include +#include +#include #include - +#include /* * Routine: mach_msg_send_from_kernel @@ -94,122 +98,6 @@ mach_msg_rpc_from_kernel(msg, send_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: @@ -371,7 +259,7 @@ mig_dealloc_reply_port( /* * Routine: mig_put_reply_port * Purpose: - * Called by client side interfaces after each RPC to + * Called by client side interfaces after each RPC to * let the client recycle the reply port if it wishes. */ void @@ -384,16 +272,16 @@ 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 + * 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. * * Parameters: - * + * * dest - Pointer to destination buffer. - * + * * src - Pointer to source string. - * + * * len - Length of destination buffer. */ void mig_strncpy(dest, src, len) @@ -444,10 +332,10 @@ port_name_to_device(name) { register ipc_port_t port; register device_t device; - + fast_send_right_lookup(name, port, goto abort); /* port is locked */ - + /* * Now map the port object to a device object. * This is an inline version of dev_port_lookup(). @@ -456,25 +344,25 @@ port_name_to_device(name) device = (device_t) port->ip_kobject; device_reference(device); ip_unlock(port); - return device; + return device; } - + ip_unlock(port); return DEVICE_NULL; - + /* * The slow case. The port wasn't easily accessible. */ abort: { ipc_port_t kern_port; kern_return_t kr; - + kr = ipc_object_copyin(current_space(), name, MACH_MSG_TYPE_COPY_SEND, (ipc_object_t *) &kern_port); if (kr != KERN_SUCCESS) return DEVICE_NULL; - + device = dev_port_lookup(kern_port); if (IP_VALID(kern_port)) ipc_port_release_send(kern_port); @@ -1040,7 +928,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 +949,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; @@ -1130,5 +1019,3 @@ syscall_device_writev_request(mach_port_ device_deallocate(dev); return res; } - -