[BACK]Return to syscall.c CVS log [TXT][DIR] Up to [local] / sys / arch / arm / arm

Annotation of sys/arch/arm/arm/syscall.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: syscall.c,v 1.9 2007/04/27 18:45:00 drahn Exp $       */
        !             2: /*     $NetBSD: syscall.c,v 1.24 2003/11/14 19:03:17 scw Exp $ */
        !             3:
        !             4: /*-
        !             5:  * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
        !             6:  * All rights reserved.
        !             7:  *
        !             8:  * This code is derived from software contributed to The NetBSD Foundation
        !             9:  * by Charles M. Hannum.
        !            10:  *
        !            11:  * Redistribution and use in source and binary forms, with or without
        !            12:  * modification, are permitted provided that the following conditions
        !            13:  * are met:
        !            14:  * 1. Redistributions of source code must retain the above copyright
        !            15:  *    notice, this list of conditions and the following disclaimer.
        !            16:  * 2. Redistributions in binary form must reproduce the above copyright
        !            17:  *    notice, this list of conditions and the following disclaimer in the
        !            18:  *    documentation and/or other materials provided with the distribution.
        !            19:  * 3. All advertising materials mentioning features or use of this software
        !            20:  *    must display the following acknowledgement:
        !            21:  *        This product includes software developed by the NetBSD
        !            22:  *        Foundation, Inc. and its contributors.
        !            23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
        !            24:  *    contributors may be used to endorse or promote products derived
        !            25:  *    from this software without specific prior written permission.
        !            26:  *
        !            27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
        !            28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
        !            29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        !            30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
        !            31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        !            32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        !            33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        !            34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        !            35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        !            36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            37:  * POSSIBILITY OF SUCH DAMAGE.
        !            38:  */
        !            39:
        !            40: /*
        !            41:  * Copyright (c) 1994-1998 Mark Brinicombe.
        !            42:  * Copyright (c) 1994 Brini.
        !            43:  * All rights reserved.
        !            44:  *
        !            45:  * This code is derived from software written for Brini by Mark Brinicombe
        !            46:  *
        !            47:  * Redistribution and use in source and binary forms, with or without
        !            48:  * modification, are permitted provided that the following conditions
        !            49:  * are met:
        !            50:  * 1. Redistributions of source code must retain the above copyright
        !            51:  *    notice, this list of conditions and the following disclaimer.
        !            52:  * 2. Redistributions in binary form must reproduce the above copyright
        !            53:  *    notice, this list of conditions and the following disclaimer in the
        !            54:  *    documentation and/or other materials provided with the distribution.
        !            55:  * 3. All advertising materials mentioning features or use of this software
        !            56:  *    must display the following acknowledgement:
        !            57:  *     This product includes software developed by Mark Brinicombe
        !            58:  *     for the NetBSD Project.
        !            59:  * 4. The name of the company nor the name of the author may be used to
        !            60:  *    endorse or promote products derived from this software without specific
        !            61:  *    prior written permission.
        !            62:  *
        !            63:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
        !            64:  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
        !            65:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            66:  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
        !            67:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        !            68:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        !            69:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            70:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            71:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            72:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            73:  * SUCH DAMAGE.
        !            74:  *
        !            75:  * syscall entry handling
        !            76:  *
        !            77:  * Created      : 09/11/94
        !            78:  */
        !            79:
        !            80: #include <sys/param.h>
        !            81:
        !            82: #include <sys/device.h>
        !            83: #include <sys/errno.h>
        !            84: #include <sys/kernel.h>
        !            85: #include <sys/reboot.h>
        !            86: #include <sys/signalvar.h>
        !            87: #include <sys/syscall.h>
        !            88: #include <sys/systm.h>
        !            89: #include <sys/user.h>
        !            90: #ifdef KTRACE
        !            91: #include <sys/ktrace.h>
        !            92: #endif
        !            93:
        !            94: #include "systrace.h"
        !            95: #include <dev/systrace.h>
        !            96:
        !            97: #include <uvm/uvm_extern.h>
        !            98:
        !            99: #include <machine/cpu.h>
        !           100: #include <machine/frame.h>
        !           101: #include <machine/pcb.h>
        !           102: #include <arm/swi.h>
        !           103:
        !           104: #ifdef acorn26
        !           105: #include <machine/machdep.h>
        !           106: #endif
        !           107:
        !           108: #define MAXARGS 8
        !           109:
        !           110: void
        !           111: swi_handler(trapframe_t *frame)
        !           112: {
        !           113:        struct proc *p = curproc;
        !           114:        const struct sysent *callp;
        !           115:        int code, error, orig_error;
        !           116:        u_int nap = 4, nargs;
        !           117:        register_t *ap, *args, copyargs[MAXARGS], rval[2];
        !           118:
        !           119:        uvmexp.syscalls++;
        !           120:
        !           121:        /* Re-enable interrupts if they were enabled previously */
        !           122:        if (__predict_true((frame->tf_spsr & I32_bit) == 0))
        !           123:                enable_interrupts(I32_bit);
        !           124:
        !           125:        p->p_addr->u_pcb.pcb_tf = frame;
        !           126:
        !           127:        code = frame->tf_r12;
        !           128:
        !           129:        ap = &frame->tf_r0;
        !           130:        callp = p->p_emul->e_sysent;
        !           131:
        !           132:        switch (code) {
        !           133:        case SYS_syscall:
        !           134:                code = *ap++;
        !           135:                nap--;
        !           136:                break;
        !           137:         case SYS___syscall:
        !           138:                code = ap[_QUAD_LOWWORD];
        !           139:                ap += 2;
        !           140:                nap -= 2;
        !           141:                break;
        !           142:        }
        !           143:
        !           144:        if (code < 0 || code >= p->p_emul->e_nsysent) {
        !           145:                callp += p->p_emul->e_nosys;
        !           146:        } else {
        !           147:                callp += code;
        !           148:        }
        !           149:        nargs = callp->sy_argsize / sizeof(register_t);
        !           150:        if (nargs <= nap) {
        !           151:                args = ap;
        !           152:                error = 0;
        !           153:        } else {
        !           154:                KASSERT(nargs <= MAXARGS);
        !           155:                memcpy(copyargs, ap, nap * sizeof(register_t));
        !           156:                error = copyin((void *)frame->tf_usr_sp, copyargs + nap,
        !           157:                    (nargs - nap) * sizeof(register_t));
        !           158:                args = copyargs;
        !           159:        }
        !           160:        orig_error = error;
        !           161: #ifdef SYSCALL_DEBUG
        !           162:         scdebug_call(p, code, args);
        !           163: #endif
        !           164: #ifdef KTRACE
        !           165:        if (KTRPOINT(p, KTR_SYSCALL))
        !           166:                ktrsyscall(p, code, callp->sy_argsize, args);
        !           167: #endif
        !           168:        if (error)
        !           169:                goto bad;
        !           170:
        !           171:        rval[0] = 0;
        !           172:        rval[1] = frame->tf_r1;
        !           173: #if NSYSTRACE > 0
        !           174:        if (ISSET(p->p_flag, P_SYSTRACE))
        !           175:                orig_error = error = systrace_redirect(code, p, args, rval);
        !           176:        else
        !           177: #endif
        !           178:                orig_error = error = (*callp->sy_call)(p, args, rval);
        !           179:
        !           180:        switch (error) {
        !           181:        case 0:
        !           182:                frame->tf_r0 = rval[0];
        !           183:                frame->tf_r1 = rval[1];
        !           184:
        !           185:                frame->tf_spsr &= ~PSR_C_bit;   /* carry bit */
        !           186:                break;
        !           187:
        !           188:        case ERESTART:
        !           189:                /*
        !           190:                 * Reconstruct the pc to point at the swi.
        !           191:                 */
        !           192:                frame->tf_pc -= INSN_SIZE;
        !           193:                break;
        !           194:
        !           195:        case EJUSTRETURN:
        !           196:                /* nothing to do */
        !           197:                break;
        !           198:
        !           199:        default:
        !           200:        bad:
        !           201:                frame->tf_r0 = error;
        !           202:                frame->tf_spsr |= PSR_C_bit;    /* carry bit */
        !           203:                break;
        !           204:        }
        !           205: #ifdef SYSCALL_DEBUG
        !           206:        scdebug_ret(p, code, orig_error, rval);
        !           207: #endif
        !           208:        userret(p);
        !           209: #ifdef KTRACE
        !           210:        if (KTRPOINT(p, KTR_SYSRET))
        !           211:                ktrsysret(p, code, orig_error, rval[0]);
        !           212: #endif
        !           213: }
        !           214:
        !           215: void
        !           216: child_return(arg)
        !           217:        void *arg;
        !           218: {
        !           219:        struct proc *p = arg;
        !           220:        struct trapframe *frame = p->p_addr->u_pcb.pcb_tf;
        !           221:
        !           222:        frame->tf_r0 = 0;
        !           223:        frame->tf_spsr &= ~PSR_C_bit;   /* carry bit */
        !           224:
        !           225:        userret(p);
        !           226:
        !           227: #ifdef KTRACE
        !           228:        if (KTRPOINT(p, KTR_SYSRET)) {
        !           229:                ktrsysret(p,
        !           230:                    (p->p_flag & P_PPWAIT) ? SYS_vfork : SYS_fork, 0, 0);
        !           231:        }
        !           232: #endif
        !           233: }

CVSweb