1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Conversion between 32-bit and 64-bit native system calls. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 2000 Silicon Graphics, Inc. 61da177e4SLinus Torvalds * Written by Ulf Carlsson (ulfc@engr.sgi.com) 71da177e4SLinus Torvalds */ 81da177e4SLinus Torvalds #include <linux/compiler.h> 91da177e4SLinus Torvalds #include <linux/mm.h> 101da177e4SLinus Torvalds #include <linux/errno.h> 111da177e4SLinus Torvalds #include <linux/file.h> 121da177e4SLinus Torvalds #include <linux/highuid.h> 131da177e4SLinus Torvalds #include <linux/resource.h> 141da177e4SLinus Torvalds #include <linux/highmem.h> 151da177e4SLinus Torvalds #include <linux/time.h> 161da177e4SLinus Torvalds #include <linux/times.h> 171da177e4SLinus Torvalds #include <linux/poll.h> 181da177e4SLinus Torvalds #include <linux/skbuff.h> 191da177e4SLinus Torvalds #include <linux/filter.h> 201da177e4SLinus Torvalds #include <linux/shm.h> 211da177e4SLinus Torvalds #include <linux/sem.h> 221da177e4SLinus Torvalds #include <linux/msg.h> 231da177e4SLinus Torvalds #include <linux/icmpv6.h> 241da177e4SLinus Torvalds #include <linux/syscalls.h> 251da177e4SLinus Torvalds #include <linux/sysctl.h> 261da177e4SLinus Torvalds #include <linux/utime.h> 271da177e4SLinus Torvalds #include <linux/utsname.h> 281da177e4SLinus Torvalds #include <linux/personality.h> 291da177e4SLinus Torvalds #include <linux/dnotify.h> 301da177e4SLinus Torvalds #include <linux/binfmts.h> 311da177e4SLinus Torvalds #include <linux/security.h> 321da177e4SLinus Torvalds #include <linux/compat.h> 331da177e4SLinus Torvalds #include <linux/vfs.h> 34cba4fbbfSAdrian Bunk #include <linux/ipc.h> 355a0e3ad6STejun Heo #include <linux/slab.h> 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds #include <net/sock.h> 381da177e4SLinus Torvalds #include <net/scm.h> 391da177e4SLinus Torvalds 40431dc804SRalf Baechle #include <asm/compat-signal.h> 411da177e4SLinus Torvalds #include <asm/sim.h> 427c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 431da177e4SLinus Torvalds #include <asm/mmu_context.h> 441da177e4SLinus Torvalds #include <asm/mman.h> 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds /* Use this to get at 32-bit user passed pointers. */ 471da177e4SLinus Torvalds /* A() macro should be used for places where you e.g. 481da177e4SLinus Torvalds have some internal variable u32 and just want to get 491da177e4SLinus Torvalds rid of a compiler warning. AA() has to be used in 501da177e4SLinus Torvalds places where you want to convert a function argument 511da177e4SLinus Torvalds to 32bit pointer or when you e.g. access pt_regs 521da177e4SLinus Torvalds structure and want to consider 32bit registers only. 531da177e4SLinus Torvalds */ 541da177e4SLinus Torvalds #define A(__x) ((unsigned long)(__x)) 551da177e4SLinus Torvalds #define AA(__x) ((unsigned long)((int)__x)) 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds #ifdef __MIPSEB__ 581da177e4SLinus Torvalds #define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL)) 591da177e4SLinus Torvalds #endif 601da177e4SLinus Torvalds #ifdef __MIPSEL__ 611da177e4SLinus Torvalds #define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL)) 621da177e4SLinus Torvalds #endif 631da177e4SLinus Torvalds 64dbda6ac0SRalf Baechle SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len, 65dbda6ac0SRalf Baechle unsigned long, prot, unsigned long, flags, unsigned long, fd, 66dbda6ac0SRalf Baechle unsigned long, pgoff) 671da177e4SLinus Torvalds { 68947df17cSH. Peter Anvin if (pgoff & (~PAGE_MASK >> 12)) 69fcf4aec1SMarkus Elfring return -EINVAL; 70fcf4aec1SMarkus Elfring return sys_mmap_pgoff(addr, len, prot, flags, fd, 71f8b72560SAl Viro pgoff >> (PAGE_SHIFT-12)); 721da177e4SLinus Torvalds } 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds #define RLIM_INFINITY32 0x7fffffff 751da177e4SLinus Torvalds #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x) 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds struct rlimit32 { 781da177e4SLinus Torvalds int rlim_cur; 791da177e4SLinus Torvalds int rlim_max; 801da177e4SLinus Torvalds }; 811da177e4SLinus Torvalds 82dbda6ac0SRalf Baechle SYSCALL_DEFINE4(32_truncate64, const char __user *, path, 83dbda6ac0SRalf Baechle unsigned long, __dummy, unsigned long, a2, unsigned long, a3) 841da177e4SLinus Torvalds { 85df260e21SDominik Brodowski return ksys_truncate(path, merge_64(a2, a3)); 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 88dbda6ac0SRalf Baechle SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy, 89dbda6ac0SRalf Baechle unsigned long, a2, unsigned long, a3) 901da177e4SLinus Torvalds { 91411d9475SDominik Brodowski return ksys_ftruncate(fd, merge_64(a2, a3)); 921da177e4SLinus Torvalds } 931da177e4SLinus Torvalds 94d6c178e9SRalf Baechle SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high, 95d6c178e9SRalf Baechle unsigned int, offset_low, loff_t __user *, result, 96d6c178e9SRalf Baechle unsigned int, origin) 971da177e4SLinus Torvalds { 981da177e4SLinus Torvalds return sys_llseek(fd, offset_high, offset_low, result, origin); 991da177e4SLinus Torvalds } 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op + 1021da177e4SLinus Torvalds lseek back to original location. They fail just like lseek does on 1031da177e4SLinus Torvalds non-seekable files. */ 1041da177e4SLinus Torvalds 105dbda6ac0SRalf Baechle SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count, 106dbda6ac0SRalf Baechle unsigned long, unused, unsigned long, a4, unsigned long, a5) 1071da177e4SLinus Torvalds { 108*36028d5dSDominik Brodowski return ksys_pread64(fd, buf, count, merge_64(a4, a5)); 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 111dbda6ac0SRalf Baechle SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf, 112dbda6ac0SRalf Baechle size_t, count, u32, unused, u64, a4, u64, a5) 1131da177e4SLinus Torvalds { 114*36028d5dSDominik Brodowski return ksys_pwrite64(fd, buf, count, merge_64(a4, a5)); 1151da177e4SLinus Torvalds } 1161da177e4SLinus Torvalds 117dbda6ac0SRalf Baechle SYSCALL_DEFINE1(32_personality, unsigned long, personality) 1181da177e4SLinus Torvalds { 119d62c9cedSDavid Daney unsigned int p = personality & 0xffffffff; 1201da177e4SLinus Torvalds int ret; 121d62c9cedSDavid Daney 12253571ce4SThiemo Seufer if (personality(current->personality) == PER_LINUX32 && 123d62c9cedSDavid Daney personality(p) == PER_LINUX) 124d62c9cedSDavid Daney p = (p & ~PER_MASK) | PER_LINUX32; 125d62c9cedSDavid Daney ret = sys_personality(p); 126d62c9cedSDavid Daney if (ret != -1 && personality(ret) == PER_LINUX32) 127d62c9cedSDavid Daney ret = (ret & ~PER_MASK) | PER_LINUX; 1281da177e4SLinus Torvalds return ret; 1291da177e4SLinus Torvalds } 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3, 1321da177e4SLinus Torvalds size_t count) 1331da177e4SLinus Torvalds { 1341da177e4SLinus Torvalds return sys_readahead(fd, merge_64(a2, a3), count); 1351da177e4SLinus Torvalds } 1361da177e4SLinus Torvalds 137a8d587a7SRalf Baechle asmlinkage long sys32_sync_file_range(int fd, int __pad, 138a8d587a7SRalf Baechle unsigned long a2, unsigned long a3, 139a8d587a7SRalf Baechle unsigned long a4, unsigned long a5, 140a8d587a7SRalf Baechle int flags) 141a8d587a7SRalf Baechle { 142806cbae1SDominik Brodowski return ksys_sync_file_range(fd, 143a8d587a7SRalf Baechle merge_64(a2, a3), merge_64(a4, a5), 144a8d587a7SRalf Baechle flags); 145a8d587a7SRalf Baechle } 146a8d587a7SRalf Baechle 1478676d2e0SAtsushi Nemoto asmlinkage long sys32_fadvise64_64(int fd, int __pad, 1488676d2e0SAtsushi Nemoto unsigned long a2, unsigned long a3, 1498676d2e0SAtsushi Nemoto unsigned long a4, unsigned long a5, 1508676d2e0SAtsushi Nemoto int flags) 1518676d2e0SAtsushi Nemoto { 1528676d2e0SAtsushi Nemoto return sys_fadvise64_64(fd, 1538676d2e0SAtsushi Nemoto merge_64(a2, a3), merge_64(a4, a5), 1548676d2e0SAtsushi Nemoto flags); 1558676d2e0SAtsushi Nemoto } 1568676d2e0SAtsushi Nemoto 1574dc46775SRalf Baechle asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2, 1584dc46775SRalf Baechle unsigned offset_a3, unsigned len_a4, unsigned len_a5) 1594dc46775SRalf Baechle { 1604dc46775SRalf Baechle return sys_fallocate(fd, mode, merge_64(offset_a2, offset_a3), 1614dc46775SRalf Baechle merge_64(len_a4, len_a5)); 1624dc46775SRalf Baechle } 163