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