xref: /openbmc/linux/arch/sparc/kernel/sys_sparc32.c (revision c7887325230aec47d47a32562a6e26014a0fafca)
1a88b5ba8SSam Ravnborg /* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
2a88b5ba8SSam Ravnborg  *
3a88b5ba8SSam Ravnborg  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
4a88b5ba8SSam Ravnborg  * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
5a88b5ba8SSam Ravnborg  *
6a88b5ba8SSam Ravnborg  * These routines maintain argument size conversion between 32bit and 64bit
7a88b5ba8SSam Ravnborg  * environment.
8a88b5ba8SSam Ravnborg  */
9a88b5ba8SSam Ravnborg 
10a88b5ba8SSam Ravnborg #include <linux/kernel.h>
11a88b5ba8SSam Ravnborg #include <linux/sched.h>
12a88b5ba8SSam Ravnborg #include <linux/capability.h>
13a88b5ba8SSam Ravnborg #include <linux/fs.h>
14a88b5ba8SSam Ravnborg #include <linux/mm.h>
15a88b5ba8SSam Ravnborg #include <linux/file.h>
16a88b5ba8SSam Ravnborg #include <linux/signal.h>
17a88b5ba8SSam Ravnborg #include <linux/resource.h>
18a88b5ba8SSam Ravnborg #include <linux/times.h>
19a88b5ba8SSam Ravnborg #include <linux/smp.h>
20a88b5ba8SSam Ravnborg #include <linux/smp_lock.h>
21a88b5ba8SSam Ravnborg #include <linux/sem.h>
22a88b5ba8SSam Ravnborg #include <linux/msg.h>
23a88b5ba8SSam Ravnborg #include <linux/shm.h>
24a88b5ba8SSam Ravnborg #include <linux/uio.h>
25a88b5ba8SSam Ravnborg #include <linux/nfs_fs.h>
26a88b5ba8SSam Ravnborg #include <linux/quota.h>
27a88b5ba8SSam Ravnborg #include <linux/module.h>
28a88b5ba8SSam Ravnborg #include <linux/poll.h>
29a88b5ba8SSam Ravnborg #include <linux/personality.h>
30a88b5ba8SSam Ravnborg #include <linux/stat.h>
31a88b5ba8SSam Ravnborg #include <linux/filter.h>
32a88b5ba8SSam Ravnborg #include <linux/highmem.h>
33a88b5ba8SSam Ravnborg #include <linux/highuid.h>
34a88b5ba8SSam Ravnborg #include <linux/mman.h>
35a88b5ba8SSam Ravnborg #include <linux/ipv6.h>
36a88b5ba8SSam Ravnborg #include <linux/in.h>
37a88b5ba8SSam Ravnborg #include <linux/icmpv6.h>
38a88b5ba8SSam Ravnborg #include <linux/syscalls.h>
39a88b5ba8SSam Ravnborg #include <linux/sysctl.h>
40a88b5ba8SSam Ravnborg #include <linux/binfmts.h>
41a88b5ba8SSam Ravnborg #include <linux/dnotify.h>
42a88b5ba8SSam Ravnborg #include <linux/security.h>
43a88b5ba8SSam Ravnborg #include <linux/compat.h>
44a88b5ba8SSam Ravnborg #include <linux/vfs.h>
45a88b5ba8SSam Ravnborg #include <linux/ptrace.h>
465a0e3ad6STejun Heo #include <linux/slab.h>
47a88b5ba8SSam Ravnborg 
48a88b5ba8SSam Ravnborg #include <asm/types.h>
49a88b5ba8SSam Ravnborg #include <asm/uaccess.h>
50a88b5ba8SSam Ravnborg #include <asm/fpumacro.h>
51a88b5ba8SSam Ravnborg #include <asm/mmu_context.h>
52a88b5ba8SSam Ravnborg #include <asm/compat_signal.h>
53a88b5ba8SSam Ravnborg 
54a88b5ba8SSam Ravnborg #ifdef CONFIG_SYSVIPC
55a88b5ba8SSam Ravnborg asmlinkage long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr, u32 fifth)
56a88b5ba8SSam Ravnborg {
57a88b5ba8SSam Ravnborg 	int version;
58a88b5ba8SSam Ravnborg 
59a88b5ba8SSam Ravnborg 	version = call >> 16; /* hack for backward compatibility */
60a88b5ba8SSam Ravnborg 	call &= 0xffff;
61a88b5ba8SSam Ravnborg 
62a88b5ba8SSam Ravnborg 	switch (call) {
63a88b5ba8SSam Ravnborg 	case SEMTIMEDOP:
64a88b5ba8SSam Ravnborg 		if (fifth)
65a88b5ba8SSam Ravnborg 			/* sign extend semid */
66a88b5ba8SSam Ravnborg 			return compat_sys_semtimedop((int)first,
67a88b5ba8SSam Ravnborg 						     compat_ptr(ptr), second,
68a88b5ba8SSam Ravnborg 						     compat_ptr(fifth));
69a88b5ba8SSam Ravnborg 		/* else fall through for normal semop() */
70a88b5ba8SSam Ravnborg 	case SEMOP:
71a88b5ba8SSam Ravnborg 		/* struct sembuf is the same on 32 and 64bit :)) */
72a88b5ba8SSam Ravnborg 		/* sign extend semid */
73a88b5ba8SSam Ravnborg 		return sys_semtimedop((int)first, compat_ptr(ptr), second,
74a88b5ba8SSam Ravnborg 				      NULL);
75a88b5ba8SSam Ravnborg 	case SEMGET:
76a88b5ba8SSam Ravnborg 		/* sign extend key, nsems */
77a88b5ba8SSam Ravnborg 		return sys_semget((int)first, (int)second, third);
78a88b5ba8SSam Ravnborg 	case SEMCTL:
79a88b5ba8SSam Ravnborg 		/* sign extend semid, semnum */
80a88b5ba8SSam Ravnborg 		return compat_sys_semctl((int)first, (int)second, third,
81a88b5ba8SSam Ravnborg 					 compat_ptr(ptr));
82a88b5ba8SSam Ravnborg 
83a88b5ba8SSam Ravnborg 	case MSGSND:
84a88b5ba8SSam Ravnborg 		/* sign extend msqid */
85a88b5ba8SSam Ravnborg 		return compat_sys_msgsnd((int)first, (int)second, third,
86a88b5ba8SSam Ravnborg 					 compat_ptr(ptr));
87a88b5ba8SSam Ravnborg 	case MSGRCV:
88a88b5ba8SSam Ravnborg 		/* sign extend msqid, msgtyp */
89a88b5ba8SSam Ravnborg 		return compat_sys_msgrcv((int)first, second, (int)fifth,
90a88b5ba8SSam Ravnborg 					 third, version, compat_ptr(ptr));
91a88b5ba8SSam Ravnborg 	case MSGGET:
92a88b5ba8SSam Ravnborg 		/* sign extend key */
93a88b5ba8SSam Ravnborg 		return sys_msgget((int)first, second);
94a88b5ba8SSam Ravnborg 	case MSGCTL:
95a88b5ba8SSam Ravnborg 		/* sign extend msqid */
96a88b5ba8SSam Ravnborg 		return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
97a88b5ba8SSam Ravnborg 
98a88b5ba8SSam Ravnborg 	case SHMAT:
99a88b5ba8SSam Ravnborg 		/* sign extend shmid */
100a88b5ba8SSam Ravnborg 		return compat_sys_shmat((int)first, second, third, version,
101a88b5ba8SSam Ravnborg 					compat_ptr(ptr));
102a88b5ba8SSam Ravnborg 	case SHMDT:
103a88b5ba8SSam Ravnborg 		return sys_shmdt(compat_ptr(ptr));
104a88b5ba8SSam Ravnborg 	case SHMGET:
105a88b5ba8SSam Ravnborg 		/* sign extend key_t */
106a88b5ba8SSam Ravnborg 		return sys_shmget((int)first, second, third);
107a88b5ba8SSam Ravnborg 	case SHMCTL:
108a88b5ba8SSam Ravnborg 		/* sign extend shmid */
109a88b5ba8SSam Ravnborg 		return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
110a88b5ba8SSam Ravnborg 
111a88b5ba8SSam Ravnborg 	default:
112a88b5ba8SSam Ravnborg 		return -ENOSYS;
113a88b5ba8SSam Ravnborg 	};
114a88b5ba8SSam Ravnborg 
115a88b5ba8SSam Ravnborg 	return -ENOSYS;
116a88b5ba8SSam Ravnborg }
117a88b5ba8SSam Ravnborg #endif
118a88b5ba8SSam Ravnborg 
119a88b5ba8SSam Ravnborg asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
120a88b5ba8SSam Ravnborg {
121a88b5ba8SSam Ravnborg 	if ((int)high < 0)
122a88b5ba8SSam Ravnborg 		return -EINVAL;
123a88b5ba8SSam Ravnborg 	else
124a88b5ba8SSam Ravnborg 		return sys_truncate(path, (high << 32) | low);
125a88b5ba8SSam Ravnborg }
126a88b5ba8SSam Ravnborg 
127a88b5ba8SSam Ravnborg asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
128a88b5ba8SSam Ravnborg {
129a88b5ba8SSam Ravnborg 	if ((int)high < 0)
130a88b5ba8SSam Ravnborg 		return -EINVAL;
131a88b5ba8SSam Ravnborg 	else
132a88b5ba8SSam Ravnborg 		return sys_ftruncate(fd, (high << 32) | low);
133a88b5ba8SSam Ravnborg }
134a88b5ba8SSam Ravnborg 
135a88b5ba8SSam Ravnborg static int cp_compat_stat64(struct kstat *stat,
136a88b5ba8SSam Ravnborg 			    struct compat_stat64 __user *statbuf)
137a88b5ba8SSam Ravnborg {
138a88b5ba8SSam Ravnborg 	int err;
139a88b5ba8SSam Ravnborg 
140a88b5ba8SSam Ravnborg 	err  = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
141a88b5ba8SSam Ravnborg 	err |= put_user(stat->ino, &statbuf->st_ino);
142a88b5ba8SSam Ravnborg 	err |= put_user(stat->mode, &statbuf->st_mode);
143a88b5ba8SSam Ravnborg 	err |= put_user(stat->nlink, &statbuf->st_nlink);
144a88b5ba8SSam Ravnborg 	err |= put_user(stat->uid, &statbuf->st_uid);
145a88b5ba8SSam Ravnborg 	err |= put_user(stat->gid, &statbuf->st_gid);
146a88b5ba8SSam Ravnborg 	err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
147a88b5ba8SSam Ravnborg 	err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
148a88b5ba8SSam Ravnborg 	err |= put_user(stat->size, &statbuf->st_size);
149a88b5ba8SSam Ravnborg 	err |= put_user(stat->blksize, &statbuf->st_blksize);
150a88b5ba8SSam Ravnborg 	err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
151a88b5ba8SSam Ravnborg 	err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
152a88b5ba8SSam Ravnborg 	err |= put_user(stat->blocks, &statbuf->st_blocks);
153a88b5ba8SSam Ravnborg 	err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
154a88b5ba8SSam Ravnborg 	err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
155a88b5ba8SSam Ravnborg 	err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
156a88b5ba8SSam Ravnborg 	err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
157a88b5ba8SSam Ravnborg 	err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
158a88b5ba8SSam Ravnborg 	err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
159a88b5ba8SSam Ravnborg 	err |= put_user(0, &statbuf->__unused4);
160a88b5ba8SSam Ravnborg 	err |= put_user(0, &statbuf->__unused5);
161a88b5ba8SSam Ravnborg 
162a88b5ba8SSam Ravnborg 	return err;
163a88b5ba8SSam Ravnborg }
164a88b5ba8SSam Ravnborg 
165*c7887325SDavid Howells asmlinkage long compat_sys_stat64(const char __user * filename,
166a88b5ba8SSam Ravnborg 		struct compat_stat64 __user *statbuf)
167a88b5ba8SSam Ravnborg {
168a88b5ba8SSam Ravnborg 	struct kstat stat;
169a88b5ba8SSam Ravnborg 	int error = vfs_stat(filename, &stat);
170a88b5ba8SSam Ravnborg 
171a88b5ba8SSam Ravnborg 	if (!error)
172a88b5ba8SSam Ravnborg 		error = cp_compat_stat64(&stat, statbuf);
173a88b5ba8SSam Ravnborg 	return error;
174a88b5ba8SSam Ravnborg }
175a88b5ba8SSam Ravnborg 
176*c7887325SDavid Howells asmlinkage long compat_sys_lstat64(const char __user * filename,
177a88b5ba8SSam Ravnborg 		struct compat_stat64 __user *statbuf)
178a88b5ba8SSam Ravnborg {
179a88b5ba8SSam Ravnborg 	struct kstat stat;
180a88b5ba8SSam Ravnborg 	int error = vfs_lstat(filename, &stat);
181a88b5ba8SSam Ravnborg 
182a88b5ba8SSam Ravnborg 	if (!error)
183a88b5ba8SSam Ravnborg 		error = cp_compat_stat64(&stat, statbuf);
184a88b5ba8SSam Ravnborg 	return error;
185a88b5ba8SSam Ravnborg }
186a88b5ba8SSam Ravnborg 
187a88b5ba8SSam Ravnborg asmlinkage long compat_sys_fstat64(unsigned int fd,
188a88b5ba8SSam Ravnborg 		struct compat_stat64 __user * statbuf)
189a88b5ba8SSam Ravnborg {
190a88b5ba8SSam Ravnborg 	struct kstat stat;
191a88b5ba8SSam Ravnborg 	int error = vfs_fstat(fd, &stat);
192a88b5ba8SSam Ravnborg 
193a88b5ba8SSam Ravnborg 	if (!error)
194a88b5ba8SSam Ravnborg 		error = cp_compat_stat64(&stat, statbuf);
195a88b5ba8SSam Ravnborg 	return error;
196a88b5ba8SSam Ravnborg }
197a88b5ba8SSam Ravnborg 
198*c7887325SDavid Howells asmlinkage long compat_sys_fstatat64(unsigned int dfd,
199*c7887325SDavid Howells 		const char __user *filename,
200a88b5ba8SSam Ravnborg 		struct compat_stat64 __user * statbuf, int flag)
201a88b5ba8SSam Ravnborg {
202a88b5ba8SSam Ravnborg 	struct kstat stat;
2030112fc22SOleg Drokin 	int error;
204a88b5ba8SSam Ravnborg 
2050112fc22SOleg Drokin 	error = vfs_fstatat(dfd, filename, &stat, flag);
2060112fc22SOleg Drokin 	if (error)
207a88b5ba8SSam Ravnborg 		return error;
2080112fc22SOleg Drokin 	return cp_compat_stat64(&stat, statbuf);
209a88b5ba8SSam Ravnborg }
210a88b5ba8SSam Ravnborg 
211a88b5ba8SSam Ravnborg asmlinkage long compat_sys_sysfs(int option, u32 arg1, u32 arg2)
212a88b5ba8SSam Ravnborg {
213a88b5ba8SSam Ravnborg 	return sys_sysfs(option, arg1, arg2);
214a88b5ba8SSam Ravnborg }
215a88b5ba8SSam Ravnborg 
216a88b5ba8SSam Ravnborg asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
217a88b5ba8SSam Ravnborg {
218a88b5ba8SSam Ravnborg 	struct timespec t;
219a88b5ba8SSam Ravnborg 	int ret;
220a88b5ba8SSam Ravnborg 	mm_segment_t old_fs = get_fs ();
221a88b5ba8SSam Ravnborg 
222a88b5ba8SSam Ravnborg 	set_fs (KERNEL_DS);
223a88b5ba8SSam Ravnborg 	ret = sys_sched_rr_get_interval(pid, (struct timespec __user *) &t);
224a88b5ba8SSam Ravnborg 	set_fs (old_fs);
225a88b5ba8SSam Ravnborg 	if (put_compat_timespec(&t, interval))
226a88b5ba8SSam Ravnborg 		return -EFAULT;
227a88b5ba8SSam Ravnborg 	return ret;
228a88b5ba8SSam Ravnborg }
229a88b5ba8SSam Ravnborg 
230a88b5ba8SSam Ravnborg asmlinkage long compat_sys_rt_sigprocmask(int how,
231a88b5ba8SSam Ravnborg 					  compat_sigset_t __user *set,
232a88b5ba8SSam Ravnborg 					  compat_sigset_t __user *oset,
233a88b5ba8SSam Ravnborg 					  compat_size_t sigsetsize)
234a88b5ba8SSam Ravnborg {
235a88b5ba8SSam Ravnborg 	sigset_t s;
236a88b5ba8SSam Ravnborg 	compat_sigset_t s32;
237a88b5ba8SSam Ravnborg 	int ret;
238a88b5ba8SSam Ravnborg 	mm_segment_t old_fs = get_fs();
239a88b5ba8SSam Ravnborg 
240a88b5ba8SSam Ravnborg 	if (set) {
241a88b5ba8SSam Ravnborg 		if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
242a88b5ba8SSam Ravnborg 			return -EFAULT;
243a88b5ba8SSam Ravnborg 		switch (_NSIG_WORDS) {
244a88b5ba8SSam Ravnborg 		case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
245a88b5ba8SSam Ravnborg 		case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
246a88b5ba8SSam Ravnborg 		case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
247a88b5ba8SSam Ravnborg 		case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
248a88b5ba8SSam Ravnborg 		}
249a88b5ba8SSam Ravnborg 	}
250a88b5ba8SSam Ravnborg 	set_fs (KERNEL_DS);
251a88b5ba8SSam Ravnborg 	ret = sys_rt_sigprocmask(how,
252a88b5ba8SSam Ravnborg 				 set ? (sigset_t __user *) &s : NULL,
253a88b5ba8SSam Ravnborg 				 oset ? (sigset_t __user *) &s : NULL,
254a88b5ba8SSam Ravnborg 				 sigsetsize);
255a88b5ba8SSam Ravnborg 	set_fs (old_fs);
256a88b5ba8SSam Ravnborg 	if (ret) return ret;
257a88b5ba8SSam Ravnborg 	if (oset) {
258a88b5ba8SSam Ravnborg 		switch (_NSIG_WORDS) {
259a88b5ba8SSam Ravnborg 		case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
260a88b5ba8SSam Ravnborg 		case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
261a88b5ba8SSam Ravnborg 		case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
262a88b5ba8SSam Ravnborg 		case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
263a88b5ba8SSam Ravnborg 		}
264a88b5ba8SSam Ravnborg 		if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
265a88b5ba8SSam Ravnborg 			return -EFAULT;
266a88b5ba8SSam Ravnborg 	}
267a88b5ba8SSam Ravnborg 	return 0;
268a88b5ba8SSam Ravnborg }
269a88b5ba8SSam Ravnborg 
270a88b5ba8SSam Ravnborg asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
271a88b5ba8SSam Ravnborg 				    compat_size_t sigsetsize)
272a88b5ba8SSam Ravnborg {
273a88b5ba8SSam Ravnborg 	sigset_t s;
274a88b5ba8SSam Ravnborg 	compat_sigset_t s32;
275a88b5ba8SSam Ravnborg 	int ret;
276a88b5ba8SSam Ravnborg 	mm_segment_t old_fs = get_fs();
277a88b5ba8SSam Ravnborg 
278a88b5ba8SSam Ravnborg 	set_fs (KERNEL_DS);
279a88b5ba8SSam Ravnborg 	ret = sys_rt_sigpending((sigset_t __user *) &s, sigsetsize);
280a88b5ba8SSam Ravnborg 	set_fs (old_fs);
281a88b5ba8SSam Ravnborg 	if (!ret) {
282a88b5ba8SSam Ravnborg 		switch (_NSIG_WORDS) {
283a88b5ba8SSam Ravnborg 		case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
284a88b5ba8SSam Ravnborg 		case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
285a88b5ba8SSam Ravnborg 		case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
286a88b5ba8SSam Ravnborg 		case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
287a88b5ba8SSam Ravnborg 		}
288a88b5ba8SSam Ravnborg 		if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
289a88b5ba8SSam Ravnborg 			return -EFAULT;
290a88b5ba8SSam Ravnborg 	}
291a88b5ba8SSam Ravnborg 	return ret;
292a88b5ba8SSam Ravnborg }
293a88b5ba8SSam Ravnborg 
294a88b5ba8SSam Ravnborg asmlinkage long compat_sys_rt_sigqueueinfo(int pid, int sig,
295a88b5ba8SSam Ravnborg 					   struct compat_siginfo __user *uinfo)
296a88b5ba8SSam Ravnborg {
297a88b5ba8SSam Ravnborg 	siginfo_t info;
298a88b5ba8SSam Ravnborg 	int ret;
299a88b5ba8SSam Ravnborg 	mm_segment_t old_fs = get_fs();
300a88b5ba8SSam Ravnborg 
301a88b5ba8SSam Ravnborg 	if (copy_siginfo_from_user32(&info, uinfo))
302a88b5ba8SSam Ravnborg 		return -EFAULT;
303a88b5ba8SSam Ravnborg 
304a88b5ba8SSam Ravnborg 	set_fs (KERNEL_DS);
305a88b5ba8SSam Ravnborg 	ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *) &info);
306a88b5ba8SSam Ravnborg 	set_fs (old_fs);
307a88b5ba8SSam Ravnborg 	return ret;
308a88b5ba8SSam Ravnborg }
309a88b5ba8SSam Ravnborg 
310a88b5ba8SSam Ravnborg asmlinkage long compat_sys_sigaction(int sig, struct old_sigaction32 __user *act,
311a88b5ba8SSam Ravnborg 				     struct old_sigaction32 __user *oact)
312a88b5ba8SSam Ravnborg {
313a88b5ba8SSam Ravnborg         struct k_sigaction new_ka, old_ka;
314a88b5ba8SSam Ravnborg         int ret;
315a88b5ba8SSam Ravnborg 
316a88b5ba8SSam Ravnborg 	WARN_ON_ONCE(sig >= 0);
317a88b5ba8SSam Ravnborg 	sig = -sig;
318a88b5ba8SSam Ravnborg 
319a88b5ba8SSam Ravnborg         if (act) {
320a88b5ba8SSam Ravnborg 		compat_old_sigset_t mask;
321a88b5ba8SSam Ravnborg 		u32 u_handler, u_restorer;
322a88b5ba8SSam Ravnborg 
323a88b5ba8SSam Ravnborg 		ret = get_user(u_handler, &act->sa_handler);
324a88b5ba8SSam Ravnborg 		new_ka.sa.sa_handler =  compat_ptr(u_handler);
325a88b5ba8SSam Ravnborg 		ret |= __get_user(u_restorer, &act->sa_restorer);
326a88b5ba8SSam Ravnborg 		new_ka.sa.sa_restorer = compat_ptr(u_restorer);
327a88b5ba8SSam Ravnborg 		ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
328a88b5ba8SSam Ravnborg 		ret |= __get_user(mask, &act->sa_mask);
329a88b5ba8SSam Ravnborg 		if (ret)
330a88b5ba8SSam Ravnborg 			return ret;
331a88b5ba8SSam Ravnborg 		new_ka.ka_restorer = NULL;
332a88b5ba8SSam Ravnborg 		siginitset(&new_ka.sa.sa_mask, mask);
333a88b5ba8SSam Ravnborg         }
334a88b5ba8SSam Ravnborg 
335a88b5ba8SSam Ravnborg         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
336a88b5ba8SSam Ravnborg 
337a88b5ba8SSam Ravnborg 	if (!ret && oact) {
338a88b5ba8SSam Ravnborg 		ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
339a88b5ba8SSam Ravnborg 		ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
340a88b5ba8SSam Ravnborg 		ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
341a88b5ba8SSam Ravnborg 		ret |= __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
342a88b5ba8SSam Ravnborg         }
343a88b5ba8SSam Ravnborg 
344a88b5ba8SSam Ravnborg 	return ret;
345a88b5ba8SSam Ravnborg }
346a88b5ba8SSam Ravnborg 
347a88b5ba8SSam Ravnborg asmlinkage long compat_sys_rt_sigaction(int sig,
348a88b5ba8SSam Ravnborg 					struct sigaction32 __user *act,
349a88b5ba8SSam Ravnborg 					struct sigaction32 __user *oact,
350a88b5ba8SSam Ravnborg 					void __user *restorer,
351a88b5ba8SSam Ravnborg 					compat_size_t sigsetsize)
352a88b5ba8SSam Ravnborg {
353a88b5ba8SSam Ravnborg         struct k_sigaction new_ka, old_ka;
354a88b5ba8SSam Ravnborg         int ret;
355a88b5ba8SSam Ravnborg 	compat_sigset_t set32;
356a88b5ba8SSam Ravnborg 
357a88b5ba8SSam Ravnborg         /* XXX: Don't preclude handling different sized sigset_t's.  */
358a88b5ba8SSam Ravnborg         if (sigsetsize != sizeof(compat_sigset_t))
359a88b5ba8SSam Ravnborg                 return -EINVAL;
360a88b5ba8SSam Ravnborg 
361a88b5ba8SSam Ravnborg         if (act) {
362a88b5ba8SSam Ravnborg 		u32 u_handler, u_restorer;
363a88b5ba8SSam Ravnborg 
364a88b5ba8SSam Ravnborg 		new_ka.ka_restorer = restorer;
365a88b5ba8SSam Ravnborg 		ret = get_user(u_handler, &act->sa_handler);
366a88b5ba8SSam Ravnborg 		new_ka.sa.sa_handler =  compat_ptr(u_handler);
367a88b5ba8SSam Ravnborg 		ret |= __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t));
368a88b5ba8SSam Ravnborg 		switch (_NSIG_WORDS) {
369a88b5ba8SSam Ravnborg 		case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6] | (((long)set32.sig[7]) << 32);
370a88b5ba8SSam Ravnborg 		case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4] | (((long)set32.sig[5]) << 32);
371a88b5ba8SSam Ravnborg 		case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2] | (((long)set32.sig[3]) << 32);
372a88b5ba8SSam Ravnborg 		case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0] | (((long)set32.sig[1]) << 32);
373a88b5ba8SSam Ravnborg 		}
374a88b5ba8SSam Ravnborg 		ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
375a88b5ba8SSam Ravnborg 		ret |= __get_user(u_restorer, &act->sa_restorer);
376a88b5ba8SSam Ravnborg 		new_ka.sa.sa_restorer = compat_ptr(u_restorer);
377a88b5ba8SSam Ravnborg                 if (ret)
378a88b5ba8SSam Ravnborg                 	return -EFAULT;
379a88b5ba8SSam Ravnborg 	}
380a88b5ba8SSam Ravnborg 
381a88b5ba8SSam Ravnborg 	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
382a88b5ba8SSam Ravnborg 
383a88b5ba8SSam Ravnborg 	if (!ret && oact) {
384a88b5ba8SSam Ravnborg 		switch (_NSIG_WORDS) {
385a88b5ba8SSam Ravnborg 		case 4: set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32); set32.sig[6] = old_ka.sa.sa_mask.sig[3];
386a88b5ba8SSam Ravnborg 		case 3: set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32); set32.sig[4] = old_ka.sa.sa_mask.sig[2];
387a88b5ba8SSam Ravnborg 		case 2: set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32); set32.sig[2] = old_ka.sa.sa_mask.sig[1];
388a88b5ba8SSam Ravnborg 		case 1: set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32); set32.sig[0] = old_ka.sa.sa_mask.sig[0];
389a88b5ba8SSam Ravnborg 		}
390a88b5ba8SSam Ravnborg 		ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
391a88b5ba8SSam Ravnborg 		ret |= __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t));
392a88b5ba8SSam Ravnborg 		ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
393a88b5ba8SSam Ravnborg 		ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
394a88b5ba8SSam Ravnborg 		if (ret)
395a88b5ba8SSam Ravnborg 			ret = -EFAULT;
396a88b5ba8SSam Ravnborg         }
397a88b5ba8SSam Ravnborg 
398a88b5ba8SSam Ravnborg         return ret;
399a88b5ba8SSam Ravnborg }
400a88b5ba8SSam Ravnborg 
401a88b5ba8SSam Ravnborg /*
402a88b5ba8SSam Ravnborg  * sparc32_execve() executes a new program after the asm stub has set
403a88b5ba8SSam Ravnborg  * things up for us.  This should basically do what I want it to.
404a88b5ba8SSam Ravnborg  */
405a88b5ba8SSam Ravnborg asmlinkage long sparc32_execve(struct pt_regs *regs)
406a88b5ba8SSam Ravnborg {
407a88b5ba8SSam Ravnborg 	int error, base = 0;
408a88b5ba8SSam Ravnborg 	char *filename;
409a88b5ba8SSam Ravnborg 
410a88b5ba8SSam Ravnborg 	/* User register window flush is done by entry.S */
411a88b5ba8SSam Ravnborg 
412a88b5ba8SSam Ravnborg 	/* Check for indirect call. */
413a88b5ba8SSam Ravnborg 	if ((u32)regs->u_regs[UREG_G1] == 0)
414a88b5ba8SSam Ravnborg 		base = 1;
415a88b5ba8SSam Ravnborg 
416a88b5ba8SSam Ravnborg 	filename = getname(compat_ptr(regs->u_regs[base + UREG_I0]));
417a88b5ba8SSam Ravnborg 	error = PTR_ERR(filename);
418a88b5ba8SSam Ravnborg 	if (IS_ERR(filename))
419a88b5ba8SSam Ravnborg 		goto out;
420a88b5ba8SSam Ravnborg 
421a88b5ba8SSam Ravnborg 	error = compat_do_execve(filename,
422a88b5ba8SSam Ravnborg 				 compat_ptr(regs->u_regs[base + UREG_I1]),
423a88b5ba8SSam Ravnborg 				 compat_ptr(regs->u_regs[base + UREG_I2]), regs);
424a88b5ba8SSam Ravnborg 
425a88b5ba8SSam Ravnborg 	putname(filename);
426a88b5ba8SSam Ravnborg 
427a88b5ba8SSam Ravnborg 	if (!error) {
428a88b5ba8SSam Ravnborg 		fprs_write(0);
429a88b5ba8SSam Ravnborg 		current_thread_info()->xfsr[0] = 0;
430a88b5ba8SSam Ravnborg 		current_thread_info()->fpsaved[0] = 0;
431a88b5ba8SSam Ravnborg 		regs->tstate &= ~TSTATE_PEF;
432a88b5ba8SSam Ravnborg 	}
433a88b5ba8SSam Ravnborg out:
434a88b5ba8SSam Ravnborg 	return error;
435a88b5ba8SSam Ravnborg }
436a88b5ba8SSam Ravnborg 
437a88b5ba8SSam Ravnborg #ifdef CONFIG_MODULES
438a88b5ba8SSam Ravnborg 
439a88b5ba8SSam Ravnborg asmlinkage long sys32_init_module(void __user *umod, u32 len,
440a88b5ba8SSam Ravnborg 				  const char __user *uargs)
441a88b5ba8SSam Ravnborg {
442a88b5ba8SSam Ravnborg 	return sys_init_module(umod, len, uargs);
443a88b5ba8SSam Ravnborg }
444a88b5ba8SSam Ravnborg 
445a88b5ba8SSam Ravnborg asmlinkage long sys32_delete_module(const char __user *name_user,
446a88b5ba8SSam Ravnborg 				    unsigned int flags)
447a88b5ba8SSam Ravnborg {
448a88b5ba8SSam Ravnborg 	return sys_delete_module(name_user, flags);
449a88b5ba8SSam Ravnborg }
450a88b5ba8SSam Ravnborg 
451a88b5ba8SSam Ravnborg #else /* CONFIG_MODULES */
452a88b5ba8SSam Ravnborg 
453a88b5ba8SSam Ravnborg asmlinkage long sys32_init_module(const char __user *name_user,
454a88b5ba8SSam Ravnborg 				  struct module __user *mod_user)
455a88b5ba8SSam Ravnborg {
456a88b5ba8SSam Ravnborg 	return -ENOSYS;
457a88b5ba8SSam Ravnborg }
458a88b5ba8SSam Ravnborg 
459a88b5ba8SSam Ravnborg asmlinkage long sys32_delete_module(const char __user *name_user)
460a88b5ba8SSam Ravnborg {
461a88b5ba8SSam Ravnborg 	return -ENOSYS;
462a88b5ba8SSam Ravnborg }
463a88b5ba8SSam Ravnborg 
464a88b5ba8SSam Ravnborg #endif  /* CONFIG_MODULES */
465a88b5ba8SSam Ravnborg 
466a88b5ba8SSam Ravnborg asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
467a88b5ba8SSam Ravnborg 					char __user *ubuf,
468a88b5ba8SSam Ravnborg 					compat_size_t count,
469a88b5ba8SSam Ravnborg 					unsigned long poshi,
470a88b5ba8SSam Ravnborg 					unsigned long poslo)
471a88b5ba8SSam Ravnborg {
472a88b5ba8SSam Ravnborg 	return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
473a88b5ba8SSam Ravnborg }
474a88b5ba8SSam Ravnborg 
475a88b5ba8SSam Ravnborg asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
476a88b5ba8SSam Ravnborg 					 char __user *ubuf,
477a88b5ba8SSam Ravnborg 					 compat_size_t count,
478a88b5ba8SSam Ravnborg 					 unsigned long poshi,
479a88b5ba8SSam Ravnborg 					 unsigned long poslo)
480a88b5ba8SSam Ravnborg {
481a88b5ba8SSam Ravnborg 	return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
482a88b5ba8SSam Ravnborg }
483a88b5ba8SSam Ravnborg 
484a88b5ba8SSam Ravnborg asmlinkage long compat_sys_readahead(int fd,
485a88b5ba8SSam Ravnborg 				     unsigned long offhi,
486a88b5ba8SSam Ravnborg 				     unsigned long offlo,
487a88b5ba8SSam Ravnborg 				     compat_size_t count)
488a88b5ba8SSam Ravnborg {
489a88b5ba8SSam Ravnborg 	return sys_readahead(fd, (offhi << 32) | offlo, count);
490a88b5ba8SSam Ravnborg }
491a88b5ba8SSam Ravnborg 
492a88b5ba8SSam Ravnborg long compat_sys_fadvise64(int fd,
493a88b5ba8SSam Ravnborg 			  unsigned long offhi,
494a88b5ba8SSam Ravnborg 			  unsigned long offlo,
495a88b5ba8SSam Ravnborg 			  compat_size_t len, int advice)
496a88b5ba8SSam Ravnborg {
497a88b5ba8SSam Ravnborg 	return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
498a88b5ba8SSam Ravnborg }
499a88b5ba8SSam Ravnborg 
500a88b5ba8SSam Ravnborg long compat_sys_fadvise64_64(int fd,
501a88b5ba8SSam Ravnborg 			     unsigned long offhi, unsigned long offlo,
502a88b5ba8SSam Ravnborg 			     unsigned long lenhi, unsigned long lenlo,
503a88b5ba8SSam Ravnborg 			     int advice)
504a88b5ba8SSam Ravnborg {
505a88b5ba8SSam Ravnborg 	return sys_fadvise64_64(fd,
506a88b5ba8SSam Ravnborg 				(offhi << 32) | offlo,
507a88b5ba8SSam Ravnborg 				(lenhi << 32) | lenlo,
508a88b5ba8SSam Ravnborg 				advice);
509a88b5ba8SSam Ravnborg }
510a88b5ba8SSam Ravnborg 
511a88b5ba8SSam Ravnborg asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
512a88b5ba8SSam Ravnborg 				    compat_off_t __user *offset,
513a88b5ba8SSam Ravnborg 				    compat_size_t count)
514a88b5ba8SSam Ravnborg {
515a88b5ba8SSam Ravnborg 	mm_segment_t old_fs = get_fs();
516a88b5ba8SSam Ravnborg 	int ret;
517a88b5ba8SSam Ravnborg 	off_t of;
518a88b5ba8SSam Ravnborg 
519a88b5ba8SSam Ravnborg 	if (offset && get_user(of, offset))
520a88b5ba8SSam Ravnborg 		return -EFAULT;
521a88b5ba8SSam Ravnborg 
522a88b5ba8SSam Ravnborg 	set_fs(KERNEL_DS);
523a88b5ba8SSam Ravnborg 	ret = sys_sendfile(out_fd, in_fd,
524a88b5ba8SSam Ravnborg 			   offset ? (off_t __user *) &of : NULL,
525a88b5ba8SSam Ravnborg 			   count);
526a88b5ba8SSam Ravnborg 	set_fs(old_fs);
527a88b5ba8SSam Ravnborg 
528a88b5ba8SSam Ravnborg 	if (offset && put_user(of, offset))
529a88b5ba8SSam Ravnborg 		return -EFAULT;
530a88b5ba8SSam Ravnborg 
531a88b5ba8SSam Ravnborg 	return ret;
532a88b5ba8SSam Ravnborg }
533a88b5ba8SSam Ravnborg 
534a88b5ba8SSam Ravnborg asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
535a88b5ba8SSam Ravnborg 				      compat_loff_t __user *offset,
536a88b5ba8SSam Ravnborg 				      compat_size_t count)
537a88b5ba8SSam Ravnborg {
538a88b5ba8SSam Ravnborg 	mm_segment_t old_fs = get_fs();
539a88b5ba8SSam Ravnborg 	int ret;
540a88b5ba8SSam Ravnborg 	loff_t lof;
541a88b5ba8SSam Ravnborg 
542a88b5ba8SSam Ravnborg 	if (offset && get_user(lof, offset))
543a88b5ba8SSam Ravnborg 		return -EFAULT;
544a88b5ba8SSam Ravnborg 
545a88b5ba8SSam Ravnborg 	set_fs(KERNEL_DS);
546a88b5ba8SSam Ravnborg 	ret = sys_sendfile64(out_fd, in_fd,
547a88b5ba8SSam Ravnborg 			     offset ? (loff_t __user *) &lof : NULL,
548a88b5ba8SSam Ravnborg 			     count);
549a88b5ba8SSam Ravnborg 	set_fs(old_fs);
550a88b5ba8SSam Ravnborg 
551a88b5ba8SSam Ravnborg 	if (offset && put_user(lof, offset))
552a88b5ba8SSam Ravnborg 		return -EFAULT;
553a88b5ba8SSam Ravnborg 
554a88b5ba8SSam Ravnborg 	return ret;
555a88b5ba8SSam Ravnborg }
556a88b5ba8SSam Ravnborg 
557a88b5ba8SSam Ravnborg /* This is just a version for 32-bit applications which does
558a88b5ba8SSam Ravnborg  * not force O_LARGEFILE on.
559a88b5ba8SSam Ravnborg  */
560a88b5ba8SSam Ravnborg 
561a88b5ba8SSam Ravnborg asmlinkage long sparc32_open(const char __user *filename,
562a88b5ba8SSam Ravnborg 			     int flags, int mode)
563a88b5ba8SSam Ravnborg {
564a88b5ba8SSam Ravnborg 	return do_sys_open(AT_FDCWD, filename, flags, mode);
565a88b5ba8SSam Ravnborg }
566a88b5ba8SSam Ravnborg 
567a88b5ba8SSam Ravnborg long sys32_lookup_dcookie(unsigned long cookie_high,
568a88b5ba8SSam Ravnborg 			  unsigned long cookie_low,
569a88b5ba8SSam Ravnborg 			  char __user *buf, size_t len)
570a88b5ba8SSam Ravnborg {
571a88b5ba8SSam Ravnborg 	return sys_lookup_dcookie((cookie_high << 32) | cookie_low,
572a88b5ba8SSam Ravnborg 				  buf, len);
573a88b5ba8SSam Ravnborg }
574a88b5ba8SSam Ravnborg 
575a88b5ba8SSam Ravnborg long compat_sync_file_range(int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, int flags)
576a88b5ba8SSam Ravnborg {
577a88b5ba8SSam Ravnborg 	return sys_sync_file_range(fd,
578a88b5ba8SSam Ravnborg 				   (off_high << 32) | off_low,
579a88b5ba8SSam Ravnborg 				   (nb_high << 32) | nb_low,
580a88b5ba8SSam Ravnborg 				   flags);
581a88b5ba8SSam Ravnborg }
582a88b5ba8SSam Ravnborg 
583a88b5ba8SSam Ravnborg asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
584a88b5ba8SSam Ravnborg 				     u32 lenhi, u32 lenlo)
585a88b5ba8SSam Ravnborg {
586a88b5ba8SSam Ravnborg 	return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
587a88b5ba8SSam Ravnborg 			     ((loff_t)lenhi << 32) | lenlo);
588a88b5ba8SSam Ravnborg }
589