blob: 318f1c05c5b34946dad665852a92ce2b83760cf5 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Conversion between 32-bit and 64-bit native system calls.
4 *
5 * Copyright (C) 2000 Silicon Graphics, Inc.
6 * Written by Ulf Carlsson (ulfc@engr.sgi.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/compiler.h>
9#include <linux/mm.h>
10#include <linux/errno.h>
11#include <linux/file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/highuid.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/resource.h>
14#include <linux/highmem.h>
15#include <linux/time.h>
16#include <linux/times.h>
17#include <linux/poll.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/skbuff.h>
19#include <linux/filter.h>
20#include <linux/shm.h>
21#include <linux/sem.h>
22#include <linux/msg.h>
23#include <linux/icmpv6.h>
24#include <linux/syscalls.h>
25#include <linux/sysctl.h>
26#include <linux/utime.h>
27#include <linux/utsname.h>
28#include <linux/personality.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/binfmts.h>
31#include <linux/security.h>
32#include <linux/compat.h>
33#include <linux/vfs.h>
Adrian Bunkcba4fbb2007-10-16 23:29:24 -070034#include <linux/ipc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <net/sock.h>
38#include <net/scm.h>
39
Ralf Baechle431dc802007-02-13 00:05:11 +000040#include <asm/compat-signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/sim.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080042#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/mmu_context.h>
44#include <asm/mman.h>
45
46/* Use this to get at 32-bit user passed pointers. */
47/* A() macro should be used for places where you e.g.
48 have some internal variable u32 and just want to get
49 rid of a compiler warning. AA() has to be used in
50 places where you want to convert a function argument
51 to 32bit pointer or when you e.g. access pt_regs
52 structure and want to consider 32bit registers only.
53 */
54#define A(__x) ((unsigned long)(__x))
55#define AA(__x) ((unsigned long)((int)__x))
56
57#ifdef __MIPSEB__
Ralf Baechle21a151d2007-10-11 23:46:15 +010058#define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#endif
60#ifdef __MIPSEL__
Ralf Baechle21a151d2007-10-11 23:46:15 +010061#define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#endif
63
Ralf Baechledbda6ac2009-02-08 16:00:26 +000064SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len,
65 unsigned long, prot, unsigned long, flags, unsigned long, fd,
66 unsigned long, pgoff)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
H. Peter Anvin947df172006-02-24 21:20:29 -080068 if (pgoff & (~PAGE_MASK >> 12))
Markus Elfringfcf4aec2017-01-18 19:00:05 +010069 return -EINVAL;
Dominik Brodowskia90f5902018-03-11 11:34:46 +010070 return ksys_mmap_pgoff(addr, len, prot, flags, fd,
71 pgoff >> (PAGE_SHIFT-12));
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Ralf Baechle70342282013-01-22 12:59:30 +010074#define RLIM_INFINITY32 0x7fffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
76
77struct rlimit32 {
78 int rlim_cur;
79 int rlim_max;
80};
81
Ralf Baechledbda6ac2009-02-08 16:00:26 +000082SYSCALL_DEFINE4(32_truncate64, const char __user *, path,
83 unsigned long, __dummy, unsigned long, a2, unsigned long, a3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Dominik Brodowskidf260e22018-03-19 17:32:11 +010085 return ksys_truncate(path, merge_64(a2, a3));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Ralf Baechledbda6ac2009-02-08 16:00:26 +000088SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy,
89 unsigned long, a2, unsigned long, a3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Dominik Brodowski411d9472018-03-11 11:34:54 +010091 return ksys_ftruncate(fd, merge_64(a2, a3));
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Ralf Baechled6c178e2009-03-28 01:36:09 +010094SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high,
95 unsigned int, offset_low, loff_t __user *, result,
96 unsigned int, origin)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 return sys_llseek(fd, offset_high, offset_low, result, origin);
99}
100
101/* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
102 lseek back to original location. They fail just like lseek does on
Ralf Baechle70342282013-01-22 12:59:30 +0100103 non-seekable files. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000105SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count,
106 unsigned long, unused, unsigned long, a4, unsigned long, a5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Dominik Brodowski36028d52018-03-19 17:38:31 +0100108 return ksys_pread64(fd, buf, count, merge_64(a4, a5));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000111SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf,
112 size_t, count, u32, unused, u64, a4, u64, a5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Dominik Brodowski36028d52018-03-19 17:38:31 +0100114 return ksys_pwrite64(fd, buf, count, merge_64(a4, a5));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115}
116
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000117SYSCALL_DEFINE1(32_personality, unsigned long, personality)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
David Daneyd62c9ce2010-11-01 17:43:08 -0700119 unsigned int p = personality & 0xffffffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 int ret;
David Daneyd62c9ce2010-11-01 17:43:08 -0700121
Thiemo Seufer53571ce2006-08-13 00:53:29 +0100122 if (personality(current->personality) == PER_LINUX32 &&
David Daneyd62c9ce2010-11-01 17:43:08 -0700123 personality(p) == PER_LINUX)
124 p = (p & ~PER_MASK) | PER_LINUX32;
125 ret = sys_personality(p);
126 if (ret != -1 && personality(ret) == PER_LINUX32)
127 ret = (ret & ~PER_MASK) | PER_LINUX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return ret;
129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
Ralf Baechle70342282013-01-22 12:59:30 +0100132 size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Dominik Brodowskic7b95d52018-03-19 17:51:36 +0100134 return ksys_readahead(fd, merge_64(a2, a3), count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
Ralf Baechlea8d587a2006-04-01 07:49:21 +0100137asmlinkage long sys32_sync_file_range(int fd, int __pad,
138 unsigned long a2, unsigned long a3,
139 unsigned long a4, unsigned long a5,
140 int flags)
141{
Dominik Brodowski806cbae2018-03-11 11:34:47 +0100142 return ksys_sync_file_range(fd,
Ralf Baechlea8d587a2006-04-01 07:49:21 +0100143 merge_64(a2, a3), merge_64(a4, a5),
144 flags);
145}
146
Atsushi Nemoto8676d2e2007-05-18 00:46:13 +0900147asmlinkage long sys32_fadvise64_64(int fd, int __pad,
148 unsigned long a2, unsigned long a3,
149 unsigned long a4, unsigned long a5,
150 int flags)
151{
Dominik Brodowski9d5b7c92018-03-11 11:34:45 +0100152 return ksys_fadvise64_64(fd,
Atsushi Nemoto8676d2e2007-05-18 00:46:13 +0900153 merge_64(a2, a3), merge_64(a4, a5),
154 flags);
155}
156
Ralf Baechle4dc46772007-07-26 03:38:24 +0100157asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2,
158 unsigned offset_a3, unsigned len_a4, unsigned len_a5)
159{
Dominik Brodowskiedf292c2018-03-19 17:46:32 +0100160 return ksys_fallocate(fd, mode, merge_64(offset_a2, offset_a3),
161 merge_64(len_a4, len_a5));
Ralf Baechle4dc46772007-07-26 03:38:24 +0100162}