1 1.5 riastrad /* $NetBSD: event.h,v 1.5 2025/04/04 20:51:32 riastradh Exp $ */ 2 1.2 christos 3 1.2 christos /*- 4 1.2 christos * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon (at) FreeBSD.org> 5 1.2 christos * All rights reserved. 6 1.2 christos * 7 1.2 christos * Redistribution and use in source and binary forms, with or without 8 1.2 christos * modification, are permitted provided that the following conditions 9 1.2 christos * are met: 10 1.2 christos * 1. Redistributions of source code must retain the above copyright 11 1.2 christos * notice, this list of conditions and the following disclaimer. 12 1.2 christos * 2. Redistributions in binary form must reproduce the above copyright 13 1.2 christos * notice, this list of conditions and the following disclaimer in the 14 1.2 christos * documentation and/or other materials provided with the distribution. 15 1.2 christos * 16 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 1.2 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 1.2 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 1.2 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 1.2 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 1.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 1.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 1.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 1.2 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 1.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 1.2 christos * SUCH DAMAGE. 27 1.2 christos * 28 1.2 christos * $FreeBSD: src/sys/sys/event.h,v 1.12 2001/02/24 01:44:03 jlemon Exp $ 29 1.2 christos */ 30 1.2 christos 31 1.2 christos #ifndef _COMPAT_SYS_EVENT_H_ 32 1.2 christos #define _COMPAT_SYS_EVENT_H_ 33 1.2 christos 34 1.2 christos #include <sys/cdefs.h> 35 1.5 riastrad 36 1.2 christos struct timespec; 37 1.5 riastrad struct timespec50; 38 1.2 christos 39 1.3 christos #ifdef _KERNEL 40 1.3 christos #include <lib/libkern/libkern.h> 41 1.3 christos #else 42 1.3 christos #include <string.h> 43 1.3 christos #endif 44 1.3 christos 45 1.3 christos struct kevent100 { 46 1.3 christos uintptr_t ident; /* identifier for this event */ 47 1.3 christos uint32_t filter; /* filter for event */ 48 1.3 christos uint32_t flags; /* action flags for kqueue */ 49 1.3 christos uint32_t fflags; /* filter flag value */ 50 1.3 christos int64_t data; /* filter data value */ 51 1.3 christos void *udata; /* opaque user data identifier */ 52 1.3 christos }; 53 1.3 christos 54 1.3 christos static __inline void 55 1.3 christos kevent100_to_kevent(const struct kevent100 *kev100, struct kevent *kev) 56 1.3 christos { 57 1.3 christos memset(kev, 0, sizeof(*kev)); 58 1.3 christos memcpy(kev, kev100, sizeof(*kev100)); 59 1.3 christos } 60 1.3 christos 61 1.3 christos static __inline void 62 1.3 christos kevent_to_kevent100(const struct kevent *kev, struct kevent100 *kev100) 63 1.3 christos { 64 1.3 christos memcpy(kev100, kev, sizeof(*kev100)); 65 1.3 christos } 66 1.3 christos 67 1.3 christos #ifdef _KERNEL 68 1.4 rin static __inline int 69 1.3 christos compat_100___kevent50_fetch_changes(void *ctx, const struct kevent *changelist, 70 1.3 christos struct kevent *changes, size_t index, int n) 71 1.3 christos { 72 1.3 christos int error, i; 73 1.3 christos struct kevent100 *buf; 74 1.3 christos const size_t buf_size = sizeof(*buf) * n; 75 1.3 christos const struct kevent100 *changelist100 = (const struct kevent100 *)changelist; 76 1.3 christos 77 1.3 christos KASSERT(n >= 0); 78 1.3 christos 79 1.3 christos buf = kmem_alloc(buf_size, KM_SLEEP); 80 1.3 christos 81 1.3 christos error = copyin(changelist100 + index, buf, buf_size); 82 1.3 christos if (error != 0) 83 1.3 christos goto leave; 84 1.3 christos 85 1.3 christos for (i = 0; i < n; i++) 86 1.3 christos kevent100_to_kevent(buf + i, changes + i); 87 1.3 christos 88 1.3 christos leave: 89 1.3 christos kmem_free(buf, buf_size); 90 1.3 christos return error; 91 1.3 christos } 92 1.3 christos 93 1.4 rin static __inline int 94 1.3 christos compat_100___kevent50_put_events(void *ctx, struct kevent *events, 95 1.3 christos struct kevent *eventlist, size_t index, int n) 96 1.3 christos { 97 1.3 christos int error, i; 98 1.3 christos struct kevent100 *buf; 99 1.3 christos const size_t buf_size = sizeof(*buf) * n; 100 1.3 christos struct kevent100 *eventlist100 = (struct kevent100 *)eventlist; 101 1.3 christos 102 1.3 christos KASSERT(n >= 0); 103 1.3 christos 104 1.3 christos buf = kmem_alloc(buf_size, KM_SLEEP); 105 1.3 christos 106 1.3 christos for (i = 0; i < n; i++) 107 1.3 christos kevent_to_kevent100(events + i, buf + i); 108 1.3 christos 109 1.3 christos error = copyout(buf, eventlist100 + index, buf_size); 110 1.3 christos 111 1.3 christos kmem_free(buf, buf_size); 112 1.3 christos return error; 113 1.3 christos } 114 1.3 christos #endif /* _KERNEL */ 115 1.3 christos 116 1.2 christos __BEGIN_DECLS 117 1.3 christos int kevent(int, const struct kevent100 *, size_t, struct kevent100 *, 118 1.3 christos size_t, const struct timespec50 *); 119 1.3 christos int __kevent50(int, const struct kevent100 *, size_t, struct kevent100 *, 120 1.3 christos size_t, const struct timespec *); 121 1.3 christos int __kevent100(int, const struct kevent *, size_t, struct kevent *, 122 1.3 christos size_t, const struct timespec *); 123 1.2 christos __END_DECLS 124 1.2 christos 125 1.2 christos #endif /* !_COMPAT_SYS_EVENT_H_ */ 126