Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sys_ppc32.c: Conversion between 32bit and 64bit native syscalls. |
| 3 | * |
| 4 | * Copyright (C) 2001 IBM |
| 5 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 6 | * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) |
| 7 | * |
| 8 | * These routines maintain argument size conversion between 32bit and 64bit |
| 9 | * environment. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * as published by the Free Software Foundation; either version |
| 14 | * 2 of the License, or (at your option) any later version. |
| 15 | */ |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/kernel.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/fs.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/file.h> |
| 22 | #include <linux/signal.h> |
| 23 | #include <linux/resource.h> |
| 24 | #include <linux/times.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/sem.h> |
| 27 | #include <linux/msg.h> |
| 28 | #include <linux/shm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/poll.h> |
| 30 | #include <linux/personality.h> |
| 31 | #include <linux/stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/mman.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/syscalls.h> |
| 35 | #include <linux/unistd.h> |
| 36 | #include <linux/sysctl.h> |
| 37 | #include <linux/binfmts.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/security.h> |
| 39 | #include <linux/compat.h> |
| 40 | #include <linux/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/elf.h> |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 42 | #include <linux/ipc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 43 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/ptrace.h> |
| 46 | #include <asm/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <asm/uaccess.h> |
| 48 | #include <asm/unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <asm/time.h> |
| 50 | #include <asm/mmu_context.h> |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 51 | #include <asm/ppc-pci.h> |
Arnd Bergmann | 369cf4b | 2006-11-27 19:18:59 +0100 | [diff] [blame] | 52 | #include <asm/syscalls.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 53 | #include <asm/switch_to.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp, |
| 57 | compat_ulong_t __user *outp, compat_ulong_t __user *exp, |
| 58 | compat_uptr_t tvp_x) |
| 59 | { |
| 60 | /* sign extend n */ |
| 61 | return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x)); |
| 62 | } |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #ifdef CONFIG_SYSVIPC |
Stephen Rothwell | b09a491 | 2005-10-18 14:51:57 +1000 | [diff] [blame] | 65 | long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | u32 fifth) |
| 67 | { |
| 68 | int version; |
| 69 | |
| 70 | version = call >> 16; /* hack for backward compatibility */ |
| 71 | call &= 0xffff; |
| 72 | |
| 73 | switch (call) { |
| 74 | |
| 75 | case SEMTIMEDOP: |
| 76 | if (fifth) |
| 77 | /* sign extend semid */ |
| 78 | return compat_sys_semtimedop((int)first, |
| 79 | compat_ptr(ptr), second, |
| 80 | compat_ptr(fifth)); |
| 81 | /* else fall through for normal semop() */ |
| 82 | case SEMOP: |
| 83 | /* struct sembuf is the same on 32 and 64bit :)) */ |
| 84 | /* sign extend semid */ |
| 85 | return sys_semtimedop((int)first, compat_ptr(ptr), second, |
| 86 | NULL); |
| 87 | case SEMGET: |
| 88 | /* sign extend key, nsems */ |
| 89 | return sys_semget((int)first, (int)second, third); |
| 90 | case SEMCTL: |
| 91 | /* sign extend semid, semnum */ |
| 92 | return compat_sys_semctl((int)first, (int)second, third, |
| 93 | compat_ptr(ptr)); |
| 94 | |
| 95 | case MSGSND: |
| 96 | /* sign extend msqid */ |
| 97 | return compat_sys_msgsnd((int)first, (int)second, third, |
| 98 | compat_ptr(ptr)); |
| 99 | case MSGRCV: |
| 100 | /* sign extend msqid, msgtyp */ |
| 101 | return compat_sys_msgrcv((int)first, second, (int)fifth, |
| 102 | third, version, compat_ptr(ptr)); |
| 103 | case MSGGET: |
| 104 | /* sign extend key */ |
| 105 | return sys_msgget((int)first, second); |
| 106 | case MSGCTL: |
| 107 | /* sign extend msqid */ |
| 108 | return compat_sys_msgctl((int)first, second, compat_ptr(ptr)); |
| 109 | |
| 110 | case SHMAT: |
| 111 | /* sign extend shmid */ |
| 112 | return compat_sys_shmat((int)first, second, third, version, |
| 113 | compat_ptr(ptr)); |
| 114 | case SHMDT: |
| 115 | return sys_shmdt(compat_ptr(ptr)); |
| 116 | case SHMGET: |
| 117 | /* sign extend key_t */ |
| 118 | return sys_shmget((int)first, second, third); |
| 119 | case SHMCTL: |
| 120 | /* sign extend shmid */ |
| 121 | return compat_sys_shmctl((int)first, second, compat_ptr(ptr)); |
| 122 | |
| 123 | default: |
| 124 | return -ENOSYS; |
| 125 | } |
| 126 | |
| 127 | return -ENOSYS; |
| 128 | } |
| 129 | #endif |
| 130 | |
| 131 | /* Note: it is necessary to treat out_fd and in_fd as unsigned ints, |
| 132 | * with the corresponding cast to a signed int to insure that the |
| 133 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) |
| 134 | * and the register representation of a signed int (msr in 64-bit mode) is performed. |
| 135 | */ |
Catalin Marinas | 8f9c011 | 2012-09-19 12:01:52 +0100 | [diff] [blame] | 136 | asmlinkage long compat_sys_sendfile_wrapper(u32 out_fd, u32 in_fd, |
| 137 | compat_off_t __user *offset, u32 count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Catalin Marinas | 8f9c011 | 2012-09-19 12:01:52 +0100 | [diff] [blame] | 139 | return compat_sys_sendfile((int)out_fd, (int)in_fd, offset, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Catalin Marinas | 8f9c011 | 2012-09-19 12:01:52 +0100 | [diff] [blame] | 142 | asmlinkage long compat_sys_sendfile64_wrapper(u32 out_fd, u32 in_fd, |
| 143 | compat_loff_t __user *offset, u32 count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Catalin Marinas | 8f9c011 | 2012-09-19 12:01:52 +0100 | [diff] [blame] | 145 | return sys_sendfile((int)out_fd, (int)in_fd, |
| 146 | (off_t __user *)offset, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Stephen Rothwell | b09a491 | 2005-10-18 14:51:57 +1000 | [diff] [blame] | 149 | unsigned long compat_sys_mmap2(unsigned long addr, size_t len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | unsigned long prot, unsigned long flags, |
| 151 | unsigned long fd, unsigned long pgoff) |
| 152 | { |
| 153 | /* This should remain 12 even if PAGE_SIZE changes */ |
| 154 | return sys_mmap(addr, len, prot, flags, fd, pgoff << 12); |
| 155 | } |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* |
| 158 | * long long munging: |
| 159 | * The 32 bit ABI passes long longs in an odd even register pair. |
| 160 | */ |
| 161 | |
Stephen Rothwell | b09a491 | 2005-10-18 14:51:57 +1000 | [diff] [blame] | 162 | compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | u32 reg6, u32 poshi, u32 poslo) |
| 164 | { |
| 165 | return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); |
| 166 | } |
| 167 | |
David Howells | c788732 | 2010-08-11 11:26:22 +0100 | [diff] [blame] | 168 | compat_ssize_t compat_sys_pwrite64(unsigned int fd, const char __user *ubuf, compat_size_t count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | u32 reg6, u32 poshi, u32 poslo) |
| 170 | { |
| 171 | return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); |
| 172 | } |
| 173 | |
Stephen Rothwell | b09a491 | 2005-10-18 14:51:57 +1000 | [diff] [blame] | 174 | compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count); |
| 177 | } |
| 178 | |
Stephen Rothwell | b09a491 | 2005-10-18 14:51:57 +1000 | [diff] [blame] | 179 | asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | unsigned long high, unsigned long low) |
| 181 | { |
| 182 | return sys_truncate(path, (high << 32) | low); |
| 183 | } |
| 184 | |
Amit Arora | 97ac735 | 2007-07-17 21:42:44 -0400 | [diff] [blame] | 185 | asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo, |
| 186 | u32 lenhi, u32 lenlo) |
| 187 | { |
| 188 | return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo, |
| 189 | ((loff_t)lenhi << 32) | lenlo); |
| 190 | } |
| 191 | |
Stephen Rothwell | b09a491 | 2005-10-18 14:51:57 +1000 | [diff] [blame] | 192 | asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | unsigned long low) |
| 194 | { |
| 195 | return sys_ftruncate(fd, (high << 32) | low); |
| 196 | } |
| 197 | |
| 198 | long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf, |
| 199 | size_t len) |
| 200 | { |
| 201 | return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low, |
| 202 | buf, len); |
| 203 | } |
| 204 | |
| 205 | long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low, |
| 206 | size_t len, int advice) |
| 207 | { |
| 208 | return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len, |
| 209 | advice); |
| 210 | } |
| 211 | |
Stephen Rothwell | b09a491 | 2005-10-18 14:51:57 +1000 | [diff] [blame] | 212 | asmlinkage long compat_sys_add_key(const char __user *_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | const char __user *_description, |
| 214 | const void __user *_payload, |
| 215 | u32 plen, |
| 216 | u32 ringid) |
| 217 | { |
| 218 | return sys_add_key(_type, _description, _payload, plen, ringid); |
| 219 | } |
| 220 | |
Stephen Rothwell | b09a491 | 2005-10-18 14:51:57 +1000 | [diff] [blame] | 221 | asmlinkage long compat_sys_request_key(const char __user *_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | const char __user *_description, |
| 223 | const char __user *_callout_info, |
| 224 | u32 destringid) |
| 225 | { |
| 226 | return sys_request_key(_type, _description, _callout_info, destringid); |
| 227 | } |
| 228 | |
David Woodhouse | edd5cd4 | 2007-06-27 14:10:09 -0700 | [diff] [blame] | 229 | asmlinkage long compat_sys_sync_file_range2(int fd, unsigned int flags, |
| 230 | unsigned offset_hi, unsigned offset_lo, |
| 231 | unsigned nbytes_hi, unsigned nbytes_lo) |
| 232 | { |
| 233 | loff_t offset = ((loff_t)offset_hi << 32) | offset_lo; |
| 234 | loff_t nbytes = ((loff_t)nbytes_hi << 32) | nbytes_lo; |
| 235 | |
| 236 | return sys_sync_file_range(fd, offset, nbytes, flags); |
| 237 | } |
Andreas Schwab | bcc30d3 | 2010-08-19 05:15:37 +0000 | [diff] [blame] | 238 | |
| 239 | asmlinkage long compat_sys_fanotify_mark(int fanotify_fd, unsigned int flags, |
| 240 | unsigned mask_hi, unsigned mask_lo, |
| 241 | int dfd, const char __user *pathname) |
| 242 | { |
| 243 | u64 mask = ((u64)mask_hi << 32) | mask_lo; |
| 244 | return sys_fanotify_mark(fanotify_fd, flags, mask, dfd, pathname); |
| 245 | } |