xref: /netbsd-src/sys/compat/sys/event.h (revision 6a611fe9f42cd26043ff2ac25e5b3c1140e40e91)
1*6a611fe9Srin /*	$NetBSD: event.h,v 1.4 2023/07/29 11:58:53 rin Exp $	*/
2461a86f9Schristos 
3461a86f9Schristos /*-
4461a86f9Schristos  * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
5461a86f9Schristos  * All rights reserved.
6461a86f9Schristos  *
7461a86f9Schristos  * Redistribution and use in source and binary forms, with or without
8461a86f9Schristos  * modification, are permitted provided that the following conditions
9461a86f9Schristos  * are met:
10461a86f9Schristos  * 1. Redistributions of source code must retain the above copyright
11461a86f9Schristos  *    notice, this list of conditions and the following disclaimer.
12461a86f9Schristos  * 2. Redistributions in binary form must reproduce the above copyright
13461a86f9Schristos  *    notice, this list of conditions and the following disclaimer in the
14461a86f9Schristos  *    documentation and/or other materials provided with the distribution.
15461a86f9Schristos  *
16461a86f9Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17461a86f9Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18461a86f9Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19461a86f9Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20461a86f9Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21461a86f9Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22461a86f9Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23461a86f9Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24461a86f9Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25461a86f9Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26461a86f9Schristos  * SUCH DAMAGE.
27461a86f9Schristos  *
28461a86f9Schristos  *	$FreeBSD: src/sys/sys/event.h,v 1.12 2001/02/24 01:44:03 jlemon Exp $
29461a86f9Schristos  */
30461a86f9Schristos 
31461a86f9Schristos #ifndef _COMPAT_SYS_EVENT_H_
32461a86f9Schristos #define	_COMPAT_SYS_EVENT_H_
33461a86f9Schristos 
34461a86f9Schristos #include <sys/cdefs.h>
35461a86f9Schristos struct timespec;
36461a86f9Schristos 
37d11110f4Schristos #ifdef _KERNEL
38d11110f4Schristos #include <lib/libkern/libkern.h>
39d11110f4Schristos #else
40d11110f4Schristos #include <string.h>
41d11110f4Schristos #endif
42d11110f4Schristos 
43d11110f4Schristos struct kevent100 {
44d11110f4Schristos 	uintptr_t	ident;		/* identifier for this event */
45d11110f4Schristos 	uint32_t	filter;		/* filter for event */
46d11110f4Schristos 	uint32_t	flags;		/* action flags for kqueue */
47d11110f4Schristos 	uint32_t	fflags;		/* filter flag value */
48d11110f4Schristos 	int64_t		data;		/* filter data value */
49d11110f4Schristos 	void		*udata;		/* opaque user data identifier */
50d11110f4Schristos };
51d11110f4Schristos 
52d11110f4Schristos static __inline void
kevent100_to_kevent(const struct kevent100 * kev100,struct kevent * kev)53d11110f4Schristos kevent100_to_kevent(const struct kevent100 *kev100, struct kevent *kev)
54d11110f4Schristos {
55d11110f4Schristos 	memset(kev, 0, sizeof(*kev));
56d11110f4Schristos 	memcpy(kev, kev100, sizeof(*kev100));
57d11110f4Schristos }
58d11110f4Schristos 
59d11110f4Schristos static __inline void
kevent_to_kevent100(const struct kevent * kev,struct kevent100 * kev100)60d11110f4Schristos kevent_to_kevent100(const struct kevent *kev, struct kevent100 *kev100)
61d11110f4Schristos {
62d11110f4Schristos 	memcpy(kev100, kev, sizeof(*kev100));
63d11110f4Schristos }
64d11110f4Schristos 
65d11110f4Schristos #ifdef _KERNEL
66*6a611fe9Srin static __inline int
compat_100___kevent50_fetch_changes(void * ctx,const struct kevent * changelist,struct kevent * changes,size_t index,int n)67d11110f4Schristos compat_100___kevent50_fetch_changes(void *ctx, const struct kevent *changelist,
68d11110f4Schristos     struct kevent *changes, size_t index, int n)
69d11110f4Schristos {
70d11110f4Schristos 	int error, i;
71d11110f4Schristos 	struct kevent100 *buf;
72d11110f4Schristos 	const size_t buf_size = sizeof(*buf) * n;
73d11110f4Schristos 	const struct kevent100 *changelist100 = (const struct kevent100 *)changelist;
74d11110f4Schristos 
75d11110f4Schristos 	KASSERT(n >= 0);
76d11110f4Schristos 
77d11110f4Schristos 	buf = kmem_alloc(buf_size, KM_SLEEP);
78d11110f4Schristos 
79d11110f4Schristos 	error = copyin(changelist100 + index, buf, buf_size);
80d11110f4Schristos 	if (error != 0)
81d11110f4Schristos 		goto leave;
82d11110f4Schristos 
83d11110f4Schristos 	for (i = 0; i < n; i++)
84d11110f4Schristos 		kevent100_to_kevent(buf + i, changes + i);
85d11110f4Schristos 
86d11110f4Schristos leave:
87d11110f4Schristos 	kmem_free(buf, buf_size);
88d11110f4Schristos 	return error;
89d11110f4Schristos }
90d11110f4Schristos 
91*6a611fe9Srin static __inline int
compat_100___kevent50_put_events(void * ctx,struct kevent * events,struct kevent * eventlist,size_t index,int n)92d11110f4Schristos compat_100___kevent50_put_events(void *ctx, struct kevent *events,
93d11110f4Schristos     struct kevent *eventlist, size_t index, int n)
94d11110f4Schristos {
95d11110f4Schristos 	int error, i;
96d11110f4Schristos         struct kevent100 *buf;
97d11110f4Schristos 	const size_t buf_size = sizeof(*buf) * n;
98d11110f4Schristos 	struct kevent100 *eventlist100 = (struct kevent100 *)eventlist;
99d11110f4Schristos 
100d11110f4Schristos 	KASSERT(n >= 0);
101d11110f4Schristos 
102d11110f4Schristos 	buf = kmem_alloc(buf_size, KM_SLEEP);
103d11110f4Schristos 
104d11110f4Schristos 	for (i = 0; i < n; i++)
105d11110f4Schristos 	        kevent_to_kevent100(events + i, buf + i);
106d11110f4Schristos 
107d11110f4Schristos 	error = copyout(buf, eventlist100 + index, buf_size);
108d11110f4Schristos 
109d11110f4Schristos 	kmem_free(buf, buf_size);
110d11110f4Schristos 	return error;
111d11110f4Schristos }
112d11110f4Schristos #endif /* _KERNEL */
113d11110f4Schristos 
114461a86f9Schristos __BEGIN_DECLS
115d11110f4Schristos int	kevent(int, const struct kevent100 *, size_t, struct kevent100 *,
116d11110f4Schristos     size_t, const struct timespec50 *);
117d11110f4Schristos int	__kevent50(int, const struct kevent100 *, size_t, struct kevent100 *,
118d11110f4Schristos     size_t, const struct timespec *);
119d11110f4Schristos int	__kevent100(int, const struct kevent *, size_t, struct kevent *,
120d11110f4Schristos     size_t, const struct timespec *);
121461a86f9Schristos __END_DECLS
122461a86f9Schristos 
123461a86f9Schristos #endif /* !_COMPAT_SYS_EVENT_H_ */
124