Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/compiler.h> |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/errno.h> |
| 11 | #include <linux/file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/highuid.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/dnotify.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/binfmts.h> |
| 31 | #include <linux/security.h> |
| 32 | #include <linux/compat.h> |
| 33 | #include <linux/vfs.h> |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 34 | #include <linux/ipc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <net/sock.h> |
| 38 | #include <net/scm.h> |
| 39 | |
Ralf Baechle | 431dc80 | 2007-02-13 00:05:11 +0000 | [diff] [blame] | 40 | #include <asm/compat-signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/sim.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 42 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/mmu_context.h> |
| 44 | #include <asm/mman.h> |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #ifdef __MIPSEB__ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 47 | #define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #endif |
| 49 | #ifdef __MIPSEL__ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 50 | #define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #endif |
| 52 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 53 | SYSCALL_DEFINE4(32_truncate64, const char __user *, path, |
| 54 | unsigned long, __dummy, unsigned long, a2, unsigned long, a3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Dominik Brodowski | df260e2 | 2018-03-19 17:32:11 +0100 | [diff] [blame] | 56 | return ksys_truncate(path, merge_64(a2, a3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 59 | SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy, |
| 60 | unsigned long, a2, unsigned long, a3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
Dominik Brodowski | 411d947 | 2018-03-11 11:34:54 +0100 | [diff] [blame] | 62 | return ksys_ftruncate(fd, merge_64(a2, a3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Ralf Baechle | d6c178e | 2009-03-28 01:36:09 +0100 | [diff] [blame] | 65 | SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high, |
| 66 | unsigned int, offset_low, loff_t __user *, result, |
| 67 | unsigned int, origin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
| 69 | return sys_llseek(fd, offset_high, offset_low, result, origin); |
| 70 | } |
| 71 | |
| 72 | /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op + |
| 73 | lseek back to original location. They fail just like lseek does on |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 74 | non-seekable files. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 76 | SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count, |
| 77 | unsigned long, unused, unsigned long, a4, unsigned long, a5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
Dominik Brodowski | 36028d5 | 2018-03-19 17:38:31 +0100 | [diff] [blame] | 79 | return ksys_pread64(fd, buf, count, merge_64(a4, a5)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 82 | SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf, |
| 83 | size_t, count, u32, unused, u64, a4, u64, a5) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Dominik Brodowski | 36028d5 | 2018-03-19 17:38:31 +0100 | [diff] [blame] | 85 | return ksys_pwrite64(fd, buf, count, merge_64(a4, a5)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 88 | SYSCALL_DEFINE1(32_personality, unsigned long, personality) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
David Daney | d62c9ce | 2010-11-01 17:43:08 -0700 | [diff] [blame] | 90 | unsigned int p = personality & 0xffffffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | int ret; |
David Daney | d62c9ce | 2010-11-01 17:43:08 -0700 | [diff] [blame] | 92 | |
Thiemo Seufer | 53571ce | 2006-08-13 00:53:29 +0100 | [diff] [blame] | 93 | if (personality(current->personality) == PER_LINUX32 && |
David Daney | d62c9ce | 2010-11-01 17:43:08 -0700 | [diff] [blame] | 94 | personality(p) == PER_LINUX) |
| 95 | p = (p & ~PER_MASK) | PER_LINUX32; |
| 96 | ret = sys_personality(p); |
| 97 | if (ret != -1 && personality(ret) == PER_LINUX32) |
| 98 | ret = (ret & ~PER_MASK) | PER_LINUX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | return ret; |
| 100 | } |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | 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] | 103 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
Dominik Brodowski | c7b95d5 | 2018-03-19 17:51:36 +0100 | [diff] [blame] | 105 | return ksys_readahead(fd, merge_64(a2, a3), count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Ralf Baechle | a8d587a | 2006-04-01 07:49:21 +0100 | [diff] [blame] | 108 | asmlinkage long sys32_sync_file_range(int fd, int __pad, |
| 109 | unsigned long a2, unsigned long a3, |
| 110 | unsigned long a4, unsigned long a5, |
| 111 | int flags) |
| 112 | { |
Dominik Brodowski | 806cbae | 2018-03-11 11:34:47 +0100 | [diff] [blame] | 113 | return ksys_sync_file_range(fd, |
Ralf Baechle | a8d587a | 2006-04-01 07:49:21 +0100 | [diff] [blame] | 114 | merge_64(a2, a3), merge_64(a4, a5), |
| 115 | flags); |
| 116 | } |
| 117 | |
Atsushi Nemoto | 8676d2e | 2007-05-18 00:46:13 +0900 | [diff] [blame] | 118 | asmlinkage long sys32_fadvise64_64(int fd, int __pad, |
| 119 | unsigned long a2, unsigned long a3, |
| 120 | unsigned long a4, unsigned long a5, |
| 121 | int flags) |
| 122 | { |
Dominik Brodowski | 9d5b7c9 | 2018-03-11 11:34:45 +0100 | [diff] [blame] | 123 | return ksys_fadvise64_64(fd, |
Atsushi Nemoto | 8676d2e | 2007-05-18 00:46:13 +0900 | [diff] [blame] | 124 | merge_64(a2, a3), merge_64(a4, a5), |
| 125 | flags); |
| 126 | } |
| 127 | |
Ralf Baechle | 4dc4677 | 2007-07-26 03:38:24 +0100 | [diff] [blame] | 128 | asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2, |
| 129 | unsigned offset_a3, unsigned len_a4, unsigned len_a5) |
| 130 | { |
Dominik Brodowski | edf292c | 2018-03-19 17:46:32 +0100 | [diff] [blame] | 131 | return ksys_fallocate(fd, mode, merge_64(offset_a2, offset_a3), |
| 132 | merge_64(len_a4, len_a5)); |
Ralf Baechle | 4dc4677 | 2007-07-26 03:38:24 +0100 | [diff] [blame] | 133 | } |