netbsd32_compat_100.c revision 1.2 1 1.2 rin /* $NetBSD: netbsd32_compat_100.c,v 1.2 2023/07/29 12:38:25 rin Exp $ */
2 1.1 pgoyette
3 1.1 pgoyette /*-
4 1.1 pgoyette * Copyright (c) 2019 The NetBSD Foundation, Inc.
5 1.1 pgoyette * All rights reserved.
6 1.1 pgoyette *
7 1.1 pgoyette * This code is derived from software developed for The NetBSD Foundation
8 1.1 pgoyette * by Christos Zoulas.
9 1.1 pgoyette *
10 1.1 pgoyette * Redistribution and use in source and binary forms, with or without
11 1.1 pgoyette * modification, are permitted provided that the following conditions
12 1.1 pgoyette * are met:
13 1.1 pgoyette * 1. Redistributions of source code must retain the above copyright
14 1.1 pgoyette * notice, this list of conditions and the following disclaimer.
15 1.1 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pgoyette * notice, this list of conditions and the following disclaimer in the
17 1.1 pgoyette * documentation and/or other materials provided with the distribution.
18 1.1 pgoyette *
19 1.1 pgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 pgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 pgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 pgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 pgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 pgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 pgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 pgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 pgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 pgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 pgoyette * POSSIBILITY OF SUCH DAMAGE.
30 1.1 pgoyette */
31 1.1 pgoyette
32 1.1 pgoyette #include <sys/cdefs.h>
33 1.2 rin __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_100.c,v 1.2 2023/07/29 12:38:25 rin Exp $");
34 1.1 pgoyette
35 1.2 rin #include <sys/types.h>
36 1.2 rin #include <sys/event.h>
37 1.2 rin #include <sys/eventvar.h>
38 1.1 pgoyette #include <sys/module.h>
39 1.2 rin #include <sys/syscallvar.h>
40 1.2 rin #include <sys/syscallargs.h>
41 1.2 rin #include <sys/systm.h>
42 1.1 pgoyette
43 1.1 pgoyette #include <compat/netbsd32/netbsd32.h>
44 1.1 pgoyette #include <compat/netbsd32/netbsd32_syscall.h>
45 1.1 pgoyette #include <compat/netbsd32/netbsd32_syscallargs.h>
46 1.1 pgoyette #include <compat/netbsd32/netbsd32_conv.h>
47 1.2 rin #include <compat/netbsd32/netbsd32_event.h>
48 1.2 rin
49 1.2 rin static int
50 1.2 rin compat_100_netbsd32_kevent_fetch_timeout(const void *src, void *dest,
51 1.2 rin size_t length)
52 1.2 rin {
53 1.2 rin struct netbsd32_timespec ts32;
54 1.2 rin int error;
55 1.2 rin
56 1.2 rin KASSERT(length == sizeof(struct timespec));
57 1.2 rin
58 1.2 rin error = copyin(src, &ts32, sizeof(ts32));
59 1.2 rin if (error)
60 1.2 rin return error;
61 1.2 rin netbsd32_to_timespec(&ts32, (struct timespec *)dest);
62 1.2 rin return 0;
63 1.2 rin }
64 1.2 rin
65 1.2 rin static void
66 1.2 rin compat_100_netbsd32_to_kevent(const struct netbsd32_kevent100 *ke32,
67 1.2 rin struct kevent *ke)
68 1.2 rin {
69 1.2 rin
70 1.2 rin memset(ke, 0, sizeof(*ke));
71 1.2 rin ke->ident = ke32->ident;
72 1.2 rin ke->filter = ke32->filter;
73 1.2 rin ke->flags = ke32->flags;
74 1.2 rin ke->fflags = ke32->fflags;
75 1.2 rin ke->data = ke32->data;
76 1.2 rin ke->udata = NETBSD32PTR64(ke32->udata);
77 1.2 rin }
78 1.2 rin
79 1.2 rin static void
80 1.2 rin compat_100_netbsd32_from_kevent(const struct kevent *ke,
81 1.2 rin struct netbsd32_kevent100 *ke32)
82 1.2 rin {
83 1.2 rin
84 1.2 rin memset(ke32, 0, sizeof(*ke32));
85 1.2 rin ke32->ident = ke->ident;
86 1.2 rin ke32->filter = ke->filter;
87 1.2 rin ke32->flags = ke->flags;
88 1.2 rin ke32->fflags = ke->fflags;
89 1.2 rin ke32->data = ke->data;
90 1.2 rin NETBSD32PTR32(ke32->udata, ke->udata);
91 1.2 rin }
92 1.2 rin
93 1.2 rin int
94 1.2 rin compat_100_netbsd32_kevent_fetch_changes(void *ctx,
95 1.2 rin const struct kevent *changelist, struct kevent *changes, size_t index,
96 1.2 rin int n)
97 1.2 rin {
98 1.2 rin const struct netbsd32_kevent100 *src =
99 1.2 rin (const struct netbsd32_kevent100 *)changelist;
100 1.2 rin struct netbsd32_kevent100 *ke32, *changes32 = ctx;
101 1.2 rin int error, i;
102 1.2 rin
103 1.2 rin error = copyin(src + index, changes32, n * sizeof(*changes32));
104 1.2 rin if (error)
105 1.2 rin return error;
106 1.2 rin for (i = 0, ke32 = changes32; i < n; i++, ke32++, changes++)
107 1.2 rin compat_100_netbsd32_to_kevent(ke32, changes);
108 1.2 rin return 0;
109 1.2 rin }
110 1.2 rin
111 1.2 rin int
112 1.2 rin compat_100_netbsd32_kevent_put_events(void *ctx, struct kevent *events,
113 1.2 rin struct kevent *eventlist, size_t index, int n)
114 1.2 rin {
115 1.2 rin struct netbsd32_kevent100 *ke32, *events32 = ctx;
116 1.2 rin int i;
117 1.2 rin
118 1.2 rin for (i = 0, ke32 = events32; i < n; i++, ke32++, events++)
119 1.2 rin compat_100_netbsd32_from_kevent(events, ke32);
120 1.2 rin ke32 = ((struct netbsd32_kevent100 *)eventlist) + index;
121 1.2 rin return copyout(events32, ke32, n * sizeof(*events32));
122 1.2 rin }
123 1.2 rin
124 1.2 rin int
125 1.2 rin compat_100_netbsd32___kevent50(struct lwp *l,
126 1.2 rin const struct compat_100_netbsd32___kevent50_args *uap, register_t *retval)
127 1.2 rin {
128 1.2 rin /* {
129 1.2 rin syscallarg(int) fd;
130 1.2 rin syscallarg(const netbsd32_kevent100p_t) changelist;
131 1.2 rin syscallarg(netbsd32_size_t) nchanges;
132 1.2 rin syscallarg(netbsd32_kevent100p_t) eventlist;
133 1.2 rin syscallarg(netbsd32_size_t) nevents;
134 1.2 rin syscallarg(netbsd32_timespecp_t) timeout;
135 1.2 rin } */
136 1.2 rin struct kevent_ops netbsd32_kevent_ops = {
137 1.2 rin .keo_fetch_timeout = compat_100_netbsd32_kevent_fetch_timeout,
138 1.2 rin .keo_fetch_changes = compat_100_netbsd32_kevent_fetch_changes,
139 1.2 rin .keo_put_events = compat_100_netbsd32_kevent_put_events,
140 1.2 rin };
141 1.2 rin
142 1.2 rin return netbsd32_kevent1(retval, SCARG(uap, fd),
143 1.2 rin (netbsd32_keventp_t)SCARG(uap, changelist), SCARG(uap, nchanges),
144 1.2 rin (netbsd32_keventp_t)SCARG(uap, eventlist), SCARG(uap, nevents),
145 1.2 rin SCARG(uap, timeout), &netbsd32_kevent_ops);
146 1.2 rin }
147 1.2 rin
148 1.2 rin static struct syscall_package compat_netbsd32_100_syscalls[] = {
149 1.2 rin { NETBSD32_SYS_compat_100_netbsd32___kevent50, 0,
150 1.2 rin (sy_call_t *)compat_100_netbsd32___kevent50 },
151 1.2 rin { 0, 0, NULL },
152 1.2 rin };
153 1.1 pgoyette
154 1.1 pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_100, "compat_netbsd32,compat_100");
155 1.1 pgoyette
156 1.1 pgoyette static int
157 1.1 pgoyette compat_netbsd32_100_modcmd(modcmd_t cmd, void *arg)
158 1.1 pgoyette {
159 1.1 pgoyette
160 1.1 pgoyette switch (cmd) {
161 1.1 pgoyette case MODULE_CMD_INIT:
162 1.2 rin return syscall_establish(&emul_netbsd32,
163 1.2 rin compat_netbsd32_100_syscalls);
164 1.1 pgoyette
165 1.1 pgoyette case MODULE_CMD_FINI:
166 1.2 rin return syscall_disestablish(&emul_netbsd32,
167 1.2 rin compat_netbsd32_100_syscalls);
168 1.1 pgoyette
169 1.1 pgoyette default:
170 1.1 pgoyette return ENOTTY;
171 1.1 pgoyette }
172 1.1 pgoyette }
173