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