fs: add ksys_fallocate() wrapper; remove in-kernel calls to sys_fallocate()
[linux-block.git] / arch / sparc / kernel / sys_sparc32.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
bc5a2e64 2/* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
1da177e4
LT
3 *
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
bc5a2e64 5 * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
1da177e4
LT
6 *
7 * These routines maintain argument size conversion between 32bit and 64bit
8 * environment.
9 */
10
1da177e4
LT
11#include <linux/kernel.h>
12#include <linux/sched.h>
a9415644 13#include <linux/capability.h>
1da177e4
LT
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>
1da177e4 20#include <linux/smp.h>
1da177e4
LT
21#include <linux/sem.h>
22#include <linux/msg.h>
23#include <linux/shm.h>
1da177e4
LT
24#include <linux/uio.h>
25#include <linux/nfs_fs.h>
26#include <linux/quota.h>
1da177e4
LT
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>
1da177e4 44#include <linux/ptrace.h>
5a0e3ad6 45#include <linux/slab.h>
1da177e4
LT
46
47#include <asm/types.h>
7c0f6ba6 48#include <linux/uaccess.h>
1da177e4 49#include <asm/fpumacro.h>
1da177e4 50#include <asm/mmu_context.h>
14cc6aba 51#include <asm/compat_signal.h>
1da177e4 52
ed8eb755
SR
53#include "systbls.h"
54
1da177e4
LT
55asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
56{
57 if ((int)high < 0)
58 return -EINVAL;
59 else
df260e21 60 return ksys_truncate(path, (high << 32) | low);
1da177e4
LT
61}
62
63asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
64{
65 if ((int)high < 0)
66 return -EINVAL;
67 else
411d9475 68 return ksys_ftruncate(fd, (high << 32) | low);
1da177e4
LT
69}
70
908f5162
AB
71static int cp_compat_stat64(struct kstat *stat,
72 struct compat_stat64 __user *statbuf)
0ba4da03
DM
73{
74 int err;
75
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);
a7c1938e
EB
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);
0ba4da03
DM
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);
97
98 return err;
99}
100
c7887325 101asmlinkage long compat_sys_stat64(const char __user * filename,
0ba4da03
DM
102 struct compat_stat64 __user *statbuf)
103{
104 struct kstat stat;
105 int error = vfs_stat(filename, &stat);
106
107 if (!error)
108 error = cp_compat_stat64(&stat, statbuf);
109 return error;
110}
111
c7887325 112asmlinkage long compat_sys_lstat64(const char __user * filename,
0ba4da03
DM
113 struct compat_stat64 __user *statbuf)
114{
115 struct kstat stat;
116 int error = vfs_lstat(filename, &stat);
117
118 if (!error)
119 error = cp_compat_stat64(&stat, statbuf);
120 return error;
121}
122
123asmlinkage long compat_sys_fstat64(unsigned int fd,
124 struct compat_stat64 __user * statbuf)
125{
126 struct kstat stat;
127 int error = vfs_fstat(fd, &stat);
128
129 if (!error)
130 error = cp_compat_stat64(&stat, statbuf);
131 return error;
132}
133
c7887325
DH
134asmlinkage long compat_sys_fstatat64(unsigned int dfd,
135 const char __user *filename,
40ad7a6a
DM
136 struct compat_stat64 __user * statbuf, int flag)
137{
138 struct kstat stat;
0112fc22 139 int error;
40ad7a6a 140
0112fc22
OD
141 error = vfs_fstatat(dfd, filename, &stat, flag);
142 if (error)
143 return error;
144 return cp_compat_stat64(&stat, statbuf);
40ad7a6a
DM
145}
146
a274bd49
AV
147COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig,
148 struct compat_old_sigaction __user *,act,
149 struct compat_old_sigaction __user *,oact)
1da177e4 150{
5526b7e4 151 WARN_ON_ONCE(sig >= 0);
a274bd49 152 return compat_sys_sigaction(-sig, act, oact);
1da177e4
LT
153}
154
bdc40abf
AV
155COMPAT_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)
1da177e4
LT
160{
161 struct k_sigaction new_ka, old_ka;
162 int ret;
1da177e4
LT
163
164 /* XXX: Don't preclude handling different sized sigset_t's. */
165 if (sigsetsize != sizeof(compat_sigset_t))
166 return -EINVAL;
167
1da177e4
LT
168 if (act) {
169 u32 u_handler, u_restorer;
170
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);
3968cf62 174 ret |= get_compat_sigset(&new_ka.sa.sa_mask, &act->sa_mask);
3ddc5b46
MD
175 ret |= get_user(new_ka.sa.sa_flags, &act->sa_flags);
176 ret |= get_user(u_restorer, &act->sa_restorer);
1da177e4
LT
177 new_ka.sa.sa_restorer = compat_ptr(u_restorer);
178 if (ret)
179 return -EFAULT;
180 }
181
182 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
183
184 if (!ret && oact) {
1da177e4 185 ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
f454322e
DL
186 ret |= put_compat_sigset(&oact->sa_mask, &old_ka.sa.sa_mask,
187 sizeof(oact->sa_mask));
3ddc5b46
MD
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);
1da177e4
LT
190 if (ret)
191 ret = -EFAULT;
192 }
193
194 return ret;
195}
196
1da177e4
LT
197asmlinkage 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)
202{
36028d5d 203 return ksys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
1da177e4
LT
204}
205
206asmlinkage 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)
211{
36028d5d 212 return ksys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
1da177e4
LT
213}
214
215asmlinkage long compat_sys_readahead(int fd,
216 unsigned long offhi,
217 unsigned long offlo,
218 compat_size_t count)
219{
220 return sys_readahead(fd, (offhi << 32) | offlo, count);
221}
222
223long compat_sys_fadvise64(int fd,
224 unsigned long offhi,
225 unsigned long offlo,
226 compat_size_t len, int advice)
227{
228 return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
229}
230
231long compat_sys_fadvise64_64(int fd,
232 unsigned long offhi, unsigned long offlo,
233 unsigned long lenhi, unsigned long lenlo,
234 int advice)
235{
236 return sys_fadvise64_64(fd,
237 (offhi << 32) | offlo,
238 (lenhi << 32) | lenlo,
239 advice);
240}
241
2ae80c43 242long 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)
289eee6f 243{
806cbae1 244 return ksys_sync_file_range(fd,
289eee6f
DM
245 (off_high << 32) | off_low,
246 (nb_high << 32) | nb_low,
247 flags);
248}
bc5a2e64
DM
249
250asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
251 u32 lenhi, u32 lenlo)
252{
edf292c7
DB
253 return ksys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
254 ((loff_t)lenhi << 32) | lenlo);
bc5a2e64 255}