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_event.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_event.c,v 1.6 2008/04/29 06:53:02 martin Exp $        */
    2 
    3 /*
    4  *  Copyright (c) 2005 The NetBSD Foundation.
    5  *  All rights reserved.
    6  *
    7  *  Redistribution and use in source and binary forms, with or without
    8  *  modification, are permitted provided that the following conditions
    9  *  are met:
   10  *  1. Redistributions of source code must retain the above copyright
   11  *     notice, this list of conditions and the following disclaimer.
   12  *  2. Redistributions in binary form must reproduce the above copyright
   13  *     notice, this list of conditions and the following disclaimer in the
   14  *     documentation and/or other materials provided with the distribution.
   15  *
   16  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   17  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   18  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   19  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   20  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   26  *  POSSIBILITY OF SUCH DAMAGE.
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __KERNEL_RCSID(0, "$NetBSD: netbsd32_event.c,v 1.6 2008/04/29 06:53:02 martin Exp $");
   31 
   32 #include <sys/types.h>
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/file.h>
   36 #include <sys/filedesc.h>
   37 #include <sys/select.h>
   38 #include <sys/event.h>
   39 #include <sys/eventvar.h>
   40 #include <sys/malloc.h>
   41 #include <sys/proc.h>
   42 #include <sys/dirent.h>
   43 
   44 #include <compat/netbsd32/netbsd32.h>
   45 #include <compat/netbsd32/netbsd32_syscall.h>
   46 #include <compat/netbsd32/netbsd32_syscallargs.h>
   47 #include <compat/netbsd32/netbsd32_conv.h>
   48 
   49 static int
   50 netbsd32_kevent_fetch_timeout(const void *src, void *dest, size_t length)
   51 {
   52         struct netbsd32_timespec ts32;
   53         int error;
   54 
   55         KASSERT(length == sizeof(struct timespec));
   56 
   57         error = copyin(src, &ts32, sizeof(ts32));
   58         if (error)
   59                 return error;
   60         netbsd32_to_timespec(&ts32, (struct timespec *)dest);
   61         return 0;
   62 }
   63 
   64 static int
   65 netbsd32_kevent_fetch_changes(void *private, const struct kevent *changelist,
   66     struct kevent *changes, size_t index, int n)
   67 {
   68         const struct netbsd32_kevent *src =
   69             (const struct netbsd32_kevent *)changelist;
   70         struct netbsd32_kevent *kev32, *changes32 = private;
   71         int error, i;
   72 
   73         error = copyin(src + index, changes32, n * sizeof(*changes32));
   74         if (error)
   75                 return error;
   76         for (i = 0, kev32 = changes32; i < n; i++, kev32++, changes++)
   77                 netbsd32_to_kevent(kev32, changes);
   78         return 0;
   79 }
   80 
   81 static int
   82 netbsd32_kevent_put_events(void *private, struct kevent *events,
   83     struct kevent *eventlist, size_t index, int n)
   84 {
   85         struct netbsd32_kevent *kev32, *events32 = private;
   86         int i;
   87 
   88         for (i = 0, kev32 = events32; i < n; i++, kev32++, events++)
   89                 netbsd32_from_kevent(events, kev32);
   90         kev32 = (struct netbsd32_kevent *)eventlist;
   91         return  copyout(events32, kev32, n * sizeof(*events32));
   92 }
   93 
   94 int
   95 netbsd32_kevent(struct lwp *l, const struct netbsd32_kevent_args *uap, register_t *retval)
   96 {
   97         /* {
   98                 syscallarg(int) fd;
   99                 syscallarg(netbsd32_keventp_t) changelist;
  100                 syscallarg(netbsd32_size_t) nchanges;
  101                 syscallarg(netbsd32_keventp_t) eventlist;
  102                 syscallarg(netbsd32_size_t) nevents;
  103                 syscallarg(netbsd32_timespecp_t) timeout;
  104         } */
  105         int error;
  106         size_t maxalloc, nchanges, nevents;
  107         struct kevent_ops netbsd32_kevent_ops = {
  108                 keo_fetch_timeout: netbsd32_kevent_fetch_timeout,
  109                 keo_fetch_changes: netbsd32_kevent_fetch_changes,
  110                 keo_put_events: netbsd32_kevent_put_events,
  111         };
  112 
  113         nchanges = SCARG(uap, nchanges);
  114         nevents = SCARG(uap, nevents);
  115         maxalloc = MIN(KQ_NEVENTS, MAX(nchanges, nevents));
  116         netbsd32_kevent_ops.keo_private =
  117             malloc(maxalloc * sizeof(struct netbsd32_kevent), M_TEMP,
  118             M_WAITOK);
  119 
  120         error = kevent1(retval, SCARG(uap, fd),
  121             NETBSD32PTR64(SCARG(uap, changelist)), nchanges,
  122             NETBSD32PTR64(SCARG(uap, eventlist)), nevents,
  123             NETBSD32PTR64(SCARG(uap, timeout)), &netbsd32_kevent_ops);
  124 
  125         free(netbsd32_kevent_ops.keo_private, M_TEMP);
  126         return error;
  127 }

Cache object: 23fec02913792171df19abbbd4f3da1c


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