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/compat/netbsd32/netbsd32_sa.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 /*      $NetBSD: netbsd32_sa.c,v 1.7.4.1 2008/11/22 04:54:42 snj Exp $  */
    2 
    3 /*
    4  *  Copyright (c) 2005 The NetBSD Foundation.
    5  *  All rights reserved.
    6  *
    7  *  This code is derived from software contributed to the NetBSD Foundation
    8  *   by Quentin Garnier.
    9  *
   10  *  Redistribution and use in source and binary forms, with or without
   11  *  modification, are permitted provided that the following conditions
   12  *  are met:
   13  *  1. Redistributions of source code must retain the above copyright
   14  *     notice, this list of conditions and the following disclaimer.
   15  *  2. Redistributions in binary form must reproduce the above copyright
   16  *     notice, this list of conditions and the following disclaimer in the
   17  *     documentation and/or other materials provided with the distribution.
   18  *  3. Neither the name of The NetBSD Foundation nor the names of its
   19  *     contributors may be used to endorse or promote products derived
   20  *     from this software without specific prior written permission.
   21  *
   22  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   23  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   24  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   25  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   26  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   27  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   28  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   29  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   30  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   31  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32  *  POSSIBILITY OF SUCH DAMAGE.
   33  */
   34 
   35 #include <sys/cdefs.h>
   36 __KERNEL_RCSID(0, "$NetBSD: netbsd32_sa.c,v 1.7.4.1 2008/11/22 04:54:42 snj Exp $");
   37 
   38 #include <sys/types.h>
   39 #include <sys/param.h>
   40 #include <sys/systm.h>
   41 #include <sys/kernel.h>
   42 #include <sys/dirent.h>
   43 #include <sys/mount.h>
   44 #include <sys/proc.h>
   45 #include <sys/sa.h>
   46 #include <sys/savar.h>
   47 #include <sys/syscallargs.h>
   48 
   49 #include <compat/netbsd32/netbsd32.h>
   50 #include <compat/netbsd32/netbsd32_syscallargs.h>
   51 #include <compat/netbsd32/netbsd32_conv.h>
   52 #include <compat/netbsd32/netbsd32_sa.h>
   53 
   54 /* SA emulation helpers */
   55 int
   56 netbsd32_sacopyout(int type, const void *src, void *dst)
   57 {
   58         switch (type) {
   59         case SAOUT_UCONTEXT:
   60                 {
   61                         const ucontext_t *u = src;
   62                         ucontext32_t u32;
   63 
   64                         memset(&u32, 0, sizeof(u32));
   65                         u32.uc_flags = u->uc_flags;
   66                         u32.uc_stack.ss_sp = (uintptr_t)u->uc_stack.ss_sp;
   67                         u32.uc_stack.ss_size = u->uc_stack.ss_size;
   68                         u32.uc_stack.ss_flags = u->uc_stack.ss_flags;
   69 
   70                         return copyout(&u32, dst, sizeof(u32));
   71                 } break;
   72         case SAOUT_SA_T:
   73                 {
   74                         const struct sa_t *sa = src;
   75                         struct netbsd32_sa_t sa32;
   76 
   77                         sa32.sa_id = sa->sa_id;
   78                         sa32.sa_cpu = sa->sa_cpu;
   79                         NETBSD32PTR32(sa32.sa_context, sa->sa_context);
   80 
   81                         return copyout(&sa32, dst, sizeof(sa32));
   82                 } break;
   83         case SAOUT_SAP_T:
   84                 {
   85                         void * const *p = src;
   86                         netbsd32_pointer_t p32;
   87 
   88                         NETBSD32PTR32(p32, *p);
   89                         return copyout(&p32, dst, sizeof(p32));
   90                 } break;
   91         }
   92         return EINVAL;
   93 }
   94 
   95 int
   96 netbsd32_upcallconv(struct lwp *l, int type, size_t *pargsize, void **parg,
   97     void (**pfunc)(void *))
   98 {
   99         switch (type & SA_UPCALL_TYPE_MASK) {
  100         case SA_UPCALL_SIGNAL:
  101         case SA_UPCALL_SIGEV:
  102                 {
  103                         siginfo32_t si32;
  104                         siginfo_t *si = *parg;
  105 
  106                         netbsd32_si_to_si32(&si32, si);
  107 
  108                         /*
  109                          * This is so wrong, but assuming
  110                          * sizeof(siginfo32_t) < sizeof(siginfo_t) is not
  111                          * very dangerous.
  112                          */
  113                         memcpy(*parg, &si32, sizeof(si32));
  114                         *pargsize = sizeof(si32);
  115                 }
  116         }
  117 
  118         return 0;
  119 }
  120 
  121 void *
  122 netbsd32_sa_ucsp(void *arg)
  123 {
  124         ucontext32_t *uc32 = arg;
  125 
  126         return NETBSD32IPTR64(_UC_MACHINE32_SP(uc32));
  127 }
  128 
  129 /* Sycalls conversion */
  130 
  131 int
  132 netbsd32_sa_register(struct lwp *l,
  133     const struct netbsd32_sa_register_args *uap, register_t *retval)
  134 {
  135 #ifdef COMPAT_40
  136         /* {
  137                 syscallarg(netbsd32_sa_upcall_t) new;
  138                 syscallarg(netbsd32_sa_upcallp_t) old;
  139                 syscallarg(int) flags;
  140                 syscallarg(netbsd32_ssize_t) stackinfo_offset;
  141         } */
  142         sa_upcall_t prev;
  143         int error;
  144 
  145         error = dosa_register(l, NETBSD32PTR64(SCARG(uap, new)), &prev,
  146             SCARG(uap, flags), SCARG(uap, stackinfo_offset));
  147         if (error)
  148                 return error;
  149 
  150         if (NETBSD32PTR64(SCARG(uap, old))) {
  151                 
  152                 netbsd32_sa_upcall_t old;
  153                 NETBSD32PTR32(old, prev);
  154                 return copyout(&old, NETBSD32PTR64(SCARG(uap, old)),
  155                     sizeof(old));
  156         }
  157 
  158         return 0;
  159 #else
  160         return ENOSYS;
  161 #endif  
  162 }
  163 
  164 #ifdef COMPAT_40
  165 static int
  166 netbsd32_sa_copyin_stack(stack_t *stacks, int index, stack_t *dest)
  167 {
  168         stack32_t s32, *stacks32;
  169         int error;
  170 
  171         stacks32 = (stack32_t *)stacks;
  172         error = copyin(stacks32 + index, &s32, sizeof(s32));
  173         if (error)
  174                 return error;
  175 
  176         dest->ss_sp = NETBSD32IPTR64(s32.ss_sp);
  177         dest->ss_size = s32.ss_size;
  178         dest->ss_flags = s32.ss_flags;
  179 
  180         return 0;
  181 }
  182 #endif
  183 
  184 int
  185 netbsd32_sa_stacks(struct lwp *l, const struct netbsd32_sa_stacks_args *uap,
  186     register_t *retval)
  187 {
  188 #ifdef COMPAT_40
  189          /* {
  190                 syscallarg(int) num;
  191                 syscallarg(netbsd32_stackp_t) stacks;
  192         } */
  193 
  194         return sa_stacks1(l, retval, SCARG(uap, num),
  195             NETBSD32PTR64(SCARG(uap, stacks)), netbsd32_sa_copyin_stack);
  196 #else
  197         return ENOSYS;
  198 #endif
  199 }
  200 
  201 int
  202 netbsd32_sa_setconcurrency(struct lwp *l,
  203     const struct netbsd32_sa_setconcurrency_args *uap, register_t *retval)
  204 {
  205         /* {
  206                 syscallarg(int) concurrency;
  207         } */
  208         struct sys_sa_setconcurrency_args ua;
  209 
  210         NETBSD32TO64_UAP(concurrency);
  211         return sys_sa_setconcurrency(l, &ua, retval);
  212 }
  213 
  214 int
  215 netbsd32_sa_preempt(struct lwp *l, const struct netbsd32_sa_preempt_args *uap,
  216     register_t *retval)
  217 {
  218          /* {
  219                 syscallarg(int) sa_id;
  220         } */
  221         struct sys_sa_preempt_args ua;
  222 
  223         NETBSD32TO64_UAP(sa_id);
  224         return sys_sa_preempt(l, &ua, retval);
  225 }

Cache object: 71ce1ed591f2f9771326ce927bb755de


[ 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.