sunos_syscall.c revision 1.12
11.12Sthorpej/* $NetBSD: sunos_syscall.c,v 1.12 2006/03/07 03:32:05 thorpej Exp $ */ 21.1Sscw 31.1Sscw/*- 41.1Sscw * Portions Copyright (c) 2000 The NetBSD Foundation, Inc. 51.1Sscw * All rights reserved. 61.1Sscw * 71.1Sscw * Redistribution and use in source and binary forms, with or without 81.1Sscw * modification, are permitted provided that the following conditions 91.1Sscw * are met: 101.1Sscw * 1. Redistributions of source code must retain the above copyright 111.1Sscw * notice, this list of conditions and the following disclaimer. 121.1Sscw * 2. Redistributions in binary form must reproduce the above copyright 131.1Sscw * notice, this list of conditions and the following disclaimer in the 141.1Sscw * documentation and/or other materials provided with the distribution. 151.1Sscw * 3. All advertising materials mentioning features or use of this software 161.1Sscw * must display the following acknowledgement: 171.1Sscw * This product includes software developed by the NetBSD 181.1Sscw * Foundation, Inc. and its contributors. 191.1Sscw * 4. Neither the name of The NetBSD Foundation nor the names of its 201.1Sscw * contributors may be used to endorse or promote products derived 211.1Sscw * from this software without specific prior written permission. 221.1Sscw * 231.1Sscw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 241.1Sscw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 251.1Sscw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 261.1Sscw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 271.1Sscw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 281.1Sscw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 291.1Sscw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 301.1Sscw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 311.1Sscw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 321.1Sscw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 331.1Sscw * POSSIBILITY OF SUCH DAMAGE. 341.1Sscw */ 351.1Sscw 361.1Sscw/* 371.1Sscw * Copyright (c) 1982, 1986, 1990, 1993 381.1Sscw * The Regents of the University of California. All rights reserved. 391.1Sscw * 401.1Sscw * This code is derived from software contributed to Berkeley by 411.1Sscw * the Systems Programming Group of the University of Utah Computer 421.1Sscw * Science Department. 431.1Sscw * 441.1Sscw * Redistribution and use in source and binary forms, with or without 451.1Sscw * modification, are permitted provided that the following conditions 461.1Sscw * are met: 471.1Sscw * 1. Redistributions of source code must retain the above copyright 481.1Sscw * notice, this list of conditions and the following disclaimer. 491.1Sscw * 2. Redistributions in binary form must reproduce the above copyright 501.1Sscw * notice, this list of conditions and the following disclaimer in the 511.1Sscw * documentation and/or other materials provided with the distribution. 521.6Sagc * 3. Neither the name of the University nor the names of its contributors 531.6Sagc * may be used to endorse or promote products derived from this software 541.6Sagc * without specific prior written permission. 551.6Sagc * 561.6Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 571.6Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 581.6Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 591.6Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 601.6Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 611.6Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 621.6Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 631.6Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 641.6Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 651.6Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 661.6Sagc * SUCH DAMAGE. 671.6Sagc * 681.6Sagc * from: Utah $Hdr: trap.c 1.37 92/12/20$ 691.6Sagc * 701.6Sagc * @(#)trap.c 8.5 (Berkeley) 1/4/94 711.6Sagc */ 721.6Sagc/* 731.6Sagc * Copyright (c) 1988 University of Utah. 741.6Sagc * 751.6Sagc * This code is derived from software contributed to Berkeley by 761.6Sagc * the Systems Programming Group of the University of Utah Computer 771.6Sagc * Science Department. 781.6Sagc * 791.6Sagc * Redistribution and use in source and binary forms, with or without 801.6Sagc * modification, are permitted provided that the following conditions 811.6Sagc * are met: 821.6Sagc * 1. Redistributions of source code must retain the above copyright 831.6Sagc * notice, this list of conditions and the following disclaimer. 841.6Sagc * 2. Redistributions in binary form must reproduce the above copyright 851.6Sagc * notice, this list of conditions and the following disclaimer in the 861.6Sagc * documentation and/or other materials provided with the distribution. 871.1Sscw * 3. All advertising materials mentioning features or use of this software 881.1Sscw * must display the following acknowledgement: 891.1Sscw * This product includes software developed by the University of 901.1Sscw * California, Berkeley and its contributors. 911.1Sscw * 4. Neither the name of the University nor the names of its contributors 921.1Sscw * may be used to endorse or promote products derived from this software 931.1Sscw * without specific prior written permission. 941.1Sscw * 951.1Sscw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 961.1Sscw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 971.1Sscw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 981.1Sscw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 991.1Sscw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1001.1Sscw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1011.1Sscw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1021.1Sscw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1031.1Sscw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1041.1Sscw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1051.1Sscw * SUCH DAMAGE. 1061.1Sscw * 1071.1Sscw * from: Utah $Hdr: trap.c 1.37 92/12/20$ 1081.1Sscw * 1091.1Sscw * @(#)trap.c 8.5 (Berkeley) 1/4/94 1101.1Sscw */ 1111.5Slukem 1121.5Slukem#include <sys/cdefs.h> 1131.12Sthorpej__KERNEL_RCSID(0, "$NetBSD: sunos_syscall.c,v 1.12 2006/03/07 03:32:05 thorpej Exp $"); 1141.1Sscw 1151.1Sscw#include "opt_syscall_debug.h" 1161.1Sscw#include "opt_execfmt.h" 1171.1Sscw 1181.1Sscw#include <sys/param.h> 1191.1Sscw#include <sys/systm.h> 1201.1Sscw#include <sys/proc.h> 1211.1Sscw#include <sys/acct.h> 1221.1Sscw#include <sys/kernel.h> 1231.1Sscw#include <sys/syscall.h> 1241.1Sscw#include <sys/syslog.h> 1251.1Sscw#include <sys/user.h> 1261.1Sscw 1271.1Sscw#include <machine/psl.h> 1281.1Sscw#include <machine/cpu.h> 1291.1Sscw#include <machine/reg.h> 1301.1Sscw 1311.1Sscw#include <uvm/uvm_extern.h> 1321.1Sscw 1331.1Sscw#include <compat/sunos/sunos_syscall.h> 1341.1Sscw#include <compat/sunos/sunos_exec.h> 1351.1Sscw 1361.1Sscwvoid sunos_syscall_intern(struct proc *); 1371.4Sthorpejstatic void sunos_syscall_plain(register_t, struct lwp *, struct frame *); 1381.4Sthorpejstatic void sunos_syscall_fancy(register_t, struct lwp *, struct frame *); 1391.1Sscw 1401.1Sscwvoid 1411.1Sscwsunos_syscall_intern(struct proc *p) 1421.1Sscw{ 1431.12Sthorpej 1441.12Sthorpej if (trace_is_enabled(p)) 1451.1Sscw p->p_md.md_syscall = sunos_syscall_fancy; 1461.1Sscw else 1471.1Sscw p->p_md.md_syscall = sunos_syscall_plain; 1481.1Sscw} 1491.1Sscw 1501.1Sscwstatic void 1511.4Sthorpejsunos_syscall_plain(register_t code, struct lwp *l, struct frame *frame) 1521.1Sscw{ 1531.4Sthorpej struct proc *p = l->l_proc; 1541.1Sscw caddr_t params; 1551.1Sscw const struct sysent *callp; 1561.1Sscw int error, nsys; 1571.1Sscw size_t argsize; 1581.1Sscw register_t args[16], rval[2]; 1591.1Sscw 1601.1Sscw nsys = p->p_emul->e_nsysent; 1611.1Sscw callp = p->p_emul->e_sysent; 1621.1Sscw 1631.1Sscw /* 1641.1Sscw * SunOS passes the syscall-number on the stack, whereas 1651.1Sscw * BSD passes it in D0. So, we have to get the real "code" 1661.1Sscw * from the stack, and clean up the stack, as SunOS glue 1671.1Sscw * code assumes the kernel pops the syscall argument the 1681.1Sscw * glue pushed on the stack. Sigh... 1691.1Sscw */ 1701.1Sscw code = fuword((caddr_t)frame->f_regs[SP]); 1711.1Sscw 1721.1Sscw /* 1731.1Sscw * XXX 1741.1Sscw * Don't do this for sunos_sigreturn, as there's no stored pc 1751.1Sscw * on the stack to skip, the argument follows the syscall 1761.1Sscw * number without a gap. 1771.1Sscw */ 1781.1Sscw if (code != SUNOS_SYS_sigreturn) { 1791.1Sscw frame->f_regs[SP] += sizeof (int); 1801.1Sscw /* 1811.1Sscw * remember that we adjusted the SP, 1821.1Sscw * might have to undo this if the system call 1831.1Sscw * returns ERESTART. 1841.1Sscw */ 1851.4Sthorpej l->l_md.md_flags |= MDL_STACKADJ; 1861.1Sscw } else 1871.4Sthorpej l->l_md.md_flags &= ~MDL_STACKADJ; 1881.1Sscw 1891.1Sscw params = (caddr_t)frame->f_regs[SP] + sizeof(int); 1901.1Sscw 1911.1Sscw switch (code) { 1921.1Sscw case SUNOS_SYS_syscall: 1931.1Sscw /* 1941.1Sscw * Code is first argument, followed by actual args. 1951.1Sscw */ 1961.1Sscw code = fuword(params); 1971.1Sscw params += sizeof(int); 1981.1Sscw break; 1991.1Sscw default: 2001.1Sscw break; 2011.1Sscw } 2021.1Sscw 2031.1Sscw if (code < 0 || code >= nsys) 2041.1Sscw callp += p->p_emul->e_nosys; /* illegal */ 2051.1Sscw else 2061.1Sscw callp += code; 2071.1Sscw 2081.1Sscw argsize = callp->sy_argsize; 2091.1Sscw if (argsize) { 2101.1Sscw error = copyin(params, (caddr_t)args, argsize); 2111.1Sscw if (error) 2121.1Sscw goto bad; 2131.1Sscw } 2141.1Sscw 2151.1Sscw#ifdef SYSCALL_DEBUG 2161.4Sthorpej scdebug_call(l, code, args); 2171.1Sscw#endif 2181.1Sscw 2191.1Sscw rval[0] = 0; 2201.1Sscw rval[1] = frame->f_regs[D1]; 2211.4Sthorpej error = (*callp->sy_call)(l, args, rval); 2221.1Sscw 2231.1Sscw switch (error) { 2241.1Sscw case 0: 2251.1Sscw /* 2261.1Sscw * Reinitialize proc pointer `p' as it may be different 2271.1Sscw * if this is a child returning from fork syscall. 2281.1Sscw */ 2291.1Sscw p = curproc; 2301.1Sscw frame->f_regs[D0] = rval[0]; 2311.1Sscw frame->f_regs[D1] = rval[1]; 2321.1Sscw frame->f_sr &= ~PSL_C; /* carry bit */ 2331.1Sscw break; 2341.1Sscw case ERESTART: 2351.1Sscw /* 2361.1Sscw * We always enter through a `trap' instruction, which is 2 2371.1Sscw * bytes, so adjust the pc by that amount. 2381.1Sscw */ 2391.1Sscw frame->f_pc = frame->f_pc - 2; 2401.1Sscw break; 2411.1Sscw case EJUSTRETURN: 2421.1Sscw /* nothing to do */ 2431.1Sscw break; 2441.1Sscw default: 2451.1Sscw bad: 2461.1Sscw frame->f_regs[D0] = error; 2471.1Sscw frame->f_sr |= PSL_C; /* carry bit */ 2481.1Sscw break; 2491.1Sscw } 2501.1Sscw 2511.1Sscw /* need new p-value for this */ 2521.4Sthorpej if (l->l_md.md_flags & MDL_STACKADJ) { 2531.4Sthorpej l->l_md.md_flags &= ~MDL_STACKADJ; 2541.1Sscw if (error == ERESTART) 2551.1Sscw frame->f_regs[SP] -= sizeof (int); 2561.1Sscw } 2571.1Sscw 2581.1Sscw#ifdef SYSCALL_DEBUG 2591.1Sscw scdebug_ret(p, code, error, rval) 2601.1Sscw#endif 2611.1Sscw} 2621.1Sscw 2631.1Sscwstatic void 2641.4Sthorpejsunos_syscall_fancy(register_t code, struct lwp *l, struct frame *frame) 2651.1Sscw{ 2661.4Sthorpej struct proc *p = l->l_proc; 2671.1Sscw caddr_t params; 2681.1Sscw const struct sysent *callp; 2691.1Sscw int error, nsys; 2701.1Sscw size_t argsize; 2711.1Sscw register_t args[16], rval[2]; 2721.1Sscw 2731.1Sscw nsys = p->p_emul->e_nsysent; 2741.1Sscw callp = p->p_emul->e_sysent; 2751.1Sscw 2761.1Sscw /* 2771.1Sscw * SunOS passes the syscall-number on the stack, whereas 2781.1Sscw * BSD passes it in D0. So, we have to get the real "code" 2791.1Sscw * from the stack, and clean up the stack, as SunOS glue 2801.1Sscw * code assumes the kernel pops the syscall argument the 2811.1Sscw * glue pushed on the stack. Sigh... 2821.1Sscw */ 2831.1Sscw code = fuword((caddr_t)frame->f_regs[SP]); 2841.1Sscw 2851.1Sscw /* 2861.1Sscw * XXX 2871.1Sscw * Don't do this for sunos_sigreturn, as there's no stored pc 2881.1Sscw * on the stack to skip, the argument follows the syscall 2891.1Sscw * number without a gap. 2901.1Sscw */ 2911.1Sscw if (code != SUNOS_SYS_sigreturn) { 2921.1Sscw frame->f_regs[SP] += sizeof (int); 2931.1Sscw /* 2941.1Sscw * remember that we adjusted the SP, 2951.1Sscw * might have to undo this if the system call 2961.1Sscw * returns ERESTART. 2971.1Sscw */ 2981.4Sthorpej l->l_md.md_flags |= MDL_STACKADJ; 2991.1Sscw } else 3001.4Sthorpej l->l_md.md_flags &= ~MDL_STACKADJ; 3011.1Sscw 3021.1Sscw params = (caddr_t)frame->f_regs[SP] + sizeof(int); 3031.1Sscw 3041.1Sscw switch (code) { 3051.1Sscw case SUNOS_SYS_syscall: 3061.1Sscw /* 3071.1Sscw * Code is first argument, followed by actual args. 3081.1Sscw */ 3091.1Sscw code = fuword(params); 3101.1Sscw params += sizeof(int); 3111.1Sscw break; 3121.1Sscw default: 3131.1Sscw break; 3141.1Sscw } 3151.1Sscw 3161.1Sscw if (code < 0 || code >= nsys) 3171.1Sscw callp += p->p_emul->e_nosys; /* illegal */ 3181.1Sscw else 3191.1Sscw callp += code; 3201.1Sscw 3211.1Sscw argsize = callp->sy_argsize; 3221.1Sscw if (argsize) { 3231.1Sscw error = copyin(params, (caddr_t)args, argsize); 3241.1Sscw if (error) 3251.1Sscw goto bad; 3261.1Sscw } 3271.1Sscw 3281.7Ssimonb if ((error = trace_enter(l, code, code, NULL, args)) != 0) 3291.8Schristos goto out; 3301.1Sscw 3311.1Sscw rval[0] = 0; 3321.1Sscw rval[1] = frame->f_regs[D1]; 3331.4Sthorpej error = (*callp->sy_call)(l, args, rval); 3341.8Schristosout: 3351.1Sscw switch (error) { 3361.1Sscw case 0: 3371.1Sscw /* 3381.1Sscw * Reinitialize proc pointer `p' as it may be different 3391.1Sscw * if this is a child returning from fork syscall. 3401.1Sscw */ 3411.1Sscw p = curproc; 3421.1Sscw frame->f_regs[D0] = rval[0]; 3431.1Sscw frame->f_regs[D1] = rval[1]; 3441.1Sscw frame->f_sr &= ~PSL_C; /* carry bit */ 3451.1Sscw break; 3461.1Sscw case ERESTART: 3471.1Sscw /* 3481.1Sscw * We always enter through a `trap' instruction, which is 2 3491.1Sscw * bytes, so adjust the pc by that amount. 3501.1Sscw */ 3511.1Sscw frame->f_pc = frame->f_pc - 2; 3521.1Sscw break; 3531.1Sscw case EJUSTRETURN: 3541.1Sscw /* nothing to do */ 3551.1Sscw break; 3561.1Sscw default: 3571.1Sscw bad: 3581.1Sscw frame->f_regs[D0] = error; 3591.1Sscw frame->f_sr |= PSL_C; /* carry bit */ 3601.1Sscw break; 3611.1Sscw } 3621.1Sscw 3631.1Sscw /* need new p-value for this */ 3641.4Sthorpej if (l->l_md.md_flags & MDL_STACKADJ) { 3651.4Sthorpej l->l_md.md_flags &= ~MDL_STACKADJ; 3661.1Sscw if (error == ERESTART) 3671.1Sscw frame->f_regs[SP] -= sizeof (int); 3681.1Sscw } 3691.1Sscw 3701.4Sthorpej trace_exit(l, code, args, rval, error); 3711.1Sscw} 372