netbsd32_compat_100.c revision 1.3 1 1.3 rin /* $NetBSD: netbsd32_compat_100.c,v 1.3 2023/07/29 12:48:15 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.3 rin __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_100.c,v 1.3 2023/07/29 12:48:15 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 void
50 1.2 rin compat_100_netbsd32_to_kevent(const struct netbsd32_kevent100 *ke32,
51 1.2 rin struct kevent *ke)
52 1.2 rin {
53 1.2 rin
54 1.2 rin memset(ke, 0, sizeof(*ke));
55 1.2 rin ke->ident = ke32->ident;
56 1.2 rin ke->filter = ke32->filter;
57 1.2 rin ke->flags = ke32->flags;
58 1.2 rin ke->fflags = ke32->fflags;
59 1.2 rin ke->data = ke32->data;
60 1.2 rin ke->udata = NETBSD32PTR64(ke32->udata);
61 1.2 rin }
62 1.2 rin
63 1.2 rin static void
64 1.2 rin compat_100_netbsd32_from_kevent(const struct kevent *ke,
65 1.2 rin struct netbsd32_kevent100 *ke32)
66 1.2 rin {
67 1.2 rin
68 1.2 rin memset(ke32, 0, sizeof(*ke32));
69 1.2 rin ke32->ident = ke->ident;
70 1.2 rin ke32->filter = ke->filter;
71 1.2 rin ke32->flags = ke->flags;
72 1.2 rin ke32->fflags = ke->fflags;
73 1.2 rin ke32->data = ke->data;
74 1.2 rin NETBSD32PTR32(ke32->udata, ke->udata);
75 1.2 rin }
76 1.2 rin
77 1.2 rin int
78 1.2 rin compat_100_netbsd32_kevent_fetch_changes(void *ctx,
79 1.2 rin const struct kevent *changelist, struct kevent *changes, size_t index,
80 1.2 rin int n)
81 1.2 rin {
82 1.2 rin const struct netbsd32_kevent100 *src =
83 1.2 rin (const struct netbsd32_kevent100 *)changelist;
84 1.2 rin struct netbsd32_kevent100 *ke32, *changes32 = ctx;
85 1.2 rin int error, i;
86 1.2 rin
87 1.2 rin error = copyin(src + index, changes32, n * sizeof(*changes32));
88 1.2 rin if (error)
89 1.2 rin return error;
90 1.2 rin for (i = 0, ke32 = changes32; i < n; i++, ke32++, changes++)
91 1.2 rin compat_100_netbsd32_to_kevent(ke32, changes);
92 1.2 rin return 0;
93 1.2 rin }
94 1.2 rin
95 1.2 rin int
96 1.2 rin compat_100_netbsd32_kevent_put_events(void *ctx, struct kevent *events,
97 1.2 rin struct kevent *eventlist, size_t index, int n)
98 1.2 rin {
99 1.2 rin struct netbsd32_kevent100 *ke32, *events32 = ctx;
100 1.2 rin int i;
101 1.2 rin
102 1.2 rin for (i = 0, ke32 = events32; i < n; i++, ke32++, events++)
103 1.2 rin compat_100_netbsd32_from_kevent(events, ke32);
104 1.2 rin ke32 = ((struct netbsd32_kevent100 *)eventlist) + index;
105 1.2 rin return copyout(events32, ke32, n * sizeof(*events32));
106 1.2 rin }
107 1.2 rin
108 1.2 rin int
109 1.2 rin compat_100_netbsd32___kevent50(struct lwp *l,
110 1.2 rin const struct compat_100_netbsd32___kevent50_args *uap, register_t *retval)
111 1.2 rin {
112 1.2 rin /* {
113 1.2 rin syscallarg(int) fd;
114 1.2 rin syscallarg(const netbsd32_kevent100p_t) changelist;
115 1.2 rin syscallarg(netbsd32_size_t) nchanges;
116 1.2 rin syscallarg(netbsd32_kevent100p_t) eventlist;
117 1.2 rin syscallarg(netbsd32_size_t) nevents;
118 1.2 rin syscallarg(netbsd32_timespecp_t) timeout;
119 1.2 rin } */
120 1.2 rin struct kevent_ops netbsd32_kevent_ops = {
121 1.3 rin .keo_fetch_timeout = netbsd32_kevent_fetch_timeout,
122 1.2 rin .keo_fetch_changes = compat_100_netbsd32_kevent_fetch_changes,
123 1.2 rin .keo_put_events = compat_100_netbsd32_kevent_put_events,
124 1.2 rin };
125 1.2 rin
126 1.2 rin return netbsd32_kevent1(retval, SCARG(uap, fd),
127 1.2 rin (netbsd32_keventp_t)SCARG(uap, changelist), SCARG(uap, nchanges),
128 1.2 rin (netbsd32_keventp_t)SCARG(uap, eventlist), SCARG(uap, nevents),
129 1.2 rin SCARG(uap, timeout), &netbsd32_kevent_ops);
130 1.2 rin }
131 1.2 rin
132 1.2 rin static struct syscall_package compat_netbsd32_100_syscalls[] = {
133 1.2 rin { NETBSD32_SYS_compat_100_netbsd32___kevent50, 0,
134 1.2 rin (sy_call_t *)compat_100_netbsd32___kevent50 },
135 1.2 rin { 0, 0, NULL },
136 1.2 rin };
137 1.1 pgoyette
138 1.1 pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_100, "compat_netbsd32,compat_100");
139 1.1 pgoyette
140 1.1 pgoyette static int
141 1.1 pgoyette compat_netbsd32_100_modcmd(modcmd_t cmd, void *arg)
142 1.1 pgoyette {
143 1.1 pgoyette
144 1.1 pgoyette switch (cmd) {
145 1.1 pgoyette case MODULE_CMD_INIT:
146 1.2 rin return syscall_establish(&emul_netbsd32,
147 1.2 rin compat_netbsd32_100_syscalls);
148 1.1 pgoyette
149 1.1 pgoyette case MODULE_CMD_FINI:
150 1.2 rin return syscall_disestablish(&emul_netbsd32,
151 1.2 rin compat_netbsd32_100_syscalls);
152 1.1 pgoyette
153 1.1 pgoyette default:
154 1.1 pgoyette return ENOTTY;
155 1.1 pgoyette }
156 1.1 pgoyette }
157