License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-2.6/btrfs-unstable.git] / arch / x86 / ia32 / sys_ia32.c
blob96cd33bbfc85494f52e4131f50b37129393d3b8a
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
4 * sys_sparc32
6 * Copyright (C) 2000 VA Linux Co
7 * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
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)
11 * Copyright (C) 2000 Hewlett-Packard Co.
12 * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
13 * Copyright (C) 2000,2001,2002 Andi Kleen, SuSE Labs (x86-64 port)
15 * These routines maintain argument size conversion between 32bit and 64bit
16 * environment. In 2.5 most of this should be moved to a generic directory.
18 * This file assumes that there is a hole at the end of user address space.
20 * Some of the functions are LE specific currently. These are
21 * hopefully all marked. This should be fixed.
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/fs.h>
27 #include <linux/file.h>
28 #include <linux/signal.h>
29 #include <linux/syscalls.h>
30 #include <linux/times.h>
31 #include <linux/utsname.h>
32 #include <linux/mm.h>
33 #include <linux/uio.h>
34 #include <linux/poll.h>
35 #include <linux/personality.h>
36 #include <linux/stat.h>
37 #include <linux/rwsem.h>
38 #include <linux/compat.h>
39 #include <linux/vfs.h>
40 #include <linux/ptrace.h>
41 #include <linux/highuid.h>
42 #include <linux/sysctl.h>
43 #include <linux/slab.h>
44 #include <asm/mman.h>
45 #include <asm/types.h>
46 #include <linux/uaccess.h>
47 #include <linux/atomic.h>
48 #include <asm/vgtod.h>
49 #include <asm/sys_ia32.h>
51 #define AA(__x) ((unsigned long)(__x))
54 asmlinkage long sys32_truncate64(const char __user *filename,
55 unsigned long offset_low,
56 unsigned long offset_high)
58 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
61 asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
62 unsigned long offset_high)
64 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
68 * Another set for IA32/LFS -- x86_64 struct stat is different due to
69 * support for 64bit inode numbers.
71 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
73 typeof(ubuf->st_uid) uid = 0;
74 typeof(ubuf->st_gid) gid = 0;
75 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
76 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
77 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
78 __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
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))
95 return -EFAULT;
96 return 0;
99 asmlinkage long sys32_stat64(const char __user *filename,
100 struct stat64 __user *statbuf)
102 struct kstat stat;
103 int ret = vfs_stat(filename, &stat);
105 if (!ret)
106 ret = cp_stat64(statbuf, &stat);
107 return ret;
110 asmlinkage long sys32_lstat64(const char __user *filename,
111 struct stat64 __user *statbuf)
113 struct kstat stat;
114 int ret = vfs_lstat(filename, &stat);
115 if (!ret)
116 ret = cp_stat64(statbuf, &stat);
117 return ret;
120 asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
122 struct kstat stat;
123 int ret = vfs_fstat(fd, &stat);
124 if (!ret)
125 ret = cp_stat64(statbuf, &stat);
126 return ret;
129 asmlinkage long sys32_fstatat(unsigned int dfd, const char __user *filename,
130 struct stat64 __user *statbuf, int flag)
132 struct kstat stat;
133 int error;
135 error = vfs_fstatat(dfd, filename, &stat, flag);
136 if (error)
137 return error;
138 return cp_stat64(statbuf, &stat);
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..
147 struct mmap_arg_struct32 {
148 unsigned int addr;
149 unsigned int len;
150 unsigned int prot;
151 unsigned int flags;
152 unsigned int fd;
153 unsigned int offset;
156 asmlinkage long sys32_mmap(struct mmap_arg_struct32 __user *arg)
158 struct mmap_arg_struct32 a;
160 if (copy_from_user(&a, arg, sizeof(a)))
161 return -EFAULT;
163 if (a.offset & ~PAGE_MASK)
164 return -EINVAL;
166 return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
167 a.offset>>PAGE_SHIFT);
170 asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
171 int options)
173 return compat_sys_wait4(pid, stat_addr, options, NULL);
176 /* warning: next two assume little endian */
177 asmlinkage long sys32_pread(unsigned int fd, char __user *ubuf, u32 count,
178 u32 poslo, u32 poshi)
180 return sys_pread64(fd, ubuf, count,
181 ((loff_t)AA(poshi) << 32) | AA(poslo));
184 asmlinkage long sys32_pwrite(unsigned int fd, const char __user *ubuf,
185 u32 count, u32 poslo, u32 poshi)
187 return sys_pwrite64(fd, ubuf, count,
188 ((loff_t)AA(poshi) << 32) | AA(poslo));
193 * Some system calls that need sign extended arguments. This could be
194 * done by a generic wrapper.
196 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
197 __u32 len_low, __u32 len_high, int advice)
199 return sys_fadvise64_64(fd,
200 (((u64)offset_high)<<32) | offset_low,
201 (((u64)len_high)<<32) | len_low,
202 advice);
205 asmlinkage ssize_t sys32_readahead(int fd, unsigned off_lo, unsigned off_hi,
206 size_t count)
208 return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
211 asmlinkage long sys32_sync_file_range(int fd, unsigned off_low, unsigned off_hi,
212 unsigned n_low, unsigned n_hi, int flags)
214 return sys_sync_file_range(fd,
215 ((u64)off_hi << 32) | off_low,
216 ((u64)n_hi << 32) | n_low, flags);
219 asmlinkage long sys32_fadvise64(int fd, unsigned offset_lo, unsigned offset_hi,
220 size_t len, int advice)
222 return sys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
223 len, advice);
226 asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_lo,
227 unsigned offset_hi, unsigned len_lo,
228 unsigned len_hi)
230 return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
231 ((u64)len_hi << 32) | len_lo);