blob: b01bdef101a85f5178d59b3b1333a1e8d96dddf2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Conversion between 32-bit and 64-bit native system calls.
3 *
4 * Copyright (C) 2000 Silicon Graphics, Inc.
5 * Written by Ulf Carlsson (ulfc@engr.sgi.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/compiler.h>
8#include <linux/mm.h>
9#include <linux/errno.h>
10#include <linux/file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/highuid.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/resource.h>
13#include <linux/highmem.h>
14#include <linux/time.h>
15#include <linux/times.h>
16#include <linux/poll.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/skbuff.h>
18#include <linux/filter.h>
19#include <linux/shm.h>
20#include <linux/sem.h>
21#include <linux/msg.h>
22#include <linux/icmpv6.h>
23#include <linux/syscalls.h>
24#include <linux/sysctl.h>
25#include <linux/utime.h>
26#include <linux/utsname.h>
27#include <linux/personality.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/binfmts.h>
30#include <linux/security.h>
31#include <linux/compat.h>
32#include <linux/vfs.h>
Adrian Bunkcba4fbb2007-10-16 23:29:24 -070033#include <linux/ipc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#include <net/sock.h>
37#include <net/scm.h>
38
Ralf Baechle431dc802007-02-13 00:05:11 +000039#include <asm/compat-signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/sim.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080041#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/mmu_context.h>
43#include <asm/mman.h>
44
45/* Use this to get at 32-bit user passed pointers. */
46/* A() macro should be used for places where you e.g.
47 have some internal variable u32 and just want to get
48 rid of a compiler warning. AA() has to be used in
49 places where you want to convert a function argument
50 to 32bit pointer or when you e.g. access pt_regs
51 structure and want to consider 32bit registers only.
52 */
53#define A(__x) ((unsigned long)(__x))
54#define AA(__x) ((unsigned long)((int)__x))
55
56#ifdef __MIPSEB__
Ralf Baechle21a151d2007-10-11 23:46:15 +010057#define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#endif
59#ifdef __MIPSEL__
Ralf Baechle21a151d2007-10-11 23:46:15 +010060#define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#endif
62
Ralf Baechledbda6ac2009-02-08 16:00:26 +000063SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len,
64 unsigned long, prot, unsigned long, flags, unsigned long, fd,
65 unsigned long, pgoff)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
H. Peter Anvin947df172006-02-24 21:20:29 -080067 if (pgoff & (~PAGE_MASK >> 12))
Markus Elfringfcf4aec2017-01-18 19:00:05 +010068 return -EINVAL;
69 return sys_mmap_pgoff(addr, len, prot, flags, fd,
70 pgoff >> (PAGE_SHIFT-12));
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Ralf Baechle70342282013-01-22 12:59:30 +010073#define RLIM_INFINITY32 0x7fffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
75
76struct rlimit32 {
77 int rlim_cur;
78 int rlim_max;
79};
80
Ralf Baechledbda6ac2009-02-08 16:00:26 +000081SYSCALL_DEFINE4(32_truncate64, const char __user *, path,
82 unsigned long, __dummy, unsigned long, a2, unsigned long, a3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Ralf Baechled4e9cff2008-01-29 10:15:02 +000084 return sys_truncate(path, merge_64(a2, a3));
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Ralf Baechledbda6ac2009-02-08 16:00:26 +000087SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy,
88 unsigned long, a2, unsigned long, a3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Ralf Baechled4e9cff2008-01-29 10:15:02 +000090 return sys_ftruncate(fd, merge_64(a2, a3));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
Ralf Baechled6c178e2009-03-28 01:36:09 +010093SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high,
94 unsigned int, offset_low, loff_t __user *, result,
95 unsigned int, origin)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 return sys_llseek(fd, offset_high, offset_low, result, origin);
98}
99
100/* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
101 lseek back to original location. They fail just like lseek does on
Ralf Baechle70342282013-01-22 12:59:30 +0100102 non-seekable files. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000104SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count,
105 unsigned long, unused, unsigned long, a4, unsigned long, a5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Al Viro6ad00132006-04-26 07:28:09 +0100107 return sys_pread64(fd, buf, count, merge_64(a4, a5));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000110SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf,
111 size_t, count, u32, unused, u64, a4, u64, a5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Al Viro6ad00132006-04-26 07:28:09 +0100113 return sys_pwrite64(fd, buf, count, merge_64(a4, a5));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000116SYSCALL_DEFINE1(32_personality, unsigned long, personality)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
David Daneyd62c9ce2010-11-01 17:43:08 -0700118 unsigned int p = personality & 0xffffffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 int ret;
David Daneyd62c9ce2010-11-01 17:43:08 -0700120
Thiemo Seufer53571ce2006-08-13 00:53:29 +0100121 if (personality(current->personality) == PER_LINUX32 &&
David Daneyd62c9ce2010-11-01 17:43:08 -0700122 personality(p) == PER_LINUX)
123 p = (p & ~PER_MASK) | PER_LINUX32;
124 ret = sys_personality(p);
125 if (ret != -1 && personality(ret) == PER_LINUX32)
126 ret = (ret & ~PER_MASK) | PER_LINUX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return ret;
128}
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
Ralf Baechle70342282013-01-22 12:59:30 +0100131 size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
133 return sys_readahead(fd, merge_64(a2, a3), count);
134}
135
Ralf Baechlea8d587a2006-04-01 07:49:21 +0100136asmlinkage long sys32_sync_file_range(int fd, int __pad,
137 unsigned long a2, unsigned long a3,
138 unsigned long a4, unsigned long a5,
139 int flags)
140{
141 return sys_sync_file_range(fd,
142 merge_64(a2, a3), merge_64(a4, a5),
143 flags);
144}
145
Atsushi Nemoto8676d2e2007-05-18 00:46:13 +0900146asmlinkage long sys32_fadvise64_64(int fd, int __pad,
147 unsigned long a2, unsigned long a3,
148 unsigned long a4, unsigned long a5,
149 int flags)
150{
151 return sys_fadvise64_64(fd,
152 merge_64(a2, a3), merge_64(a4, a5),
153 flags);
154}
155
Ralf Baechle4dc46772007-07-26 03:38:24 +0100156asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2,
157 unsigned offset_a3, unsigned len_a4, unsigned len_a5)
158{
159 return sys_fallocate(fd, mode, merge_64(offset_a2, offset_a3),
Ralf Baechle70342282013-01-22 12:59:30 +0100160 merge_64(len_a4, len_a5));
Ralf Baechle4dc46772007-07-26 03:38:24 +0100161}