event.h revision 1.3 1 1.3 christos /* $NetBSD: event.h,v 1.3 2023/07/28 18:19:01 christos 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.2 christos struct timespec;
36 1.2 christos
37 1.3 christos #ifdef _KERNEL
38 1.3 christos #include <lib/libkern/libkern.h>
39 1.3 christos #else
40 1.3 christos #include <string.h>
41 1.3 christos #endif
42 1.3 christos
43 1.3 christos struct kevent100 {
44 1.3 christos uintptr_t ident; /* identifier for this event */
45 1.3 christos uint32_t filter; /* filter for event */
46 1.3 christos uint32_t flags; /* action flags for kqueue */
47 1.3 christos uint32_t fflags; /* filter flag value */
48 1.3 christos int64_t data; /* filter data value */
49 1.3 christos void *udata; /* opaque user data identifier */
50 1.3 christos };
51 1.3 christos
52 1.3 christos static __inline void
53 1.3 christos kevent100_to_kevent(const struct kevent100 *kev100, struct kevent *kev)
54 1.3 christos {
55 1.3 christos memset(kev, 0, sizeof(*kev));
56 1.3 christos memcpy(kev, kev100, sizeof(*kev100));
57 1.3 christos }
58 1.3 christos
59 1.3 christos static __inline void
60 1.3 christos kevent_to_kevent100(const struct kevent *kev, struct kevent100 *kev100)
61 1.3 christos {
62 1.3 christos memcpy(kev100, kev, sizeof(*kev100));
63 1.3 christos }
64 1.3 christos
65 1.3 christos #ifdef _KERNEL
66 1.3 christos static int
67 1.3 christos compat_100___kevent50_fetch_changes(void *ctx, const struct kevent *changelist,
68 1.3 christos struct kevent *changes, size_t index, int n)
69 1.3 christos {
70 1.3 christos int error, i;
71 1.3 christos struct kevent100 *buf;
72 1.3 christos const size_t buf_size = sizeof(*buf) * n;
73 1.3 christos const struct kevent100 *changelist100 = (const struct kevent100 *)changelist;
74 1.3 christos
75 1.3 christos KASSERT(n >= 0);
76 1.3 christos
77 1.3 christos buf = kmem_alloc(buf_size, KM_SLEEP);
78 1.3 christos
79 1.3 christos error = copyin(changelist100 + index, buf, buf_size);
80 1.3 christos if (error != 0)
81 1.3 christos goto leave;
82 1.3 christos
83 1.3 christos for (i = 0; i < n; i++)
84 1.3 christos kevent100_to_kevent(buf + i, changes + i);
85 1.3 christos
86 1.3 christos leave:
87 1.3 christos kmem_free(buf, buf_size);
88 1.3 christos return error;
89 1.3 christos }
90 1.3 christos
91 1.3 christos static int
92 1.3 christos compat_100___kevent50_put_events(void *ctx, struct kevent *events,
93 1.3 christos struct kevent *eventlist, size_t index, int n)
94 1.3 christos {
95 1.3 christos int error, i;
96 1.3 christos struct kevent100 *buf;
97 1.3 christos const size_t buf_size = sizeof(*buf) * n;
98 1.3 christos struct kevent100 *eventlist100 = (struct kevent100 *)eventlist;
99 1.3 christos
100 1.3 christos KASSERT(n >= 0);
101 1.3 christos
102 1.3 christos buf = kmem_alloc(buf_size, KM_SLEEP);
103 1.3 christos
104 1.3 christos for (i = 0; i < n; i++)
105 1.3 christos kevent_to_kevent100(events + i, buf + i);
106 1.3 christos
107 1.3 christos error = copyout(buf, eventlist100 + index, buf_size);
108 1.3 christos
109 1.3 christos kmem_free(buf, buf_size);
110 1.3 christos return error;
111 1.3 christos }
112 1.3 christos #endif /* _KERNEL */
113 1.3 christos
114 1.2 christos __BEGIN_DECLS
115 1.3 christos int kevent(int, const struct kevent100 *, size_t, struct kevent100 *,
116 1.3 christos size_t, const struct timespec50 *);
117 1.3 christos int __kevent50(int, const struct kevent100 *, size_t, struct kevent100 *,
118 1.3 christos size_t, const struct timespec *);
119 1.3 christos int __kevent100(int, const struct kevent *, size_t, struct kevent *,
120 1.3 christos size_t, const struct timespec *);
121 1.2 christos __END_DECLS
122 1.2 christos
123 1.2 christos #endif /* !_COMPAT_SYS_EVENT_H_ */
124