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 #ifdef __MIPSEB__
471da177e4SLinus Torvalds #define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
481da177e4SLinus Torvalds #endif
491da177e4SLinus Torvalds #ifdef __MIPSEL__
501da177e4SLinus Torvalds #define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
511da177e4SLinus Torvalds #endif
521da177e4SLinus Torvalds
53dbda6ac0SRalf Baechle SYSCALL_DEFINE4(32_truncate64, const char __user *, path,
54dbda6ac0SRalf Baechle unsigned long, __dummy, unsigned long, a2, unsigned long, a3)
551da177e4SLinus Torvalds {
56df260e21SDominik Brodowski return ksys_truncate(path, merge_64(a2, a3));
571da177e4SLinus Torvalds }
581da177e4SLinus Torvalds
59dbda6ac0SRalf Baechle SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy,
60dbda6ac0SRalf Baechle unsigned long, a2, unsigned long, a3)
611da177e4SLinus Torvalds {
62411d9475SDominik Brodowski return ksys_ftruncate(fd, merge_64(a2, a3));
631da177e4SLinus Torvalds }
641da177e4SLinus Torvalds
65d6c178e9SRalf Baechle SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high,
66d6c178e9SRalf Baechle unsigned int, offset_low, loff_t __user *, result,
67d6c178e9SRalf Baechle unsigned int, origin)
681da177e4SLinus Torvalds {
691da177e4SLinus Torvalds return sys_llseek(fd, offset_high, offset_low, result, origin);
701da177e4SLinus Torvalds }
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
731da177e4SLinus Torvalds lseek back to original location. They fail just like lseek does on
741da177e4SLinus Torvalds non-seekable files. */
751da177e4SLinus Torvalds
76dbda6ac0SRalf Baechle SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count,
77dbda6ac0SRalf Baechle unsigned long, unused, unsigned long, a4, unsigned long, a5)
781da177e4SLinus Torvalds {
7936028d5dSDominik Brodowski return ksys_pread64(fd, buf, count, merge_64(a4, a5));
801da177e4SLinus Torvalds }
811da177e4SLinus Torvalds
82dbda6ac0SRalf Baechle SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf,
83dbda6ac0SRalf Baechle size_t, count, u32, unused, u64, a4, u64, a5)
841da177e4SLinus Torvalds {
8536028d5dSDominik Brodowski return ksys_pwrite64(fd, buf, count, merge_64(a4, a5));
861da177e4SLinus Torvalds }
871da177e4SLinus Torvalds
88dbda6ac0SRalf Baechle SYSCALL_DEFINE1(32_personality, unsigned long, personality)
891da177e4SLinus Torvalds {
90d62c9cedSDavid Daney unsigned int p = personality & 0xffffffff;
911da177e4SLinus Torvalds int ret;
92d62c9cedSDavid Daney
9353571ce4SThiemo Seufer if (personality(current->personality) == PER_LINUX32 &&
94d62c9cedSDavid Daney personality(p) == PER_LINUX)
95d62c9cedSDavid Daney p = (p & ~PER_MASK) | PER_LINUX32;
96d62c9cedSDavid Daney ret = sys_personality(p);
97d62c9cedSDavid Daney if (ret != -1 && personality(ret) == PER_LINUX32)
98d62c9cedSDavid Daney ret = (ret & ~PER_MASK) | PER_LINUX;
991da177e4SLinus Torvalds return ret;
1001da177e4SLinus Torvalds }
1011da177e4SLinus Torvalds
sys32_readahead(int fd,u32 pad0,u64 a2,u64 a3,size_t count)1021da177e4SLinus Torvalds asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
1031da177e4SLinus Torvalds size_t count)
1041da177e4SLinus Torvalds {
105*c7b95d51SDominik Brodowski return ksys_readahead(fd, merge_64(a2, a3), count);
1061da177e4SLinus Torvalds }
1071da177e4SLinus Torvalds
sys32_sync_file_range(int fd,int __pad,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,int flags)108a8d587a7SRalf Baechle asmlinkage long sys32_sync_file_range(int fd, int __pad,
109a8d587a7SRalf Baechle unsigned long a2, unsigned long a3,
110a8d587a7SRalf Baechle unsigned long a4, unsigned long a5,
111a8d587a7SRalf Baechle int flags)
112a8d587a7SRalf Baechle {
113806cbae1SDominik Brodowski return ksys_sync_file_range(fd,
114a8d587a7SRalf Baechle merge_64(a2, a3), merge_64(a4, a5),
115a8d587a7SRalf Baechle flags);
116a8d587a7SRalf Baechle }
117a8d587a7SRalf Baechle
sys32_fadvise64_64(int fd,int __pad,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,int flags)1188676d2e0SAtsushi Nemoto asmlinkage long sys32_fadvise64_64(int fd, int __pad,
1198676d2e0SAtsushi Nemoto unsigned long a2, unsigned long a3,
1208676d2e0SAtsushi Nemoto unsigned long a4, unsigned long a5,
1218676d2e0SAtsushi Nemoto int flags)
1228676d2e0SAtsushi Nemoto {
1239d5b7c95SDominik Brodowski return ksys_fadvise64_64(fd,
1248676d2e0SAtsushi Nemoto merge_64(a2, a3), merge_64(a4, a5),
1258676d2e0SAtsushi Nemoto flags);
1268676d2e0SAtsushi Nemoto }
1278676d2e0SAtsushi Nemoto
sys32_fallocate(int fd,int mode,unsigned offset_a2,unsigned offset_a3,unsigned len_a4,unsigned len_a5)1284dc46775SRalf Baechle asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2,
1294dc46775SRalf Baechle unsigned offset_a3, unsigned len_a4, unsigned len_a5)
1304dc46775SRalf Baechle {
131edf292c7SDominik Brodowski return ksys_fallocate(fd, mode, merge_64(offset_a2, offset_a3),
1324dc46775SRalf Baechle merge_64(len_a4, len_a5));
1334dc46775SRalf Baechle }
134