• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/arch/x86/ia32/
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
20 * hopefully all marked.  This should be fixed.
21 */
22
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/times.h>
30#include <linux/utsname.h>
31#include <linux/smp_lock.h>
32#include <linux/mm.h>
33#include <linux/uio.h>
34#include <linux/poll.h>
35#include <linux/personality.h>
36#include <linux/stat.h>
37#include <linux/rwsem.h>
38#include <linux/compat.h>
39#include <linux/vfs.h>
40#include <linux/ptrace.h>
41#include <linux/highuid.h>
42#include <linux/sysctl.h>
43#include <linux/slab.h>
44#include <asm/mman.h>
45#include <asm/types.h>
46#include <asm/uaccess.h>
47#include <asm/atomic.h>
48#include <asm/vgtod.h>
49#include <asm/sys_ia32.h>
50
51#define AA(__x)		((unsigned long)(__x))
52
53
54asmlinkage long sys32_truncate64(const char __user *filename,
55				 unsigned long offset_low,
56				 unsigned long offset_high)
57{
58       return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
59}
60
61asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
62				  unsigned long offset_high)
63{
64       return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
65}
66
67/*
68 * Another set for IA32/LFS -- x86_64 struct stat is different due to
69 * support for 64bit inode numbers.
70 */
71static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
72{
73	typeof(ubuf->st_uid) uid = 0;
74	typeof(ubuf->st_gid) gid = 0;
75	SET_UID(uid, stat->uid);
76	SET_GID(gid, stat->gid);
77	if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
78	    __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
79	    __put_user(stat->ino, &ubuf->__st_ino) ||
80	    __put_user(stat->ino, &ubuf->st_ino) ||
81	    __put_user(stat->mode, &ubuf->st_mode) ||
82	    __put_user(stat->nlink, &ubuf->st_nlink) ||
83	    __put_user(uid, &ubuf->st_uid) ||
84	    __put_user(gid, &ubuf->st_gid) ||
85	    __put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
86	    __put_user(stat->size, &ubuf->st_size) ||
87	    __put_user(stat->atime.tv_sec, &ubuf->st_atime) ||
88	    __put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
89	    __put_user(stat->mtime.tv_sec, &ubuf->st_mtime) ||
90	    __put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
91	    __put_user(stat->ctime.tv_sec, &ubuf->st_ctime) ||
92	    __put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
93	    __put_user(stat->blksize, &ubuf->st_blksize) ||
94	    __put_user(stat->blocks, &ubuf->st_blocks))
95		return -EFAULT;
96	return 0;
97}
98
99asmlinkage long sys32_stat64(const char __user *filename,
100			     struct stat64 __user *statbuf)
101{
102	struct kstat stat;
103	int ret = vfs_stat(filename, &stat);
104
105	if (!ret)
106		ret = cp_stat64(statbuf, &stat);
107	return ret;
108}
109
110asmlinkage long sys32_lstat64(const char __user *filename,
111			      struct stat64 __user *statbuf)
112{
113	struct kstat stat;
114	int ret = vfs_lstat(filename, &stat);
115	if (!ret)
116		ret = cp_stat64(statbuf, &stat);
117	return ret;
118}
119
120asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
121{
122	struct kstat stat;
123	int ret = vfs_fstat(fd, &stat);
124	if (!ret)
125		ret = cp_stat64(statbuf, &stat);
126	return ret;
127}
128
129asmlinkage long sys32_fstatat(unsigned int dfd, const char __user *filename,
130			      struct stat64 __user *statbuf, int flag)
131{
132	struct kstat stat;
133	int error;
134
135	error = vfs_fstatat(dfd, filename, &stat, flag);
136	if (error)
137		return error;
138	return cp_stat64(statbuf, &stat);
139}
140
141/*
142 * Linux/i386 didn't use to be able to handle more than
143 * 4 system call parameters, so these system calls used a memory
144 * block for parameter passing..
145 */
146
147struct mmap_arg_struct32 {
148	unsigned int addr;
149	unsigned int len;
150	unsigned int prot;
151	unsigned int flags;
152	unsigned int fd;
153	unsigned int offset;
154};
155
156asmlinkage long sys32_mmap(struct mmap_arg_struct32 __user *arg)
157{
158	struct mmap_arg_struct32 a;
159
160	if (copy_from_user(&a, arg, sizeof(a)))
161		return -EFAULT;
162
163	if (a.offset & ~PAGE_MASK)
164		return -EINVAL;
165
166	return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
167			       a.offset>>PAGE_SHIFT);
168}
169
170asmlinkage long sys32_mprotect(unsigned long start, size_t len,
171			       unsigned long prot)
172{
173	return sys_mprotect(start, len, prot);
174}
175
176asmlinkage long sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
177				   struct sigaction32 __user *oact,
178				   unsigned int sigsetsize)
179{
180	struct k_sigaction new_ka, old_ka;
181	int ret;
182	compat_sigset_t set32;
183
184	if (sigsetsize != sizeof(compat_sigset_t))
185		return -EINVAL;
186
187	if (act) {
188		compat_uptr_t handler, restorer;
189
190		if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
191		    __get_user(handler, &act->sa_handler) ||
192		    __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
193		    __get_user(restorer, &act->sa_restorer) ||
194		    __copy_from_user(&set32, &act->sa_mask,
195				     sizeof(compat_sigset_t)))
196			return -EFAULT;
197		new_ka.sa.sa_handler = compat_ptr(handler);
198		new_ka.sa.sa_restorer = compat_ptr(restorer);
199
200		switch (_NSIG_WORDS) {
201		case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
202				| (((long)set32.sig[7]) << 32);
203		case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
204				| (((long)set32.sig[5]) << 32);
205		case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
206				| (((long)set32.sig[3]) << 32);
207		case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
208				| (((long)set32.sig[1]) << 32);
209		}
210	}
211
212	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
213
214	if (!ret && oact) {
215		switch (_NSIG_WORDS) {
216		case 4:
217			set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
218			set32.sig[6] = old_ka.sa.sa_mask.sig[3];
219		case 3:
220			set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
221			set32.sig[4] = old_ka.sa.sa_mask.sig[2];
222		case 2:
223			set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
224			set32.sig[2] = old_ka.sa.sa_mask.sig[1];
225		case 1:
226			set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
227			set32.sig[0] = old_ka.sa.sa_mask.sig[0];
228		}
229		if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
230		    __put_user(ptr_to_compat(old_ka.sa.sa_handler),
231			       &oact->sa_handler) ||
232		    __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
233			       &oact->sa_restorer) ||
234		    __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
235		    __copy_to_user(&oact->sa_mask, &set32,
236				   sizeof(compat_sigset_t)))
237			return -EFAULT;
238	}
239
240	return ret;
241}
242
243asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
244				struct old_sigaction32 __user *oact)
245{
246	struct k_sigaction new_ka, old_ka;
247	int ret;
248
249	if (act) {
250		compat_old_sigset_t mask;
251		compat_uptr_t handler, restorer;
252
253		if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
254		    __get_user(handler, &act->sa_handler) ||
255		    __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
256		    __get_user(restorer, &act->sa_restorer) ||
257		    __get_user(mask, &act->sa_mask))
258			return -EFAULT;
259
260		new_ka.sa.sa_handler = compat_ptr(handler);
261		new_ka.sa.sa_restorer = compat_ptr(restorer);
262
263		siginitset(&new_ka.sa.sa_mask, mask);
264	}
265
266	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
267
268	if (!ret && oact) {
269		if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
270		    __put_user(ptr_to_compat(old_ka.sa.sa_handler),
271			       &oact->sa_handler) ||
272		    __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
273			       &oact->sa_restorer) ||
274		    __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
275		    __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
276			return -EFAULT;
277	}
278
279	return ret;
280}
281
282asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
283				     compat_sigset_t __user *oset,
284				     unsigned int sigsetsize)
285{
286	sigset_t s;
287	compat_sigset_t s32;
288	int ret;
289	mm_segment_t old_fs = get_fs();
290
291	if (set) {
292		if (copy_from_user(&s32, set, sizeof(compat_sigset_t)))
293			return -EFAULT;
294		switch (_NSIG_WORDS) {
295		case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
296		case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
297		case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
298		case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
299		}
300	}
301	set_fs(KERNEL_DS);
302	ret = sys_rt_sigprocmask(how,
303				 set ? (sigset_t __user *)&s : NULL,
304				 oset ? (sigset_t __user *)&s : NULL,
305				 sigsetsize);
306	set_fs(old_fs);
307	if (ret)
308		return ret;
309	if (oset) {
310		switch (_NSIG_WORDS) {
311		case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
312		case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
313		case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
314		case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
315		}
316		if (copy_to_user(oset, &s32, sizeof(compat_sigset_t)))
317			return -EFAULT;
318	}
319	return 0;
320}
321
322asmlinkage long sys32_alarm(unsigned int seconds)
323{
324	return alarm_setitimer(seconds);
325}
326
327asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
328			      int options)
329{
330	return compat_sys_wait4(pid, stat_addr, options, NULL);
331}
332
333/* 32-bit timeval and related flotsam.  */
334
335asmlinkage long sys32_sysfs(int option, u32 arg1, u32 arg2)
336{
337	return sys_sysfs(option, arg1, arg2);
338}
339
340asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
341				    struct compat_timespec __user *interval)
342{
343	struct timespec t;
344	int ret;
345	mm_segment_t old_fs = get_fs();
346
347	set_fs(KERNEL_DS);
348	ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
349	set_fs(old_fs);
350	if (put_compat_timespec(&t, interval))
351		return -EFAULT;
352	return ret;
353}
354
355asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
356				    compat_size_t sigsetsize)
357{
358	sigset_t s;
359	compat_sigset_t s32;
360	int ret;
361	mm_segment_t old_fs = get_fs();
362
363	set_fs(KERNEL_DS);
364	ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
365	set_fs(old_fs);
366	if (!ret) {
367		switch (_NSIG_WORDS) {
368		case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
369		case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
370		case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
371		case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
372		}
373		if (copy_to_user(set, &s32, sizeof(compat_sigset_t)))
374			return -EFAULT;
375	}
376	return ret;
377}
378
379asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
380				      compat_siginfo_t __user *uinfo)
381{
382	siginfo_t info;
383	int ret;
384	mm_segment_t old_fs = get_fs();
385
386	if (copy_siginfo_from_user32(&info, uinfo))
387		return -EFAULT;
388	set_fs(KERNEL_DS);
389	ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
390	set_fs(old_fs);
391	return ret;
392}
393
394/* warning: next two assume little endian */
395asmlinkage long sys32_pread(unsigned int fd, char __user *ubuf, u32 count,
396			    u32 poslo, u32 poshi)
397{
398	return sys_pread64(fd, ubuf, count,
399			 ((loff_t)AA(poshi) << 32) | AA(poslo));
400}
401
402asmlinkage long sys32_pwrite(unsigned int fd, const char __user *ubuf,
403			     u32 count, u32 poslo, u32 poshi)
404{
405	return sys_pwrite64(fd, ubuf, count,
406			  ((loff_t)AA(poshi) << 32) | AA(poslo));
407}
408
409
410asmlinkage long sys32_personality(unsigned long personality)
411{
412	int ret;
413
414	if (personality(current->personality) == PER_LINUX32 &&
415		personality == PER_LINUX)
416		personality = PER_LINUX32;
417	ret = sys_personality(personality);
418	if (ret == PER_LINUX32)
419		ret = PER_LINUX;
420	return ret;
421}
422
423asmlinkage long sys32_sendfile(int out_fd, int in_fd,
424			       compat_off_t __user *offset, s32 count)
425{
426	mm_segment_t old_fs = get_fs();
427	int ret;
428	off_t of;
429
430	if (offset && get_user(of, offset))
431		return -EFAULT;
432
433	set_fs(KERNEL_DS);
434	ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
435			   count);
436	set_fs(old_fs);
437
438	if (offset && put_user(of, offset))
439		return -EFAULT;
440	return ret;
441}
442
443asmlinkage long sys32_execve(const char __user *name, compat_uptr_t __user *argv,
444			     compat_uptr_t __user *envp, struct pt_regs *regs)
445{
446	long error;
447	char *filename;
448
449	filename = getname(name);
450	error = PTR_ERR(filename);
451	if (IS_ERR(filename))
452		return error;
453	error = compat_do_execve(filename, argv, envp, regs);
454	putname(filename);
455	return error;
456}
457
458asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
459			    struct pt_regs *regs)
460{
461	void __user *parent_tid = (void __user *)regs->dx;
462	void __user *child_tid = (void __user *)regs->di;
463
464	if (!newsp)
465		newsp = regs->sp;
466	return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
467}
468
469/*
470 * Some system calls that need sign extended arguments. This could be
471 * done by a generic wrapper.
472 */
473long sys32_lseek(unsigned int fd, int offset, unsigned int whence)
474{
475	return sys_lseek(fd, offset, whence);
476}
477
478long sys32_kill(int pid, int sig)
479{
480	return sys_kill(pid, sig);
481}
482
483long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
484			__u32 len_low, __u32 len_high, int advice)
485{
486	return sys_fadvise64_64(fd,
487			       (((u64)offset_high)<<32) | offset_low,
488			       (((u64)len_high)<<32) | len_low,
489				advice);
490}
491
492long sys32_vm86_warning(void)
493{
494	struct task_struct *me = current;
495	static char lastcomm[sizeof(me->comm)];
496
497	if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
498		compat_printk(KERN_INFO
499			      "%s: vm86 mode not supported on 64 bit kernel\n",
500			      me->comm);
501		strncpy(lastcomm, me->comm, sizeof(lastcomm));
502	}
503	return -ENOSYS;
504}
505
506long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
507			  char __user *buf, size_t len)
508{
509	return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
510}
511
512asmlinkage ssize_t sys32_readahead(int fd, unsigned off_lo, unsigned off_hi,
513				   size_t count)
514{
515	return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
516}
517
518asmlinkage long sys32_sync_file_range(int fd, unsigned off_low, unsigned off_hi,
519				      unsigned n_low, unsigned n_hi,  int flags)
520{
521	return sys_sync_file_range(fd,
522				   ((u64)off_hi << 32) | off_low,
523				   ((u64)n_hi << 32) | n_low, flags);
524}
525
526asmlinkage long sys32_fadvise64(int fd, unsigned offset_lo, unsigned offset_hi,
527				size_t len, int advice)
528{
529	return sys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
530				len, advice);
531}
532
533asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_lo,
534				unsigned offset_hi, unsigned len_lo,
535				unsigned len_hi)
536{
537	return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
538			     ((u64)len_hi << 32) | len_lo);
539}
540
541asmlinkage long sys32_fanotify_mark(int fanotify_fd, unsigned int flags,
542				    u32 mask_lo, u32 mask_hi,
543				    int fd, const char  __user *pathname)
544{
545	return sys_fanotify_mark(fanotify_fd, flags,
546				 ((u64)mask_hi << 32) | mask_lo,
547				 fd, pathname);
548}
549