]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/blame - arch/sparc/kernel/sys_sparc32.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-disco-kernel.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
60 return sys_truncate(path, (high << 32) | low);
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
68 return sys_ftruncate(fd, (high << 32) | low);
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;
163 compat_sigset_t set32;
164
165 /* XXX: Don't preclude handling different sized sigset_t's. */
166 if (sigsetsize != sizeof(compat_sigset_t))
167 return -EINVAL;
168
1da177e4
LT
169 if (act) {
170 u32 u_handler, u_restorer;
171
172 new_ka.ka_restorer = restorer;
173 ret = get_user(u_handler, &act->sa_handler);
174 new_ka.sa.sa_handler = compat_ptr(u_handler);
3ddc5b46 175 ret |= copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t));
bdc40abf 176 sigset_from_compat(&new_ka.sa.sa_mask, &set32);
3ddc5b46
MD
177 ret |= get_user(new_ka.sa.sa_flags, &act->sa_flags);
178 ret |= get_user(u_restorer, &act->sa_restorer);
1da177e4
LT
179 new_ka.sa.sa_restorer = compat_ptr(u_restorer);
180 if (ret)
181 return -EFAULT;
182 }
183
184 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
185
186 if (!ret && oact) {
bdc40abf 187 sigset_to_compat(&set32, &old_ka.sa.sa_mask);
1da177e4 188 ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
3ddc5b46
MD
189 ret |= copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t));
190 ret |= put_user(old_ka.sa.sa_flags, &oact->sa_flags);
191 ret |= put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
1da177e4
LT
192 if (ret)
193 ret = -EFAULT;
194 }
195
196 return ret;
197}
198
1da177e4
LT
199asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
200 char __user *ubuf,
201 compat_size_t count,
202 unsigned long poshi,
203 unsigned long poslo)
204{
205 return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
206}
207
208asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
209 char __user *ubuf,
210 compat_size_t count,
211 unsigned long poshi,
212 unsigned long poslo)
213{
214 return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
215}
216
217asmlinkage long compat_sys_readahead(int fd,
218 unsigned long offhi,
219 unsigned long offlo,
220 compat_size_t count)
221{
222 return sys_readahead(fd, (offhi << 32) | offlo, count);
223}
224
225long compat_sys_fadvise64(int fd,
226 unsigned long offhi,
227 unsigned long offlo,
228 compat_size_t len, int advice)
229{
230 return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
231}
232
233long compat_sys_fadvise64_64(int fd,
234 unsigned long offhi, unsigned long offlo,
235 unsigned long lenhi, unsigned long lenlo,
236 int advice)
237{
238 return sys_fadvise64_64(fd,
239 (offhi << 32) | offlo,
240 (lenhi << 32) | lenlo,
241 advice);
242}
243
2ae80c43 244long 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
DM
245{
246 return sys_sync_file_range(fd,
247 (off_high << 32) | off_low,
248 (nb_high << 32) | nb_low,
249 flags);
250}
bc5a2e64
DM
251
252asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
253 u32 lenhi, u32 lenlo)
254{
255 return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
256 ((loff_t)lenhi << 32) | lenlo);
257}