netbsd32_compat_100.c revision 1.4 1 1.4 christos /* $NetBSD: netbsd32_compat_100.c,v 1.4 2024/05/20 01:30:33 christos 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.4 christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_100.c,v 1.4 2024/05/20 01:30:33 christos Exp $");
34 1.1 pgoyette
35 1.2 rin #include <sys/types.h>
36 1.4 christos #include <sys/filedesc.h>
37 1.2 rin #include <sys/event.h>
38 1.2 rin #include <sys/eventvar.h>
39 1.1 pgoyette #include <sys/module.h>
40 1.2 rin #include <sys/syscallvar.h>
41 1.2 rin #include <sys/syscallargs.h>
42 1.2 rin #include <sys/systm.h>
43 1.1 pgoyette
44 1.1 pgoyette #include <compat/netbsd32/netbsd32.h>
45 1.1 pgoyette #include <compat/netbsd32/netbsd32_syscall.h>
46 1.1 pgoyette #include <compat/netbsd32/netbsd32_syscallargs.h>
47 1.1 pgoyette #include <compat/netbsd32/netbsd32_conv.h>
48 1.2 rin #include <compat/netbsd32/netbsd32_event.h>
49 1.2 rin
50 1.2 rin static void
51 1.2 rin compat_100_netbsd32_to_kevent(const struct netbsd32_kevent100 *ke32,
52 1.2 rin struct kevent *ke)
53 1.2 rin {
54 1.2 rin
55 1.2 rin memset(ke, 0, sizeof(*ke));
56 1.2 rin ke->ident = ke32->ident;
57 1.2 rin ke->filter = ke32->filter;
58 1.2 rin ke->flags = ke32->flags;
59 1.2 rin ke->fflags = ke32->fflags;
60 1.2 rin ke->data = ke32->data;
61 1.2 rin ke->udata = NETBSD32PTR64(ke32->udata);
62 1.2 rin }
63 1.2 rin
64 1.2 rin static void
65 1.2 rin compat_100_netbsd32_from_kevent(const struct kevent *ke,
66 1.2 rin struct netbsd32_kevent100 *ke32)
67 1.2 rin {
68 1.2 rin
69 1.2 rin memset(ke32, 0, sizeof(*ke32));
70 1.2 rin ke32->ident = ke->ident;
71 1.2 rin ke32->filter = ke->filter;
72 1.2 rin ke32->flags = ke->flags;
73 1.2 rin ke32->fflags = ke->fflags;
74 1.2 rin ke32->data = ke->data;
75 1.2 rin NETBSD32PTR32(ke32->udata, ke->udata);
76 1.2 rin }
77 1.2 rin
78 1.2 rin int
79 1.2 rin compat_100_netbsd32_kevent_fetch_changes(void *ctx,
80 1.2 rin const struct kevent *changelist, struct kevent *changes, size_t index,
81 1.2 rin int n)
82 1.2 rin {
83 1.2 rin const struct netbsd32_kevent100 *src =
84 1.2 rin (const struct netbsd32_kevent100 *)changelist;
85 1.2 rin struct netbsd32_kevent100 *ke32, *changes32 = ctx;
86 1.2 rin int error, i;
87 1.2 rin
88 1.2 rin error = copyin(src + index, changes32, n * sizeof(*changes32));
89 1.2 rin if (error)
90 1.2 rin return error;
91 1.2 rin for (i = 0, ke32 = changes32; i < n; i++, ke32++, changes++)
92 1.2 rin compat_100_netbsd32_to_kevent(ke32, changes);
93 1.2 rin return 0;
94 1.2 rin }
95 1.2 rin
96 1.2 rin int
97 1.2 rin compat_100_netbsd32_kevent_put_events(void *ctx, struct kevent *events,
98 1.2 rin struct kevent *eventlist, size_t index, int n)
99 1.2 rin {
100 1.2 rin struct netbsd32_kevent100 *ke32, *events32 = ctx;
101 1.2 rin int i;
102 1.2 rin
103 1.2 rin for (i = 0, ke32 = events32; i < n; i++, ke32++, events++)
104 1.2 rin compat_100_netbsd32_from_kevent(events, ke32);
105 1.2 rin ke32 = ((struct netbsd32_kevent100 *)eventlist) + index;
106 1.2 rin return copyout(events32, ke32, n * sizeof(*events32));
107 1.2 rin }
108 1.2 rin
109 1.2 rin int
110 1.2 rin compat_100_netbsd32___kevent50(struct lwp *l,
111 1.2 rin const struct compat_100_netbsd32___kevent50_args *uap, register_t *retval)
112 1.2 rin {
113 1.2 rin /* {
114 1.2 rin syscallarg(int) fd;
115 1.2 rin syscallarg(const netbsd32_kevent100p_t) changelist;
116 1.2 rin syscallarg(netbsd32_size_t) nchanges;
117 1.2 rin syscallarg(netbsd32_kevent100p_t) eventlist;
118 1.2 rin syscallarg(netbsd32_size_t) nevents;
119 1.2 rin syscallarg(netbsd32_timespecp_t) timeout;
120 1.2 rin } */
121 1.2 rin struct kevent_ops netbsd32_kevent_ops = {
122 1.3 rin .keo_fetch_timeout = netbsd32_kevent_fetch_timeout,
123 1.2 rin .keo_fetch_changes = compat_100_netbsd32_kevent_fetch_changes,
124 1.2 rin .keo_put_events = compat_100_netbsd32_kevent_put_events,
125 1.2 rin };
126 1.2 rin
127 1.2 rin return netbsd32_kevent1(retval, SCARG(uap, fd),
128 1.2 rin (netbsd32_keventp_t)SCARG(uap, changelist), SCARG(uap, nchanges),
129 1.2 rin (netbsd32_keventp_t)SCARG(uap, eventlist), SCARG(uap, nevents),
130 1.2 rin SCARG(uap, timeout), &netbsd32_kevent_ops);
131 1.2 rin }
132 1.2 rin
133 1.4 christos int
134 1.4 christos compat_100_netbsd32_dup3(struct lwp *l,
135 1.4 christos const struct compat_100_netbsd32_dup3_args *uap, register_t *retval)
136 1.4 christos {
137 1.4 christos /* {
138 1.4 christos syscallarg(int) from;
139 1.4 christos syscallarg(int) to;
140 1.4 christos syscallarg(int) flags;
141 1.4 christos syscallarg(const netbsd32_kevent100p_t) changelist;
142 1.4 christos syscallarg(netbsd32_size_t) nchanges;
143 1.4 christos syscallarg(netbsd32_kevent100p_t) eventlist;
144 1.4 christos syscallarg(netbsd32_size_t) nevents;
145 1.4 christos syscallarg(netbsd32_timespecp_t) timeout;
146 1.4 christos } */
147 1.4 christos return dodup(l, SCARG(uap, from), SCARG(uap, to), SCARG(uap, flags),
148 1.4 christos retval);
149 1.4 christos }
150 1.4 christos
151 1.2 rin static struct syscall_package compat_netbsd32_100_syscalls[] = {
152 1.2 rin { NETBSD32_SYS_compat_100_netbsd32___kevent50, 0,
153 1.2 rin (sy_call_t *)compat_100_netbsd32___kevent50 },
154 1.4 christos { NETBSD32_SYS_compat_100_netbsd32_dup3, 0,
155 1.4 christos (sy_call_t *)compat_100_netbsd32_dup3 },
156 1.2 rin { 0, 0, NULL },
157 1.2 rin };
158 1.1 pgoyette
159 1.1 pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_100, "compat_netbsd32,compat_100");
160 1.1 pgoyette
161 1.1 pgoyette static int
162 1.1 pgoyette compat_netbsd32_100_modcmd(modcmd_t cmd, void *arg)
163 1.1 pgoyette {
164 1.1 pgoyette
165 1.1 pgoyette switch (cmd) {
166 1.1 pgoyette case MODULE_CMD_INIT:
167 1.2 rin return syscall_establish(&emul_netbsd32,
168 1.2 rin compat_netbsd32_100_syscalls);
169 1.1 pgoyette
170 1.1 pgoyette case MODULE_CMD_FINI:
171 1.2 rin return syscall_disestablish(&emul_netbsd32,
172 1.2 rin compat_netbsd32_100_syscalls);
173 1.1 pgoyette
174 1.1 pgoyette default:
175 1.1 pgoyette return ENOTTY;
176 1.1 pgoyette }
177 1.1 pgoyette }
178