Merge tag 'xtensa-20180225' of git://github.com/jcmvbkbc/linux-xtensa
[cris-mirror.git] / arch / sparc / kernel / sys_sparc32.c
blob6d964bdefbaa96ca74e9c2ea84cb4caba0708fdb
1 // SPDX-License-Identifier: GPL-2.0
2 /* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
7 * These routines maintain argument size conversion between 32bit and 64bit
8 * environment.
9 */
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/capability.h>
14 #include <linux/fs.h>
15 #include <linux/mm.h>
16 #include <linux/file.h>
17 #include <linux/signal.h>
18 #include <linux/resource.h>
19 #include <linux/times.h>
20 #include <linux/smp.h>
21 #include <linux/sem.h>
22 #include <linux/msg.h>
23 #include <linux/shm.h>
24 #include <linux/uio.h>
25 #include <linux/nfs_fs.h>
26 #include <linux/quota.h>
27 #include <linux/poll.h>
28 #include <linux/personality.h>
29 #include <linux/stat.h>
30 #include <linux/filter.h>
31 #include <linux/highmem.h>
32 #include <linux/highuid.h>
33 #include <linux/mman.h>
34 #include <linux/ipv6.h>
35 #include <linux/in.h>
36 #include <linux/icmpv6.h>
37 #include <linux/syscalls.h>
38 #include <linux/sysctl.h>
39 #include <linux/binfmts.h>
40 #include <linux/dnotify.h>
41 #include <linux/security.h>
42 #include <linux/compat.h>
43 #include <linux/vfs.h>
44 #include <linux/ptrace.h>
45 #include <linux/slab.h>
47 #include <asm/types.h>
48 #include <linux/uaccess.h>
49 #include <asm/fpumacro.h>
50 #include <asm/mmu_context.h>
51 #include <asm/compat_signal.h>
53 #include "systbls.h"
55 asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
57 if ((int)high < 0)
58 return -EINVAL;
59 else
60 return sys_truncate(path, (high << 32) | low);
63 asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
65 if ((int)high < 0)
66 return -EINVAL;
67 else
68 return sys_ftruncate(fd, (high << 32) | low);
71 static int cp_compat_stat64(struct kstat *stat,
72 struct compat_stat64 __user *statbuf)
74 int err;
76 err = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
77 err |= put_user(stat->ino, &statbuf->st_ino);
78 err |= put_user(stat->mode, &statbuf->st_mode);
79 err |= put_user(stat->nlink, &statbuf->st_nlink);
80 err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
81 err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
82 err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
83 err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
84 err |= put_user(stat->size, &statbuf->st_size);
85 err |= put_user(stat->blksize, &statbuf->st_blksize);
86 err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
87 err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
88 err |= put_user(stat->blocks, &statbuf->st_blocks);
89 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
90 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
91 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
92 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
93 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
94 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
95 err |= put_user(0, &statbuf->__unused4);
96 err |= put_user(0, &statbuf->__unused5);
98 return err;
101 asmlinkage long compat_sys_stat64(const char __user * filename,
102 struct compat_stat64 __user *statbuf)
104 struct kstat stat;
105 int error = vfs_stat(filename, &stat);
107 if (!error)
108 error = cp_compat_stat64(&stat, statbuf);
109 return error;
112 asmlinkage long compat_sys_lstat64(const char __user * filename,
113 struct compat_stat64 __user *statbuf)
115 struct kstat stat;
116 int error = vfs_lstat(filename, &stat);
118 if (!error)
119 error = cp_compat_stat64(&stat, statbuf);
120 return error;
123 asmlinkage long compat_sys_fstat64(unsigned int fd,
124 struct compat_stat64 __user * statbuf)
126 struct kstat stat;
127 int error = vfs_fstat(fd, &stat);
129 if (!error)
130 error = cp_compat_stat64(&stat, statbuf);
131 return error;
134 asmlinkage long compat_sys_fstatat64(unsigned int dfd,
135 const char __user *filename,
136 struct compat_stat64 __user * statbuf, int flag)
138 struct kstat stat;
139 int error;
141 error = vfs_fstatat(dfd, filename, &stat, flag);
142 if (error)
143 return error;
144 return cp_compat_stat64(&stat, statbuf);
147 COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig,
148 struct compat_old_sigaction __user *,act,
149 struct compat_old_sigaction __user *,oact)
151 WARN_ON_ONCE(sig >= 0);
152 return compat_sys_sigaction(-sig, act, oact);
155 COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig,
156 struct compat_sigaction __user *,act,
157 struct compat_sigaction __user *,oact,
158 void __user *,restorer,
159 compat_size_t,sigsetsize)
161 struct k_sigaction new_ka, old_ka;
162 int ret;
164 /* XXX: Don't preclude handling different sized sigset_t's. */
165 if (sigsetsize != sizeof(compat_sigset_t))
166 return -EINVAL;
168 if (act) {
169 u32 u_handler, u_restorer;
171 new_ka.ka_restorer = restorer;
172 ret = get_user(u_handler, &act->sa_handler);
173 new_ka.sa.sa_handler = compat_ptr(u_handler);
174 ret |= get_compat_sigset(&new_ka.sa.sa_mask, &act->sa_mask);
175 ret |= get_user(new_ka.sa.sa_flags, &act->sa_flags);
176 ret |= get_user(u_restorer, &act->sa_restorer);
177 new_ka.sa.sa_restorer = compat_ptr(u_restorer);
178 if (ret)
179 return -EFAULT;
182 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
184 if (!ret && oact) {
185 ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
186 ret |= put_compat_sigset(&oact->sa_mask, &old_ka.sa.sa_mask,
187 sizeof(oact->sa_mask));
188 ret |= put_user(old_ka.sa.sa_flags, &oact->sa_flags);
189 ret |= put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
190 if (ret)
191 ret = -EFAULT;
194 return ret;
197 asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
198 char __user *ubuf,
199 compat_size_t count,
200 unsigned long poshi,
201 unsigned long poslo)
203 return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
206 asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
207 char __user *ubuf,
208 compat_size_t count,
209 unsigned long poshi,
210 unsigned long poslo)
212 return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
215 asmlinkage long compat_sys_readahead(int fd,
216 unsigned long offhi,
217 unsigned long offlo,
218 compat_size_t count)
220 return sys_readahead(fd, (offhi << 32) | offlo, count);
223 long compat_sys_fadvise64(int fd,
224 unsigned long offhi,
225 unsigned long offlo,
226 compat_size_t len, int advice)
228 return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
231 long compat_sys_fadvise64_64(int fd,
232 unsigned long offhi, unsigned long offlo,
233 unsigned long lenhi, unsigned long lenlo,
234 int advice)
236 return sys_fadvise64_64(fd,
237 (offhi << 32) | offlo,
238 (lenhi << 32) | lenlo,
239 advice);
242 long sys32_sync_file_range(unsigned int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, unsigned int flags)
244 return sys_sync_file_range(fd,
245 (off_high << 32) | off_low,
246 (nb_high << 32) | nb_low,
247 flags);
250 asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
251 u32 lenhi, u32 lenlo)
253 return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
254 ((loff_t)lenhi << 32) | lenlo);