--- Gnu-Mach/ipc/ipc_port.c 2020/09/02 04:36:56 1.1 +++ Gnu-Mach/ipc/ipc_port.c 2020/09/02 04:49:43 1.1.1.5 @@ -34,7 +34,8 @@ * Functions to manipulate IPC ports. */ -#include +#include +#include #include #include @@ -49,10 +50,11 @@ #include #include #include -#if NORMA_IPC -#include -#endif NORMA_IPC +#if MACH_KDB +#include +#include +#endif /* MACH_KDB */ decl_simple_lock_data(, ipc_port_multiple_lock_data) @@ -92,11 +94,11 @@ ipc_port_timestamp(void) */ kern_return_t -ipc_port_dnrequest(port, name, soright, indexp) - ipc_port_t port; - mach_port_t name; - ipc_port_t soright; - ipc_port_request_index_t *indexp; +ipc_port_dnrequest( + ipc_port_t port, + mach_port_t name, + ipc_port_t soright, + ipc_port_request_index_t *indexp) { ipc_port_request_t ipr, table; ipc_port_request_index_t index; @@ -140,8 +142,7 @@ ipc_port_dnrequest(port, name, soright, */ kern_return_t -ipc_port_dngrow(port) - ipc_port_t port; +ipc_port_dngrow(ipc_port_t port) { ipc_table_size_t its; ipc_port_request_t otable, ntable; @@ -187,7 +188,7 @@ ipc_port_dngrow(port) osize = oits->its_size; free = otable->ipr_next; - bcopy((char *)(otable + 1), (char *)(ntable + 1), + memcpy((ntable + 1), (otable + 1), (osize - 1) * sizeof(struct ipc_port_request)); } else { osize = 1; @@ -221,7 +222,7 @@ ipc_port_dngrow(port) return KERN_SUCCESS; } - + /* * Routine: ipc_port_dncancel * Purpose: @@ -273,9 +274,9 @@ ipc_port_dncancel( void ipc_port_pdrequest( - ipc_port_t port, - ipc_port_t notify, - ipc_port_t *previousp) + ipc_port_t port, + const ipc_port_t notify, + ipc_port_t *previousp) { ipc_port_t previous; @@ -380,8 +381,7 @@ ipc_port_set_qlimit( */ ipc_mqueue_t -ipc_port_lock_mqueue(port) - ipc_port_t port; +ipc_port_lock_mqueue(ipc_port_t port) { if (port->ip_pset != IPS_NULL) { ipc_pset_t pset = port->ip_pset; @@ -411,9 +411,9 @@ ipc_port_lock_mqueue(port) */ void -ipc_port_set_seqno(port, seqno) - ipc_port_t port; - mach_port_seqno_t seqno; +ipc_port_set_seqno( + ipc_port_t port, + mach_port_seqno_t seqno) { ipc_mqueue_t mqueue; @@ -423,6 +423,44 @@ ipc_port_set_seqno(port, seqno) } /* + * Routine: ipc_port_set_protected_payload + * Purpose: + * Changes a port's protected payload. + * Conditions: + * The port is locked and active. + */ + +void +ipc_port_set_protected_payload(ipc_port_t port, unsigned long payload) +{ + ipc_mqueue_t mqueue; + + mqueue = ipc_port_lock_mqueue(port); + port->ip_protected_payload = payload; + ipc_port_flag_protected_payload_set(port); + imq_unlock(mqueue); +} + +/* + * Routine: ipc_port_clear_protected_payload + * Purpose: + * Clear a port's protected payload. + * Conditions: + * The port is locked and active. + */ + +void +ipc_port_clear_protected_payload(ipc_port_t port) +{ + ipc_mqueue_t mqueue; + + mqueue = ipc_port_lock_mqueue(port); + ipc_port_flag_protected_payload_clear(port); + imq_unlock(mqueue); +} + + +/* * Routine: ipc_port_clear_receiver * Purpose: * Prepares a receive right for transmission/destruction. @@ -491,24 +529,8 @@ ipc_port_init( port->ip_seqno = 0; port->ip_msgcount = 0; port->ip_qlimit = MACH_PORT_QLIMIT_DEFAULT; - -#if NORMA_IPC - port->ip_norma_uid = 0; - port->ip_norma_dest_node = 0; - port->ip_norma_stransit = 0; - port->ip_norma_sotransit = 0; - port->ip_norma_xmm_object_refs = 0; - port->ip_norma_is_proxy = FALSE; - port->ip_norma_is_special = FALSE; - port->ip_norma_atrium = IP_NULL; - port->ip_norma_queue_next = port; - port->ip_norma_xmm_object = IP_NULL; - port->ip_norma_next = port; - port->ip_norma_spare1 = 0L; - port->ip_norma_spare2 = 0L; - port->ip_norma_spare3 = 0L; - port->ip_norma_spare4 = 0L; -#endif NORMA_IPC + ipc_port_flag_protected_payload_clear(port); + port->ip_protected_payload = 0; ipc_mqueue_init(&port->ip_messages); ipc_thread_queue_init(&port->ip_blocked); @@ -590,55 +612,6 @@ ipc_port_alloc_name( return KERN_SUCCESS; } -#if MACH_IPC_COMPAT -/* - * Routine: ipc_port_delete_compat - * Purpose: - * Find and destroy a compat entry for a dead port. - * If successful, generate a port-deleted notification. - * Conditions: - * Nothing locked; the port is dead. - * Frees a ref for the space. - */ - -void -ipc_port_delete_compat(port, space, name) - ipc_port_t port; - ipc_space_t space; - mach_port_t name; -{ - ipc_entry_t entry; - kern_return_t kr; - - assert(!ip_active(port)); - - kr = ipc_right_lookup_write(space, name, &entry); - if (kr == KERN_SUCCESS) { - ipc_port_t sright; - - /* space is write-locked and active */ - - if ((ipc_port_t) entry->ie_object == port) { - assert(entry->ie_bits & IE_BITS_COMPAT); - - sright = ipc_space_make_notify(space); - - kr = ipc_right_destroy(space, name, entry); - /* space is unlocked */ - assert(kr == KERN_INVALID_NAME); - } else { - is_write_unlock(space); - sright = IP_NULL; - } - - if (IP_VALID(sright)) - ipc_notify_port_deleted_compat(sright, name); - } - - is_release(space); -} -#endif MACH_IPC_COMPAT - /* * Routine: ipc_port_destroy * Purpose: @@ -680,30 +653,9 @@ ipc_port_destroy( /* make port be in limbo */ port->ip_receiver_name = MACH_PORT_NULL; port->ip_destination = IP_NULL; + ipc_port_flag_protected_payload_clear(port); ip_unlock(port); -#if MACH_IPC_COMPAT - /* - * pdrequest might actually be a send right instead - * of a send-once right, indicated by the low bit - * of the pointer value. If this is the case, - * we must use ipc_notify_port_destroyed_compat. - */ - - if (ip_pdsendp(pdrequest)) { - ipc_port_t sright = ip_pdsend(pdrequest); - - if (!ipc_port_check_circularity(port, sright)) { - /* consumes our refs for port and sright */ - ipc_notify_port_destroyed_compat(sright, port); - return; - } else { - /* consume sright and destroy port */ - ipc_port_release_send(sright); - } - } else -#endif MACH_IPC_COMPAT - if (!ipc_port_check_circularity(port, pdrequest)) { /* consumes our refs for port and pdrequest */ ipc_notify_port_destroyed(pdrequest, port); @@ -725,13 +677,6 @@ ipc_port_destroy( /* fall through and destroy the port */ } -#if NORMA_IPC - /* - * destroy any NORMA_IPC state associated with port - */ - norma_ipc_port_destroy(port); -#endif NORMA_IPC - /* * rouse all blocked senders * @@ -798,14 +743,6 @@ ipc_port_destroy( soright = ipr->ipr_soright; assert(soright != IP_NULL); -#if MACH_IPC_COMPAT - if (ipr_spacep(soright)) { - ipc_port_delete_compat(port, - ipr_space(soright), name); - continue; - } -#endif MACH_IPC_COMPAT - ipc_notify_dead_name(soright, name); } @@ -1237,24 +1174,15 @@ ipc_port_release_receive( */ ipc_port_t -ipc_port_alloc_special(space) - ipc_space_t space; +ipc_port_alloc_special(ipc_space_t space) { -#if NORMA_IPC -#if i386 - int ret = (&ret)[2]; /* where we were called from */ -#else - int ret = (int) ipc_port_alloc_special; -#endif - extern int input_msgh_id; -#endif NORMA_IPC ipc_port_t port; - port = (ipc_port_t) io_alloc(IOT_PORT); + port = ip_alloc(); if (port == IP_NULL) return IP_NULL; - io_lock_init(&port->ip_object); + ip_lock_init(port); port->ip_references = 1; port->ip_object.io_bits = io_makebits(TRUE, IOT_PORT, 0); @@ -1271,10 +1199,6 @@ ipc_port_alloc_special(space) ipc_port_init(port, space, (mach_port_t)port); -#if NORMA_IPC - port->ip_norma_spare1 = ret; - port->ip_norma_spare2 = input_msgh_id; -#endif NORMA_IPC return port; } @@ -1315,168 +1239,6 @@ ipc_port_dealloc_special( ipc_port_destroy(port); } -#if MACH_IPC_COMPAT - -/* - * Routine: ipc_port_alloc_compat - * Purpose: - * Allocate a port. - * Conditions: - * Nothing locked. If successful, the port is returned - * locked. (The caller doesn't have a reference.) - * - * Like ipc_port_alloc, except that the new entry - * is IE_BITS_COMPAT. - * Returns: - * KERN_SUCCESS The port is allocated. - * KERN_INVALID_TASK The space is dead. - * KERN_NO_SPACE No room for an entry in the space. - * KERN_RESOURCE_SHORTAGE Couldn't allocate memory. - */ - -kern_return_t -ipc_port_alloc_compat(space, namep, portp) - ipc_space_t space; - mach_port_t *namep; - ipc_port_t *portp; -{ - ipc_port_t port; - ipc_entry_t entry; - mach_port_t name; - ipc_table_size_t its; - ipc_port_request_t table; - ipc_table_elems_t size; - ipc_port_request_index_t free, i; - kern_return_t kr; - - port = ip_alloc(); - if (port == IP_NULL) - return KERN_RESOURCE_SHORTAGE; - - its = &ipc_table_dnrequests[0]; - table = it_dnrequests_alloc(its); - if (table == IPR_NULL) { - ip_free(port); - return KERN_RESOURCE_SHORTAGE; - } - - kr = ipc_entry_alloc(space, &name, &entry); - if (kr != KERN_SUCCESS) { - ip_free(port); - it_dnrequests_free(its, table); - return kr; - } - /* space is write-locked */ - - entry->ie_object = (ipc_object_t) port; - entry->ie_request = 1; - entry->ie_bits |= IE_BITS_COMPAT|MACH_PORT_TYPE_RECEIVE; - - ip_lock_init(port); - ip_lock(port); - is_write_unlock(space); - - port->ip_references = 1; /* for entry, not caller */ - port->ip_bits = io_makebits(TRUE, IOT_PORT, 0); - - ipc_port_init(port, space, name); - - size = its->its_size; - assert(size > 1); - free = 0; - - for (i = 2; i < size; i++) { - ipc_port_request_t ipr = &table[i]; - - ipr->ipr_name = MACH_PORT_NULL; - ipr->ipr_next = free; - free = i; - } - - table->ipr_next = free; - table->ipr_size = its; - port->ip_dnrequests = table; - - table[1].ipr_name = name; - table[1].ipr_soright = ipr_spacem(space); - is_reference(space); - - *namep = name; - *portp = port; - return KERN_SUCCESS; -} - -/* - * Routine: ipc_port_copyout_send_compat - * Purpose: - * Copyout a naked send right (possibly null/dead), - * or if that fails, destroy the right. - * Like ipc_port_copyout_send, except that if a - * new translation is created it has the compat bit. - * Conditions: - * Nothing locked. - */ - -mach_port_t -ipc_port_copyout_send_compat(sright, space) - ipc_port_t sright; - ipc_space_t space; -{ - mach_port_t name; - - if (IP_VALID(sright)) { - kern_return_t kr; - - kr = ipc_object_copyout_compat(space, (ipc_object_t) sright, - MACH_MSG_TYPE_PORT_SEND, &name); - if (kr != KERN_SUCCESS) { - ipc_port_release_send(sright); - name = MACH_PORT_NULL; - } - } else - name = (mach_port_t) sright; - - return name; -} - -/* - * Routine: ipc_port_copyout_receiver - * Purpose: - * Copyout a port reference (possibly null) - * by giving the caller his name for the port, - * if he is the receiver. - * Conditions: - * Nothing locked. Consumes a ref for the port. - */ - -mach_port_t -ipc_port_copyout_receiver(port, space) - ipc_port_t port; - ipc_space_t space; -{ - mach_port_t name; - - if (!IP_VALID(port)) - return MACH_PORT_NULL; - - ip_lock(port); - if (port->ip_receiver == space) { - name = port->ip_receiver_name; - assert(MACH_PORT_VALID(name)); - } else - name = MACH_PORT_NULL; - - ip_release(port); - ip_check_unlock(port); - - return name; -} - -#endif MACH_IPC_COMPAT - -#include - - #if MACH_KDB #define printf kdbprintf @@ -1488,14 +1250,17 @@ ipc_port_copyout_receiver(port, space) void ipc_port_print(port) - ipc_port_t port; + const ipc_port_t port; { - extern int indent; - printf("port 0x%x\n", port); indent += 2; + iprintf("flags "); + printf("has_protected_payload=%d", + ipc_port_flag_protected_payload(port)); + printf("\n"); + ipc_object_print(&port->ip_object); iprintf("receiver=0x%x", port->ip_receiver); printf(", receiver_name=0x%x\n", port->ip_receiver_name); @@ -1518,28 +1283,9 @@ ipc_port_print(port) printf(", sndrs=0x%x", port->ip_blocked.ithq_base); printf(", kobj=0x%x\n", port->ip_kobject); -#if NORMA_IPC - iprintf("norma_uid=%x", port->ip_norma_uid); - printf(", dest_node=%d", port->ip_norma_dest_node); - printf(", stransit=%d", port->ip_norma_stransit); - printf(", xorefs=%d", port->ip_norma_xmm_object_refs); - printf(", sotransit=%d\n", port->ip_norma_sotransit); - - iprintf("norma_is_proxy=%d", port->ip_norma_is_proxy); - printf(", is_special=%d\n", port->ip_norma_is_special); - - iprintf("norma_atrium=0x%x", port->ip_norma_atrium); - printf(", queue_next=0x%x", port->ip_norma_queue_next); - printf(", xmm_object=0x%x", port->ip_norma_xmm_object); - printf(", next=0x%x\n", port->ip_norma_next); - - iprintf("norma_spare1=0x%x", port->ip_norma_spare1); - printf(", norma_spare2=0x%x", port->ip_norma_spare2); - printf(", norma_spare3=0x%x", port->ip_norma_spare3); - printf(", norma_spare4=0x%x\n", port->ip_norma_spare4); -#endif NORMA_IPC + iprintf("protected_payload=%p\n", (void *) port->ip_protected_payload); - indent -=2; + indent -= 2; } -#endif MACH_KDB +#endif /* MACH_KDB */