Annotation of OSKit-Mach/ipc/mach_rpc.c, revision 1.1

1.1     ! root        1: /* 
        !             2:  * Copyright (c) 1994 The University of Utah and
        !             3:  * the Computer Systems Laboratory (CSL).  All rights reserved.
        !             4:  *
        !             5:  * Permission to use, copy, modify and distribute this software is hereby
        !             6:  * granted provided that (1) source code retains these copyright, permission,
        !             7:  * and disclaimer notices, and (2) redistributions including binaries
        !             8:  * reproduce the notices in supporting documentation, and (3) all advertising
        !             9:  * materials mentioning features or use of this software display the following
        !            10:  * acknowledgement: ``This product includes software developed by the
        !            11:  * Computer Systems Laboratory at the University of Utah.''
        !            12:  *
        !            13:  * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
        !            14:  * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
        !            15:  * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
        !            16:  *
        !            17:  * CSL requests users of this software to return to [email protected] any
        !            18:  * improvements that they make and grant CSL redistribution rights.
        !            19:  *
        !            20:  */
        !            21: 
        !            22: #ifdef MIGRATING_THREADS
        !            23: 
        !            24: #include <mach/kern_return.h>
        !            25: #include <mach/port.h>
        !            26: #include <mach/rpc.h>
        !            27: #include <mach/notify.h>
        !            28: #include <mach/mach_param.h>
        !            29: #include <mach/vm_param.h>
        !            30: #include <mach/vm_prot.h>
        !            31: #include <kern/task.h>
        !            32: #include <kern/act.h>
        !            33: #include <vm/vm_map.h>
        !            34: #include <vm/vm_kern.h>
        !            35: #include <vm/vm_user.h>
        !            36: #include <ipc/ipc_entry.h>
        !            37: #include <ipc/ipc_space.h>
        !            38: #include <ipc/ipc_object.h>
        !            39: #include <ipc/ipc_notify.h>
        !            40: #include <ipc/ipc_port.h>
        !            41: #include <ipc/ipc_pset.h>
        !            42: #include <ipc/ipc_right.h>
        !            43: 
        !            44: #undef DEBUG_MPRC
        !            45: 
        !            46: /*
        !            47:  * XXX need to identify if one endpoint of an RPC is the kernel to
        !            48:  * ensure proper port name translation (or lack of).  This is bogus.
        !            49:  */
        !            50: #define ISKERNELACT(act)       ((act)->task == kernel_task)
        !            51: 
        !            52: /*
        !            53:  * Copy the indicated port from the task associated with the source
        !            54:  * activation into the task associated with the destination activation.
        !            55:  *
        !            56:  * XXX on errors we should probably clear the portp to avoid leaking
        !            57:  * info to the other side.
        !            58:  */
        !            59: kern_return_t
        !            60: mach_port_rpc_copy(portp, sact, dact)
        !            61:        struct rpc_port_desc *portp;
        !            62:        struct Act *sact, *dact;
        !            63: {
        !            64:        ipc_space_t sspace, dspace;
        !            65:        mach_msg_type_name_t tname;
        !            66:        ipc_object_t iname;
        !            67:        kern_return_t kr;
        !            68: 
        !            69: #ifdef DEBUG_MPRC
        !            70:        printf("m_p_rpc_copy(portp=%x/%x, sact=%x, dact=%x): ",
        !            71:               portp->name, portp->msgt_name, sact, dact);
        !            72: #endif
        !            73:        sspace = sact->task->itk_space;
        !            74:        dspace = dact->task->itk_space;
        !            75:        if (sspace == IS_NULL || dspace == IS_NULL) {
        !            76: #ifdef DEBUG_MPRC
        !            77:                printf("bogus src (%x) or dst (%x) space\n", sspace, dspace);
        !            78: #endif
        !            79:                return KERN_INVALID_TASK;
        !            80:        }
        !            81: 
        !            82:        if (!MACH_MSG_TYPE_PORT_ANY(portp->msgt_name)) {
        !            83: #ifdef DEBUG_MPRC
        !            84:                printf("invalid port type\n");
        !            85: #endif
        !            86:                return KERN_INVALID_VALUE;
        !            87:        }
        !            88: 
        !            89:        if (ISKERNELACT(sact)) {
        !            90:                iname = (ipc_object_t) portp->name;
        !            91:                ipc_object_copyin_from_kernel(iname, portp->msgt_name);
        !            92:                kr = KERN_SUCCESS;
        !            93:        } else {
        !            94:                kr = ipc_object_copyin(sspace, portp->name, portp->msgt_name,
        !            95:                                       &iname);
        !            96:        }
        !            97:        if (kr != KERN_SUCCESS) {
        !            98: #ifdef DEBUG_MPRC
        !            99:                printf("copyin returned %x\n", kr);
        !           100: #endif
        !           101:                return kr;
        !           102:        }
        !           103: 
        !           104:        tname = ipc_object_copyin_type(portp->msgt_name);
        !           105:        if (!IO_VALID(iname)) {
        !           106:                portp->name = (mach_port_t) iname;
        !           107:                portp->msgt_name = tname;
        !           108: #ifdef DEBUG_MPRC
        !           109:                printf("iport %x invalid\n", iname);
        !           110: #endif
        !           111:                return KERN_SUCCESS;
        !           112:        }
        !           113: 
        !           114:        if (ISKERNELACT(dact)) {
        !           115:                portp->name = (mach_port_t) iname;
        !           116:                kr = KERN_SUCCESS;
        !           117:        } else {
        !           118:                kr = ipc_object_copyout(dspace, iname, tname, TRUE,
        !           119:                                        &portp->name);
        !           120:        }
        !           121:        if (kr != KERN_SUCCESS) {
        !           122:                ipc_object_destroy(iname, tname);
        !           123: 
        !           124:                if (kr == KERN_INVALID_CAPABILITY)
        !           125:                        portp->name = MACH_PORT_DEAD;
        !           126:                else {
        !           127:                        portp->name = MACH_PORT_NULL;
        !           128: #ifdef DEBUG_MPRC
        !           129:                        printf("copyout iport %x returned %x\n", iname);
        !           130: #endif
        !           131:                        return kr;
        !           132:                }
        !           133:        }
        !           134: 
        !           135:        portp->msgt_name = tname;
        !           136: #ifdef DEBUG_MPRC
        !           137:        printf("portp=%x/%x, iname=%x\n", portp->name, portp->msgt_name, iname);
        !           138: #endif
        !           139:        return KERN_SUCCESS;
        !           140: }
        !           141: 
        !           142: kern_return_t
        !           143: mach_port_rpc_sig(space, name, buffer, buflen)
        !           144: {
        !           145:        return KERN_FAILURE;
        !           146: }
        !           147: 
        !           148: #endif /* MIGRATING_THREADS */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.