Tue Nov 2 18:18:07 2010 UTC ()
personality() now interprets its parameter as having
the base personality type in the low byte and
various flags in the upper bytes.  for now just mask off
the flags to make sure the base type is one we accept.
store the current personality in the emuldata so that
we can return the expected value for PER_QUERY.


(chs)
diff -r1.17 -r1.18 src/sys/compat/linux/common/linux_emuldata.h
diff -r1.217 -r1.218 src/sys/compat/linux/common/linux_misc.c
diff -r1.19 -r1.20 src/sys/compat/linux/common/linux_misc.h
diff -r1.20 -r1.21 src/sys/compat/linux32/common/linux32_misc.c

cvs diff -r1.17 -r1.18 src/sys/compat/linux/common/linux_emuldata.h (switch to unified diff)

--- src/sys/compat/linux/common/linux_emuldata.h 2010/07/07 01:30:35 1.17
+++ src/sys/compat/linux/common/linux_emuldata.h 2010/11/02 18:18:07 1.18
@@ -1,53 +1,54 @@ @@ -1,53 +1,54 @@
1/* $NetBSD: linux_emuldata.h,v 1.17 2010/07/07 01:30:35 chs Exp $ */ 1/* $NetBSD: linux_emuldata.h,v 1.18 2010/11/02 18:18:07 chs Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998,2002 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998,2002 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Eric Haszlakiewicz. 8 * by Eric Haszlakiewicz.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <compat/linux/common/linux_futex.h> 32#include <compat/linux/common/linux_futex.h>
33 33
34#ifndef _COMMON_LINUX_EMULDATA_H 34#ifndef _COMMON_LINUX_EMULDATA_H
35#define _COMMON_LINUX_EMULDATA_H 35#define _COMMON_LINUX_EMULDATA_H
36 36
37/* 37/*
38 * This is auxillary data the linux compat code 38 * This is auxillary data the linux compat code
39 * needs to do its work. A pointer to it is 39 * needs to do its work. A pointer to it is
40 * stored in the emuldata field of the proc 40 * stored in the emuldata field of the proc
41 * structure. 41 * structure.
42 */ 42 */
43 43
44struct linux_emuldata { 44struct linux_emuldata {
45 int led_debugreg[8]; /* GDB information for ptrace - for use, */ 45 int led_debugreg[8]; /* GDB information for ptrace - for use, */
46 /* see ../arch/i386/linux_ptrace.c */ 46 /* see ../arch/i386/linux_ptrace.c */
47 47
48 void *led_child_tidptr; /* Used during clone() */ 48 void *led_child_tidptr; /* Used during clone() */
49 void *led_clear_tid; /* Own TID to clear on exit */ 49 void *led_clear_tid; /* Own TID to clear on exit */
50 struct linux_robust_list_head *led_robust_head; 50 struct linux_robust_list_head *led_robust_head;
 51 long led_personality;
51}; 52};
52 53
53#endif /* !_COMMON_LINUX_EMULDATA_H */ 54#endif /* !_COMMON_LINUX_EMULDATA_H */

cvs diff -r1.217 -r1.218 src/sys/compat/linux/common/linux_misc.c (switch to unified diff)

--- src/sys/compat/linux/common/linux_misc.c 2010/09/11 20:53:04 1.217
+++ src/sys/compat/linux/common/linux_misc.c 2010/11/02 18:18:07 1.218
@@ -1,1329 +1,1340 @@ @@ -1,1329 +1,1340 @@
1/* $NetBSD: linux_misc.c,v 1.217 2010/09/11 20:53:04 chs Exp $ */ 1/* $NetBSD: linux_misc.c,v 1.218 2010/11/02 18:18:07 chs Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe 8 * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
9 * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center. 9 * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * Linux compatibility module. Try to deal with various Linux system calls. 34 * Linux compatibility module. Try to deal with various Linux system calls.
35 */ 35 */
36 36
37/* 37/*
38 * These functions have been moved to multiarch to allow 38 * These functions have been moved to multiarch to allow
39 * selection of which machines include them to be 39 * selection of which machines include them to be
40 * determined by the individual files.linux_<arch> files. 40 * determined by the individual files.linux_<arch> files.
41 * 41 *
42 * Function in multiarch: 42 * Function in multiarch:
43 * linux_sys_break : linux_break.c 43 * linux_sys_break : linux_break.c
44 * linux_sys_alarm : linux_misc_notalpha.c 44 * linux_sys_alarm : linux_misc_notalpha.c
45 * linux_sys_getresgid : linux_misc_notalpha.c 45 * linux_sys_getresgid : linux_misc_notalpha.c
46 * linux_sys_nice : linux_misc_notalpha.c 46 * linux_sys_nice : linux_misc_notalpha.c
47 * linux_sys_readdir : linux_misc_notalpha.c 47 * linux_sys_readdir : linux_misc_notalpha.c
48 * linux_sys_setresgid : linux_misc_notalpha.c 48 * linux_sys_setresgid : linux_misc_notalpha.c
49 * linux_sys_time : linux_misc_notalpha.c 49 * linux_sys_time : linux_misc_notalpha.c
50 * linux_sys_utime : linux_misc_notalpha.c 50 * linux_sys_utime : linux_misc_notalpha.c
51 * linux_sys_waitpid : linux_misc_notalpha.c 51 * linux_sys_waitpid : linux_misc_notalpha.c
52 * linux_sys_old_mmap : linux_oldmmap.c 52 * linux_sys_old_mmap : linux_oldmmap.c
53 * linux_sys_oldolduname : linux_oldolduname.c 53 * linux_sys_oldolduname : linux_oldolduname.c
54 * linux_sys_oldselect : linux_oldselect.c 54 * linux_sys_oldselect : linux_oldselect.c
55 * linux_sys_olduname : linux_olduname.c 55 * linux_sys_olduname : linux_olduname.c
56 * linux_sys_pipe : linux_pipe.c 56 * linux_sys_pipe : linux_pipe.c
57 */ 57 */
58 58
59#include <sys/cdefs.h> 59#include <sys/cdefs.h>
60__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.217 2010/09/11 20:53:04 chs Exp $"); 60__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.218 2010/11/02 18:18:07 chs Exp $");
61 61
62#include <sys/param.h> 62#include <sys/param.h>
63#include <sys/systm.h> 63#include <sys/systm.h>
64#include <sys/namei.h> 64#include <sys/namei.h>
65#include <sys/proc.h> 65#include <sys/proc.h>
66#include <sys/dirent.h> 66#include <sys/dirent.h>
67#include <sys/file.h> 67#include <sys/file.h>
68#include <sys/stat.h> 68#include <sys/stat.h>
69#include <sys/filedesc.h> 69#include <sys/filedesc.h>
70#include <sys/ioctl.h> 70#include <sys/ioctl.h>
71#include <sys/kernel.h> 71#include <sys/kernel.h>
72#include <sys/malloc.h> 72#include <sys/malloc.h>
73#include <sys/mbuf.h> 73#include <sys/mbuf.h>
74#include <sys/mman.h> 74#include <sys/mman.h>
75#include <sys/mount.h> 75#include <sys/mount.h>
76#include <sys/prot.h> 76#include <sys/prot.h>
77#include <sys/reboot.h> 77#include <sys/reboot.h>
78#include <sys/resource.h> 78#include <sys/resource.h>
79#include <sys/resourcevar.h> 79#include <sys/resourcevar.h>
80#include <sys/select.h> 80#include <sys/select.h>
81#include <sys/signal.h> 81#include <sys/signal.h>
82#include <sys/signalvar.h> 82#include <sys/signalvar.h>
83#include <sys/socket.h> 83#include <sys/socket.h>
84#include <sys/time.h> 84#include <sys/time.h>
85#include <sys/times.h> 85#include <sys/times.h>
86#include <sys/vnode.h> 86#include <sys/vnode.h>
87#include <sys/uio.h> 87#include <sys/uio.h>
88#include <sys/wait.h> 88#include <sys/wait.h>
89#include <sys/utsname.h> 89#include <sys/utsname.h>
90#include <sys/unistd.h> 90#include <sys/unistd.h>
91#include <sys/vfs_syscalls.h> 91#include <sys/vfs_syscalls.h>
92#include <sys/swap.h> /* for SWAP_ON */ 92#include <sys/swap.h> /* for SWAP_ON */
93#include <sys/sysctl.h> /* for KERN_DOMAINNAME */ 93#include <sys/sysctl.h> /* for KERN_DOMAINNAME */
94#include <sys/kauth.h> 94#include <sys/kauth.h>
95 95
96#include <sys/ptrace.h> 96#include <sys/ptrace.h>
97#include <machine/ptrace.h> 97#include <machine/ptrace.h>
98 98
99#include <sys/syscall.h> 99#include <sys/syscall.h>
100#include <sys/syscallargs.h> 100#include <sys/syscallargs.h>
101 101
102#include <compat/sys/resource.h> 102#include <compat/sys/resource.h>
103 103
104#include <compat/linux/common/linux_machdep.h> 104#include <compat/linux/common/linux_machdep.h>
105#include <compat/linux/common/linux_types.h> 105#include <compat/linux/common/linux_types.h>
106#include <compat/linux/common/linux_signal.h> 106#include <compat/linux/common/linux_signal.h>
107#include <compat/linux/common/linux_ipc.h> 107#include <compat/linux/common/linux_ipc.h>
108#include <compat/linux/common/linux_sem.h> 108#include <compat/linux/common/linux_sem.h>
109 109
110#include <compat/linux/common/linux_fcntl.h> 110#include <compat/linux/common/linux_fcntl.h>
111#include <compat/linux/common/linux_mmap.h> 111#include <compat/linux/common/linux_mmap.h>
112#include <compat/linux/common/linux_dirent.h> 112#include <compat/linux/common/linux_dirent.h>
113#include <compat/linux/common/linux_util.h> 113#include <compat/linux/common/linux_util.h>
114#include <compat/linux/common/linux_misc.h> 114#include <compat/linux/common/linux_misc.h>
115#ifndef COMPAT_LINUX32 115#ifndef COMPAT_LINUX32
116#include <compat/linux/common/linux_statfs.h> 116#include <compat/linux/common/linux_statfs.h>
117#include <compat/linux/common/linux_limit.h> 117#include <compat/linux/common/linux_limit.h>
118#endif 118#endif
119#include <compat/linux/common/linux_ptrace.h> 119#include <compat/linux/common/linux_ptrace.h>
120#include <compat/linux/common/linux_reboot.h> 120#include <compat/linux/common/linux_reboot.h>
121#include <compat/linux/common/linux_emuldata.h> 121#include <compat/linux/common/linux_emuldata.h>
122 122
123#include <compat/linux/linux_syscallargs.h> 123#include <compat/linux/linux_syscallargs.h>
124 124
125#ifndef COMPAT_LINUX32 125#ifndef COMPAT_LINUX32
126const int linux_ptrace_request_map[] = { 126const int linux_ptrace_request_map[] = {
127 LINUX_PTRACE_TRACEME, PT_TRACE_ME, 127 LINUX_PTRACE_TRACEME, PT_TRACE_ME,
128 LINUX_PTRACE_PEEKTEXT, PT_READ_I, 128 LINUX_PTRACE_PEEKTEXT, PT_READ_I,
129 LINUX_PTRACE_PEEKDATA, PT_READ_D, 129 LINUX_PTRACE_PEEKDATA, PT_READ_D,
130 LINUX_PTRACE_POKETEXT, PT_WRITE_I, 130 LINUX_PTRACE_POKETEXT, PT_WRITE_I,
131 LINUX_PTRACE_POKEDATA, PT_WRITE_D, 131 LINUX_PTRACE_POKEDATA, PT_WRITE_D,
132 LINUX_PTRACE_CONT, PT_CONTINUE, 132 LINUX_PTRACE_CONT, PT_CONTINUE,
133 LINUX_PTRACE_KILL, PT_KILL, 133 LINUX_PTRACE_KILL, PT_KILL,
134 LINUX_PTRACE_ATTACH, PT_ATTACH, 134 LINUX_PTRACE_ATTACH, PT_ATTACH,
135 LINUX_PTRACE_DETACH, PT_DETACH, 135 LINUX_PTRACE_DETACH, PT_DETACH,
136# ifdef PT_STEP 136# ifdef PT_STEP
137 LINUX_PTRACE_SINGLESTEP, PT_STEP, 137 LINUX_PTRACE_SINGLESTEP, PT_STEP,
138# endif 138# endif
139 LINUX_PTRACE_SYSCALL, PT_SYSCALL, 139 LINUX_PTRACE_SYSCALL, PT_SYSCALL,
140 -1 140 -1
141}; 141};
142 142
143const struct linux_mnttypes linux_fstypes[] = { 143const struct linux_mnttypes linux_fstypes[] = {
144 { MOUNT_FFS, LINUX_DEFAULT_SUPER_MAGIC }, 144 { MOUNT_FFS, LINUX_DEFAULT_SUPER_MAGIC },
145 { MOUNT_NFS, LINUX_NFS_SUPER_MAGIC }, 145 { MOUNT_NFS, LINUX_NFS_SUPER_MAGIC },
146 { MOUNT_MFS, LINUX_DEFAULT_SUPER_MAGIC }, 146 { MOUNT_MFS, LINUX_DEFAULT_SUPER_MAGIC },
147 { MOUNT_MSDOS, LINUX_MSDOS_SUPER_MAGIC }, 147 { MOUNT_MSDOS, LINUX_MSDOS_SUPER_MAGIC },
148 { MOUNT_LFS, LINUX_DEFAULT_SUPER_MAGIC }, 148 { MOUNT_LFS, LINUX_DEFAULT_SUPER_MAGIC },
149 { MOUNT_FDESC, LINUX_DEFAULT_SUPER_MAGIC }, 149 { MOUNT_FDESC, LINUX_DEFAULT_SUPER_MAGIC },
150 { MOUNT_NULL, LINUX_DEFAULT_SUPER_MAGIC }, 150 { MOUNT_NULL, LINUX_DEFAULT_SUPER_MAGIC },
151 { MOUNT_OVERLAY, LINUX_DEFAULT_SUPER_MAGIC }, 151 { MOUNT_OVERLAY, LINUX_DEFAULT_SUPER_MAGIC },
152 { MOUNT_UMAP, LINUX_DEFAULT_SUPER_MAGIC }, 152 { MOUNT_UMAP, LINUX_DEFAULT_SUPER_MAGIC },
153 { MOUNT_KERNFS, LINUX_DEFAULT_SUPER_MAGIC }, 153 { MOUNT_KERNFS, LINUX_DEFAULT_SUPER_MAGIC },
154 { MOUNT_PROCFS, LINUX_PROC_SUPER_MAGIC }, 154 { MOUNT_PROCFS, LINUX_PROC_SUPER_MAGIC },
155 { MOUNT_AFS, LINUX_DEFAULT_SUPER_MAGIC }, 155 { MOUNT_AFS, LINUX_DEFAULT_SUPER_MAGIC },
156 { MOUNT_CD9660, LINUX_ISOFS_SUPER_MAGIC }, 156 { MOUNT_CD9660, LINUX_ISOFS_SUPER_MAGIC },
157 { MOUNT_UNION, LINUX_DEFAULT_SUPER_MAGIC }, 157 { MOUNT_UNION, LINUX_DEFAULT_SUPER_MAGIC },
158 { MOUNT_ADOSFS, LINUX_ADFS_SUPER_MAGIC }, 158 { MOUNT_ADOSFS, LINUX_ADFS_SUPER_MAGIC },
159 { MOUNT_EXT2FS, LINUX_EXT2_SUPER_MAGIC }, 159 { MOUNT_EXT2FS, LINUX_EXT2_SUPER_MAGIC },
160 { MOUNT_CFS, LINUX_DEFAULT_SUPER_MAGIC }, 160 { MOUNT_CFS, LINUX_DEFAULT_SUPER_MAGIC },
161 { MOUNT_CODA, LINUX_CODA_SUPER_MAGIC }, 161 { MOUNT_CODA, LINUX_CODA_SUPER_MAGIC },
162 { MOUNT_FILECORE, LINUX_DEFAULT_SUPER_MAGIC }, 162 { MOUNT_FILECORE, LINUX_DEFAULT_SUPER_MAGIC },
163 { MOUNT_NTFS, LINUX_DEFAULT_SUPER_MAGIC }, 163 { MOUNT_NTFS, LINUX_DEFAULT_SUPER_MAGIC },
164 { MOUNT_SMBFS, LINUX_SMB_SUPER_MAGIC }, 164 { MOUNT_SMBFS, LINUX_SMB_SUPER_MAGIC },
165 { MOUNT_PTYFS, LINUX_DEVPTS_SUPER_MAGIC }, 165 { MOUNT_PTYFS, LINUX_DEVPTS_SUPER_MAGIC },
166 { MOUNT_TMPFS, LINUX_TMPFS_SUPER_MAGIC } 166 { MOUNT_TMPFS, LINUX_TMPFS_SUPER_MAGIC }
167}; 167};
168const int linux_fstypes_cnt = sizeof(linux_fstypes) / sizeof(linux_fstypes[0]); 168const int linux_fstypes_cnt = sizeof(linux_fstypes) / sizeof(linux_fstypes[0]);
169 169
170# ifdef DEBUG_LINUX 170# ifdef DEBUG_LINUX
171#define DPRINTF(a) uprintf a 171#define DPRINTF(a) uprintf a
172# else 172# else
173#define DPRINTF(a) 173#define DPRINTF(a)
174# endif 174# endif
175 175
176/* Local linux_misc.c functions: */ 176/* Local linux_misc.c functions: */
177static void linux_to_bsd_mmap_args(struct sys_mmap_args *, 177static void linux_to_bsd_mmap_args(struct sys_mmap_args *,
178 const struct linux_sys_mmap_args *); 178 const struct linux_sys_mmap_args *);
179static int linux_mmap(struct lwp *, const struct linux_sys_mmap_args *, 179static int linux_mmap(struct lwp *, const struct linux_sys_mmap_args *,
180 register_t *, off_t); 180 register_t *, off_t);
181 181
182 182
183/* 183/*
184 * The information on a terminated (or stopped) process needs 184 * The information on a terminated (or stopped) process needs
185 * to be converted in order for Linux binaries to get a valid signal 185 * to be converted in order for Linux binaries to get a valid signal
186 * number out of it. 186 * number out of it.
187 */ 187 */
188int 188int
189bsd_to_linux_wstat(int st) 189bsd_to_linux_wstat(int st)
190{ 190{
191 191
192 int sig; 192 int sig;
193 193
194 if (WIFSIGNALED(st)) { 194 if (WIFSIGNALED(st)) {
195 sig = WTERMSIG(st); 195 sig = WTERMSIG(st);
196 if (sig >= 0 && sig < NSIG) 196 if (sig >= 0 && sig < NSIG)
197 st= (st & ~0177) | native_to_linux_signo[sig]; 197 st= (st & ~0177) | native_to_linux_signo[sig];
198 } else if (WIFSTOPPED(st)) { 198 } else if (WIFSTOPPED(st)) {
199 sig = WSTOPSIG(st); 199 sig = WSTOPSIG(st);
200 if (sig >= 0 && sig < NSIG) 200 if (sig >= 0 && sig < NSIG)
201 st = (st & ~0xff00) | 201 st = (st & ~0xff00) |
202 (native_to_linux_signo[sig] << 8); 202 (native_to_linux_signo[sig] << 8);
203 } 203 }
204 return st; 204 return st;
205} 205}
206 206
207/* 207/*
208 * wait4(2). Passed on to the NetBSD call, surrounded by code to 208 * wait4(2). Passed on to the NetBSD call, surrounded by code to
209 * reserve some space for a NetBSD-style wait status, and converting 209 * reserve some space for a NetBSD-style wait status, and converting
210 * it to what Linux wants. 210 * it to what Linux wants.
211 */ 211 */
212int 212int
213linux_sys_wait4(struct lwp *l, const struct linux_sys_wait4_args *uap, register_t *retval) 213linux_sys_wait4(struct lwp *l, const struct linux_sys_wait4_args *uap, register_t *retval)
214{ 214{
215 /* { 215 /* {
216 syscallarg(int) pid; 216 syscallarg(int) pid;
217 syscallarg(int *) status; 217 syscallarg(int *) status;
218 syscallarg(int) options; 218 syscallarg(int) options;
219 syscallarg(struct rusage50 *) rusage; 219 syscallarg(struct rusage50 *) rusage;
220 } */ 220 } */
221 int error, status, options, linux_options, pid = SCARG(uap, pid); 221 int error, status, options, linux_options, pid = SCARG(uap, pid);
222 struct rusage50 ru50; 222 struct rusage50 ru50;
223 struct rusage ru; 223 struct rusage ru;
224 proc_t *p; 224 proc_t *p;
225 225
226 linux_options = SCARG(uap, options); 226 linux_options = SCARG(uap, options);
227 options = WOPTSCHECKED; 227 options = WOPTSCHECKED;
228 if (linux_options & ~(LINUX_WAIT4_KNOWNFLAGS)) 228 if (linux_options & ~(LINUX_WAIT4_KNOWNFLAGS))
229 return (EINVAL); 229 return (EINVAL);
230 230
231 if (linux_options & LINUX_WAIT4_WNOHANG) 231 if (linux_options & LINUX_WAIT4_WNOHANG)
232 options |= WNOHANG; 232 options |= WNOHANG;
233 if (linux_options & LINUX_WAIT4_WUNTRACED) 233 if (linux_options & LINUX_WAIT4_WUNTRACED)
234 options |= WUNTRACED; 234 options |= WUNTRACED;
235 if (linux_options & LINUX_WAIT4_WALL) 235 if (linux_options & LINUX_WAIT4_WALL)
236 options |= WALLSIG; 236 options |= WALLSIG;
237 if (linux_options & LINUX_WAIT4_WCLONE) 237 if (linux_options & LINUX_WAIT4_WCLONE)
238 options |= WALTSIG; 238 options |= WALTSIG;
239# ifdef DIAGNOSTIC 239# ifdef DIAGNOSTIC
240 if (linux_options & LINUX_WAIT4_WNOTHREAD) 240 if (linux_options & LINUX_WAIT4_WNOTHREAD)
241 printf("WARNING: %s: linux process %d.%d called " 241 printf("WARNING: %s: linux process %d.%d called "
242 "waitpid with __WNOTHREAD set!", 242 "waitpid with __WNOTHREAD set!",
243 __FILE__, l->l_proc->p_pid, l->l_lid); 243 __FILE__, l->l_proc->p_pid, l->l_lid);
244 244
245# endif 245# endif
246 246
247 error = do_sys_wait(&pid, &status, options, 247 error = do_sys_wait(&pid, &status, options,
248 SCARG(uap, rusage) != NULL ? &ru : NULL); 248 SCARG(uap, rusage) != NULL ? &ru : NULL);
249 249
250 retval[0] = pid; 250 retval[0] = pid;
251 if (pid == 0) 251 if (pid == 0)
252 return error; 252 return error;
253 253
254 p = curproc; 254 p = curproc;
255 mutex_enter(p->p_lock); 255 mutex_enter(p->p_lock);
256 sigdelset(&p->p_sigpend.sp_set, SIGCHLD); /* XXXAD ksiginfo leak */ 256 sigdelset(&p->p_sigpend.sp_set, SIGCHLD); /* XXXAD ksiginfo leak */
257 mutex_exit(p->p_lock); 257 mutex_exit(p->p_lock);
258 258
259 if (SCARG(uap, rusage) != NULL) { 259 if (SCARG(uap, rusage) != NULL) {
260 rusage_to_rusage50(&ru, &ru50); 260 rusage_to_rusage50(&ru, &ru50);
261 error = copyout(&ru, SCARG(uap, rusage), sizeof(ru)); 261 error = copyout(&ru, SCARG(uap, rusage), sizeof(ru));
262 } 262 }
263 263
264 if (error == 0 && SCARG(uap, status) != NULL) { 264 if (error == 0 && SCARG(uap, status) != NULL) {
265 status = bsd_to_linux_wstat(status); 265 status = bsd_to_linux_wstat(status);
266 error = copyout(&status, SCARG(uap, status), sizeof status); 266 error = copyout(&status, SCARG(uap, status), sizeof status);
267 } 267 }
268 268
269 return error; 269 return error;
270} 270}
271 271
272/* 272/*
273 * Linux brk(2). Like native, but always return the new break value. 273 * Linux brk(2). Like native, but always return the new break value.
274 */ 274 */
275int 275int
276linux_sys_brk(struct lwp *l, const struct linux_sys_brk_args *uap, register_t *retval) 276linux_sys_brk(struct lwp *l, const struct linux_sys_brk_args *uap, register_t *retval)
277{ 277{
278 /* { 278 /* {
279 syscallarg(char *) nsize; 279 syscallarg(char *) nsize;
280 } */ 280 } */
281 struct proc *p = l->l_proc; 281 struct proc *p = l->l_proc;
282 struct vmspace *vm = p->p_vmspace; 282 struct vmspace *vm = p->p_vmspace;
283 struct sys_obreak_args oba; 283 struct sys_obreak_args oba;
284 284
285 SCARG(&oba, nsize) = SCARG(uap, nsize); 285 SCARG(&oba, nsize) = SCARG(uap, nsize);
286 286
287 (void) sys_obreak(l, &oba, retval); 287 (void) sys_obreak(l, &oba, retval);
288 retval[0] = (register_t)((char *)vm->vm_daddr + ptoa(vm->vm_dsize)); 288 retval[0] = (register_t)((char *)vm->vm_daddr + ptoa(vm->vm_dsize));
289 return 0; 289 return 0;
290} 290}
291 291
292/* 292/*
293 * Implement the fs stat functions. Straightforward. 293 * Implement the fs stat functions. Straightforward.
294 */ 294 */
295int 295int
296linux_sys_statfs(struct lwp *l, const struct linux_sys_statfs_args *uap, register_t *retval) 296linux_sys_statfs(struct lwp *l, const struct linux_sys_statfs_args *uap, register_t *retval)
297{ 297{
298 /* { 298 /* {
299 syscallarg(const char *) path; 299 syscallarg(const char *) path;
300 syscallarg(struct linux_statfs *) sp; 300 syscallarg(struct linux_statfs *) sp;
301 } */ 301 } */
302 struct statvfs *sb; 302 struct statvfs *sb;
303 struct linux_statfs ltmp; 303 struct linux_statfs ltmp;
304 int error; 304 int error;
305 305
306 sb = STATVFSBUF_GET(); 306 sb = STATVFSBUF_GET();
307 error = do_sys_pstatvfs(l, SCARG(uap, path), ST_WAIT, sb); 307 error = do_sys_pstatvfs(l, SCARG(uap, path), ST_WAIT, sb);
308 if (error == 0) { 308 if (error == 0) {
309 bsd_to_linux_statfs(sb, &ltmp); 309 bsd_to_linux_statfs(sb, &ltmp);
310 error = copyout(&ltmp, SCARG(uap, sp), sizeof ltmp); 310 error = copyout(&ltmp, SCARG(uap, sp), sizeof ltmp);
311 } 311 }
312 STATVFSBUF_PUT(sb); 312 STATVFSBUF_PUT(sb);
313 313
314 return error; 314 return error;
315} 315}
316 316
317int 317int
318linux_sys_fstatfs(struct lwp *l, const struct linux_sys_fstatfs_args *uap, register_t *retval) 318linux_sys_fstatfs(struct lwp *l, const struct linux_sys_fstatfs_args *uap, register_t *retval)
319{ 319{
320 /* { 320 /* {
321 syscallarg(int) fd; 321 syscallarg(int) fd;
322 syscallarg(struct linux_statfs *) sp; 322 syscallarg(struct linux_statfs *) sp;
323 } */ 323 } */
324 struct statvfs *sb; 324 struct statvfs *sb;
325 struct linux_statfs ltmp; 325 struct linux_statfs ltmp;
326 int error; 326 int error;
327 327
328 sb = STATVFSBUF_GET(); 328 sb = STATVFSBUF_GET();
329 error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb); 329 error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb);
330 if (error == 0) { 330 if (error == 0) {
331 bsd_to_linux_statfs(sb, &ltmp); 331 bsd_to_linux_statfs(sb, &ltmp);
332 error = copyout(&ltmp, SCARG(uap, sp), sizeof ltmp); 332 error = copyout(&ltmp, SCARG(uap, sp), sizeof ltmp);
333 } 333 }
334 STATVFSBUF_PUT(sb); 334 STATVFSBUF_PUT(sb);
335 335
336 return error; 336 return error;
337} 337}
338 338
339/* 339/*
340 * uname(). Just copy the info from the various strings stored in the 340 * uname(). Just copy the info from the various strings stored in the
341 * kernel, and put it in the Linux utsname structure. That structure 341 * kernel, and put it in the Linux utsname structure. That structure
342 * is almost the same as the NetBSD one, only it has fields 65 characters 342 * is almost the same as the NetBSD one, only it has fields 65 characters
343 * long, and an extra domainname field. 343 * long, and an extra domainname field.
344 */ 344 */
345int 345int
346linux_sys_uname(struct lwp *l, const struct linux_sys_uname_args *uap, register_t *retval) 346linux_sys_uname(struct lwp *l, const struct linux_sys_uname_args *uap, register_t *retval)
347{ 347{
348 /* { 348 /* {
349 syscallarg(struct linux_utsname *) up; 349 syscallarg(struct linux_utsname *) up;
350 } */ 350 } */
351 struct linux_utsname luts; 351 struct linux_utsname luts;
352 352
353 strlcpy(luts.l_sysname, linux_sysname, sizeof(luts.l_sysname)); 353 strlcpy(luts.l_sysname, linux_sysname, sizeof(luts.l_sysname));
354 strlcpy(luts.l_nodename, hostname, sizeof(luts.l_nodename)); 354 strlcpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
355 strlcpy(luts.l_release, linux_release, sizeof(luts.l_release)); 355 strlcpy(luts.l_release, linux_release, sizeof(luts.l_release));
356 strlcpy(luts.l_version, linux_version, sizeof(luts.l_version)); 356 strlcpy(luts.l_version, linux_version, sizeof(luts.l_version));
357 strlcpy(luts.l_machine, LINUX_UNAME_ARCH, sizeof(luts.l_machine)); 357 strlcpy(luts.l_machine, LINUX_UNAME_ARCH, sizeof(luts.l_machine));
358 strlcpy(luts.l_domainname, domainname, sizeof(luts.l_domainname)); 358 strlcpy(luts.l_domainname, domainname, sizeof(luts.l_domainname));
359 359
360 return copyout(&luts, SCARG(uap, up), sizeof(luts)); 360 return copyout(&luts, SCARG(uap, up), sizeof(luts));
361} 361}
362 362
363/* Used directly on: alpha, mips, ppc, sparc, sparc64 */ 363/* Used directly on: alpha, mips, ppc, sparc, sparc64 */
364/* Used indirectly on: arm, i386, m68k */ 364/* Used indirectly on: arm, i386, m68k */
365 365
366/* 366/*
367 * New type Linux mmap call. 367 * New type Linux mmap call.
368 * Only called directly on machines with >= 6 free regs. 368 * Only called directly on machines with >= 6 free regs.
369 */ 369 */
370int 370int
371linux_sys_mmap(struct lwp *l, const struct linux_sys_mmap_args *uap, register_t *retval) 371linux_sys_mmap(struct lwp *l, const struct linux_sys_mmap_args *uap, register_t *retval)
372{ 372{
373 /* { 373 /* {
374 syscallarg(unsigned long) addr; 374 syscallarg(unsigned long) addr;
375 syscallarg(size_t) len; 375 syscallarg(size_t) len;
376 syscallarg(int) prot; 376 syscallarg(int) prot;
377 syscallarg(int) flags; 377 syscallarg(int) flags;
378 syscallarg(int) fd; 378 syscallarg(int) fd;
379 syscallarg(linux_off_t) offset; 379 syscallarg(linux_off_t) offset;
380 } */ 380 } */
381 381
382 if (SCARG(uap, offset) & PAGE_MASK) 382 if (SCARG(uap, offset) & PAGE_MASK)
383 return EINVAL; 383 return EINVAL;
384 384
385 return linux_mmap(l, uap, retval, SCARG(uap, offset)); 385 return linux_mmap(l, uap, retval, SCARG(uap, offset));
386} 386}
387 387
388/* 388/*
389 * Guts of most architectures' mmap64() implementations. This shares 389 * Guts of most architectures' mmap64() implementations. This shares
390 * its list of arguments with linux_sys_mmap(). 390 * its list of arguments with linux_sys_mmap().
391 * 391 *
392 * The difference in linux_sys_mmap2() is that "offset" is actually 392 * The difference in linux_sys_mmap2() is that "offset" is actually
393 * (offset / pagesize), not an absolute byte count. This translation 393 * (offset / pagesize), not an absolute byte count. This translation
394 * to pagesize offsets is done inside glibc between the mmap64() call 394 * to pagesize offsets is done inside glibc between the mmap64() call
395 * point, and the actual syscall. 395 * point, and the actual syscall.
396 */ 396 */
397int 397int
398linux_sys_mmap2(struct lwp *l, const struct linux_sys_mmap2_args *uap, register_t *retval) 398linux_sys_mmap2(struct lwp *l, const struct linux_sys_mmap2_args *uap, register_t *retval)
399{ 399{
400 /* { 400 /* {
401 syscallarg(unsigned long) addr; 401 syscallarg(unsigned long) addr;
402 syscallarg(size_t) len; 402 syscallarg(size_t) len;
403 syscallarg(int) prot; 403 syscallarg(int) prot;
404 syscallarg(int) flags; 404 syscallarg(int) flags;
405 syscallarg(int) fd; 405 syscallarg(int) fd;
406 syscallarg(linux_off_t) offset; 406 syscallarg(linux_off_t) offset;
407 } */ 407 } */
408 408
409 return linux_mmap(l, uap, retval, 409 return linux_mmap(l, uap, retval,
410 ((off_t)SCARG(uap, offset)) << PAGE_SHIFT); 410 ((off_t)SCARG(uap, offset)) << PAGE_SHIFT);
411} 411}
412 412
413/* 413/*
414 * Massage arguments and call system mmap(2). 414 * Massage arguments and call system mmap(2).
415 */ 415 */
416static int 416static int
417linux_mmap(struct lwp *l, const struct linux_sys_mmap_args *uap, register_t *retval, off_t offset) 417linux_mmap(struct lwp *l, const struct linux_sys_mmap_args *uap, register_t *retval, off_t offset)
418{ 418{
419 struct sys_mmap_args cma; 419 struct sys_mmap_args cma;
420 int error; 420 int error;
421 size_t mmoff=0; 421 size_t mmoff=0;
422 422
423 linux_to_bsd_mmap_args(&cma, uap); 423 linux_to_bsd_mmap_args(&cma, uap);
424 SCARG(&cma, pos) = offset; 424 SCARG(&cma, pos) = offset;
425 425
426 if (SCARG(uap, flags) & LINUX_MAP_GROWSDOWN) { 426 if (SCARG(uap, flags) & LINUX_MAP_GROWSDOWN) {
427 /* 427 /*
428 * Request for stack-like memory segment. On linux, this 428 * Request for stack-like memory segment. On linux, this
429 * works by mmap()ping (small) segment, which is automatically 429 * works by mmap()ping (small) segment, which is automatically
430 * extended when page fault happens below the currently 430 * extended when page fault happens below the currently
431 * allocated area. We emulate this by allocating (typically 431 * allocated area. We emulate this by allocating (typically
432 * bigger) segment sized at current stack size limit, and 432 * bigger) segment sized at current stack size limit, and
433 * offsetting the requested and returned address accordingly. 433 * offsetting the requested and returned address accordingly.
434 * Since physical pages are only allocated on-demand, this 434 * Since physical pages are only allocated on-demand, this
435 * is effectively identical. 435 * is effectively identical.
436 */ 436 */
437 rlim_t ssl = l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur; 437 rlim_t ssl = l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur;
438 438
439 if (SCARG(&cma, len) < ssl) { 439 if (SCARG(&cma, len) < ssl) {
440 /* Compute the address offset */ 440 /* Compute the address offset */
441 mmoff = round_page(ssl) - SCARG(uap, len); 441 mmoff = round_page(ssl) - SCARG(uap, len);
442 442
443 if (SCARG(&cma, addr)) 443 if (SCARG(&cma, addr))
444 SCARG(&cma, addr) = (char *)SCARG(&cma, addr) - mmoff; 444 SCARG(&cma, addr) = (char *)SCARG(&cma, addr) - mmoff;
445 445
446 SCARG(&cma, len) = (size_t) ssl; 446 SCARG(&cma, len) = (size_t) ssl;
447 } 447 }
448 } 448 }
449 449
450 error = sys_mmap(l, &cma, retval); 450 error = sys_mmap(l, &cma, retval);
451 if (error) 451 if (error)
452 return (error); 452 return (error);
453 453
454 /* Shift the returned address for stack-like segment if necessary */ 454 /* Shift the returned address for stack-like segment if necessary */
455 retval[0] += mmoff; 455 retval[0] += mmoff;
456 456
457 return (0); 457 return (0);
458} 458}
459 459
460static void 460static void
461linux_to_bsd_mmap_args(struct sys_mmap_args *cma, const struct linux_sys_mmap_args *uap) 461linux_to_bsd_mmap_args(struct sys_mmap_args *cma, const struct linux_sys_mmap_args *uap)
462{ 462{
463 int flags = MAP_TRYFIXED, fl = SCARG(uap, flags); 463 int flags = MAP_TRYFIXED, fl = SCARG(uap, flags);
464 464
465 flags |= cvtto_bsd_mask(fl, LINUX_MAP_SHARED, MAP_SHARED); 465 flags |= cvtto_bsd_mask(fl, LINUX_MAP_SHARED, MAP_SHARED);
466 flags |= cvtto_bsd_mask(fl, LINUX_MAP_PRIVATE, MAP_PRIVATE); 466 flags |= cvtto_bsd_mask(fl, LINUX_MAP_PRIVATE, MAP_PRIVATE);
467 flags |= cvtto_bsd_mask(fl, LINUX_MAP_FIXED, MAP_FIXED); 467 flags |= cvtto_bsd_mask(fl, LINUX_MAP_FIXED, MAP_FIXED);
468 flags |= cvtto_bsd_mask(fl, LINUX_MAP_ANON, MAP_ANON); 468 flags |= cvtto_bsd_mask(fl, LINUX_MAP_ANON, MAP_ANON);
469 /* XXX XAX ERH: Any other flags here? There are more defined... */ 469 /* XXX XAX ERH: Any other flags here? There are more defined... */
470 470
471 SCARG(cma, addr) = (void *)SCARG(uap, addr); 471 SCARG(cma, addr) = (void *)SCARG(uap, addr);
472 SCARG(cma, len) = SCARG(uap, len); 472 SCARG(cma, len) = SCARG(uap, len);
473 SCARG(cma, prot) = SCARG(uap, prot); 473 SCARG(cma, prot) = SCARG(uap, prot);
474 if (SCARG(cma, prot) & VM_PROT_WRITE) /* XXX */ 474 if (SCARG(cma, prot) & VM_PROT_WRITE) /* XXX */
475 SCARG(cma, prot) |= VM_PROT_READ; 475 SCARG(cma, prot) |= VM_PROT_READ;
476 SCARG(cma, flags) = flags; 476 SCARG(cma, flags) = flags;
477 SCARG(cma, fd) = flags & MAP_ANON ? -1 : SCARG(uap, fd); 477 SCARG(cma, fd) = flags & MAP_ANON ? -1 : SCARG(uap, fd);
478 SCARG(cma, PAD) = 0; 478 SCARG(cma, PAD) = 0;
479} 479}
480 480
481#define LINUX_MREMAP_MAYMOVE 1 481#define LINUX_MREMAP_MAYMOVE 1
482#define LINUX_MREMAP_FIXED 2 482#define LINUX_MREMAP_FIXED 2
483 483
484int 484int
485linux_sys_mremap(struct lwp *l, const struct linux_sys_mremap_args *uap, register_t *retval) 485linux_sys_mremap(struct lwp *l, const struct linux_sys_mremap_args *uap, register_t *retval)
486{ 486{
487 /* { 487 /* {
488 syscallarg(void *) old_address; 488 syscallarg(void *) old_address;
489 syscallarg(size_t) old_size; 489 syscallarg(size_t) old_size;
490 syscallarg(size_t) new_size; 490 syscallarg(size_t) new_size;
491 syscallarg(u_long) flags; 491 syscallarg(u_long) flags;
492 } */ 492 } */
493 493
494 struct proc *p; 494 struct proc *p;
495 struct vm_map *map; 495 struct vm_map *map;
496 vaddr_t oldva; 496 vaddr_t oldva;
497 vaddr_t newva; 497 vaddr_t newva;
498 size_t oldsize; 498 size_t oldsize;
499 size_t newsize; 499 size_t newsize;
500 int flags; 500 int flags;
501 int uvmflags; 501 int uvmflags;
502 int error; 502 int error;
503 503
504 flags = SCARG(uap, flags); 504 flags = SCARG(uap, flags);
505 oldva = (vaddr_t)SCARG(uap, old_address); 505 oldva = (vaddr_t)SCARG(uap, old_address);
506 oldsize = round_page(SCARG(uap, old_size)); 506 oldsize = round_page(SCARG(uap, old_size));
507 newsize = round_page(SCARG(uap, new_size)); 507 newsize = round_page(SCARG(uap, new_size));
508 if ((flags & ~(LINUX_MREMAP_FIXED|LINUX_MREMAP_MAYMOVE)) != 0) { 508 if ((flags & ~(LINUX_MREMAP_FIXED|LINUX_MREMAP_MAYMOVE)) != 0) {
509 error = EINVAL; 509 error = EINVAL;
510 goto done; 510 goto done;
511 } 511 }
512 if ((flags & LINUX_MREMAP_FIXED) != 0) { 512 if ((flags & LINUX_MREMAP_FIXED) != 0) {
513 if ((flags & LINUX_MREMAP_MAYMOVE) == 0) { 513 if ((flags & LINUX_MREMAP_MAYMOVE) == 0) {
514 error = EINVAL; 514 error = EINVAL;
515 goto done; 515 goto done;
516 } 516 }
517#if 0 /* notyet */ 517#if 0 /* notyet */
518 newva = SCARG(uap, new_address); 518 newva = SCARG(uap, new_address);
519 uvmflags = MAP_FIXED; 519 uvmflags = MAP_FIXED;
520#else /* notyet */ 520#else /* notyet */
521 error = EOPNOTSUPP; 521 error = EOPNOTSUPP;
522 goto done; 522 goto done;
523#endif /* notyet */ 523#endif /* notyet */
524 } else if ((flags & LINUX_MREMAP_MAYMOVE) != 0) { 524 } else if ((flags & LINUX_MREMAP_MAYMOVE) != 0) {
525 uvmflags = 0; 525 uvmflags = 0;
526 } else { 526 } else {
527 newva = oldva; 527 newva = oldva;
528 uvmflags = MAP_FIXED; 528 uvmflags = MAP_FIXED;
529 } 529 }
530 p = l->l_proc; 530 p = l->l_proc;
531 map = &p->p_vmspace->vm_map; 531 map = &p->p_vmspace->vm_map;
532 error = uvm_mremap(map, oldva, oldsize, map, &newva, newsize, p, 532 error = uvm_mremap(map, oldva, oldsize, map, &newva, newsize, p,
533 uvmflags); 533 uvmflags);
534 534
535done: 535done:
536 *retval = (error != 0) ? 0 : (register_t)newva; 536 *retval = (error != 0) ? 0 : (register_t)newva;
537 return error; 537 return error;
538} 538}
539 539
540int 540int
541linux_sys_mprotect(struct lwp *l, const struct linux_sys_mprotect_args *uap, register_t *retval) 541linux_sys_mprotect(struct lwp *l, const struct linux_sys_mprotect_args *uap, register_t *retval)
542{ 542{
543 /* { 543 /* {
544 syscallarg(const void *) start; 544 syscallarg(const void *) start;
545 syscallarg(unsigned long) len; 545 syscallarg(unsigned long) len;
546 syscallarg(int) prot; 546 syscallarg(int) prot;
547 } */ 547 } */
548 struct vm_map_entry *entry; 548 struct vm_map_entry *entry;
549 struct vm_map *map; 549 struct vm_map *map;
550 struct proc *p; 550 struct proc *p;
551 vaddr_t end, start, len, stacklim; 551 vaddr_t end, start, len, stacklim;
552 int prot, grows; 552 int prot, grows;
553 553
554 start = (vaddr_t)SCARG(uap, start); 554 start = (vaddr_t)SCARG(uap, start);
555 len = round_page(SCARG(uap, len)); 555 len = round_page(SCARG(uap, len));
556 prot = SCARG(uap, prot); 556 prot = SCARG(uap, prot);
557 grows = prot & (LINUX_PROT_GROWSDOWN | LINUX_PROT_GROWSUP); 557 grows = prot & (LINUX_PROT_GROWSDOWN | LINUX_PROT_GROWSUP);
558 prot &= ~grows; 558 prot &= ~grows;
559 end = start + len; 559 end = start + len;
560 560
561 if (start & PAGE_MASK) 561 if (start & PAGE_MASK)
562 return EINVAL; 562 return EINVAL;
563 if (end < start) 563 if (end < start)
564 return EINVAL; 564 return EINVAL;
565 if (end == start) 565 if (end == start)
566 return 0; 566 return 0;
567 567
568 if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) 568 if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
569 return EINVAL; 569 return EINVAL;
570 if (grows == (LINUX_PROT_GROWSDOWN | LINUX_PROT_GROWSUP)) 570 if (grows == (LINUX_PROT_GROWSDOWN | LINUX_PROT_GROWSUP))
571 return EINVAL; 571 return EINVAL;
572 572
573 p = l->l_proc; 573 p = l->l_proc;
574 map = &p->p_vmspace->vm_map; 574 map = &p->p_vmspace->vm_map;
575 vm_map_lock(map); 575 vm_map_lock(map);
576# ifdef notdef 576# ifdef notdef
577 VM_MAP_RANGE_CHECK(map, start, end); 577 VM_MAP_RANGE_CHECK(map, start, end);
578# endif 578# endif
579 if (!uvm_map_lookup_entry(map, start, &entry) || entry->start > start) { 579 if (!uvm_map_lookup_entry(map, start, &entry) || entry->start > start) {
580 vm_map_unlock(map); 580 vm_map_unlock(map);
581 return ENOMEM; 581 return ENOMEM;
582 } 582 }
583 583
584 /* 584 /*
585 * Approximate the behaviour of PROT_GROWS{DOWN,UP}. 585 * Approximate the behaviour of PROT_GROWS{DOWN,UP}.
586 */ 586 */
587 587
588 stacklim = (vaddr_t)p->p_limit->pl_rlimit[RLIMIT_STACK].rlim_cur; 588 stacklim = (vaddr_t)p->p_limit->pl_rlimit[RLIMIT_STACK].rlim_cur;
589 if (grows & LINUX_PROT_GROWSDOWN) { 589 if (grows & LINUX_PROT_GROWSDOWN) {
590 if (USRSTACK - stacklim <= start && start < USRSTACK) { 590 if (USRSTACK - stacklim <= start && start < USRSTACK) {
591 start = USRSTACK - stacklim; 591 start = USRSTACK - stacklim;
592 } else { 592 } else {
593 start = entry->start; 593 start = entry->start;
594 } 594 }
595 } else if (grows & LINUX_PROT_GROWSUP) { 595 } else if (grows & LINUX_PROT_GROWSUP) {
596 if (USRSTACK <= end && end < USRSTACK + stacklim) { 596 if (USRSTACK <= end && end < USRSTACK + stacklim) {
597 end = USRSTACK + stacklim; 597 end = USRSTACK + stacklim;
598 } else { 598 } else {
599 end = entry->end; 599 end = entry->end;
600 } 600 }
601 } 601 }
602 vm_map_unlock(map); 602 vm_map_unlock(map);
603 return uvm_map_protect(map, start, end, prot, FALSE); 603 return uvm_map_protect(map, start, end, prot, FALSE);
604} 604}
605 605
606/* 606/*
607 * This code is partly stolen from src/lib/libc/compat-43/times.c 607 * This code is partly stolen from src/lib/libc/compat-43/times.c
608 */ 608 */
609 609
610#define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz)) 610#define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
611 611
612int 612int
613linux_sys_times(struct lwp *l, const struct linux_sys_times_args *uap, register_t *retval) 613linux_sys_times(struct lwp *l, const struct linux_sys_times_args *uap, register_t *retval)
614{ 614{
615 /* { 615 /* {
616 syscallarg(struct times *) tms; 616 syscallarg(struct times *) tms;
617 } */ 617 } */
618 struct proc *p = l->l_proc; 618 struct proc *p = l->l_proc;
619 struct timeval t; 619 struct timeval t;
620 int error; 620 int error;
621 621
622 if (SCARG(uap, tms)) { 622 if (SCARG(uap, tms)) {
623 struct linux_tms ltms; 623 struct linux_tms ltms;
624 struct rusage ru; 624 struct rusage ru;
625 625
626 mutex_enter(p->p_lock); 626 mutex_enter(p->p_lock);
627 calcru(p, &ru.ru_utime, &ru.ru_stime, NULL, NULL); 627 calcru(p, &ru.ru_utime, &ru.ru_stime, NULL, NULL);
628 ltms.ltms_utime = CONVTCK(ru.ru_utime); 628 ltms.ltms_utime = CONVTCK(ru.ru_utime);
629 ltms.ltms_stime = CONVTCK(ru.ru_stime); 629 ltms.ltms_stime = CONVTCK(ru.ru_stime);
630 ltms.ltms_cutime = CONVTCK(p->p_stats->p_cru.ru_utime); 630 ltms.ltms_cutime = CONVTCK(p->p_stats->p_cru.ru_utime);
631 ltms.ltms_cstime = CONVTCK(p->p_stats->p_cru.ru_stime); 631 ltms.ltms_cstime = CONVTCK(p->p_stats->p_cru.ru_stime);
632 mutex_exit(p->p_lock); 632 mutex_exit(p->p_lock);
633 633
634 if ((error = copyout(&ltms, SCARG(uap, tms), sizeof ltms))) 634 if ((error = copyout(&ltms, SCARG(uap, tms), sizeof ltms)))
635 return error; 635 return error;
636 } 636 }
637 637
638 getmicrouptime(&t); 638 getmicrouptime(&t);
639 639
640 retval[0] = ((linux_clock_t)(CONVTCK(t))); 640 retval[0] = ((linux_clock_t)(CONVTCK(t)));
641 return 0; 641 return 0;
642} 642}
643 643
644#undef CONVTCK 644#undef CONVTCK
645 645
646/* 646/*
647 * Linux 'readdir' call. This code is mostly taken from the 647 * Linux 'readdir' call. This code is mostly taken from the
648 * SunOS getdents call (see compat/sunos/sunos_misc.c), though 648 * SunOS getdents call (see compat/sunos/sunos_misc.c), though
649 * an attempt has been made to keep it a little cleaner (failing 649 * an attempt has been made to keep it a little cleaner (failing
650 * miserably, because of the cruft needed if count 1 is passed). 650 * miserably, because of the cruft needed if count 1 is passed).
651 * 651 *
652 * The d_off field should contain the offset of the next valid entry, 652 * The d_off field should contain the offset of the next valid entry,
653 * but in Linux it has the offset of the entry itself. We emulate 653 * but in Linux it has the offset of the entry itself. We emulate
654 * that bug here. 654 * that bug here.
655 * 655 *
656 * Read in BSD-style entries, convert them, and copy them out. 656 * Read in BSD-style entries, convert them, and copy them out.
657 * 657 *
658 * Note that this doesn't handle union-mounted filesystems. 658 * Note that this doesn't handle union-mounted filesystems.
659 */ 659 */
660int 660int
661linux_sys_getdents(struct lwp *l, const struct linux_sys_getdents_args *uap, register_t *retval) 661linux_sys_getdents(struct lwp *l, const struct linux_sys_getdents_args *uap, register_t *retval)
662{ 662{
663 /* { 663 /* {
664 syscallarg(int) fd; 664 syscallarg(int) fd;
665 syscallarg(struct linux_dirent *) dent; 665 syscallarg(struct linux_dirent *) dent;
666 syscallarg(unsigned int) count; 666 syscallarg(unsigned int) count;
667 } */ 667 } */
668 struct dirent *bdp; 668 struct dirent *bdp;
669 struct vnode *vp; 669 struct vnode *vp;
670 char *inp, *tbuf; /* BSD-format */ 670 char *inp, *tbuf; /* BSD-format */
671 int len, reclen; /* BSD-format */ 671 int len, reclen; /* BSD-format */
672 char *outp; /* Linux-format */ 672 char *outp; /* Linux-format */
673 int resid, linux_reclen = 0; /* Linux-format */ 673 int resid, linux_reclen = 0; /* Linux-format */
674 struct file *fp; 674 struct file *fp;
675 struct uio auio; 675 struct uio auio;
676 struct iovec aiov; 676 struct iovec aiov;
677 struct linux_dirent idb; 677 struct linux_dirent idb;
678 off_t off; /* true file offset */ 678 off_t off; /* true file offset */
679 int buflen, error, eofflag, nbytes, oldcall; 679 int buflen, error, eofflag, nbytes, oldcall;
680 struct vattr va; 680 struct vattr va;
681 off_t *cookiebuf = NULL, *cookie; 681 off_t *cookiebuf = NULL, *cookie;
682 int ncookies; 682 int ncookies;
683 683
684 /* fd_getvnode() will use the descriptor for us */ 684 /* fd_getvnode() will use the descriptor for us */
685 if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0) 685 if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
686 return (error); 686 return (error);
687 687
688 if ((fp->f_flag & FREAD) == 0) { 688 if ((fp->f_flag & FREAD) == 0) {
689 error = EBADF; 689 error = EBADF;
690 goto out1; 690 goto out1;
691 } 691 }
692 692
693 vp = (struct vnode *)fp->f_data; 693 vp = (struct vnode *)fp->f_data;
694 if (vp->v_type != VDIR) { 694 if (vp->v_type != VDIR) {
695 error = ENOTDIR; 695 error = ENOTDIR;
696 goto out1; 696 goto out1;
697 } 697 }
698 698
699 if ((error = VOP_GETATTR(vp, &va, l->l_cred))) 699 if ((error = VOP_GETATTR(vp, &va, l->l_cred)))
700 goto out1; 700 goto out1;
701 701
702 nbytes = SCARG(uap, count); 702 nbytes = SCARG(uap, count);
703 if (nbytes == 1) { /* emulating old, broken behaviour */ 703 if (nbytes == 1) { /* emulating old, broken behaviour */
704 nbytes = sizeof (idb); 704 nbytes = sizeof (idb);
705 buflen = max(va.va_blocksize, nbytes); 705 buflen = max(va.va_blocksize, nbytes);
706 oldcall = 1; 706 oldcall = 1;
707 } else { 707 } else {
708 buflen = min(MAXBSIZE, nbytes); 708 buflen = min(MAXBSIZE, nbytes);
709 if (buflen < va.va_blocksize) 709 if (buflen < va.va_blocksize)
710 buflen = va.va_blocksize; 710 buflen = va.va_blocksize;
711 oldcall = 0; 711 oldcall = 0;
712 } 712 }
713 tbuf = malloc(buflen, M_TEMP, M_WAITOK); 713 tbuf = malloc(buflen, M_TEMP, M_WAITOK);
714 714
715 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 715 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
716 off = fp->f_offset; 716 off = fp->f_offset;
717again: 717again:
718 aiov.iov_base = tbuf; 718 aiov.iov_base = tbuf;
719 aiov.iov_len = buflen; 719 aiov.iov_len = buflen;
720 auio.uio_iov = &aiov; 720 auio.uio_iov = &aiov;
721 auio.uio_iovcnt = 1; 721 auio.uio_iovcnt = 1;
722 auio.uio_rw = UIO_READ; 722 auio.uio_rw = UIO_READ;
723 auio.uio_resid = buflen; 723 auio.uio_resid = buflen;
724 auio.uio_offset = off; 724 auio.uio_offset = off;
725 UIO_SETUP_SYSSPACE(&auio); 725 UIO_SETUP_SYSSPACE(&auio);
726 /* 726 /*
727 * First we read into the malloc'ed buffer, then 727 * First we read into the malloc'ed buffer, then
728 * we massage it into user space, one record at a time. 728 * we massage it into user space, one record at a time.
729 */ 729 */
730 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf, 730 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
731 &ncookies); 731 &ncookies);
732 if (error) 732 if (error)
733 goto out; 733 goto out;
734 734
735 inp = tbuf; 735 inp = tbuf;
736 outp = (void *)SCARG(uap, dent); 736 outp = (void *)SCARG(uap, dent);
737 resid = nbytes; 737 resid = nbytes;
738 if ((len = buflen - auio.uio_resid) == 0) 738 if ((len = buflen - auio.uio_resid) == 0)
739 goto eof; 739 goto eof;
740 740
741 for (cookie = cookiebuf; len > 0; len -= reclen) { 741 for (cookie = cookiebuf; len > 0; len -= reclen) {
742 bdp = (struct dirent *)inp; 742 bdp = (struct dirent *)inp;
743 reclen = bdp->d_reclen; 743 reclen = bdp->d_reclen;
744 if (reclen & 3) 744 if (reclen & 3)
745 panic("linux_readdir"); 745 panic("linux_readdir");
746 if (bdp->d_fileno == 0) { 746 if (bdp->d_fileno == 0) {
747 inp += reclen; /* it is a hole; squish it out */ 747 inp += reclen; /* it is a hole; squish it out */
748 if (cookie) 748 if (cookie)
749 off = *cookie++; 749 off = *cookie++;
750 else 750 else
751 off += reclen; 751 off += reclen;
752 continue; 752 continue;
753 } 753 }
754 linux_reclen = LINUX_RECLEN(&idb, bdp->d_namlen); 754 linux_reclen = LINUX_RECLEN(&idb, bdp->d_namlen);
755 if (reclen > len || resid < linux_reclen) { 755 if (reclen > len || resid < linux_reclen) {
756 /* entry too big for buffer, so just stop */ 756 /* entry too big for buffer, so just stop */
757 outp++; 757 outp++;
758 break; 758 break;
759 } 759 }
760 /* 760 /*
761 * Massage in place to make a Linux-shaped dirent (otherwise 761 * Massage in place to make a Linux-shaped dirent (otherwise
762 * we have to worry about touching user memory outside of 762 * we have to worry about touching user memory outside of
763 * the copyout() call). 763 * the copyout() call).
764 */ 764 */
765 idb.d_ino = bdp->d_fileno; 765 idb.d_ino = bdp->d_fileno;
766 /* 766 /*
767 * The old readdir() call misuses the offset and reclen fields. 767 * The old readdir() call misuses the offset and reclen fields.
768 */ 768 */
769 if (oldcall) { 769 if (oldcall) {
770 idb.d_off = (linux_off_t)linux_reclen; 770 idb.d_off = (linux_off_t)linux_reclen;
771 idb.d_reclen = (u_short)bdp->d_namlen; 771 idb.d_reclen = (u_short)bdp->d_namlen;
772 } else { 772 } else {
773 if (sizeof (idb.d_off) <= 4 && (off >> 32) != 0) { 773 if (sizeof (idb.d_off) <= 4 && (off >> 32) != 0) {
774 compat_offseterr(vp, "linux_getdents"); 774 compat_offseterr(vp, "linux_getdents");
775 error = EINVAL; 775 error = EINVAL;
776 goto out; 776 goto out;
777 } 777 }
778 idb.d_off = (linux_off_t)off; 778 idb.d_off = (linux_off_t)off;
779 idb.d_reclen = (u_short)linux_reclen; 779 idb.d_reclen = (u_short)linux_reclen;
780 } 780 }
781 strcpy(idb.d_name, bdp->d_name); 781 strcpy(idb.d_name, bdp->d_name);
782 idb.d_name[strlen(idb.d_name) + 1] = bdp->d_type; 782 idb.d_name[strlen(idb.d_name) + 1] = bdp->d_type;
783 if ((error = copyout((void *)&idb, outp, linux_reclen))) 783 if ((error = copyout((void *)&idb, outp, linux_reclen)))
784 goto out; 784 goto out;
785 /* advance past this real entry */ 785 /* advance past this real entry */
786 inp += reclen; 786 inp += reclen;
787 if (cookie) 787 if (cookie)
788 off = *cookie++; /* each entry points to itself */ 788 off = *cookie++; /* each entry points to itself */
789 else 789 else
790 off += reclen; 790 off += reclen;
791 /* advance output past Linux-shaped entry */ 791 /* advance output past Linux-shaped entry */
792 outp += linux_reclen; 792 outp += linux_reclen;
793 resid -= linux_reclen; 793 resid -= linux_reclen;
794 if (oldcall) 794 if (oldcall)
795 break; 795 break;
796 } 796 }
797 797
798 /* if we squished out the whole block, try again */ 798 /* if we squished out the whole block, try again */
799 if (outp == (void *)SCARG(uap, dent)) { 799 if (outp == (void *)SCARG(uap, dent)) {
800 if (cookiebuf) 800 if (cookiebuf)
801 free(cookiebuf, M_TEMP); 801 free(cookiebuf, M_TEMP);
802 cookiebuf = NULL; 802 cookiebuf = NULL;
803 goto again; 803 goto again;
804 } 804 }
805 fp->f_offset = off; /* update the vnode offset */ 805 fp->f_offset = off; /* update the vnode offset */
806 806
807 if (oldcall) 807 if (oldcall)
808 nbytes = resid + linux_reclen; 808 nbytes = resid + linux_reclen;
809 809
810eof: 810eof:
811 *retval = nbytes - resid; 811 *retval = nbytes - resid;
812out: 812out:
813 VOP_UNLOCK(vp); 813 VOP_UNLOCK(vp);
814 if (cookiebuf) 814 if (cookiebuf)
815 free(cookiebuf, M_TEMP); 815 free(cookiebuf, M_TEMP);
816 free(tbuf, M_TEMP); 816 free(tbuf, M_TEMP);
817out1: 817out1:
818 fd_putfile(SCARG(uap, fd)); 818 fd_putfile(SCARG(uap, fd));
819 return error; 819 return error;
820} 820}
821 821
822/* 822/*
823 * Even when just using registers to pass arguments to syscalls you can 823 * Even when just using registers to pass arguments to syscalls you can
824 * have 5 of them on the i386. So this newer version of select() does 824 * have 5 of them on the i386. So this newer version of select() does
825 * this. 825 * this.
826 */ 826 */
827int 827int
828linux_sys_select(struct lwp *l, const struct linux_sys_select_args *uap, register_t *retval) 828linux_sys_select(struct lwp *l, const struct linux_sys_select_args *uap, register_t *retval)
829{ 829{
830 /* { 830 /* {
831 syscallarg(int) nfds; 831 syscallarg(int) nfds;
832 syscallarg(fd_set *) readfds; 832 syscallarg(fd_set *) readfds;
833 syscallarg(fd_set *) writefds; 833 syscallarg(fd_set *) writefds;
834 syscallarg(fd_set *) exceptfds; 834 syscallarg(fd_set *) exceptfds;
835 syscallarg(struct timeval50 *) timeout; 835 syscallarg(struct timeval50 *) timeout;
836 } */ 836 } */
837 837
838 return linux_select1(l, retval, SCARG(uap, nfds), SCARG(uap, readfds), 838 return linux_select1(l, retval, SCARG(uap, nfds), SCARG(uap, readfds),
839 SCARG(uap, writefds), SCARG(uap, exceptfds), 839 SCARG(uap, writefds), SCARG(uap, exceptfds),
840 (struct linux_timeval *)SCARG(uap, timeout)); 840 (struct linux_timeval *)SCARG(uap, timeout));
841} 841}
842 842
843/* 843/*
844 * Common code for the old and new versions of select(). A couple of 844 * Common code for the old and new versions of select(). A couple of
845 * things are important: 845 * things are important:
846 * 1) return the amount of time left in the 'timeout' parameter 846 * 1) return the amount of time left in the 'timeout' parameter
847 * 2) select never returns ERESTART on Linux, always return EINTR 847 * 2) select never returns ERESTART on Linux, always return EINTR
848 */ 848 */
849int 849int
850linux_select1(struct lwp *l, register_t *retval, int nfds, fd_set *readfds, 850linux_select1(struct lwp *l, register_t *retval, int nfds, fd_set *readfds,
851 fd_set *writefds, fd_set *exceptfds, struct linux_timeval *timeout) 851 fd_set *writefds, fd_set *exceptfds, struct linux_timeval *timeout)
852{ 852{
853 struct timespec ts0, ts1, uts, *ts = NULL; 853 struct timespec ts0, ts1, uts, *ts = NULL;
854 struct linux_timeval ltv; 854 struct linux_timeval ltv;
855 int error; 855 int error;
856 856
857 /* 857 /*
858 * Store current time for computation of the amount of 858 * Store current time for computation of the amount of
859 * time left. 859 * time left.
860 */ 860 */
861 if (timeout) { 861 if (timeout) {
862 if ((error = copyin(timeout, &ltv, sizeof(ltv)))) 862 if ((error = copyin(timeout, &ltv, sizeof(ltv))))
863 return error; 863 return error;
864 uts.tv_sec = ltv.tv_sec; 864 uts.tv_sec = ltv.tv_sec;
865 uts.tv_nsec = ltv.tv_usec * 1000; 865 uts.tv_nsec = ltv.tv_usec * 1000;
866 if (itimespecfix(&uts)) { 866 if (itimespecfix(&uts)) {
867 /* 867 /*
868 * The timeval was invalid. Convert it to something 868 * The timeval was invalid. Convert it to something
869 * valid that will act as it does under Linux. 869 * valid that will act as it does under Linux.
870 */ 870 */
871 uts.tv_sec += uts.tv_nsec / 1000000000; 871 uts.tv_sec += uts.tv_nsec / 1000000000;
872 uts.tv_nsec %= 1000000000; 872 uts.tv_nsec %= 1000000000;
873 if (uts.tv_nsec < 0) { 873 if (uts.tv_nsec < 0) {
874 uts.tv_sec -= 1; 874 uts.tv_sec -= 1;
875 uts.tv_nsec += 1000000000; 875 uts.tv_nsec += 1000000000;
876 } 876 }
877 if (uts.tv_sec < 0) 877 if (uts.tv_sec < 0)
878 timespecclear(&uts); 878 timespecclear(&uts);
879 } 879 }
880 ts = &uts; 880 ts = &uts;
881 nanotime(&ts0); 881 nanotime(&ts0);
882 } 882 }
883 883
884 error = selcommon(retval, nfds, readfds, writefds, exceptfds, ts, NULL); 884 error = selcommon(retval, nfds, readfds, writefds, exceptfds, ts, NULL);
885 885
886 if (error) { 886 if (error) {
887 /* 887 /*
888 * See fs/select.c in the Linux kernel. Without this, 888 * See fs/select.c in the Linux kernel. Without this,
889 * Maelstrom doesn't work. 889 * Maelstrom doesn't work.
890 */ 890 */
891 if (error == ERESTART) 891 if (error == ERESTART)
892 error = EINTR; 892 error = EINTR;
893 return error; 893 return error;
894 } 894 }
895 895
896 if (timeout) { 896 if (timeout) {
897 if (*retval) { 897 if (*retval) {
898 /* 898 /*
899 * Compute how much time was left of the timeout, 899 * Compute how much time was left of the timeout,
900 * by subtracting the current time and the time 900 * by subtracting the current time and the time
901 * before we started the call, and subtracting 901 * before we started the call, and subtracting
902 * that result from the user-supplied value. 902 * that result from the user-supplied value.
903 */ 903 */
904 nanotime(&ts1); 904 nanotime(&ts1);
905 timespecsub(&ts1, &ts0, &ts1); 905 timespecsub(&ts1, &ts0, &ts1);
906 timespecsub(&uts, &ts1, &uts); 906 timespecsub(&uts, &ts1, &uts);
907 if (uts.tv_sec < 0) 907 if (uts.tv_sec < 0)
908 timespecclear(&uts); 908 timespecclear(&uts);
909 } else 909 } else
910 timespecclear(&uts); 910 timespecclear(&uts);
911 ltv.tv_sec = uts.tv_sec; 911 ltv.tv_sec = uts.tv_sec;
912 ltv.tv_usec = uts.tv_nsec / 1000; 912 ltv.tv_usec = uts.tv_nsec / 1000;
913 if ((error = copyout(&ltv, timeout, sizeof(ltv)))) 913 if ((error = copyout(&ltv, timeout, sizeof(ltv))))
914 return error; 914 return error;
915 } 915 }
916 916
917 return 0; 917 return 0;
918} 918}
919 919
920/* 920/*
921 * Set the 'personality' (emulation mode) for the current process. Only 921 * Set the 'personality' (emulation mode) for the current process. Only
922 * accept the Linux personality here (0). This call is needed because 922 * accept the Linux personality here (0). This call is needed because
923 * the Linux ELF crt0 issues it in an ugly kludge to make sure that 923 * the Linux ELF crt0 issues it in an ugly kludge to make sure that
924 * ELF binaries run in Linux mode, not SVR4 mode. 924 * ELF binaries run in Linux mode, not SVR4 mode.
925 */ 925 */
926int 926int
927linux_sys_personality(struct lwp *l, const struct linux_sys_personality_args *uap, register_t *retval) 927linux_sys_personality(struct lwp *l, const struct linux_sys_personality_args *uap, register_t *retval)
928{ 928{
929 /* { 929 /* {
930 syscallarg(unsigned long) per; 930 syscallarg(unsigned long) per;
931 } */ 931 } */
 932 struct linux_emuldata *led;
 933 int per;
932 934
933 switch (SCARG(uap, per)) { 935 per = SCARG(uap, per);
 936 led = l->l_emuldata;
 937 if (per == LINUX_PER_QUERY) {
 938 retval[0] = led->led_personality;
 939 return 0;
 940 }
 941
 942 switch (per & LINUX_PER_MASK) {
934 case LINUX_PER_LINUX: 943 case LINUX_PER_LINUX:
935 case LINUX_PER_QUERY: 944 case LINUX_PER_LINUX32:
 945 led->led_personality = per;
936 break; 946 break;
 947
937 default: 948 default:
938 return EINVAL; 949 return EINVAL;
939 } 950 }
940 951
941 retval[0] = LINUX_PER_LINUX; 952 retval[0] = per;
942 return 0; 953 return 0;
943} 954}
944 955
945/* 956/*
946 * We have nonexistent fsuid equal to uid. 957 * We have nonexistent fsuid equal to uid.
947 * If modification is requested, refuse. 958 * If modification is requested, refuse.
948 */ 959 */
949int 960int
950linux_sys_setfsuid(struct lwp *l, const struct linux_sys_setfsuid_args *uap, register_t *retval) 961linux_sys_setfsuid(struct lwp *l, const struct linux_sys_setfsuid_args *uap, register_t *retval)
951{ 962{
952 /* { 963 /* {
953 syscallarg(uid_t) uid; 964 syscallarg(uid_t) uid;
954 } */ 965 } */
955 uid_t uid; 966 uid_t uid;
956 967
957 uid = SCARG(uap, uid); 968 uid = SCARG(uap, uid);
958 if (kauth_cred_getuid(l->l_cred) != uid) 969 if (kauth_cred_getuid(l->l_cred) != uid)
959 return sys_nosys(l, uap, retval); 970 return sys_nosys(l, uap, retval);
960 971
961 *retval = uid; 972 *retval = uid;
962 return 0; 973 return 0;
963} 974}
964 975
965int 976int
966linux_sys_setfsgid(struct lwp *l, const struct linux_sys_setfsgid_args *uap, register_t *retval) 977linux_sys_setfsgid(struct lwp *l, const struct linux_sys_setfsgid_args *uap, register_t *retval)
967{ 978{
968 /* { 979 /* {
969 syscallarg(gid_t) gid; 980 syscallarg(gid_t) gid;
970 } */ 981 } */
971 gid_t gid; 982 gid_t gid;
972 983
973 gid = SCARG(uap, gid); 984 gid = SCARG(uap, gid);
974 if (kauth_cred_getgid(l->l_cred) != gid) 985 if (kauth_cred_getgid(l->l_cred) != gid)
975 return sys_nosys(l, uap, retval); 986 return sys_nosys(l, uap, retval);
976 987
977 *retval = gid; 988 *retval = gid;
978 return 0; 989 return 0;
979} 990}
980 991
981int 992int
982linux_sys_setresuid(struct lwp *l, const struct linux_sys_setresuid_args *uap, register_t *retval) 993linux_sys_setresuid(struct lwp *l, const struct linux_sys_setresuid_args *uap, register_t *retval)
983{ 994{
984 /* { 995 /* {
985 syscallarg(uid_t) ruid; 996 syscallarg(uid_t) ruid;
986 syscallarg(uid_t) euid; 997 syscallarg(uid_t) euid;
987 syscallarg(uid_t) suid; 998 syscallarg(uid_t) suid;
988 } */ 999 } */
989 1000
990 /* 1001 /*
991 * Note: These checks are a little different than the NetBSD 1002 * Note: These checks are a little different than the NetBSD
992 * setreuid(2) call performs. This precisely follows the 1003 * setreuid(2) call performs. This precisely follows the
993 * behavior of the Linux kernel. 1004 * behavior of the Linux kernel.
994 */ 1005 */
995 1006
996 return do_setresuid(l, SCARG(uap, ruid), SCARG(uap, euid), 1007 return do_setresuid(l, SCARG(uap, ruid), SCARG(uap, euid),
997 SCARG(uap, suid), 1008 SCARG(uap, suid),
998 ID_R_EQ_R | ID_R_EQ_E | ID_R_EQ_S | 1009 ID_R_EQ_R | ID_R_EQ_E | ID_R_EQ_S |
999 ID_E_EQ_R | ID_E_EQ_E | ID_E_EQ_S | 1010 ID_E_EQ_R | ID_E_EQ_E | ID_E_EQ_S |
1000 ID_S_EQ_R | ID_S_EQ_E | ID_S_EQ_S ); 1011 ID_S_EQ_R | ID_S_EQ_E | ID_S_EQ_S );
1001} 1012}
1002 1013
1003int 1014int
1004linux_sys_getresuid(struct lwp *l, const struct linux_sys_getresuid_args *uap, register_t *retval) 1015linux_sys_getresuid(struct lwp *l, const struct linux_sys_getresuid_args *uap, register_t *retval)
1005{ 1016{
1006 /* { 1017 /* {
1007 syscallarg(uid_t *) ruid; 1018 syscallarg(uid_t *) ruid;
1008 syscallarg(uid_t *) euid; 1019 syscallarg(uid_t *) euid;
1009 syscallarg(uid_t *) suid; 1020 syscallarg(uid_t *) suid;
1010 } */ 1021 } */
1011 kauth_cred_t pc = l->l_cred; 1022 kauth_cred_t pc = l->l_cred;
1012 int error; 1023 int error;
1013 uid_t uid; 1024 uid_t uid;
1014 1025
1015 /* 1026 /*
1016 * Linux copies these values out to userspace like so: 1027 * Linux copies these values out to userspace like so:
1017 * 1028 *
1018 * 1. Copy out ruid. 1029 * 1. Copy out ruid.
1019 * 2. If that succeeds, copy out euid. 1030 * 2. If that succeeds, copy out euid.
1020 * 3. If both of those succeed, copy out suid. 1031 * 3. If both of those succeed, copy out suid.
1021 */ 1032 */
1022 uid = kauth_cred_getuid(pc); 1033 uid = kauth_cred_getuid(pc);
1023 if ((error = copyout(&uid, SCARG(uap, ruid), sizeof(uid_t))) != 0) 1034 if ((error = copyout(&uid, SCARG(uap, ruid), sizeof(uid_t))) != 0)
1024 return (error); 1035 return (error);
1025 1036
1026 uid = kauth_cred_geteuid(pc); 1037 uid = kauth_cred_geteuid(pc);
1027 if ((error = copyout(&uid, SCARG(uap, euid), sizeof(uid_t))) != 0) 1038 if ((error = copyout(&uid, SCARG(uap, euid), sizeof(uid_t))) != 0)
1028 return (error); 1039 return (error);
1029 1040
1030 uid = kauth_cred_getsvuid(pc); 1041 uid = kauth_cred_getsvuid(pc);
1031 1042
1032 return (copyout(&uid, SCARG(uap, suid), sizeof(uid_t))); 1043 return (copyout(&uid, SCARG(uap, suid), sizeof(uid_t)));
1033} 1044}
1034 1045
1035int 1046int
1036linux_sys_ptrace(struct lwp *l, const struct linux_sys_ptrace_args *uap, register_t *retval) 1047linux_sys_ptrace(struct lwp *l, const struct linux_sys_ptrace_args *uap, register_t *retval)
1037{ 1048{
1038 /* { 1049 /* {
1039 i386, m68k, powerpc: T=int 1050 i386, m68k, powerpc: T=int
1040 alpha, amd64: T=long 1051 alpha, amd64: T=long
1041 syscallarg(T) request; 1052 syscallarg(T) request;
1042 syscallarg(T) pid; 1053 syscallarg(T) pid;
1043 syscallarg(T) addr; 1054 syscallarg(T) addr;
1044 syscallarg(T) data; 1055 syscallarg(T) data;
1045 } */ 1056 } */
1046 const int *ptr; 1057 const int *ptr;
1047 int request; 1058 int request;
1048 int error; 1059 int error;
1049 1060
1050 ptr = linux_ptrace_request_map; 1061 ptr = linux_ptrace_request_map;
1051 request = SCARG(uap, request); 1062 request = SCARG(uap, request);
1052 while (*ptr != -1) 1063 while (*ptr != -1)
1053 if (*ptr++ == request) { 1064 if (*ptr++ == request) {
1054 struct sys_ptrace_args pta; 1065 struct sys_ptrace_args pta;
1055 1066
1056 SCARG(&pta, req) = *ptr; 1067 SCARG(&pta, req) = *ptr;
1057 SCARG(&pta, pid) = SCARG(uap, pid); 1068 SCARG(&pta, pid) = SCARG(uap, pid);
1058 SCARG(&pta, addr) = (void *)SCARG(uap, addr); 1069 SCARG(&pta, addr) = (void *)SCARG(uap, addr);
1059 SCARG(&pta, data) = SCARG(uap, data); 1070 SCARG(&pta, data) = SCARG(uap, data);
1060 1071
1061 /* 1072 /*
1062 * Linux ptrace(PTRACE_CONT, pid, 0, 0) means actually 1073 * Linux ptrace(PTRACE_CONT, pid, 0, 0) means actually
1063 * to continue where the process left off previously. 1074 * to continue where the process left off previously.
1064 * The same thing is achieved by addr == (void *) 1 1075 * The same thing is achieved by addr == (void *) 1
1065 * on NetBSD, so rewrite 'addr' appropriately. 1076 * on NetBSD, so rewrite 'addr' appropriately.
1066 */ 1077 */
1067 if (request == LINUX_PTRACE_CONT && SCARG(uap, addr)==0) 1078 if (request == LINUX_PTRACE_CONT && SCARG(uap, addr)==0)
1068 SCARG(&pta, addr) = (void *) 1; 1079 SCARG(&pta, addr) = (void *) 1;
1069 1080
1070 error = sysent[SYS_ptrace].sy_call(l, &pta, retval); 1081 error = sysent[SYS_ptrace].sy_call(l, &pta, retval);
1071 if (error) 1082 if (error)
1072 return error; 1083 return error;
1073 switch (request) { 1084 switch (request) {
1074 case LINUX_PTRACE_PEEKTEXT: 1085 case LINUX_PTRACE_PEEKTEXT:
1075 case LINUX_PTRACE_PEEKDATA: 1086 case LINUX_PTRACE_PEEKDATA:
1076 error = copyout (retval, 1087 error = copyout (retval,
1077 (void *)SCARG(uap, data),  1088 (void *)SCARG(uap, data),
1078 sizeof *retval); 1089 sizeof *retval);
1079 *retval = SCARG(uap, data); 1090 *retval = SCARG(uap, data);
1080 break; 1091 break;
1081 default: 1092 default:
1082 break; 1093 break;
1083 } 1094 }
1084 return error; 1095 return error;
1085 } 1096 }
1086 else 1097 else
1087 ptr++; 1098 ptr++;
1088 1099
1089 return LINUX_SYS_PTRACE_ARCH(l, uap, retval); 1100 return LINUX_SYS_PTRACE_ARCH(l, uap, retval);
1090} 1101}
1091 1102
1092int 1103int
1093linux_sys_reboot(struct lwp *l, const struct linux_sys_reboot_args *uap, register_t *retval) 1104linux_sys_reboot(struct lwp *l, const struct linux_sys_reboot_args *uap, register_t *retval)
1094{ 1105{
1095 /* { 1106 /* {
1096 syscallarg(int) magic1; 1107 syscallarg(int) magic1;
1097 syscallarg(int) magic2; 1108 syscallarg(int) magic2;
1098 syscallarg(int) cmd; 1109 syscallarg(int) cmd;
1099 syscallarg(void *) arg; 1110 syscallarg(void *) arg;
1100 } */ 1111 } */
1101 struct sys_reboot_args /* { 1112 struct sys_reboot_args /* {
1102 syscallarg(int) opt; 1113 syscallarg(int) opt;
1103 syscallarg(char *) bootstr; 1114 syscallarg(char *) bootstr;
1104 } */ sra; 1115 } */ sra;
1105 int error; 1116 int error;
1106 1117
1107 if ((error = kauth_authorize_system(l->l_cred, 1118 if ((error = kauth_authorize_system(l->l_cred,
1108 KAUTH_SYSTEM_REBOOT, 0, NULL, NULL, NULL)) != 0) 1119 KAUTH_SYSTEM_REBOOT, 0, NULL, NULL, NULL)) != 0)
1109 return(error); 1120 return(error);
1110 1121
1111 if (SCARG(uap, magic1) != LINUX_REBOOT_MAGIC1) 1122 if (SCARG(uap, magic1) != LINUX_REBOOT_MAGIC1)
1112 return(EINVAL); 1123 return(EINVAL);
1113 if (SCARG(uap, magic2) != LINUX_REBOOT_MAGIC2 && 1124 if (SCARG(uap, magic2) != LINUX_REBOOT_MAGIC2 &&
1114 SCARG(uap, magic2) != LINUX_REBOOT_MAGIC2A && 1125 SCARG(uap, magic2) != LINUX_REBOOT_MAGIC2A &&
1115 SCARG(uap, magic2) != LINUX_REBOOT_MAGIC2B) 1126 SCARG(uap, magic2) != LINUX_REBOOT_MAGIC2B)
1116 return(EINVAL); 1127 return(EINVAL);
1117 1128
1118 switch ((unsigned long)SCARG(uap, cmd)) { 1129 switch ((unsigned long)SCARG(uap, cmd)) {
1119 case LINUX_REBOOT_CMD_RESTART: 1130 case LINUX_REBOOT_CMD_RESTART:
1120 SCARG(&sra, opt) = RB_AUTOBOOT; 1131 SCARG(&sra, opt) = RB_AUTOBOOT;
1121 break; 1132 break;
1122 case LINUX_REBOOT_CMD_HALT: 1133 case LINUX_REBOOT_CMD_HALT:
1123 SCARG(&sra, opt) = RB_HALT; 1134 SCARG(&sra, opt) = RB_HALT;
1124 break; 1135 break;
1125 case LINUX_REBOOT_CMD_POWER_OFF: 1136 case LINUX_REBOOT_CMD_POWER_OFF:
1126 SCARG(&sra, opt) = RB_HALT|RB_POWERDOWN; 1137 SCARG(&sra, opt) = RB_HALT|RB_POWERDOWN;
1127 break; 1138 break;
1128 case LINUX_REBOOT_CMD_RESTART2: 1139 case LINUX_REBOOT_CMD_RESTART2:
1129 /* Reboot with an argument. */ 1140 /* Reboot with an argument. */
1130 SCARG(&sra, opt) = RB_AUTOBOOT|RB_STRING; 1141 SCARG(&sra, opt) = RB_AUTOBOOT|RB_STRING;
1131 SCARG(&sra, bootstr) = SCARG(uap, arg); 1142 SCARG(&sra, bootstr) = SCARG(uap, arg);
1132 break; 1143 break;
1133 case LINUX_REBOOT_CMD_CAD_ON: 1144 case LINUX_REBOOT_CMD_CAD_ON:
1134 return(EINVAL); /* We don't implement ctrl-alt-delete */ 1145 return(EINVAL); /* We don't implement ctrl-alt-delete */
1135 case LINUX_REBOOT_CMD_CAD_OFF: 1146 case LINUX_REBOOT_CMD_CAD_OFF:
1136 return(0); 1147 return(0);
1137 default: 1148 default:
1138 return(EINVAL); 1149 return(EINVAL);
1139 } 1150 }
1140 1151
1141 return(sys_reboot(l, &sra, retval)); 1152 return(sys_reboot(l, &sra, retval));
1142} 1153}
1143 1154
1144/* 1155/*
1145 * Copy of compat_12_sys_swapon(). 1156 * Copy of compat_12_sys_swapon().
1146 */ 1157 */
1147int 1158int
1148linux_sys_swapon(struct lwp *l, const struct linux_sys_swapon_args *uap, register_t *retval) 1159linux_sys_swapon(struct lwp *l, const struct linux_sys_swapon_args *uap, register_t *retval)
1149{ 1160{
1150 /* { 1161 /* {
1151 syscallarg(const char *) name; 1162 syscallarg(const char *) name;
1152 } */ 1163 } */
1153 struct sys_swapctl_args ua; 1164 struct sys_swapctl_args ua;
1154 1165
1155 SCARG(&ua, cmd) = SWAP_ON; 1166 SCARG(&ua, cmd) = SWAP_ON;
1156 SCARG(&ua, arg) = (void *)__UNCONST(SCARG(uap, name)); 1167 SCARG(&ua, arg) = (void *)__UNCONST(SCARG(uap, name));
1157 SCARG(&ua, misc) = 0; /* priority */ 1168 SCARG(&ua, misc) = 0; /* priority */
1158 return (sys_swapctl(l, &ua, retval)); 1169 return (sys_swapctl(l, &ua, retval));
1159} 1170}
1160 1171
1161/* 1172/*
1162 * Stop swapping to the file or block device specified by path. 1173 * Stop swapping to the file or block device specified by path.
1163 */ 1174 */
1164int 1175int
1165linux_sys_swapoff(struct lwp *l, const struct linux_sys_swapoff_args *uap, register_t *retval) 1176linux_sys_swapoff(struct lwp *l, const struct linux_sys_swapoff_args *uap, register_t *retval)
1166{ 1177{
1167 /* { 1178 /* {
1168 syscallarg(const char *) path; 1179 syscallarg(const char *) path;
1169 } */ 1180 } */
1170 struct sys_swapctl_args ua; 1181 struct sys_swapctl_args ua;
1171 1182
1172 SCARG(&ua, cmd) = SWAP_OFF; 1183 SCARG(&ua, cmd) = SWAP_OFF;
1173 SCARG(&ua, arg) = __UNCONST(SCARG(uap, path)); /*XXXUNCONST*/ 1184 SCARG(&ua, arg) = __UNCONST(SCARG(uap, path)); /*XXXUNCONST*/
1174 return (sys_swapctl(l, &ua, retval)); 1185 return (sys_swapctl(l, &ua, retval));
1175} 1186}
1176 1187
1177/* 1188/*
1178 * Copy of compat_09_sys_setdomainname() 1189 * Copy of compat_09_sys_setdomainname()
1179 */ 1190 */
1180/* ARGSUSED */ 1191/* ARGSUSED */
1181int 1192int
1182linux_sys_setdomainname(struct lwp *l, const struct linux_sys_setdomainname_args *uap, register_t *retval) 1193linux_sys_setdomainname(struct lwp *l, const struct linux_sys_setdomainname_args *uap, register_t *retval)
1183{ 1194{
1184 /* { 1195 /* {
1185 syscallarg(char *) domainname; 1196 syscallarg(char *) domainname;
1186 syscallarg(int) len; 1197 syscallarg(int) len;
1187 } */ 1198 } */
1188 int name[2]; 1199 int name[2];
1189 1200
1190 name[0] = CTL_KERN; 1201 name[0] = CTL_KERN;
1191 name[1] = KERN_DOMAINNAME; 1202 name[1] = KERN_DOMAINNAME;
1192 return (old_sysctl(&name[0], 2, 0, 0, SCARG(uap, domainname), 1203 return (old_sysctl(&name[0], 2, 0, 0, SCARG(uap, domainname),
1193 SCARG(uap, len), l)); 1204 SCARG(uap, len), l));
1194} 1205}
1195 1206
1196/* 1207/*
1197 * sysinfo() 1208 * sysinfo()
1198 */ 1209 */
1199/* ARGSUSED */ 1210/* ARGSUSED */
1200int 1211int
1201linux_sys_sysinfo(struct lwp *l, const struct linux_sys_sysinfo_args *uap, register_t *retval) 1212linux_sys_sysinfo(struct lwp *l, const struct linux_sys_sysinfo_args *uap, register_t *retval)
1202{ 1213{
1203 /* { 1214 /* {
1204 syscallarg(struct linux_sysinfo *) arg; 1215 syscallarg(struct linux_sysinfo *) arg;
1205 } */ 1216 } */
1206 struct linux_sysinfo si; 1217 struct linux_sysinfo si;
1207 struct loadavg *la; 1218 struct loadavg *la;
1208 1219
1209 si.uptime = time_uptime; 1220 si.uptime = time_uptime;
1210 la = &averunnable; 1221 la = &averunnable;
1211 si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; 1222 si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
1212 si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; 1223 si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
1213 si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale; 1224 si.loads[2] = la->ldavg[2] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
1214 si.totalram = ctob((u_long)physmem); 1225 si.totalram = ctob((u_long)physmem);
1215 si.freeram = (u_long)uvmexp.free * uvmexp.pagesize; 1226 si.freeram = (u_long)uvmexp.free * uvmexp.pagesize;
1216 si.sharedram = 0; /* XXX */ 1227 si.sharedram = 0; /* XXX */
1217 si.bufferram = (u_long)uvmexp.filepages * uvmexp.pagesize; 1228 si.bufferram = (u_long)uvmexp.filepages * uvmexp.pagesize;
1218 si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize; 1229 si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize;
1219 si.freeswap =  1230 si.freeswap =
1220 (u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize; 1231 (u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize;
1221 si.procs = nprocs; 1232 si.procs = nprocs;
1222 1233
1223 /* The following are only present in newer Linux kernels. */ 1234 /* The following are only present in newer Linux kernels. */
1224 si.totalbig = 0; 1235 si.totalbig = 0;
1225 si.freebig = 0; 1236 si.freebig = 0;
1226 si.mem_unit = 1; 1237 si.mem_unit = 1;
1227 1238
1228 return (copyout(&si, SCARG(uap, arg), sizeof si)); 1239 return (copyout(&si, SCARG(uap, arg), sizeof si));
1229} 1240}
1230 1241
1231int 1242int
1232linux_sys_getrlimit(struct lwp *l, const struct linux_sys_getrlimit_args *uap, register_t *retval) 1243linux_sys_getrlimit(struct lwp *l, const struct linux_sys_getrlimit_args *uap, register_t *retval)
1233{ 1244{
1234 /* { 1245 /* {
1235 syscallarg(int) which; 1246 syscallarg(int) which;
1236# ifdef LINUX_LARGEFILE64 1247# ifdef LINUX_LARGEFILE64
1237 syscallarg(struct rlimit *) rlp; 1248 syscallarg(struct rlimit *) rlp;
1238# else 1249# else
1239 syscallarg(struct orlimit *) rlp; 1250 syscallarg(struct orlimit *) rlp;
1240# endif 1251# endif
1241 } */ 1252 } */
1242# ifdef LINUX_LARGEFILE64 1253# ifdef LINUX_LARGEFILE64
1243 struct rlimit orl; 1254 struct rlimit orl;
1244# else 1255# else
1245 struct orlimit orl; 1256 struct orlimit orl;
1246# endif 1257# endif
1247 int which; 1258 int which;
1248 1259
1249 which = linux_to_bsd_limit(SCARG(uap, which)); 1260 which = linux_to_bsd_limit(SCARG(uap, which));
1250 if (which < 0) 1261 if (which < 0)
1251 return -which; 1262 return -which;
1252 1263
1253 bsd_to_linux_rlimit(&orl, &l->l_proc->p_rlimit[which]); 1264 bsd_to_linux_rlimit(&orl, &l->l_proc->p_rlimit[which]);
1254 1265
1255 return copyout(&orl, SCARG(uap, rlp), sizeof(orl)); 1266 return copyout(&orl, SCARG(uap, rlp), sizeof(orl));
1256} 1267}
1257 1268
1258int 1269int
1259linux_sys_setrlimit(struct lwp *l, const struct linux_sys_setrlimit_args *uap, register_t *retval) 1270linux_sys_setrlimit(struct lwp *l, const struct linux_sys_setrlimit_args *uap, register_t *retval)
1260{ 1271{
1261 /* { 1272 /* {
1262 syscallarg(int) which; 1273 syscallarg(int) which;
1263# ifdef LINUX_LARGEFILE64 1274# ifdef LINUX_LARGEFILE64
1264 syscallarg(struct rlimit *) rlp; 1275 syscallarg(struct rlimit *) rlp;
1265# else 1276# else
1266 syscallarg(struct orlimit *) rlp; 1277 syscallarg(struct orlimit *) rlp;
1267# endif 1278# endif
1268 } */ 1279 } */
1269 struct rlimit rl; 1280 struct rlimit rl;
1270# ifdef LINUX_LARGEFILE64 1281# ifdef LINUX_LARGEFILE64
1271 struct rlimit orl; 1282 struct rlimit orl;
1272# else 1283# else
1273 struct orlimit orl; 1284 struct orlimit orl;
1274# endif 1285# endif
1275 int error; 1286 int error;
1276 int which; 1287 int which;
1277 1288
1278 if ((error = copyin(SCARG(uap, rlp), &orl, sizeof(orl))) != 0) 1289 if ((error = copyin(SCARG(uap, rlp), &orl, sizeof(orl))) != 0)
1279 return error; 1290 return error;
1280 1291
1281 which = linux_to_bsd_limit(SCARG(uap, which)); 1292 which = linux_to_bsd_limit(SCARG(uap, which));
1282 if (which < 0) 1293 if (which < 0)
1283 return -which; 1294 return -which;
1284 1295
1285 linux_to_bsd_rlimit(&rl, &orl); 1296 linux_to_bsd_rlimit(&rl, &orl);
1286 return dosetrlimit(l, l->l_proc, which, &rl); 1297 return dosetrlimit(l, l->l_proc, which, &rl);
1287} 1298}
1288 1299
1289# if !defined(__mips__) && !defined(__amd64__) 1300# if !defined(__mips__) && !defined(__amd64__)
1290/* XXX: this doesn't look 100% common, at least mips doesn't have it */ 1301/* XXX: this doesn't look 100% common, at least mips doesn't have it */
1291int 1302int
1292linux_sys_ugetrlimit(struct lwp *l, const struct linux_sys_ugetrlimit_args *uap, register_t *retval) 1303linux_sys_ugetrlimit(struct lwp *l, const struct linux_sys_ugetrlimit_args *uap, register_t *retval)
1293{ 1304{
1294 return linux_sys_getrlimit(l, (const void *)uap, retval); 1305 return linux_sys_getrlimit(l, (const void *)uap, retval);
1295} 1306}
1296# endif 1307# endif
1297 1308
1298/* 1309/*
1299 * This gets called for unsupported syscalls. The difference to sys_nosys() 1310 * This gets called for unsupported syscalls. The difference to sys_nosys()
1300 * is that process does not get SIGSYS, the call just returns with ENOSYS. 1311 * is that process does not get SIGSYS, the call just returns with ENOSYS.
1301 * This is the way Linux does it and glibc depends on this behaviour. 1312 * This is the way Linux does it and glibc depends on this behaviour.
1302 */ 1313 */
1303int 1314int
1304linux_sys_nosys(struct lwp *l, const void *v, register_t *retval) 1315linux_sys_nosys(struct lwp *l, const void *v, register_t *retval)
1305{ 1316{
1306 return (ENOSYS); 1317 return (ENOSYS);
1307} 1318}
1308 1319
1309int 1320int
1310linux_sys_getpriority(struct lwp *l, const struct linux_sys_getpriority_args *uap, register_t *retval) 1321linux_sys_getpriority(struct lwp *l, const struct linux_sys_getpriority_args *uap, register_t *retval)
1311{ 1322{
1312 /* { 1323 /* {
1313 syscallarg(int) which; 1324 syscallarg(int) which;
1314 syscallarg(int) who; 1325 syscallarg(int) who;
1315 } */ 1326 } */
1316 struct sys_getpriority_args bsa; 1327 struct sys_getpriority_args bsa;
1317 int error; 1328 int error;
1318 1329
1319 SCARG(&bsa, which) = SCARG(uap, which); 1330 SCARG(&bsa, which) = SCARG(uap, which);
1320 SCARG(&bsa, who) = SCARG(uap, who); 1331 SCARG(&bsa, who) = SCARG(uap, who);
1321 1332
1322 if ((error = sys_getpriority(l, &bsa, retval))) 1333 if ((error = sys_getpriority(l, &bsa, retval)))
1323 return error; 1334 return error;
1324 1335
1325 *retval = NZERO - *retval; 1336 *retval = NZERO - *retval;
1326 1337
1327 return 0; 1338 return 0;
1328} 1339}
1329#endif /* !COMPAT_LINUX32 */ 1340#endif /* !COMPAT_LINUX32 */

cvs diff -r1.19 -r1.20 src/sys/compat/linux/common/linux_misc.h (switch to unified diff)

--- src/sys/compat/linux/common/linux_misc.h 2009/01/19 13:31:40 1.19
+++ src/sys/compat/linux/common/linux_misc.h 2010/11/02 18:18:07 1.20
@@ -1,138 +1,142 @@ @@ -1,138 +1,142 @@
1/* $NetBSD: linux_misc.h,v 1.19 2009/01/19 13:31:40 njoly Exp $ */ 1/* $NetBSD: linux_misc.h,v 1.20 2010/11/02 18:18:07 chs Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Eric Haszlakiewicz. 8 * by Eric Haszlakiewicz.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef _LINUX_MISC_H 32#ifndef _LINUX_MISC_H
33#define _LINUX_MISC_H 33#define _LINUX_MISC_H
34 34
35/* 35/*
36 * Options passed to the Linux wait4() system call. 36 * Options passed to the Linux wait4() system call.
37 */ 37 */
38#define LINUX_WAIT4_WNOHANG 0x00000001 38#define LINUX_WAIT4_WNOHANG 0x00000001
39#define LINUX_WAIT4_WUNTRACED 0x00000002 39#define LINUX_WAIT4_WUNTRACED 0x00000002
40#define LINUX_WAIT4_WNOTHREAD 0x20000000 40#define LINUX_WAIT4_WNOTHREAD 0x20000000
41#define LINUX_WAIT4_WALL 0x40000000 41#define LINUX_WAIT4_WALL 0x40000000
42#define LINUX_WAIT4_WCLONE 0x80000000 42#define LINUX_WAIT4_WCLONE 0x80000000
43 43
44#define LINUX_WAIT4_KNOWNFLAGS (LINUX_WAIT4_WNOHANG | \ 44#define LINUX_WAIT4_KNOWNFLAGS (LINUX_WAIT4_WNOHANG | \
45 LINUX_WAIT4_WUNTRACED | \ 45 LINUX_WAIT4_WUNTRACED | \
46 LINUX_WAIT4_WNOTHREAD | \ 46 LINUX_WAIT4_WNOTHREAD | \
47 LINUX_WAIT4_WALL | \ 47 LINUX_WAIT4_WALL | \
48 LINUX_WAIT4_WCLONE) 48 LINUX_WAIT4_WCLONE)
49 49
50/* This looks very unportable to me, but this is how Linux defines it. */ 50/* This looks very unportable to me, but this is how Linux defines it. */
51struct linux_sysinfo { 51struct linux_sysinfo {
52 long uptime; 52 long uptime;
53 unsigned long loads[3]; 53 unsigned long loads[3];
54#define LINUX_SYSINFO_LOADS_SCALE 65536 54#define LINUX_SYSINFO_LOADS_SCALE 65536
55 unsigned long totalram; 55 unsigned long totalram;
56 unsigned long freeram; 56 unsigned long freeram;
57 unsigned long sharedram; 57 unsigned long sharedram;
58 unsigned long bufferram; 58 unsigned long bufferram;
59 unsigned long totalswap; 59 unsigned long totalswap;
60 unsigned long freeswap; 60 unsigned long freeswap;
61 unsigned short procs; 61 unsigned short procs;
62 unsigned long totalbig; 62 unsigned long totalbig;
63 unsigned long freebig; 63 unsigned long freebig;
64 unsigned int mem_unit; 64 unsigned int mem_unit;
65 char _f[20-2*sizeof(long)-sizeof(int)]; 65 char _f[20-2*sizeof(long)-sizeof(int)];
66}; 66};
67 67
68#define LINUX_RLIMIT_CPU 0 68#define LINUX_RLIMIT_CPU 0
69#define LINUX_RLIMIT_FSIZE 1 69#define LINUX_RLIMIT_FSIZE 1
70#define LINUX_RLIMIT_DATA 2 70#define LINUX_RLIMIT_DATA 2
71#define LINUX_RLIMIT_STACK 3 71#define LINUX_RLIMIT_STACK 3
72#define LINUX_RLIMIT_CORE 4 72#define LINUX_RLIMIT_CORE 4
73#define LINUX_RLIMIT_RSS 5 73#define LINUX_RLIMIT_RSS 5
74#define LINUX_RLIMIT_NPROC 6 74#define LINUX_RLIMIT_NPROC 6
75#define LINUX_RLIMIT_NOFILE 7 75#define LINUX_RLIMIT_NOFILE 7
76#define LINUX_RLIMIT_MEMLOCK 8 76#define LINUX_RLIMIT_MEMLOCK 8
77#define LINUX_RLIMIT_AS 9 77#define LINUX_RLIMIT_AS 9
78#define LINUX_RLIMIT_LOCKS 10 78#define LINUX_RLIMIT_LOCKS 10
79#ifdef __mips__ /* XXX only mips32. On mips64, it's ~0ul */ 79#ifdef __mips__ /* XXX only mips32. On mips64, it's ~0ul */
80#define LINUX_RLIM_INFINITY 0x7fffffffUL 80#define LINUX_RLIM_INFINITY 0x7fffffffUL
81#else 81#else
82#define LINUX_RLIM_INFINITY ~0ul 82#define LINUX_RLIM_INFINITY ~0ul
83#endif 83#endif
84 84
85 85
86/* When we don't know what to do, let it believe it is local */ 86/* When we don't know what to do, let it believe it is local */
87#define LINUX_DEFAULT_SUPER_MAGIC LINUX_EXT2_SUPER_MAGIC 87#define LINUX_DEFAULT_SUPER_MAGIC LINUX_EXT2_SUPER_MAGIC
88 88
89#define LINUX_ADFS_SUPER_MAGIC 0x0000adf5 89#define LINUX_ADFS_SUPER_MAGIC 0x0000adf5
90#define LINUX_AFFS_SUPER_MAGIC 0x0000adff 90#define LINUX_AFFS_SUPER_MAGIC 0x0000adff
91#define LINUX_CODA_SUPER_MAGIC 0x73757245 91#define LINUX_CODA_SUPER_MAGIC 0x73757245
92#define LINUX_COH_SUPER_MAGIC (LINUX_SYSV_MAGIC_BASE + 4) 92#define LINUX_COH_SUPER_MAGIC (LINUX_SYSV_MAGIC_BASE + 4)
93#define LINUX_DEVFS_SUPER_MAGIC 0x00001373 93#define LINUX_DEVFS_SUPER_MAGIC 0x00001373
94#define LINUX_EFS_SUPER_MAGIC 0x00414A53 94#define LINUX_EFS_SUPER_MAGIC 0x00414A53
95#define LINUX_EXT2_SUPER_MAGIC 0x0000EF53 95#define LINUX_EXT2_SUPER_MAGIC 0x0000EF53
96#define LINUX_HPFS_SUPER_MAGIC 0xf995e849 96#define LINUX_HPFS_SUPER_MAGIC 0xf995e849
97#define LINUX_ISOFS_SUPER_MAGIC 0x00009660 97#define LINUX_ISOFS_SUPER_MAGIC 0x00009660
98#define LINUX_MINIX2_SUPER_MAGIC 0x00002468 98#define LINUX_MINIX2_SUPER_MAGIC 0x00002468
99#define LINUX_MINIX2_SUPER_MAGIC2 0x00002478 99#define LINUX_MINIX2_SUPER_MAGIC2 0x00002478
100#define LINUX_MINIX_SUPER_MAGIC 0x0000137F 100#define LINUX_MINIX_SUPER_MAGIC 0x0000137F
101#define LINUX_MINIX_SUPER_MAGIC2 0x0000138F 101#define LINUX_MINIX_SUPER_MAGIC2 0x0000138F
102#define LINUX_MSDOS_SUPER_MAGIC 0x00004d44 102#define LINUX_MSDOS_SUPER_MAGIC 0x00004d44
103#define LINUX_NCP_SUPER_MAGIC 0x0000564c 103#define LINUX_NCP_SUPER_MAGIC 0x0000564c
104#define LINUX_NFS_SUPER_MAGIC 0x00006969 104#define LINUX_NFS_SUPER_MAGIC 0x00006969
105#define LINUX_OPENPROM_SUPER_MAGIC 0x00009fa1 105#define LINUX_OPENPROM_SUPER_MAGIC 0x00009fa1
106#define LINUX_PROC_SUPER_MAGIC 0x00009fa0 106#define LINUX_PROC_SUPER_MAGIC 0x00009fa0
107#define LINUX_QNX4_SUPER_MAGIC 0x0000002f 107#define LINUX_QNX4_SUPER_MAGIC 0x0000002f
108#define LINUX_REISERFS_SUPER_MAGIC 0x52654973 108#define LINUX_REISERFS_SUPER_MAGIC 0x52654973
109#define LINUX_SMB_SUPER_MAGIC 0x0000517B 109#define LINUX_SMB_SUPER_MAGIC 0x0000517B
110#define LINUX_SYSV2_SUPER_MAGIC (LINUX_SYSV_MAGIC_BASE + 3) 110#define LINUX_SYSV2_SUPER_MAGIC (LINUX_SYSV_MAGIC_BASE + 3)
111#define LINUX_SYSV4_SUPER_MAGIC (LINUX_SYSV_MAGIC_BASE + 2) 111#define LINUX_SYSV4_SUPER_MAGIC (LINUX_SYSV_MAGIC_BASE + 2)
112#define LINUX_SYSV_MAGIC_BASE 0x012FF7B3 112#define LINUX_SYSV_MAGIC_BASE 0x012FF7B3
113#define LINUX_TMPFS_SUPER_MAGIC 0x01021994 113#define LINUX_TMPFS_SUPER_MAGIC 0x01021994
114#define LINUX_USBDEVICE_SUPER_MAGIC 0x00009fa2 114#define LINUX_USBDEVICE_SUPER_MAGIC 0x00009fa2
115#define LINUX_DEVPTS_SUPER_MAGIC 0x00001cd1 115#define LINUX_DEVPTS_SUPER_MAGIC 0x00001cd1
116#define LINUX_XENIX_SUPER_MAGIC (LINUX_SYSV_MAGIC_BASE + 1) 116#define LINUX_XENIX_SUPER_MAGIC (LINUX_SYSV_MAGIC_BASE + 1)
117 117
118struct linux_mnttypes { 118struct linux_mnttypes {
119 const char *bsd; 119 const char *bsd;
120 int linux; 120 int linux;
121}; 121};
122extern const struct linux_mnttypes linux_fstypes[]; 122extern const struct linux_mnttypes linux_fstypes[];
123extern const int linux_fstypes_cnt; 123extern const int linux_fstypes_cnt;
124 124
125/* Personality types. */ 125/* Personality types. */
126#define LINUX_PER_LINUX 0x00000000 
127#define LINUX_PER_LINUX32 0x00000008 
128#define LINUX_PER_QUERY 0xffffffff 126#define LINUX_PER_QUERY 0xffffffff
 127#define LINUX_PER_LINUX 0x00
 128#define LINUX_PER_LINUX32 0x08
 129#define LINUX_PER_MASK 0xff
 130
 131/* Personality flags. */
 132#define LINUX_PER_ADDR_NO_RANDOMIZE 0x00040000
129 133
130#ifdef _KERNEL 134#ifdef _KERNEL
131__BEGIN_DECLS 135__BEGIN_DECLS
132int bsd_to_linux_wstat(int); 136int bsd_to_linux_wstat(int);
133int linux_select1(struct lwp *, register_t *, int, fd_set *, fd_set *, 137int linux_select1(struct lwp *, register_t *, int, fd_set *, fd_set *,
134 fd_set *, struct linux_timeval *); 138 fd_set *, struct linux_timeval *);
135__END_DECLS 139__END_DECLS
136#endif /* !_KERNEL */ 140#endif /* !_KERNEL */
137 141
138#endif /* !_LINUX_MISC_H */ 142#endif /* !_LINUX_MISC_H */

cvs diff -r1.20 -r1.21 src/sys/compat/linux32/common/linux32_misc.c (switch to unified diff)

--- src/sys/compat/linux32/common/linux32_misc.c 2010/11/02 18:14:06 1.20
+++ src/sys/compat/linux32/common/linux32_misc.c 2010/11/02 18:18:07 1.21
@@ -1,356 +1,348 @@ @@ -1,356 +1,348 @@
1/* $NetBSD: linux32_misc.c,v 1.20 2010/11/02 18:14:06 chs Exp $ */ 1/* $NetBSD: linux32_misc.c,v 1.21 2010/11/02 18:18:07 chs Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc. 4 * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe 8 * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
9 * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center; 9 * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center;
10 * by Edgar Fu\ss, Mathematisches Institut der Uni Bonn. 10 * by Edgar Fu\ss, Mathematisches Institut der Uni Bonn.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
15 * 1. Redistributions of source code must retain the above copyright 15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer. 16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright 17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the 18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution. 19 * documentation and/or other materials provided with the distribution.
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE. 31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.20 2010/11/02 18:14:06 chs Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.21 2010/11/02 18:18:07 chs Exp $");
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/proc.h> 38#include <sys/proc.h>
39#include <sys/time.h> 39#include <sys/time.h>
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/malloc.h> 41#include <sys/malloc.h>
42#include <sys/fstypes.h> 42#include <sys/fstypes.h>
43#include <sys/vfs_syscalls.h> 43#include <sys/vfs_syscalls.h>
44#include <sys/ptrace.h> 44#include <sys/ptrace.h>
45#include <sys/syscall.h> 45#include <sys/syscall.h>
46 46
47#include <compat/netbsd32/netbsd32.h> 47#include <compat/netbsd32/netbsd32.h>
48#include <compat/netbsd32/netbsd32_syscallargs.h> 48#include <compat/netbsd32/netbsd32_syscallargs.h>
49 49
50#include <compat/linux32/common/linux32_types.h> 50#include <compat/linux32/common/linux32_types.h>
51#include <compat/linux32/common/linux32_signal.h> 51#include <compat/linux32/common/linux32_signal.h>
52#include <compat/linux32/linux32_syscallargs.h> 52#include <compat/linux32/linux32_syscallargs.h>
53 53
54#include <compat/linux/common/linux_ptrace.h> 54#include <compat/linux/common/linux_ptrace.h>
55#include <compat/linux/common/linux_types.h> 55#include <compat/linux/common/linux_types.h>
56#include <compat/linux/common/linux_emuldata.h> 56#include <compat/linux/common/linux_emuldata.h>
57#include <compat/linux/common/linux_signal.h> 57#include <compat/linux/common/linux_signal.h>
58#include <compat/linux/common/linux_misc.h> 58#include <compat/linux/common/linux_misc.h>
59#include <compat/linux/common/linux_statfs.h> 59#include <compat/linux/common/linux_statfs.h>
60#include <compat/linux/common/linux_ipc.h> 60#include <compat/linux/common/linux_ipc.h>
61#include <compat/linux/common/linux_sem.h> 61#include <compat/linux/common/linux_sem.h>
62#include <compat/linux/common/linux_futex.h> 62#include <compat/linux/common/linux_futex.h>
63#include <compat/linux/linux_syscallargs.h> 63#include <compat/linux/linux_syscallargs.h>
64 64
65extern const struct linux_mnttypes linux_fstypes[]; 65extern const struct linux_mnttypes linux_fstypes[];
66extern const int linux_fstypes_cnt; 66extern const int linux_fstypes_cnt;
67 67
68void linux32_to_native_timespec(struct timespec *, struct linux32_timespec *); 68void linux32_to_native_timespec(struct timespec *, struct linux32_timespec *);
69 69
70/* 70/*
71 * Implement the fs stat functions. Straightforward. 71 * Implement the fs stat functions. Straightforward.
72 */ 72 */
73int 73int
74linux32_sys_statfs(struct lwp *l, const struct linux32_sys_statfs_args *uap, register_t *retval) 74linux32_sys_statfs(struct lwp *l, const struct linux32_sys_statfs_args *uap, register_t *retval)
75{ 75{
76 /* { 76 /* {
77 syscallarg(const netbsd32_charp char) path; 77 syscallarg(const netbsd32_charp char) path;
78 syscallarg(linux32_statfsp) sp; 78 syscallarg(linux32_statfsp) sp;
79 } */ 79 } */
80 struct statvfs *sb; 80 struct statvfs *sb;
81 struct linux_statfs ltmp; 81 struct linux_statfs ltmp;
82 int error; 82 int error;
83 83
84 sb = STATVFSBUF_GET(); 84 sb = STATVFSBUF_GET();
85 error = do_sys_pstatvfs(l, SCARG_P32(uap, path), ST_WAIT, sb); 85 error = do_sys_pstatvfs(l, SCARG_P32(uap, path), ST_WAIT, sb);
86 if (error == 0) { 86 if (error == 0) {
87 bsd_to_linux_statfs(sb, &ltmp); 87 bsd_to_linux_statfs(sb, &ltmp);
88 error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp); 88 error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
89 } 89 }
90 90
91 STATVFSBUF_PUT(sb); 91 STATVFSBUF_PUT(sb);
92 return error; 92 return error;
93} 93}
94 94
95int 95int
96linux32_sys_fstatfs(struct lwp *l, const struct linux32_sys_fstatfs_args *uap, register_t *retval) 96linux32_sys_fstatfs(struct lwp *l, const struct linux32_sys_fstatfs_args *uap, register_t *retval)
97{ 97{
98 /* { 98 /* {
99 syscallarg(int) fd; 99 syscallarg(int) fd;
100 syscallarg(linux32_statfsp) sp; 100 syscallarg(linux32_statfsp) sp;
101 } */ 101 } */
102 struct statvfs *sb; 102 struct statvfs *sb;
103 struct linux_statfs ltmp; 103 struct linux_statfs ltmp;
104 int error; 104 int error;
105 105
106 sb = STATVFSBUF_GET(); 106 sb = STATVFSBUF_GET();
107 error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb); 107 error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb);
108 if (error == 0) { 108 if (error == 0) {
109 bsd_to_linux_statfs(sb, &ltmp); 109 bsd_to_linux_statfs(sb, &ltmp);
110 error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp); 110 error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
111 } 111 }
112 STATVFSBUF_PUT(sb); 112 STATVFSBUF_PUT(sb);
113 113
114 return error; 114 return error;
115} 115}
116 116
117int 117int
118linux32_sys_statfs64(struct lwp *l, const struct linux32_sys_statfs64_args *uap, register_t *retval) 118linux32_sys_statfs64(struct lwp *l, const struct linux32_sys_statfs64_args *uap, register_t *retval)
119{ 119{
120 /* { 120 /* {
121 syscallarg(const netbsd32_charp char) path; 121 syscallarg(const netbsd32_charp char) path;
122 syscallarg(linux32_statfs64p) sp; 122 syscallarg(linux32_statfs64p) sp;
123 } */ 123 } */
124 struct statvfs *sb; 124 struct statvfs *sb;
125 struct linux_statfs64 ltmp; 125 struct linux_statfs64 ltmp;
126 int error; 126 int error;
127 127
128 sb = STATVFSBUF_GET(); 128 sb = STATVFSBUF_GET();
129 error = do_sys_pstatvfs(l, SCARG_P32(uap, path), ST_WAIT, sb); 129 error = do_sys_pstatvfs(l, SCARG_P32(uap, path), ST_WAIT, sb);
130 if (error == 0) { 130 if (error == 0) {
131 bsd_to_linux_statfs64(sb, &ltmp); 131 bsd_to_linux_statfs64(sb, &ltmp);
132 error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp); 132 error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
133 } 133 }
134 134
135 STATVFSBUF_PUT(sb); 135 STATVFSBUF_PUT(sb);
136 return error; 136 return error;
137} 137}
138 138
139int 139int
140linux32_sys_fstatfs64(struct lwp *l, const struct linux32_sys_fstatfs64_args *uap, register_t *retval) 140linux32_sys_fstatfs64(struct lwp *l, const struct linux32_sys_fstatfs64_args *uap, register_t *retval)
141{ 141{
142 /* { 142 /* {
143 syscallarg(int) fd; 143 syscallarg(int) fd;
144 syscallarg(linux32_statfs64p) sp; 144 syscallarg(linux32_statfs64p) sp;
145 } */ 145 } */
146 struct statvfs *sb; 146 struct statvfs *sb;
147 struct linux_statfs64 ltmp; 147 struct linux_statfs64 ltmp;
148 int error; 148 int error;
149 149
150 sb = STATVFSBUF_GET(); 150 sb = STATVFSBUF_GET();
151 error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb); 151 error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb);
152 if (error == 0) { 152 if (error == 0) {
153 bsd_to_linux_statfs64(sb, &ltmp); 153 bsd_to_linux_statfs64(sb, &ltmp);
154 error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp); 154 error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
155 } 155 }
156 STATVFSBUF_PUT(sb); 156 STATVFSBUF_PUT(sb);
157 157
158 return error; 158 return error;
159} 159}
160 160
161extern const int linux_ptrace_request_map[]; 161extern const int linux_ptrace_request_map[];
162 162
163int 163int
164linux32_sys_ptrace(struct lwp *l, const struct linux32_sys_ptrace_args *uap, register_t *retval) 164linux32_sys_ptrace(struct lwp *l, const struct linux32_sys_ptrace_args *uap, register_t *retval)
165{ 165{
166 /* { 166 /* {
167 i386, m68k, powerpc: T=int 167 i386, m68k, powerpc: T=int
168 alpha, amd64: T=long 168 alpha, amd64: T=long
169 syscallarg(T) request; 169 syscallarg(T) request;
170 syscallarg(T) pid; 170 syscallarg(T) pid;
171 syscallarg(T) addr; 171 syscallarg(T) addr;
172 syscallarg(T) data; 172 syscallarg(T) data;
173 } */ 173 } */
174 const int *ptr; 174 const int *ptr;
175 int request; 175 int request;
176 int error; 176 int error;
177 177
178 ptr = linux_ptrace_request_map; 178 ptr = linux_ptrace_request_map;
179 request = SCARG(uap, request); 179 request = SCARG(uap, request);
180 while (*ptr != -1) 180 while (*ptr != -1)
181 if (*ptr++ == request) { 181 if (*ptr++ == request) {
182 struct sys_ptrace_args pta; 182 struct sys_ptrace_args pta;
183 183
184 SCARG(&pta, req) = *ptr; 184 SCARG(&pta, req) = *ptr;
185 SCARG(&pta, pid) = SCARG(uap, pid); 185 SCARG(&pta, pid) = SCARG(uap, pid);
186 SCARG(&pta, addr) = NETBSD32IPTR64(SCARG(uap, addr)); 186 SCARG(&pta, addr) = NETBSD32IPTR64(SCARG(uap, addr));
187 SCARG(&pta, data) = SCARG(uap, data); 187 SCARG(&pta, data) = SCARG(uap, data);
188 188
189 /* 189 /*
190 * Linux ptrace(PTRACE_CONT, pid, 0, 0) means actually 190 * Linux ptrace(PTRACE_CONT, pid, 0, 0) means actually
191 * to continue where the process left off previously. 191 * to continue where the process left off previously.
192 * The same thing is achieved by addr == (void *) 1 192 * The same thing is achieved by addr == (void *) 1
193 * on NetBSD, so rewrite 'addr' appropriately. 193 * on NetBSD, so rewrite 'addr' appropriately.
194 */ 194 */
195 if (request == LINUX_PTRACE_CONT && SCARG(uap, addr)==0) 195 if (request == LINUX_PTRACE_CONT && SCARG(uap, addr)==0)
196 SCARG(&pta, addr) = (void *) 1; 196 SCARG(&pta, addr) = (void *) 1;
197 197
198 error = sysent[SYS_ptrace].sy_call(l, &pta, retval); 198 error = sysent[SYS_ptrace].sy_call(l, &pta, retval);
199 if (error) 199 if (error)
200 return error; 200 return error;
201 switch (request) { 201 switch (request) {
202 case LINUX_PTRACE_PEEKTEXT: 202 case LINUX_PTRACE_PEEKTEXT:
203 case LINUX_PTRACE_PEEKDATA: 203 case LINUX_PTRACE_PEEKDATA:
204 error = copyout (retval, 204 error = copyout (retval,
205 NETBSD32IPTR64(SCARG(uap, data)),  205 NETBSD32IPTR64(SCARG(uap, data)),
206 sizeof *retval); 206 sizeof *retval);
207 *retval = SCARG(uap, data); 207 *retval = SCARG(uap, data);
208 break; 208 break;
209 default: 209 default:
210 break; 210 break;
211 } 211 }
212 return error; 212 return error;
213 } 213 }
214 else 214 else
215 ptr++; 215 ptr++;
216 216
217 return EIO; 217 return EIO;
218} 218}
219 219
220int 220int
221linux32_sys_personality(struct lwp *l, const struct linux32_sys_personality_args *uap, register_t *retval) 221linux32_sys_personality(struct lwp *l, const struct linux32_sys_personality_args *uap, register_t *retval)
222{ 222{
223 /* { 223 /* {
224 syscallarg(netbsd32_u_long) per; 224 syscallarg(netbsd32_u_long) per;
225 } */ 225 } */
 226 struct linux_sys_personality_args ua;
226 227
227 switch (SCARG(uap, per)) { 228 NETBSD32TOX_UAP(per, long);
228 case LINUX_PER_LINUX: 229 return linux_sys_personality(l, &ua, retval);
229 case LINUX_PER_LINUX32: 
230 case LINUX_PER_QUERY: 
231 break; 
232 default: 
233 return EINVAL; 
234 } 
235 
236 retval[0] = LINUX_PER_LINUX; 
237 return 0; 
238} 230}
239 231
240int 232int
241linux32_sys_futex(struct lwp *l, 233linux32_sys_futex(struct lwp *l,
242 const struct linux32_sys_futex_args *uap, register_t *retval) 234 const struct linux32_sys_futex_args *uap, register_t *retval)
243{ 235{
244 /* { 236 /* {
245 syscallarg(linux32_intp_t) uaddr; 237 syscallarg(linux32_intp_t) uaddr;
246 syscallarg(int) op; 238 syscallarg(int) op;
247 syscallarg(int) val; 239 syscallarg(int) val;
248 syscallarg(linux32_timespecp_t) timeout; 240 syscallarg(linux32_timespecp_t) timeout;
249 syscallarg(linux32_intp_t) uaddr2; 241 syscallarg(linux32_intp_t) uaddr2;
250 syscallarg(int) val3; 242 syscallarg(int) val3;
251 } */ 243 } */
252 struct linux_sys_futex_args ua; 244 struct linux_sys_futex_args ua;
253 struct linux32_timespec lts; 245 struct linux32_timespec lts;
254 struct timespec ts = { 0, 0 }; 246 struct timespec ts = { 0, 0 };
255 int error; 247 int error;
256 248
257 NETBSD32TOP_UAP(uaddr, int); 249 NETBSD32TOP_UAP(uaddr, int);
258 NETBSD32TO64_UAP(op); 250 NETBSD32TO64_UAP(op);
259 NETBSD32TO64_UAP(val); 251 NETBSD32TO64_UAP(val);
260 NETBSD32TOP_UAP(timeout, struct linux_timespec); 252 NETBSD32TOP_UAP(timeout, struct linux_timespec);
261 NETBSD32TOP_UAP(uaddr2, int); 253 NETBSD32TOP_UAP(uaddr2, int);
262 NETBSD32TO64_UAP(val3); 254 NETBSD32TO64_UAP(val3);
263 if ((SCARG(uap, op) & ~LINUX_FUTEX_PRIVATE_FLAG) == LINUX_FUTEX_WAIT && 255 if ((SCARG(uap, op) & ~LINUX_FUTEX_PRIVATE_FLAG) == LINUX_FUTEX_WAIT &&
264 SCARG_P32(uap, timeout) != NULL) { 256 SCARG_P32(uap, timeout) != NULL) {
265 if ((error = copyin((void *)SCARG_P32(uap, timeout),  257 if ((error = copyin((void *)SCARG_P32(uap, timeout),
266 &lts, sizeof(lts))) != 0) { 258 &lts, sizeof(lts))) != 0) {
267 return error; 259 return error;
268 } 260 }
269 linux32_to_native_timespec(&ts, &lts); 261 linux32_to_native_timespec(&ts, &lts);
270 } 262 }
271 return linux_do_futex(l, &ua, retval, &ts); 263 return linux_do_futex(l, &ua, retval, &ts);
272} 264}
273 265
274int 266int
275linux32_sys_set_robust_list(struct lwp *l, 267linux32_sys_set_robust_list(struct lwp *l,
276 const struct linux32_sys_set_robust_list_args *uap, register_t *retval) 268 const struct linux32_sys_set_robust_list_args *uap, register_t *retval)
277{ 269{
278 /* { 270 /* {
279 syscallarg(linux32_robust_list_headp_t) head; 271 syscallarg(linux32_robust_list_headp_t) head;
280 syscallarg(linux32_size_t) len; 272 syscallarg(linux32_size_t) len;
281 } */ 273 } */
282 struct linux_sys_set_robust_list_args ua; 274 struct linux_sys_set_robust_list_args ua;
283 struct linux_emuldata *led; 275 struct linux_emuldata *led;
284 276
285 if (SCARG(uap, len) != 12) 277 if (SCARG(uap, len) != 12)
286 return EINVAL; 278 return EINVAL;
287 279
288 NETBSD32TOP_UAP(head, struct robust_list_head); 280 NETBSD32TOP_UAP(head, struct robust_list_head);
289 NETBSD32TOX64_UAP(len, size_t); 281 NETBSD32TOX64_UAP(len, size_t);
290 282
291 led = l->l_emuldata; 283 led = l->l_emuldata;
292 led->led_robust_head = SCARG(&ua, head); 284 led->led_robust_head = SCARG(&ua, head);
293 *retval = 0; 285 *retval = 0;
294 return 0; 286 return 0;
295} 287}
296 288
297int 289int
298linux32_sys_get_robust_list(struct lwp *l, 290linux32_sys_get_robust_list(struct lwp *l,
299 const struct linux32_sys_get_robust_list_args *uap, register_t *retval) 291 const struct linux32_sys_get_robust_list_args *uap, register_t *retval)
300{ 292{
301 /* { 293 /* {
302 syscallarg(linux32_robust_list_headpp_t) head; 294 syscallarg(linux32_robust_list_headpp_t) head;
303 syscallarg(linux32_sizep_t) len; 295 syscallarg(linux32_sizep_t) len;
304 } */ 296 } */
305 struct linux_sys_get_robust_list_args ua; 297 struct linux_sys_get_robust_list_args ua;
306 298
307 NETBSD32TOP_UAP(head, struct robust_list_head *); 299 NETBSD32TOP_UAP(head, struct robust_list_head *);
308 NETBSD32TOP_UAP(len, size_t *); 300 NETBSD32TOP_UAP(len, size_t *);
309 return linux_sys_get_robust_list(l, &ua, retval); 301 return linux_sys_get_robust_list(l, &ua, retval);
310} 302}
311 303
312int 304int
313linux32_sys_truncate64(struct lwp *l, const struct linux32_sys_truncate64_args *uap, register_t *retval) 305linux32_sys_truncate64(struct lwp *l, const struct linux32_sys_truncate64_args *uap, register_t *retval)
314{ 306{
315 /* { 307 /* {
316 syscallarg(netbsd32_charp) path; 308 syscallarg(netbsd32_charp) path;
317 syscallarg(off_t) length; 309 syscallarg(off_t) length;
318 } */ 310 } */
319 struct sys_truncate_args ua; 311 struct sys_truncate_args ua;
320 312
321 /* Linux doesn't have the 'pad' pseudo-parameter */ 313 /* Linux doesn't have the 'pad' pseudo-parameter */
322 NETBSD32TOP_UAP(path, const char *); 314 NETBSD32TOP_UAP(path, const char *);
323 SCARG(&ua, PAD) = 0; 315 SCARG(&ua, PAD) = 0;
324 SCARG(&ua, length) = ((off_t)SCARG(uap, lenhi) << 32) + SCARG(uap, lenlo); 316 SCARG(&ua, length) = ((off_t)SCARG(uap, lenhi) << 32) + SCARG(uap, lenlo);
325 return sys_truncate(l, &ua, retval); 317 return sys_truncate(l, &ua, retval);
326} 318}
327 319
328int 320int
329linux32_sys_ftruncate64(struct lwp *l, const struct linux32_sys_ftruncate64_args *uap, register_t *retval) 321linux32_sys_ftruncate64(struct lwp *l, const struct linux32_sys_ftruncate64_args *uap, register_t *retval)
330{ 322{
331 /* { 323 /* {
332 syscallarg(unsigned int) fd; 324 syscallarg(unsigned int) fd;
333 syscallarg(off_t) length; 325 syscallarg(off_t) length;
334 } */ 326 } */
335 struct sys_ftruncate_args ua; 327 struct sys_ftruncate_args ua;
336 328
337 /* Linux doesn't have the 'pad' pseudo-parameter */ 329 /* Linux doesn't have the 'pad' pseudo-parameter */
338 NETBSD32TO64_UAP(fd); 330 NETBSD32TO64_UAP(fd);
339 SCARG(&ua, PAD) = 0; 331 SCARG(&ua, PAD) = 0;
340 SCARG(&ua, length) = ((off_t)SCARG(uap, lenhi) << 32) + SCARG(uap, lenlo); 332 SCARG(&ua, length) = ((off_t)SCARG(uap, lenhi) << 32) + SCARG(uap, lenlo);
341 return sys_ftruncate(l, &ua, retval); 333 return sys_ftruncate(l, &ua, retval);
342} 334}
343 335
344int 336int
345linux32_sys_setdomainname(struct lwp *l, const struct linux32_sys_setdomainname_args *uap, register_t *retval) 337linux32_sys_setdomainname(struct lwp *l, const struct linux32_sys_setdomainname_args *uap, register_t *retval)
346{ 338{
347 /* { 339 /* {
348 syscallarg(netbsd32_charp) domainname; 340 syscallarg(netbsd32_charp) domainname;
349 syscallarg(int) len; 341 syscallarg(int) len;
350 } */ 342 } */
351 struct linux_sys_setdomainname_args ua; 343 struct linux_sys_setdomainname_args ua;
352 344
353 NETBSD32TOP_UAP(domainname, char); 345 NETBSD32TOP_UAP(domainname, char);
354 NETBSD32TO64_UAP(len); 346 NETBSD32TO64_UAP(len);
355 return linux_sys_setdomainname(l, &ua, retval); 347 return linux_sys_setdomainname(l, &ua, retval);
356} 348}