1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright IBM Corp. 2000
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
6 * Gerhard Tonn (ton@de.ibm.com)
7 * Thomas Spatzier (tspat@de.ibm.com)
9 * Conversion between 31bit and 64bit native syscalls.
11 * Heavily inspired by the 32-bit Sparc compat code which is
12 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
13 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
22 #include <linux/file.h>
23 #include <linux/signal.h>
24 #include <linux/resource.h>
25 #include <linux/times.h>
26 #include <linux/smp.h>
27 #include <linux/sem.h>
28 #include <linux/msg.h>
29 #include <linux/shm.h>
30 #include <linux/uio.h>
31 #include <linux/quota.h>
32 #include <linux/poll.h>
33 #include <linux/personality.h>
34 #include <linux/stat.h>
35 #include <linux/filter.h>
36 #include <linux/highmem.h>
37 #include <linux/mman.h>
38 #include <linux/ipv6.h>
40 #include <linux/icmpv6.h>
41 #include <linux/syscalls.h>
42 #include <linux/sysctl.h>
43 #include <linux/binfmts.h>
44 #include <linux/capability.h>
45 #include <linux/compat.h>
46 #include <linux/vfs.h>
47 #include <linux/ptrace.h>
48 #include <linux/fadvise.h>
49 #include <linux/ipc.h>
50 #include <linux/slab.h>
52 #include <asm/types.h>
53 #include <linux/uaccess.h>
58 #include "compat_linux.h"
61 COMPAT_SYSCALL_DEFINE5(s390_ipc
, uint
, call
, int, first
, compat_ulong_t
, second
,
62 compat_ulong_t
, third
, compat_uptr_t
, ptr
)
64 if (call
>> 16) /* hack for backward compatibility */
66 return compat_ksys_ipc(call
, first
, second
, third
, ptr
, third
);
70 COMPAT_SYSCALL_DEFINE3(s390_truncate64
, const char __user
*, path
, u32
, high
, u32
, low
)
72 return ksys_truncate(path
, (unsigned long)high
<< 32 | low
);
75 COMPAT_SYSCALL_DEFINE3(s390_ftruncate64
, unsigned int, fd
, u32
, high
, u32
, low
)
77 return ksys_ftruncate(fd
, (unsigned long)high
<< 32 | low
);
80 COMPAT_SYSCALL_DEFINE5(s390_pread64
, unsigned int, fd
, char __user
*, ubuf
,
81 compat_size_t
, count
, u32
, high
, u32
, low
)
83 if ((compat_ssize_t
) count
< 0)
85 return ksys_pread64(fd
, ubuf
, count
, (unsigned long)high
<< 32 | low
);
88 COMPAT_SYSCALL_DEFINE5(s390_pwrite64
, unsigned int, fd
, const char __user
*, ubuf
,
89 compat_size_t
, count
, u32
, high
, u32
, low
)
91 if ((compat_ssize_t
) count
< 0)
93 return ksys_pwrite64(fd
, ubuf
, count
, (unsigned long)high
<< 32 | low
);
96 COMPAT_SYSCALL_DEFINE4(s390_readahead
, int, fd
, u32
, high
, u32
, low
, s32
, count
)
98 return ksys_readahead(fd
, (unsigned long)high
<< 32 | low
, count
);
101 struct stat64_emu31
{
102 unsigned long long st_dev
;
104 #define STAT64_HAS_BROKEN_ST_INO 1
106 unsigned int st_mode
;
107 unsigned int st_nlink
;
110 unsigned long long st_rdev
;
114 unsigned char __pad4
[4];
115 u32 __pad5
; /* future possible st_blocks high bits */
116 u32 st_blocks
; /* Number 512-byte blocks allocated. */
122 u32 __pad8
; /* will be high 32 bits of ctime someday */
123 unsigned long st_ino
;
126 static int cp_stat64(struct stat64_emu31 __user
*ubuf
, struct kstat
*stat
)
128 struct stat64_emu31 tmp
;
130 memset(&tmp
, 0, sizeof(tmp
));
132 tmp
.st_dev
= huge_encode_dev(stat
->dev
);
133 tmp
.st_ino
= stat
->ino
;
134 tmp
.__st_ino
= (u32
)stat
->ino
;
135 tmp
.st_mode
= stat
->mode
;
136 tmp
.st_nlink
= (unsigned int)stat
->nlink
;
137 tmp
.st_uid
= from_kuid_munged(current_user_ns(), stat
->uid
);
138 tmp
.st_gid
= from_kgid_munged(current_user_ns(), stat
->gid
);
139 tmp
.st_rdev
= huge_encode_dev(stat
->rdev
);
140 tmp
.st_size
= stat
->size
;
141 tmp
.st_blksize
= (u32
)stat
->blksize
;
142 tmp
.st_blocks
= (u32
)stat
->blocks
;
143 tmp
.st_atime
= (u32
)stat
->atime
.tv_sec
;
144 tmp
.st_mtime
= (u32
)stat
->mtime
.tv_sec
;
145 tmp
.st_ctime
= (u32
)stat
->ctime
.tv_sec
;
147 return copy_to_user(ubuf
,&tmp
,sizeof(tmp
)) ? -EFAULT
: 0;
150 COMPAT_SYSCALL_DEFINE2(s390_stat64
, const char __user
*, filename
, struct stat64_emu31 __user
*, statbuf
)
153 int ret
= vfs_stat(filename
, &stat
);
155 ret
= cp_stat64(statbuf
, &stat
);
159 COMPAT_SYSCALL_DEFINE2(s390_lstat64
, const char __user
*, filename
, struct stat64_emu31 __user
*, statbuf
)
162 int ret
= vfs_lstat(filename
, &stat
);
164 ret
= cp_stat64(statbuf
, &stat
);
168 COMPAT_SYSCALL_DEFINE2(s390_fstat64
, unsigned int, fd
, struct stat64_emu31 __user
*, statbuf
)
171 int ret
= vfs_fstat(fd
, &stat
);
173 ret
= cp_stat64(statbuf
, &stat
);
177 COMPAT_SYSCALL_DEFINE4(s390_fstatat64
, unsigned int, dfd
, const char __user
*, filename
,
178 struct stat64_emu31 __user
*, statbuf
, int, flag
)
183 error
= vfs_fstatat(dfd
, filename
, &stat
, flag
);
186 return cp_stat64(statbuf
, &stat
);
190 * Linux/i386 didn't use to be able to handle more than
191 * 4 system call parameters, so these system calls used a memory
192 * block for parameter passing..
195 struct mmap_arg_struct_emu31
{
199 compat_ulong_t flags
;
201 compat_ulong_t offset
;
204 COMPAT_SYSCALL_DEFINE1(s390_old_mmap
, struct mmap_arg_struct_emu31 __user
*, arg
)
206 struct mmap_arg_struct_emu31 a
;
208 if (copy_from_user(&a
, arg
, sizeof(a
)))
210 if (a
.offset
& ~PAGE_MASK
)
212 return ksys_mmap_pgoff(a
.addr
, a
.len
, a
.prot
, a
.flags
, a
.fd
,
213 a
.offset
>> PAGE_SHIFT
);
216 COMPAT_SYSCALL_DEFINE1(s390_mmap2
, struct mmap_arg_struct_emu31 __user
*, arg
)
218 struct mmap_arg_struct_emu31 a
;
220 if (copy_from_user(&a
, arg
, sizeof(a
)))
222 return ksys_mmap_pgoff(a
.addr
, a
.len
, a
.prot
, a
.flags
, a
.fd
, a
.offset
);
225 COMPAT_SYSCALL_DEFINE3(s390_read
, unsigned int, fd
, char __user
*, buf
, compat_size_t
, count
)
227 if ((compat_ssize_t
) count
< 0)
230 return ksys_read(fd
, buf
, count
);
233 COMPAT_SYSCALL_DEFINE3(s390_write
, unsigned int, fd
, const char __user
*, buf
, compat_size_t
, count
)
235 if ((compat_ssize_t
) count
< 0)
238 return ksys_write(fd
, buf
, count
);
242 * 31 bit emulation wrapper functions for sys_fadvise64/fadvise64_64.
243 * These need to rewrite the advise values for POSIX_FADV_{DONTNEED,NOREUSE}
244 * because the 31 bit values differ from the 64 bit values.
247 COMPAT_SYSCALL_DEFINE5(s390_fadvise64
, int, fd
, u32
, high
, u32
, low
, compat_size_t
, len
, int, advise
)
250 advise
= POSIX_FADV_DONTNEED
;
251 else if (advise
== 5)
252 advise
= POSIX_FADV_NOREUSE
;
253 return ksys_fadvise64_64(fd
, (unsigned long)high
<< 32 | low
, len
,
257 struct fadvise64_64_args
{
264 COMPAT_SYSCALL_DEFINE1(s390_fadvise64_64
, struct fadvise64_64_args __user
*, args
)
266 struct fadvise64_64_args a
;
268 if ( copy_from_user(&a
, args
, sizeof(a
)) )
271 a
.advice
= POSIX_FADV_DONTNEED
;
272 else if (a
.advice
== 5)
273 a
.advice
= POSIX_FADV_NOREUSE
;
274 return ksys_fadvise64_64(a
.fd
, a
.offset
, a
.len
, a
.advice
);
277 COMPAT_SYSCALL_DEFINE6(s390_sync_file_range
, int, fd
, u32
, offhigh
, u32
, offlow
,
278 u32
, nhigh
, u32
, nlow
, unsigned int, flags
)
280 return ksys_sync_file_range(fd
, ((loff_t
)offhigh
<< 32) + offlow
,
281 ((u64
)nhigh
<< 32) + nlow
, flags
);
284 COMPAT_SYSCALL_DEFINE6(s390_fallocate
, int, fd
, int, mode
, u32
, offhigh
, u32
, offlow
,
285 u32
, lenhigh
, u32
, lenlow
)
287 return ksys_fallocate(fd
, mode
, ((loff_t
)offhigh
<< 32) + offlow
,
288 ((u64
)lenhigh
<< 32) + lenlow
);