The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/amd64/ia32/ia32_syscall.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (C) 1994, David Greenman
    3  * Copyright (c) 1990, 1993
    4  *      The Regents of the University of California.  All rights reserved.
    5  *
    6  * This code is derived from software contributed to Berkeley by
    7  * the University of Utah, and William Jolitz.
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  * 1. Redistributions of source code must retain the above copyright
   13  *    notice, this list of conditions and the following disclaimer.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  * 3. All advertising materials mentioning features or use of this software
   18  *    must display the following acknowledgement:
   19  *      This product includes software developed by the University of
   20  *      California, Berkeley and its contributors.
   21  * 4. Neither the name of the University nor the names of its contributors
   22  *    may be used to endorse or promote products derived from this software
   23  *    without specific prior written permission.
   24  *
   25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   35  * SUCH DAMAGE.
   36  */
   37 
   38 #include <sys/cdefs.h>
   39 __FBSDID("$FreeBSD: releng/8.4/sys/amd64/ia32/ia32_syscall.c 225855 2011-09-29 00:39:56Z kib $");
   40 
   41 /*
   42  * 386 Trap and System call handling
   43  */
   44 
   45 #include "opt_clock.h"
   46 #include "opt_cpu.h"
   47 #include "opt_isa.h"
   48 #include "opt_ktrace.h"
   49 
   50 #include <sys/param.h>
   51 #include <sys/bus.h>
   52 #include <sys/systm.h>
   53 #include <sys/proc.h>
   54 #include <sys/pioctl.h>
   55 #include <sys/kernel.h>
   56 #include <sys/ktr.h>
   57 #include <sys/lock.h>
   58 #include <sys/mutex.h>
   59 #include <sys/proc.h>
   60 #include <sys/ptrace.h>
   61 #include <sys/resourcevar.h>
   62 #include <sys/signalvar.h>
   63 #include <sys/syscall.h>
   64 #include <sys/sysctl.h>
   65 #include <sys/sysent.h>
   66 #include <sys/uio.h>
   67 #include <sys/vmmeter.h>
   68 #ifdef KTRACE
   69 #include <sys/ktrace.h>
   70 #endif
   71 #include <security/audit/audit.h>
   72 
   73 #include <vm/vm.h>
   74 #include <vm/vm_param.h>
   75 #include <vm/pmap.h>
   76 #include <vm/vm_kern.h>
   77 #include <vm/vm_map.h>
   78 #include <vm/vm_page.h>
   79 #include <vm/vm_extern.h>
   80 
   81 #include <machine/cpu.h>
   82 #include <machine/intr_machdep.h>
   83 #include <machine/md_var.h>
   84 
   85 #include <compat/freebsd32/freebsd32_util.h>
   86 
   87 #define IDTVEC(name)    __CONCAT(X,name)
   88 
   89 extern inthand_t IDTVEC(int0x80_syscall), IDTVEC(rsvd);
   90 
   91 void ia32_syscall(struct trapframe *frame);     /* Called from asm code */
   92 
   93 void
   94 ia32_set_syscall_retval(struct thread *td, int error)
   95 {
   96 
   97         cpu_set_syscall_retval(td, error);
   98 }
   99 
  100 int
  101 ia32_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
  102 {
  103         struct proc *p;
  104         struct trapframe *frame;
  105         caddr_t params;
  106         u_int32_t args[8];
  107         int error, i;
  108 
  109         p = td->td_proc;
  110         frame = td->td_frame;
  111 
  112         params = (caddr_t)frame->tf_rsp + sizeof(u_int32_t);
  113         sa->code = frame->tf_rax;
  114 
  115         /*
  116          * Need to check if this is a 32 bit or 64 bit syscall.
  117          */
  118         if (sa->code == SYS_syscall) {
  119                 /*
  120                  * Code is first argument, followed by actual args.
  121                  */
  122                 sa->code = fuword32(params);
  123                 params += sizeof(int);
  124         } else if (sa->code == SYS___syscall) {
  125                 /*
  126                  * Like syscall, but code is a quad, so as to maintain
  127                  * quad alignment for the rest of the arguments.
  128                  * We use a 32-bit fetch in case params is not
  129                  * aligned.
  130                  */
  131                 sa->code = fuword32(params);
  132                 params += sizeof(quad_t);
  133         }
  134         if (p->p_sysent->sv_mask)
  135                 sa->code &= p->p_sysent->sv_mask;
  136         if (sa->code >= p->p_sysent->sv_size)
  137                 sa->callp = &p->p_sysent->sv_table[0];
  138         else
  139                 sa->callp = &p->p_sysent->sv_table[sa->code];
  140         sa->narg = sa->callp->sy_narg;
  141 
  142         if (params != NULL && sa->narg != 0)
  143                 error = copyin(params, (caddr_t)args,
  144                     (u_int)(sa->narg * sizeof(int)));
  145         else
  146                 error = 0;
  147 
  148         for (i = 0; i < sa->narg; i++)
  149                 sa->args[i] = args[i];
  150 
  151         if (error == 0) {
  152                 td->td_retval[0] = 0;
  153                 td->td_retval[1] = frame->tf_rdx;
  154         }
  155 
  156         return (error);
  157 }
  158 
  159 #include "../../kern/subr_syscall.c"
  160 
  161 void
  162 ia32_syscall(struct trapframe *frame)
  163 {
  164         struct thread *td;
  165         struct syscall_args sa;
  166         register_t orig_tf_rflags;
  167         int error;
  168         ksiginfo_t ksi;
  169 
  170         orig_tf_rflags = frame->tf_rflags;
  171         td = curthread;
  172         td->td_frame = frame;
  173 
  174         error = syscallenter(td, &sa);
  175 
  176         /*
  177          * Traced syscall.
  178          */
  179         if (orig_tf_rflags & PSL_T) {
  180                 frame->tf_rflags &= ~PSL_T;
  181                 ksiginfo_init_trap(&ksi);
  182                 ksi.ksi_signo = SIGTRAP;
  183                 ksi.ksi_code = TRAP_TRACE;
  184                 ksi.ksi_addr = (void *)frame->tf_rip;
  185                 trapsignal(td, &ksi);
  186         }
  187 
  188         syscallret(td, error, &sa);
  189 }
  190 
  191 static void
  192 ia32_syscall_enable(void *dummy)
  193 {
  194 
  195         setidt(IDT_SYSCALL, &IDTVEC(int0x80_syscall), SDT_SYSIGT, SEL_UPL, 0);
  196 }
  197 
  198 static void
  199 ia32_syscall_disable(void *dummy)
  200 {
  201 
  202         setidt(IDT_SYSCALL, &IDTVEC(rsvd), SDT_SYSIGT, SEL_KPL, 0);
  203 }
  204 
  205 SYSINIT(ia32_syscall, SI_SUB_EXEC, SI_ORDER_ANY, ia32_syscall_enable, NULL);
  206 SYSUNINIT(ia32_syscall, SI_SUB_EXEC, SI_ORDER_ANY, ia32_syscall_disable, NULL);

Cache object: 104bca797f990617315e673519dd3b6e


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.