]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - arch/sparc/kernel/sys_sparc32.c
Merge remote-tracking branches 'asoc/topic/ac97', 'asoc/topic/ac97-mfd', 'asoc/topic...
[mirror_ubuntu-focal-kernel.git] / arch / sparc / kernel / sys_sparc32.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
3 *
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
6 *
7 * These routines maintain argument size conversion between 32bit and 64bit
8 * environment.
9 */
10
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>
46
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>
52
53 #include "systbls.h"
54
55 asmlinkage 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
63 asmlinkage 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
71 static int cp_compat_stat64(struct kstat *stat,
72 struct compat_stat64 __user *statbuf)
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);
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);
97
98 return err;
99 }
100
101 asmlinkage long compat_sys_stat64(const char __user * filename,
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
112 asmlinkage long compat_sys_lstat64(const char __user * filename,
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
123 asmlinkage 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
134 asmlinkage long compat_sys_fstatat64(unsigned int dfd,
135 const char __user *filename,
136 struct compat_stat64 __user * statbuf, int flag)
137 {
138 struct kstat stat;
139 int error;
140
141 error = vfs_fstatat(dfd, filename, &stat, flag);
142 if (error)
143 return error;
144 return cp_compat_stat64(&stat, statbuf);
145 }
146
147 COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig,
148 struct compat_old_sigaction __user *,act,
149 struct compat_old_sigaction __user *,oact)
150 {
151 WARN_ON_ONCE(sig >= 0);
152 return compat_sys_sigaction(-sig, act, oact);
153 }
154
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)
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
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);
175 ret |= copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t));
176 sigset_from_compat(&new_ka.sa.sa_mask, &set32);
177 ret |= get_user(new_ka.sa.sa_flags, &act->sa_flags);
178 ret |= get_user(u_restorer, &act->sa_restorer);
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) {
187 sigset_to_compat(&set32, &old_ka.sa.sa_mask);
188 ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
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);
192 if (ret)
193 ret = -EFAULT;
194 }
195
196 return ret;
197 }
198
199 asmlinkage 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
208 asmlinkage 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
217 asmlinkage 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
225 long 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
233 long 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
244 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)
245 {
246 return sys_sync_file_range(fd,
247 (off_high << 32) | off_low,
248 (nb_high << 32) | nb_low,
249 flags);
250 }
251
252 asmlinkage 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 }