Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on | |
3 | * sys_sparc32 | |
4 | * | |
5 | * Copyright (C) 2000 VA Linux Co | |
6 | * Copyright (C) 2000 Don Dugger <n0ano@valinux.com> | |
7 | * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com> | |
8 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | |
9 | * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) | |
10 | * Copyright (C) 2000 Hewlett-Packard Co. | |
11 | * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com> | |
12 | * Copyright (C) 2000,2001,2002 Andi Kleen, SuSE Labs (x86-64 port) | |
13 | * | |
14 | * These routines maintain argument size conversion between 32bit and 64bit | |
15 | * environment. In 2.5 most of this should be moved to a generic directory. | |
16 | * | |
17 | * This file assumes that there is a hole at the end of user address space. | |
18 | * | |
19 | * Some of the functions are LE specific currently. These are hopefully all marked. | |
20 | * This should be fixed. | |
21 | */ | |
22 | ||
1da177e4 LT |
23 | #include <linux/kernel.h> |
24 | #include <linux/sched.h> | |
25 | #include <linux/fs.h> | |
26 | #include <linux/file.h> | |
27 | #include <linux/signal.h> | |
28 | #include <linux/syscalls.h> | |
29 | #include <linux/resource.h> | |
30 | #include <linux/times.h> | |
31 | #include <linux/utsname.h> | |
1da177e4 LT |
32 | #include <linux/smp.h> |
33 | #include <linux/smp_lock.h> | |
34 | #include <linux/sem.h> | |
35 | #include <linux/msg.h> | |
36 | #include <linux/mm.h> | |
37 | #include <linux/shm.h> | |
38 | #include <linux/slab.h> | |
39 | #include <linux/uio.h> | |
40 | #include <linux/nfs_fs.h> | |
41 | #include <linux/quota.h> | |
42 | #include <linux/module.h> | |
43 | #include <linux/sunrpc/svc.h> | |
44 | #include <linux/nfsd/nfsd.h> | |
45 | #include <linux/nfsd/cache.h> | |
46 | #include <linux/nfsd/xdr.h> | |
47 | #include <linux/nfsd/syscall.h> | |
48 | #include <linux/poll.h> | |
49 | #include <linux/personality.h> | |
50 | #include <linux/stat.h> | |
51 | #include <linux/ipc.h> | |
52 | #include <linux/rwsem.h> | |
53 | #include <linux/binfmts.h> | |
54 | #include <linux/init.h> | |
55 | #include <linux/aio_abi.h> | |
56 | #include <linux/aio.h> | |
57 | #include <linux/compat.h> | |
58 | #include <linux/vfs.h> | |
59 | #include <linux/ptrace.h> | |
60 | #include <linux/highuid.h> | |
61 | #include <linux/vmalloc.h> | |
9e566d8b | 62 | #include <linux/fsnotify.h> |
1da177e4 LT |
63 | #include <asm/mman.h> |
64 | #include <asm/types.h> | |
65 | #include <asm/uaccess.h> | |
66 | #include <asm/semaphore.h> | |
67 | #include <asm/atomic.h> | |
68 | #include <asm/ldt.h> | |
69 | ||
70 | #include <net/scm.h> | |
71 | #include <net/sock.h> | |
72 | #include <asm/ia32.h> | |
73 | ||
74 | #define AA(__x) ((unsigned long)(__x)) | |
75 | ||
76 | int cp_compat_stat(struct kstat *kbuf, struct compat_stat __user *ubuf) | |
77 | { | |
78 | typeof(ubuf->st_uid) uid = 0; | |
79 | typeof(ubuf->st_gid) gid = 0; | |
80 | SET_UID(uid, kbuf->uid); | |
81 | SET_GID(gid, kbuf->gid); | |
82 | if (!old_valid_dev(kbuf->dev) || !old_valid_dev(kbuf->rdev)) | |
83 | return -EOVERFLOW; | |
84 | if (kbuf->size >= 0x7fffffff) | |
85 | return -EOVERFLOW; | |
86 | if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct compat_stat)) || | |
87 | __put_user (old_encode_dev(kbuf->dev), &ubuf->st_dev) || | |
88 | __put_user (kbuf->ino, &ubuf->st_ino) || | |
89 | __put_user (kbuf->mode, &ubuf->st_mode) || | |
90 | __put_user (kbuf->nlink, &ubuf->st_nlink) || | |
91 | __put_user (uid, &ubuf->st_uid) || | |
92 | __put_user (gid, &ubuf->st_gid) || | |
93 | __put_user (old_encode_dev(kbuf->rdev), &ubuf->st_rdev) || | |
94 | __put_user (kbuf->size, &ubuf->st_size) || | |
95 | __put_user (kbuf->atime.tv_sec, &ubuf->st_atime) || | |
96 | __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime_nsec) || | |
97 | __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime) || | |
98 | __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec) || | |
99 | __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime) || | |
100 | __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec) || | |
101 | __put_user (kbuf->blksize, &ubuf->st_blksize) || | |
102 | __put_user (kbuf->blocks, &ubuf->st_blocks)) | |
103 | return -EFAULT; | |
104 | return 0; | |
105 | } | |
106 | ||
107 | asmlinkage long | |
108 | sys32_truncate64(char __user * filename, unsigned long offset_low, unsigned long offset_high) | |
109 | { | |
110 | return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low); | |
111 | } | |
112 | ||
113 | asmlinkage long | |
114 | sys32_ftruncate64(unsigned int fd, unsigned long offset_low, unsigned long offset_high) | |
115 | { | |
116 | return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low); | |
117 | } | |
118 | ||
119 | /* Another set for IA32/LFS -- x86_64 struct stat is different due to | |
120 | support for 64bit inode numbers. */ | |
121 | ||
122 | static int | |
123 | cp_stat64(struct stat64 __user *ubuf, struct kstat *stat) | |
124 | { | |
125 | typeof(ubuf->st_uid) uid = 0; | |
126 | typeof(ubuf->st_gid) gid = 0; | |
127 | SET_UID(uid, stat->uid); | |
128 | SET_GID(gid, stat->gid); | |
129 | if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) || | |
130 | __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) || | |
131 | __put_user (stat->ino, &ubuf->__st_ino) || | |
132 | __put_user (stat->ino, &ubuf->st_ino) || | |
133 | __put_user (stat->mode, &ubuf->st_mode) || | |
134 | __put_user (stat->nlink, &ubuf->st_nlink) || | |
135 | __put_user (uid, &ubuf->st_uid) || | |
136 | __put_user (gid, &ubuf->st_gid) || | |
137 | __put_user (huge_encode_dev(stat->rdev), &ubuf->st_rdev) || | |
138 | __put_user (stat->size, &ubuf->st_size) || | |
139 | __put_user (stat->atime.tv_sec, &ubuf->st_atime) || | |
140 | __put_user (stat->atime.tv_nsec, &ubuf->st_atime_nsec) || | |
141 | __put_user (stat->mtime.tv_sec, &ubuf->st_mtime) || | |
142 | __put_user (stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) || | |
143 | __put_user (stat->ctime.tv_sec, &ubuf->st_ctime) || | |
144 | __put_user (stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) || | |
145 | __put_user (stat->blksize, &ubuf->st_blksize) || | |
146 | __put_user (stat->blocks, &ubuf->st_blocks)) | |
147 | return -EFAULT; | |
148 | return 0; | |
149 | } | |
150 | ||
151 | asmlinkage long | |
152 | sys32_stat64(char __user * filename, struct stat64 __user *statbuf) | |
153 | { | |
154 | struct kstat stat; | |
155 | int ret = vfs_stat(filename, &stat); | |
156 | if (!ret) | |
157 | ret = cp_stat64(statbuf, &stat); | |
158 | return ret; | |
159 | } | |
160 | ||
161 | asmlinkage long | |
162 | sys32_lstat64(char __user * filename, struct stat64 __user *statbuf) | |
163 | { | |
164 | struct kstat stat; | |
165 | int ret = vfs_lstat(filename, &stat); | |
166 | if (!ret) | |
167 | ret = cp_stat64(statbuf, &stat); | |
168 | return ret; | |
169 | } | |
170 | ||
171 | asmlinkage long | |
172 | sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf) | |
173 | { | |
174 | struct kstat stat; | |
175 | int ret = vfs_fstat(fd, &stat); | |
176 | if (!ret) | |
177 | ret = cp_stat64(statbuf, &stat); | |
178 | return ret; | |
179 | } | |
180 | ||
cff2b760 UD |
181 | asmlinkage long |
182 | sys32_fstatat(unsigned int dfd, char __user *filename, | |
183 | struct stat64 __user* statbuf, int flag) | |
184 | { | |
185 | struct kstat stat; | |
186 | int error = -EINVAL; | |
187 | ||
188 | if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0) | |
189 | goto out; | |
190 | ||
191 | if (flag & AT_SYMLINK_NOFOLLOW) | |
192 | error = vfs_lstat_fd(dfd, filename, &stat); | |
193 | else | |
194 | error = vfs_stat_fd(dfd, filename, &stat); | |
195 | ||
196 | if (!error) | |
197 | error = cp_stat64(statbuf, &stat); | |
198 | ||
199 | out: | |
200 | return error; | |
201 | } | |
202 | ||
1da177e4 LT |
203 | /* |
204 | * Linux/i386 didn't use to be able to handle more than | |
205 | * 4 system call parameters, so these system calls used a memory | |
206 | * block for parameter passing.. | |
207 | */ | |
208 | ||
209 | struct mmap_arg_struct { | |
210 | unsigned int addr; | |
211 | unsigned int len; | |
212 | unsigned int prot; | |
213 | unsigned int flags; | |
214 | unsigned int fd; | |
215 | unsigned int offset; | |
216 | }; | |
217 | ||
218 | asmlinkage long | |
219 | sys32_mmap(struct mmap_arg_struct __user *arg) | |
220 | { | |
221 | struct mmap_arg_struct a; | |
222 | struct file *file = NULL; | |
223 | unsigned long retval; | |
224 | struct mm_struct *mm ; | |
225 | ||
226 | if (copy_from_user(&a, arg, sizeof(a))) | |
227 | return -EFAULT; | |
228 | ||
229 | if (a.offset & ~PAGE_MASK) | |
230 | return -EINVAL; | |
231 | ||
232 | if (!(a.flags & MAP_ANONYMOUS)) { | |
233 | file = fget(a.fd); | |
234 | if (!file) | |
235 | return -EBADF; | |
236 | } | |
237 | ||
238 | mm = current->mm; | |
239 | down_write(&mm->mmap_sem); | |
240 | retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT); | |
241 | if (file) | |
242 | fput(file); | |
243 | ||
244 | up_write(&mm->mmap_sem); | |
245 | ||
246 | return retval; | |
247 | } | |
248 | ||
249 | asmlinkage long | |
250 | sys32_mprotect(unsigned long start, size_t len, unsigned long prot) | |
251 | { | |
252 | return sys_mprotect(start,len,prot); | |
253 | } | |
254 | ||
255 | asmlinkage long | |
256 | sys32_pipe(int __user *fd) | |
257 | { | |
258 | int retval; | |
259 | int fds[2]; | |
260 | ||
261 | retval = do_pipe(fds); | |
262 | if (retval) | |
263 | goto out; | |
264 | if (copy_to_user(fd, fds, sizeof(fds))) | |
265 | retval = -EFAULT; | |
266 | out: | |
267 | return retval; | |
268 | } | |
269 | ||
270 | asmlinkage long | |
271 | sys32_rt_sigaction(int sig, struct sigaction32 __user *act, | |
272 | struct sigaction32 __user *oact, unsigned int sigsetsize) | |
273 | { | |
274 | struct k_sigaction new_ka, old_ka; | |
275 | int ret; | |
276 | compat_sigset_t set32; | |
277 | ||
278 | /* XXX: Don't preclude handling different sized sigset_t's. */ | |
279 | if (sigsetsize != sizeof(compat_sigset_t)) | |
280 | return -EINVAL; | |
281 | ||
282 | if (act) { | |
283 | compat_uptr_t handler, restorer; | |
284 | ||
285 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || | |
286 | __get_user(handler, &act->sa_handler) || | |
287 | __get_user(new_ka.sa.sa_flags, &act->sa_flags) || | |
288 | __get_user(restorer, &act->sa_restorer)|| | |
289 | __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t))) | |
290 | return -EFAULT; | |
291 | new_ka.sa.sa_handler = compat_ptr(handler); | |
292 | new_ka.sa.sa_restorer = compat_ptr(restorer); | |
293 | /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */ | |
294 | switch (_NSIG_WORDS) { | |
295 | case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6] | |
296 | | (((long)set32.sig[7]) << 32); | |
297 | case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4] | |
298 | | (((long)set32.sig[5]) << 32); | |
299 | case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2] | |
300 | | (((long)set32.sig[3]) << 32); | |
301 | case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0] | |
302 | | (((long)set32.sig[1]) << 32); | |
303 | } | |
304 | } | |
305 | ||
306 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | |
307 | ||
308 | if (!ret && oact) { | |
309 | /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */ | |
310 | switch (_NSIG_WORDS) { | |
311 | case 4: | |
312 | set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32); | |
313 | set32.sig[6] = old_ka.sa.sa_mask.sig[3]; | |
314 | case 3: | |
315 | set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32); | |
316 | set32.sig[4] = old_ka.sa.sa_mask.sig[2]; | |
317 | case 2: | |
318 | set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32); | |
319 | set32.sig[2] = old_ka.sa.sa_mask.sig[1]; | |
320 | case 1: | |
321 | set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32); | |
322 | set32.sig[0] = old_ka.sa.sa_mask.sig[0]; | |
323 | } | |
324 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || | |
325 | __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) || | |
326 | __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) || | |
327 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || | |
328 | __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t))) | |
329 | return -EFAULT; | |
330 | } | |
331 | ||
332 | return ret; | |
333 | } | |
334 | ||
335 | asmlinkage long | |
336 | sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact) | |
337 | { | |
338 | struct k_sigaction new_ka, old_ka; | |
339 | int ret; | |
340 | ||
341 | if (act) { | |
342 | compat_old_sigset_t mask; | |
343 | compat_uptr_t handler, restorer; | |
344 | ||
345 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || | |
346 | __get_user(handler, &act->sa_handler) || | |
347 | __get_user(new_ka.sa.sa_flags, &act->sa_flags) || | |
348 | __get_user(restorer, &act->sa_restorer) || | |
349 | __get_user(mask, &act->sa_mask)) | |
350 | return -EFAULT; | |
351 | ||
352 | new_ka.sa.sa_handler = compat_ptr(handler); | |
353 | new_ka.sa.sa_restorer = compat_ptr(restorer); | |
354 | ||
355 | siginitset(&new_ka.sa.sa_mask, mask); | |
356 | } | |
357 | ||
358 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | |
359 | ||
360 | if (!ret && oact) { | |
361 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || | |
362 | __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) || | |
363 | __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) || | |
364 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || | |
365 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask)) | |
366 | return -EFAULT; | |
367 | } | |
368 | ||
369 | return ret; | |
370 | } | |
371 | ||
372 | asmlinkage long | |
373 | sys32_rt_sigprocmask(int how, compat_sigset_t __user *set, | |
374 | compat_sigset_t __user *oset, unsigned int sigsetsize) | |
375 | { | |
376 | sigset_t s; | |
377 | compat_sigset_t s32; | |
378 | int ret; | |
379 | mm_segment_t old_fs = get_fs(); | |
380 | ||
381 | if (set) { | |
382 | if (copy_from_user (&s32, set, sizeof(compat_sigset_t))) | |
383 | return -EFAULT; | |
384 | switch (_NSIG_WORDS) { | |
385 | case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32); | |
386 | case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32); | |
387 | case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32); | |
388 | case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32); | |
389 | } | |
390 | } | |
391 | set_fs (KERNEL_DS); | |
392 | ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL, | |
393 | sigsetsize); | |
394 | set_fs (old_fs); | |
395 | if (ret) return ret; | |
396 | if (oset) { | |
397 | switch (_NSIG_WORDS) { | |
398 | case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3]; | |
399 | case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2]; | |
400 | case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1]; | |
401 | case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0]; | |
402 | } | |
403 | if (copy_to_user (oset, &s32, sizeof(compat_sigset_t))) | |
404 | return -EFAULT; | |
405 | } | |
406 | return 0; | |
407 | } | |
408 | ||
409 | static inline long | |
410 | get_tv32(struct timeval *o, struct compat_timeval __user *i) | |
411 | { | |
412 | int err = -EFAULT; | |
413 | if (access_ok(VERIFY_READ, i, sizeof(*i))) { | |
414 | err = __get_user(o->tv_sec, &i->tv_sec); | |
415 | err |= __get_user(o->tv_usec, &i->tv_usec); | |
416 | } | |
417 | return err; | |
418 | } | |
419 | ||
420 | static inline long | |
421 | put_tv32(struct compat_timeval __user *o, struct timeval *i) | |
422 | { | |
423 | int err = -EFAULT; | |
424 | if (access_ok(VERIFY_WRITE, o, sizeof(*o))) { | |
425 | err = __put_user(i->tv_sec, &o->tv_sec); | |
426 | err |= __put_user(i->tv_usec, &o->tv_usec); | |
427 | } | |
428 | return err; | |
429 | } | |
430 | ||
c08b8a49 | 431 | extern unsigned int alarm_setitimer(unsigned int seconds); |
1da177e4 LT |
432 | |
433 | asmlinkage long | |
434 | sys32_alarm(unsigned int seconds) | |
435 | { | |
c08b8a49 | 436 | return alarm_setitimer(seconds); |
1da177e4 LT |
437 | } |
438 | ||
439 | /* Translations due to time_t size differences. Which affects all | |
440 | sorts of things, like timeval and itimerval. */ | |
441 | ||
442 | extern struct timezone sys_tz; | |
443 | ||
444 | asmlinkage long | |
445 | sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) | |
446 | { | |
447 | if (tv) { | |
448 | struct timeval ktv; | |
449 | do_gettimeofday(&ktv); | |
450 | if (put_tv32(tv, &ktv)) | |
451 | return -EFAULT; | |
452 | } | |
453 | if (tz) { | |
454 | if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) | |
455 | return -EFAULT; | |
456 | } | |
457 | return 0; | |
458 | } | |
459 | ||
460 | asmlinkage long | |
461 | sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) | |
462 | { | |
463 | struct timeval ktv; | |
464 | struct timespec kts; | |
465 | struct timezone ktz; | |
466 | ||
467 | if (tv) { | |
468 | if (get_tv32(&ktv, tv)) | |
469 | return -EFAULT; | |
470 | kts.tv_sec = ktv.tv_sec; | |
471 | kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC; | |
472 | } | |
473 | if (tz) { | |
474 | if (copy_from_user(&ktz, tz, sizeof(ktz))) | |
475 | return -EFAULT; | |
476 | } | |
477 | ||
478 | return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); | |
479 | } | |
480 | ||
481 | struct sel_arg_struct { | |
482 | unsigned int n; | |
483 | unsigned int inp; | |
484 | unsigned int outp; | |
485 | unsigned int exp; | |
486 | unsigned int tvp; | |
487 | }; | |
488 | ||
489 | asmlinkage long | |
490 | sys32_old_select(struct sel_arg_struct __user *arg) | |
491 | { | |
492 | struct sel_arg_struct a; | |
493 | ||
494 | if (copy_from_user(&a, arg, sizeof(a))) | |
495 | return -EFAULT; | |
496 | return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp), | |
497 | compat_ptr(a.exp), compat_ptr(a.tvp)); | |
498 | } | |
499 | ||
500 | extern asmlinkage long | |
501 | compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options, | |
502 | struct compat_rusage *ru); | |
503 | ||
504 | asmlinkage long | |
505 | sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options) | |
506 | { | |
507 | return compat_sys_wait4(pid, stat_addr, options, NULL); | |
508 | } | |
509 | ||
1da177e4 LT |
510 | /* 32-bit timeval and related flotsam. */ |
511 | ||
512 | asmlinkage long | |
513 | sys32_sysfs(int option, u32 arg1, u32 arg2) | |
514 | { | |
515 | return sys_sysfs(option, arg1, arg2); | |
516 | } | |
517 | ||
518 | struct sysinfo32 { | |
519 | s32 uptime; | |
520 | u32 loads[3]; | |
521 | u32 totalram; | |
522 | u32 freeram; | |
523 | u32 sharedram; | |
524 | u32 bufferram; | |
525 | u32 totalswap; | |
526 | u32 freeswap; | |
527 | unsigned short procs; | |
528 | unsigned short pad; | |
529 | u32 totalhigh; | |
530 | u32 freehigh; | |
531 | u32 mem_unit; | |
532 | char _f[20-2*sizeof(u32)-sizeof(int)]; | |
533 | }; | |
534 | ||
535 | asmlinkage long | |
536 | sys32_sysinfo(struct sysinfo32 __user *info) | |
537 | { | |
538 | struct sysinfo s; | |
539 | int ret; | |
540 | mm_segment_t old_fs = get_fs (); | |
541 | int bitcount = 0; | |
542 | ||
543 | set_fs (KERNEL_DS); | |
544 | ret = sys_sysinfo(&s); | |
545 | set_fs (old_fs); | |
546 | ||
547 | /* Check to see if any memory value is too large for 32-bit and scale | |
548 | * down if needed | |
549 | */ | |
550 | if ((s.totalram >> 32) || (s.totalswap >> 32)) { | |
551 | while (s.mem_unit < PAGE_SIZE) { | |
552 | s.mem_unit <<= 1; | |
553 | bitcount++; | |
554 | } | |
555 | s.totalram >>= bitcount; | |
556 | s.freeram >>= bitcount; | |
557 | s.sharedram >>= bitcount; | |
558 | s.bufferram >>= bitcount; | |
559 | s.totalswap >>= bitcount; | |
560 | s.freeswap >>= bitcount; | |
561 | s.totalhigh >>= bitcount; | |
562 | s.freehigh >>= bitcount; | |
563 | } | |
564 | ||
565 | if (!access_ok(VERIFY_WRITE, info, sizeof(struct sysinfo32)) || | |
566 | __put_user (s.uptime, &info->uptime) || | |
567 | __put_user (s.loads[0], &info->loads[0]) || | |
568 | __put_user (s.loads[1], &info->loads[1]) || | |
569 | __put_user (s.loads[2], &info->loads[2]) || | |
570 | __put_user (s.totalram, &info->totalram) || | |
571 | __put_user (s.freeram, &info->freeram) || | |
572 | __put_user (s.sharedram, &info->sharedram) || | |
573 | __put_user (s.bufferram, &info->bufferram) || | |
574 | __put_user (s.totalswap, &info->totalswap) || | |
575 | __put_user (s.freeswap, &info->freeswap) || | |
576 | __put_user (s.procs, &info->procs) || | |
577 | __put_user (s.totalhigh, &info->totalhigh) || | |
578 | __put_user (s.freehigh, &info->freehigh) || | |
579 | __put_user (s.mem_unit, &info->mem_unit)) | |
580 | return -EFAULT; | |
581 | return 0; | |
582 | } | |
583 | ||
584 | asmlinkage long | |
585 | sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval) | |
586 | { | |
587 | struct timespec t; | |
588 | int ret; | |
589 | mm_segment_t old_fs = get_fs (); | |
590 | ||
591 | set_fs (KERNEL_DS); | |
592 | ret = sys_sched_rr_get_interval(pid, &t); | |
593 | set_fs (old_fs); | |
594 | if (put_compat_timespec(&t, interval)) | |
595 | return -EFAULT; | |
596 | return ret; | |
597 | } | |
598 | ||
599 | asmlinkage long | |
600 | sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize) | |
601 | { | |
602 | sigset_t s; | |
603 | compat_sigset_t s32; | |
604 | int ret; | |
605 | mm_segment_t old_fs = get_fs(); | |
606 | ||
607 | set_fs (KERNEL_DS); | |
608 | ret = sys_rt_sigpending(&s, sigsetsize); | |
609 | set_fs (old_fs); | |
610 | if (!ret) { | |
611 | switch (_NSIG_WORDS) { | |
612 | case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3]; | |
613 | case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2]; | |
614 | case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1]; | |
615 | case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0]; | |
616 | } | |
617 | if (copy_to_user (set, &s32, sizeof(compat_sigset_t))) | |
618 | return -EFAULT; | |
619 | } | |
620 | return ret; | |
621 | } | |
622 | ||
623 | asmlinkage long | |
624 | sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo) | |
625 | { | |
626 | siginfo_t info; | |
627 | int ret; | |
628 | mm_segment_t old_fs = get_fs(); | |
629 | ||
630 | if (copy_siginfo_from_user32(&info, uinfo)) | |
631 | return -EFAULT; | |
632 | set_fs (KERNEL_DS); | |
633 | ret = sys_rt_sigqueueinfo(pid, sig, &info); | |
634 | set_fs (old_fs); | |
635 | return ret; | |
636 | } | |
637 | ||
638 | /* These are here just in case some old ia32 binary calls it. */ | |
639 | asmlinkage long | |
640 | sys32_pause(void) | |
641 | { | |
642 | current->state = TASK_INTERRUPTIBLE; | |
643 | schedule(); | |
644 | return -ERESTARTNOHAND; | |
645 | } | |
646 | ||
647 | ||
648 | #ifdef CONFIG_SYSCTL | |
649 | struct sysctl_ia32 { | |
650 | unsigned int name; | |
651 | int nlen; | |
652 | unsigned int oldval; | |
653 | unsigned int oldlenp; | |
654 | unsigned int newval; | |
655 | unsigned int newlen; | |
656 | unsigned int __unused[4]; | |
657 | }; | |
658 | ||
659 | ||
660 | asmlinkage long | |
661 | sys32_sysctl(struct sysctl_ia32 __user *args32) | |
662 | { | |
663 | struct sysctl_ia32 a32; | |
664 | mm_segment_t old_fs = get_fs (); | |
665 | void __user *oldvalp, *newvalp; | |
666 | size_t oldlen; | |
667 | int __user *namep; | |
668 | long ret; | |
669 | extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp, | |
670 | void *newval, size_t newlen); | |
671 | ||
672 | ||
673 | if (copy_from_user(&a32, args32, sizeof (a32))) | |
674 | return -EFAULT; | |
675 | ||
676 | /* | |
677 | * We need to pre-validate these because we have to disable address checking | |
678 | * before calling do_sysctl() because of OLDLEN but we can't run the risk of the | |
679 | * user specifying bad addresses here. Well, since we're dealing with 32 bit | |
680 | * addresses, we KNOW that access_ok() will always succeed, so this is an | |
681 | * expensive NOP, but so what... | |
682 | */ | |
683 | namep = compat_ptr(a32.name); | |
684 | oldvalp = compat_ptr(a32.oldval); | |
685 | newvalp = compat_ptr(a32.newval); | |
686 | ||
687 | if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp))) | |
688 | || !access_ok(VERIFY_WRITE, namep, 0) | |
689 | || !access_ok(VERIFY_WRITE, oldvalp, 0) | |
690 | || !access_ok(VERIFY_WRITE, newvalp, 0)) | |
691 | return -EFAULT; | |
692 | ||
693 | set_fs(KERNEL_DS); | |
694 | lock_kernel(); | |
695 | ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen); | |
696 | unlock_kernel(); | |
697 | set_fs(old_fs); | |
698 | ||
699 | if (oldvalp && put_user (oldlen, (int __user *)compat_ptr(a32.oldlenp))) | |
700 | return -EFAULT; | |
701 | ||
702 | return ret; | |
703 | } | |
704 | #endif | |
705 | ||
706 | /* warning: next two assume little endian */ | |
707 | asmlinkage long | |
708 | sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi) | |
709 | { | |
710 | return sys_pread64(fd, ubuf, count, | |
711 | ((loff_t)AA(poshi) << 32) | AA(poslo)); | |
712 | } | |
713 | ||
714 | asmlinkage long | |
715 | sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi) | |
716 | { | |
717 | return sys_pwrite64(fd, ubuf, count, | |
718 | ((loff_t)AA(poshi) << 32) | AA(poslo)); | |
719 | } | |
720 | ||
721 | ||
722 | asmlinkage long | |
723 | sys32_personality(unsigned long personality) | |
724 | { | |
725 | int ret; | |
726 | if (personality(current->personality) == PER_LINUX32 && | |
727 | personality == PER_LINUX) | |
728 | personality = PER_LINUX32; | |
729 | ret = sys_personality(personality); | |
730 | if (ret == PER_LINUX32) | |
731 | ret = PER_LINUX; | |
732 | return ret; | |
733 | } | |
734 | ||
735 | asmlinkage long | |
736 | sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count) | |
737 | { | |
738 | mm_segment_t old_fs = get_fs(); | |
739 | int ret; | |
740 | off_t of; | |
741 | ||
742 | if (offset && get_user(of, offset)) | |
743 | return -EFAULT; | |
744 | ||
745 | set_fs(KERNEL_DS); | |
746 | ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count); | |
747 | set_fs(old_fs); | |
748 | ||
83b942bd | 749 | if (offset && put_user(of, offset)) |
1da177e4 LT |
750 | return -EFAULT; |
751 | ||
752 | return ret; | |
753 | } | |
754 | ||
1da177e4 LT |
755 | asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len, |
756 | unsigned long prot, unsigned long flags, | |
757 | unsigned long fd, unsigned long pgoff) | |
758 | { | |
759 | struct mm_struct *mm = current->mm; | |
760 | unsigned long error; | |
761 | struct file * file = NULL; | |
762 | ||
763 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | |
764 | if (!(flags & MAP_ANONYMOUS)) { | |
765 | file = fget(fd); | |
766 | if (!file) | |
767 | return -EBADF; | |
768 | } | |
769 | ||
770 | down_write(&mm->mmap_sem); | |
771 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | |
772 | up_write(&mm->mmap_sem); | |
773 | ||
774 | if (file) | |
775 | fput(file); | |
776 | return error; | |
777 | } | |
778 | ||
779 | asmlinkage long sys32_olduname(struct oldold_utsname __user * name) | |
780 | { | |
781 | int error; | |
782 | ||
783 | if (!name) | |
784 | return -EFAULT; | |
785 | if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) | |
786 | return -EFAULT; | |
787 | ||
788 | down_read(&uts_sem); | |
789 | ||
790 | error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN); | |
791 | __put_user(0,name->sysname+__OLD_UTS_LEN); | |
792 | __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN); | |
793 | __put_user(0,name->nodename+__OLD_UTS_LEN); | |
794 | __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN); | |
795 | __put_user(0,name->release+__OLD_UTS_LEN); | |
796 | __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN); | |
797 | __put_user(0,name->version+__OLD_UTS_LEN); | |
798 | { | |
799 | char *arch = "x86_64"; | |
800 | if (personality(current->personality) == PER_LINUX32) | |
801 | arch = "i686"; | |
802 | ||
803 | __copy_to_user(&name->machine,arch,strlen(arch)+1); | |
804 | } | |
805 | ||
806 | up_read(&uts_sem); | |
807 | ||
808 | error = error ? -EFAULT : 0; | |
809 | ||
810 | return error; | |
811 | } | |
812 | ||
813 | long sys32_uname(struct old_utsname __user * name) | |
814 | { | |
815 | int err; | |
816 | if (!name) | |
817 | return -EFAULT; | |
818 | down_read(&uts_sem); | |
819 | err=copy_to_user(name, &system_utsname, sizeof (*name)); | |
820 | up_read(&uts_sem); | |
821 | if (personality(current->personality) == PER_LINUX32) | |
822 | err |= copy_to_user(&name->machine, "i686", 5); | |
823 | return err?-EFAULT:0; | |
824 | } | |
825 | ||
826 | long sys32_ustat(unsigned dev, struct ustat32 __user *u32p) | |
827 | { | |
828 | struct ustat u; | |
829 | mm_segment_t seg; | |
830 | int ret; | |
831 | ||
832 | seg = get_fs(); | |
833 | set_fs(KERNEL_DS); | |
834 | ret = sys_ustat(dev,&u); | |
835 | set_fs(seg); | |
836 | if (ret >= 0) { | |
837 | if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) || | |
838 | __put_user((__u32) u.f_tfree, &u32p->f_tfree) || | |
839 | __put_user((__u32) u.f_tinode, &u32p->f_tfree) || | |
840 | __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) || | |
841 | __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack))) | |
842 | ret = -EFAULT; | |
843 | } | |
844 | return ret; | |
845 | } | |
846 | ||
847 | asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv, | |
848 | compat_uptr_t __user *envp, struct pt_regs *regs) | |
849 | { | |
850 | long error; | |
851 | char * filename; | |
852 | ||
853 | filename = getname(name); | |
854 | error = PTR_ERR(filename); | |
855 | if (IS_ERR(filename)) | |
856 | return error; | |
857 | error = compat_do_execve(filename, argv, envp, regs); | |
858 | if (error == 0) { | |
859 | task_lock(current); | |
860 | current->ptrace &= ~PT_DTRACE; | |
861 | task_unlock(current); | |
862 | } | |
863 | putname(filename); | |
864 | return error; | |
865 | } | |
866 | ||
867 | asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp, | |
868 | struct pt_regs *regs) | |
869 | { | |
870 | void __user *parent_tid = (void __user *)regs->rdx; | |
871 | void __user *child_tid = (void __user *)regs->rdi; | |
872 | if (!newsp) | |
873 | newsp = regs->rsp; | |
874 | return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid); | |
875 | } | |
876 | ||
877 | /* | |
878 | * Some system calls that need sign extended arguments. This could be done by a generic wrapper. | |
879 | */ | |
880 | ||
881 | long sys32_lseek (unsigned int fd, int offset, unsigned int whence) | |
882 | { | |
883 | return sys_lseek(fd, offset, whence); | |
884 | } | |
885 | ||
886 | long sys32_kill(int pid, int sig) | |
887 | { | |
888 | return sys_kill(pid, sig); | |
889 | } | |
890 | ||
1da177e4 LT |
891 | long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high, |
892 | __u32 len_low, __u32 len_high, int advice) | |
893 | { | |
894 | return sys_fadvise64_64(fd, | |
895 | (((u64)offset_high)<<32) | offset_low, | |
896 | (((u64)len_high)<<32) | len_low, | |
897 | advice); | |
898 | } | |
899 | ||
900 | long sys32_vm86_warning(void) | |
901 | { | |
902 | struct task_struct *me = current; | |
903 | static char lastcomm[sizeof(me->comm)]; | |
904 | if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) { | |
bebfa101 | 905 | compat_printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n", |
1da177e4 LT |
906 | me->comm); |
907 | strncpy(lastcomm, me->comm, sizeof(lastcomm)); | |
908 | } | |
909 | return -ENOSYS; | |
910 | } | |
911 | ||
912 | long sys32_lookup_dcookie(u32 addr_low, u32 addr_high, | |
913 | char __user * buf, size_t len) | |
914 | { | |
915 | return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len); | |
916 | } | |
917 |