Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/compiler.h> |
| 8 | #include <linux/mm.h> |
| 9 | #include <linux/errno.h> |
| 10 | #include <linux/file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/highuid.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/dnotify.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/binfmts.h> |
| 30 | #include <linux/security.h> |
| 31 | #include <linux/compat.h> |
| 32 | #include <linux/vfs.h> |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 33 | #include <linux/ipc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include <net/sock.h> |
| 37 | #include <net/scm.h> |
| 38 | |
Ralf Baechle | 431dc80 | 2007-02-13 00:05:11 +0000 | [diff] [blame] | 39 | #include <asm/compat-signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/sim.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame^] | 41 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #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 Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 57 | #define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #endif |
| 59 | #ifdef __MIPSEL__ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 60 | #define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #endif |
| 62 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 63 | SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len, |
| 64 | unsigned long, prot, unsigned long, flags, unsigned long, fd, |
| 65 | unsigned long, pgoff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | unsigned long error; |
| 68 | |
| 69 | error = -EINVAL; |
H. Peter Anvin | 947df17 | 2006-02-24 21:20:29 -0800 | [diff] [blame] | 70 | if (pgoff & (~PAGE_MASK >> 12)) |
| 71 | goto out; |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 72 | error = sys_mmap_pgoff(addr, len, prot, flags, fd, |
| 73 | pgoff >> (PAGE_SHIFT-12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | out: |
| 75 | return error; |
| 76 | } |
| 77 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 78 | #define RLIM_INFINITY32 0x7fffffff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x) |
| 80 | |
| 81 | struct rlimit32 { |
| 82 | int rlim_cur; |
| 83 | int rlim_max; |
| 84 | }; |
| 85 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 86 | SYSCALL_DEFINE4(32_truncate64, const char __user *, path, |
| 87 | unsigned long, __dummy, unsigned long, a2, unsigned long, a3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Ralf Baechle | d4e9cff | 2008-01-29 10:15:02 +0000 | [diff] [blame] | 89 | return sys_truncate(path, merge_64(a2, a3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 92 | SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy, |
| 93 | unsigned long, a2, unsigned long, a3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Ralf Baechle | d4e9cff | 2008-01-29 10:15:02 +0000 | [diff] [blame] | 95 | return sys_ftruncate(fd, merge_64(a2, a3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Ralf Baechle | d6c178e | 2009-03-28 01:36:09 +0100 | [diff] [blame] | 98 | SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high, |
| 99 | unsigned int, offset_low, loff_t __user *, result, |
| 100 | unsigned int, origin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | return sys_llseek(fd, offset_high, offset_low, result, origin); |
| 103 | } |
| 104 | |
| 105 | /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op + |
| 106 | lseek back to original location. They fail just like lseek does on |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 107 | non-seekable files. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 109 | SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count, |
| 110 | unsigned long, unused, unsigned long, a4, unsigned long, a5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
Al Viro | 6ad0013 | 2006-04-26 07:28:09 +0100 | [diff] [blame] | 112 | return sys_pread64(fd, buf, count, merge_64(a4, a5)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 115 | SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf, |
| 116 | size_t, count, u32, unused, u64, a4, u64, a5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
Al Viro | 6ad0013 | 2006-04-26 07:28:09 +0100 | [diff] [blame] | 118 | return sys_pwrite64(fd, buf, count, merge_64(a4, a5)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 121 | SYSCALL_DEFINE1(32_personality, unsigned long, personality) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
David Daney | d62c9ce | 2010-11-01 17:43:08 -0700 | [diff] [blame] | 123 | unsigned int p = personality & 0xffffffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | int ret; |
David Daney | d62c9ce | 2010-11-01 17:43:08 -0700 | [diff] [blame] | 125 | |
Thiemo Seufer | 53571ce | 2006-08-13 00:53:29 +0100 | [diff] [blame] | 126 | if (personality(current->personality) == PER_LINUX32 && |
David Daney | d62c9ce | 2010-11-01 17:43:08 -0700 | [diff] [blame] | 127 | personality(p) == PER_LINUX) |
| 128 | p = (p & ~PER_MASK) | PER_LINUX32; |
| 129 | ret = sys_personality(p); |
| 130 | if (ret != -1 && personality(ret) == PER_LINUX32) |
| 131 | ret = (ret & ~PER_MASK) | PER_LINUX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | return ret; |
| 133 | } |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3, |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 136 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
| 138 | return sys_readahead(fd, merge_64(a2, a3), count); |
| 139 | } |
| 140 | |
Ralf Baechle | a8d587a | 2006-04-01 07:49:21 +0100 | [diff] [blame] | 141 | asmlinkage long sys32_sync_file_range(int fd, int __pad, |
| 142 | unsigned long a2, unsigned long a3, |
| 143 | unsigned long a4, unsigned long a5, |
| 144 | int flags) |
| 145 | { |
| 146 | return sys_sync_file_range(fd, |
| 147 | merge_64(a2, a3), merge_64(a4, a5), |
| 148 | flags); |
| 149 | } |
| 150 | |
Atsushi Nemoto | 8676d2e | 2007-05-18 00:46:13 +0900 | [diff] [blame] | 151 | asmlinkage long sys32_fadvise64_64(int fd, int __pad, |
| 152 | unsigned long a2, unsigned long a3, |
| 153 | unsigned long a4, unsigned long a5, |
| 154 | int flags) |
| 155 | { |
| 156 | return sys_fadvise64_64(fd, |
| 157 | merge_64(a2, a3), merge_64(a4, a5), |
| 158 | flags); |
| 159 | } |
| 160 | |
Ralf Baechle | 4dc4677 | 2007-07-26 03:38:24 +0100 | [diff] [blame] | 161 | asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2, |
| 162 | unsigned offset_a3, unsigned len_a4, unsigned len_a5) |
| 163 | { |
| 164 | return sys_fallocate(fd, mode, merge_64(offset_a2, offset_a3), |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 165 | merge_64(len_a4, len_a5)); |
Ralf Baechle | 4dc4677 | 2007-07-26 03:38:24 +0100 | [diff] [blame] | 166 | } |