License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-2.6-block.git] / arch / x86 / ia32 / sys_ia32.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
3 * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
c202f298 4 * sys_sparc32
1da177e4
LT
5 *
6 * Copyright (C) 2000 VA Linux Co
7 * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
c202f298
TG
8 * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
9 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
10 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
1da177e4
LT
11 * Copyright (C) 2000 Hewlett-Packard Co.
12 * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
c202f298 13 * Copyright (C) 2000,2001,2002 Andi Kleen, SuSE Labs (x86-64 port)
1da177e4
LT
14 *
15 * These routines maintain argument size conversion between 32bit and 64bit
c202f298 16 * environment. In 2.5 most of this should be moved to a generic directory.
1da177e4
LT
17 *
18 * This file assumes that there is a hole at the end of user address space.
c202f298
TG
19 *
20 * Some of the functions are LE specific currently. These are
21 * hopefully all marked. This should be fixed.
1da177e4
LT
22 */
23
1da177e4
LT
24#include <linux/kernel.h>
25#include <linux/sched.h>
c202f298
TG
26#include <linux/fs.h>
27#include <linux/file.h>
1da177e4
LT
28#include <linux/signal.h>
29#include <linux/syscalls.h>
1da177e4
LT
30#include <linux/times.h>
31#include <linux/utsname.h>
1da177e4 32#include <linux/mm.h>
1da177e4 33#include <linux/uio.h>
1da177e4
LT
34#include <linux/poll.h>
35#include <linux/personality.h>
36#include <linux/stat.h>
1da177e4 37#include <linux/rwsem.h>
1da177e4
LT
38#include <linux/compat.h>
39#include <linux/vfs.h>
40#include <linux/ptrace.h>
41#include <linux/highuid.h>
ddb15ec1 42#include <linux/sysctl.h>
5a0e3ad6 43#include <linux/slab.h>
1da177e4
LT
44#include <asm/mman.h>
45#include <asm/types.h>
7c0f6ba6 46#include <linux/uaccess.h>
60063497 47#include <linux/atomic.h>
28d23128 48#include <asm/vgtod.h>
2f06de06 49#include <asm/sys_ia32.h>
1da177e4
LT
50
51#define AA(__x) ((unsigned long)(__x))
52
1da177e4 53
c7887325 54asmlinkage long sys32_truncate64(const char __user *filename,
c202f298
TG
55 unsigned long offset_low,
56 unsigned long offset_high)
1da177e4
LT
57{
58 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
59}
60
c202f298
TG
61asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
62 unsigned long offset_high)
1da177e4
LT
63{
64 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
65}
66
c202f298
TG
67/*
68 * Another set for IA32/LFS -- x86_64 struct stat is different due to
69 * support for 64bit inode numbers.
70 */
71static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
1da177e4
LT
72{
73 typeof(ubuf->st_uid) uid = 0;
74 typeof(ubuf->st_gid) gid = 0;
a7c1938e
EB
75 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
76 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
1da177e4
LT
77 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
78 __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
c202f298
TG
79 __put_user(stat->ino, &ubuf->__st_ino) ||
80 __put_user(stat->ino, &ubuf->st_ino) ||
81 __put_user(stat->mode, &ubuf->st_mode) ||
82 __put_user(stat->nlink, &ubuf->st_nlink) ||
83 __put_user(uid, &ubuf->st_uid) ||
84 __put_user(gid, &ubuf->st_gid) ||
85 __put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
86 __put_user(stat->size, &ubuf->st_size) ||
87 __put_user(stat->atime.tv_sec, &ubuf->st_atime) ||
88 __put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
89 __put_user(stat->mtime.tv_sec, &ubuf->st_mtime) ||
90 __put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
91 __put_user(stat->ctime.tv_sec, &ubuf->st_ctime) ||
92 __put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
93 __put_user(stat->blksize, &ubuf->st_blksize) ||
94 __put_user(stat->blocks, &ubuf->st_blocks))
1da177e4
LT
95 return -EFAULT;
96 return 0;
97}
98
c7887325 99asmlinkage long sys32_stat64(const char __user *filename,
c202f298 100 struct stat64 __user *statbuf)
1da177e4
LT
101{
102 struct kstat stat;
103 int ret = vfs_stat(filename, &stat);
c202f298 104
1da177e4
LT
105 if (!ret)
106 ret = cp_stat64(statbuf, &stat);
107 return ret;
108}
109
c7887325 110asmlinkage long sys32_lstat64(const char __user *filename,
c202f298 111 struct stat64 __user *statbuf)
1da177e4
LT
112{
113 struct kstat stat;
114 int ret = vfs_lstat(filename, &stat);
115 if (!ret)
116 ret = cp_stat64(statbuf, &stat);
117 return ret;
118}
119
c202f298 120asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
1da177e4
LT
121{
122 struct kstat stat;
123 int ret = vfs_fstat(fd, &stat);
124 if (!ret)
125 ret = cp_stat64(statbuf, &stat);
126 return ret;
127}
128
c7887325 129asmlinkage long sys32_fstatat(unsigned int dfd, const char __user *filename,
c202f298 130 struct stat64 __user *statbuf, int flag)
cff2b760
UD
131{
132 struct kstat stat;
0112fc22 133 int error;
cff2b760 134
0112fc22
OD
135 error = vfs_fstatat(dfd, filename, &stat, flag);
136 if (error)
137 return error;
138 return cp_stat64(statbuf, &stat);
cff2b760
UD
139}
140
1da177e4
LT
141/*
142 * Linux/i386 didn't use to be able to handle more than
143 * 4 system call parameters, so these system calls used a memory
144 * block for parameter passing..
145 */
146
a4679373 147struct mmap_arg_struct32 {
1da177e4
LT
148 unsigned int addr;
149 unsigned int len;
150 unsigned int prot;
151 unsigned int flags;
152 unsigned int fd;
153 unsigned int offset;
154};
155
a4679373 156asmlinkage long sys32_mmap(struct mmap_arg_struct32 __user *arg)
1da177e4 157{
a4679373 158 struct mmap_arg_struct32 a;
1da177e4
LT
159
160 if (copy_from_user(&a, arg, sizeof(a)))
161 return -EFAULT;
162
163 if (a.offset & ~PAGE_MASK)
c202f298 164 return -EINVAL;
1da177e4 165
f8b72560 166 return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
c202f298 167 a.offset>>PAGE_SHIFT);
1da177e4
LT
168}
169
f0002627 170asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
c202f298 171 int options)
1da177e4
LT
172{
173 return compat_sys_wait4(pid, stat_addr, options, NULL);
174}
175
c202f298
TG
176/* warning: next two assume little endian */
177asmlinkage long sys32_pread(unsigned int fd, char __user *ubuf, u32 count,
178 u32 poslo, u32 poshi)
1da177e4
LT
179{
180 return sys_pread64(fd, ubuf, count,
181 ((loff_t)AA(poshi) << 32) | AA(poslo));
182}
183
c7887325
DH
184asmlinkage long sys32_pwrite(unsigned int fd, const char __user *ubuf,
185 u32 count, u32 poslo, u32 poshi)
1da177e4
LT
186{
187 return sys_pwrite64(fd, ubuf, count,
188 ((loff_t)AA(poshi) << 32) | AA(poslo));
189}
190
191
1da177e4 192/*
c202f298
TG
193 * Some system calls that need sign extended arguments. This could be
194 * done by a generic wrapper.
195 */
c202f298 196long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
1da177e4 197 __u32 len_low, __u32 len_high, int advice)
c202f298 198{
1da177e4
LT
199 return sys_fadvise64_64(fd,
200 (((u64)offset_high)<<32) | offset_low,
201 (((u64)len_high)<<32) | len_low,
c202f298
TG
202 advice);
203}
1da177e4 204
c202f298
TG
205asmlinkage ssize_t sys32_readahead(int fd, unsigned off_lo, unsigned off_hi,
206 size_t count)
e412ac49
AK
207{
208 return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
209}
210
211asmlinkage long sys32_sync_file_range(int fd, unsigned off_low, unsigned off_hi,
c202f298 212 unsigned n_low, unsigned n_hi, int flags)
e412ac49
AK
213{
214 return sys_sync_file_range(fd,
215 ((u64)off_hi << 32) | off_low,
216 ((u64)n_hi << 32) | n_low, flags);
217}
218
c202f298
TG
219asmlinkage long sys32_fadvise64(int fd, unsigned offset_lo, unsigned offset_hi,
220 size_t len, int advice)
e412ac49
AK
221{
222 return sys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
223 len, advice);
224}
97ac7350
AA
225
226asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_lo,
227 unsigned offset_hi, unsigned len_lo,
228 unsigned len_hi)
229{
230 return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
231 ((u64)len_hi << 32) | len_lo);
232}