| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: netbsd32_epoll.c,v 1.1 2023/07/30 06:52:20 rin Exp $ */ | | 1 | /* $NetBSD: netbsd32_epoll.c,v 1.2 2023/07/30 07:48:54 rin Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * SPDX-License-Identifier: BSD-2-Clause | | 4 | * SPDX-License-Identifier: BSD-2-Clause |
5 | * | | 5 | * |
6 | * Copyright (c) 2007 Roman Divacky | | 6 | * Copyright (c) 2007 Roman Divacky |
7 | * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org> | | 7 | * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org> |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
28 | * SUCH DAMAGE. | | 28 | * SUCH DAMAGE. |
29 | */ | | 29 | */ |
30 | #include <sys/cdefs.h> | | 30 | #include <sys/cdefs.h> |
31 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_epoll.c,v 1.1 2023/07/30 06:52:20 rin Exp $"); | | 31 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_epoll.c,v 1.2 2023/07/30 07:48:54 rin Exp $"); |
32 | | | 32 | |
33 | #include <sys/types.h> | | 33 | #include <sys/types.h> |
34 | #include <sys/epoll.h> | | 34 | #include <sys/epoll.h> |
35 | #include <sys/kmem.h> | | 35 | #include <sys/kmem.h> |
36 | #include <sys/systm.h> | | 36 | #include <sys/systm.h> |
37 | #include <sys/syscall.h> | | 37 | #include <sys/syscall.h> |
38 | #include <sys/syscallargs.h> | | 38 | #include <sys/syscallargs.h> |
39 | | | 39 | |
40 | #include <compat/netbsd32/netbsd32.h> | | 40 | #include <compat/netbsd32/netbsd32.h> |
41 | #include <compat/netbsd32/netbsd32_conv.h> | | 41 | #include <compat/netbsd32/netbsd32_conv.h> |
42 | #include <compat/netbsd32/netbsd32_syscall.h> | | 42 | #include <compat/netbsd32/netbsd32_syscall.h> |
43 | #include <compat/netbsd32/netbsd32_syscallargs.h> | | 43 | #include <compat/netbsd32/netbsd32_syscallargs.h> |
44 | | | 44 | |
| @@ -119,27 +119,27 @@ netbsd32_epoll_pwait2(struct lwp *l, | | | @@ -119,27 +119,27 @@ netbsd32_epoll_pwait2(struct lwp *l, |
119 | if (SCARG_P32(uap, sigmask) != NULL) { | | 119 | if (SCARG_P32(uap, sigmask) != NULL) { |
120 | error = copyin(SCARG_P32(uap, sigmask), &ss, sizeof(ss)); | | 120 | error = copyin(SCARG_P32(uap, sigmask), &ss, sizeof(ss)); |
121 | if (error != 0) | | 121 | if (error != 0) |
122 | return error; | | 122 | return error; |
123 | | | 123 | |
124 | ssp = &ss; | | 124 | ssp = &ss; |
125 | } else | | 125 | } else |
126 | ssp = NULL; | | 126 | ssp = NULL; |
127 | | | 127 | |
128 | events = kmem_alloc(maxevents * sizeof(*events), KM_SLEEP); | | 128 | events = kmem_alloc(maxevents * sizeof(*events), KM_SLEEP); |
129 | | | 129 | |
130 | error = epoll_wait_common(l, retval, SCARG(uap, epfd), events, | | 130 | error = epoll_wait_common(l, retval, SCARG(uap, epfd), events, |
131 | maxevents, tsp, ssp); | | 131 | maxevents, tsp, ssp); |
132 | if (error != 0) { | | 132 | if (error != 0 || *retval == 0) { |
133 | kmem_free(events, maxevents * sizeof(*events)); | | 133 | kmem_free(events, maxevents * sizeof(*events)); |
134 | return error; | | 134 | return error; |
135 | } | | 135 | } |
136 | | | 136 | |
137 | struct netbsd32_epoll_event *events32 = | | 137 | struct netbsd32_epoll_event *events32 = |
138 | kmem_alloc(*retval * sizeof(*events32), KM_SLEEP); | | 138 | kmem_alloc(*retval * sizeof(*events32), KM_SLEEP); |
139 | | | 139 | |
140 | for (int i = 0; i < *retval; i++) | | 140 | for (int i = 0; i < *retval; i++) |
141 | netbsd32_from_epoll_event(&events[i], &events32[i]); | | 141 | netbsd32_from_epoll_event(&events[i], &events32[i]); |
142 | | | 142 | |
143 | kmem_free(events, maxevents * sizeof(*events)); | | 143 | kmem_free(events, maxevents * sizeof(*events)); |
144 | | | 144 | |
145 | error = copyout(events, SCARG_P32(uap, events), | | 145 | error = copyout(events, SCARG_P32(uap, events), |