Annotation of XNU/bsd/dev/ppc/stubs.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /*
        !            23:  * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
        !            24:  * Copyright (c) 1993 NeXT Computer, Inc.
        !            25:  *
        !            26:  */
        !            27: 
        !            28: #include <sys/param.h>
        !            29: #include <sys/systm.h>
        !            30: #include <sys/buf.h>
        !            31: #include <sys/ioctl.h>
        !            32: #include <sys/tty.h>
        !            33: #include <sys/conf.h>
        !            34: #include <sys/proc.h>
        !            35: #include <sys/user.h>
        !            36: #include <kern/thread.h>
        !            37: #include <kern/thread_act.h>
        !            38: #include <kern/task.h>
        !            39: #include <vm/vm_map.h>
        !            40: 
        !            41: 
        !            42: /* 
        !            43:  * copy a null terminated string from the kernel address space into
        !            44:  * the user address space.
        !            45:  *   - if the user is denied write access, return EFAULT.
        !            46:  *   - if the end of string isn't found before
        !            47:  *     maxlen bytes are copied,  return ENAMETOOLONG,
        !            48:  *     indicating an incomplete copy.
        !            49:  *   - otherwise, return 0, indicating success.
        !            50:  * the number of bytes copied is always returned in lencopied.
        !            51:  */
        !            52: int
        !            53: copyoutstr(from, to, maxlen, lencopied)
        !            54:     void * from, * to;
        !            55:     size_t maxlen, *lencopied;
        !            56: {
        !            57:        int slen,len,error=0;
        !            58: 
        !            59:        /* XXX Must optimize this */
        !            60: 
        !            61:        slen = strlen(from) + 1;
        !            62:        if (slen > maxlen)
        !            63:                error = ENAMETOOLONG;
        !            64: 
        !            65:        len = min(maxlen,slen);
        !            66:        if (copyout(from, to, len))
        !            67:                error = EFAULT;
        !            68:        *lencopied = len;
        !            69: 
        !            70:        return error;
        !            71: }
        !            72: 
        !            73: 
        !            74: /* 
        !            75:  * copy a null terminated string from one point to another in 
        !            76:  * the kernel address space.
        !            77:  *   - no access checks are performed.
        !            78:  *   - if the end of string isn't found before
        !            79:  *     maxlen bytes are copied,  return ENAMETOOLONG,
        !            80:  *     indicating an incomplete copy.
        !            81:  *   - otherwise, return 0, indicating success.
        !            82:  * the number of bytes copied is always returned in lencopied.
        !            83:  */
        !            84: /* from ppc/fault_copy.c -Titan1T4 VERSION  */
        !            85: int
        !            86: copystr(vfrom, vto, maxlen, lencopied)
        !            87:     register void * vfrom, *vto;
        !            88:     size_t maxlen, *lencopied;
        !            89: {
        !            90:     register unsigned l;
        !            91:     int error;
        !            92: caddr_t from, to;
        !            93: 
        !            94:        from = vfrom;
        !            95:        to = vto;
        !            96:     for (l = 0; l < maxlen; l++)
        !            97:         if ((*to++ = *from++) == '\0') {
        !            98:             if (lencopied)
        !            99:                 *lencopied = l + 1;
        !           100:             return 0;
        !           101:         }
        !           102:     if (lencopied)
        !           103:        *lencopied = maxlen;
        !           104:     return ENAMETOOLONG;
        !           105: }
        !           106: 
        !           107: int copywithin(src, dst, count)
        !           108: void  * src, *dst;
        !           109: size_t count;
        !           110: {
        !           111:        bcopy(src,dst,count);
        !           112:        return 0;
        !           113: }
        !           114: 
        !           115: struct unix_syscallargs {
        !           116:        int flavor;
        !           117:        int r3;
        !           118:        int arg1, arg2,arg3,arg4,arg5,arg6,arg7;
        !           119: };
        !           120: 
        !           121: set_bsduthreadargs(thread_t th, void * pcb, struct unix_syscallargs * sarg)
        !           122: {
        !           123: struct uthread * ut;
        !           124: 
        !           125:        ut = get_bsdthread_info(th);
        !           126:        ut->uu_ar0 = (int *)pcb;
        !           127: 
        !           128:        if (sarg->flavor)
        !           129:        {
        !           130:        ut->uu_arg[0] = sarg->arg1;
        !           131:        ut->uu_arg[1] = sarg->arg2;
        !           132:        ut->uu_arg[2] = sarg->arg3;
        !           133:        ut->uu_arg[3] = sarg->arg4;
        !           134:        ut->uu_arg[4] = sarg->arg5;
        !           135:        ut->uu_arg[5] = sarg->arg6;
        !           136:        ut->uu_arg[7] = sarg->arg7;
        !           137:        }
        !           138:        else
        !           139:        {
        !           140:        ut->uu_arg[0] = sarg->r3; 
        !           141:        ut->uu_arg[1] = sarg->arg1;
        !           142:        ut->uu_arg[2] = sarg->arg2;
        !           143:        ut->uu_arg[3] = sarg->arg3;
        !           144:        ut->uu_arg[4] = sarg->arg4;
        !           145:        ut->uu_arg[5] = sarg->arg5;
        !           146:        ut->uu_arg[6] = sarg->arg6;
        !           147:        ut->uu_arg[7] = sarg->arg7;
        !           148:        }
        !           149: 
        !           150:        return(1);
        !           151: }
        !           152: 
        !           153: void *
        !           154: get_bsduthreadarg(thread_t th)
        !           155: {
        !           156: struct uthread *ut;
        !           157:        ut = get_bsdthread_info(th);
        !           158:        return((void *)(ut->uu_arg));
        !           159: }
        !           160: 
        !           161: int *
        !           162: get_bsduthreadrval(thread_act_t th)
        !           163: {
        !           164: struct uthread *ut;
        !           165:        ut = get_bsdthread_info(th);
        !           166:        return(&ut->uu_rval[0]);
        !           167: }
        !           168: 

unix.superglobalmegacorp.com

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