^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * sys_ppc32.c: Conversion between 32bit and 64bit native syscalls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2001 IBM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * These routines maintain argument size conversion between 32bit and 64bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * environment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/resource.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/times.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/sem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/msg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/shm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/personality.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/binfmts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/ipc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <asm/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <asm/ppc-pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <asm/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned long compat_sys_mmap2(unsigned long addr, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long prot, unsigned long flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned long fd, unsigned long pgoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* This should remain 12 even if PAGE_SIZE changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * long long munging:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * The 32 bit ABI passes long longs in an odd even register pair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u32 reg6, u32 poshi, u32 poslo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return ksys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) compat_ssize_t compat_sys_pwrite64(unsigned int fd, const char __user *ubuf, compat_size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u32 reg6, u32 poshi, u32 poslo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return ksys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return ksys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) unsigned long high, unsigned long low)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return ksys_truncate(path, (high << 32) | low);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 lenhi, u32 lenlo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return ksys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ((loff_t)lenhi << 32) | lenlo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) unsigned long low)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return ksys_ftruncate(fd, (high << 32) | low);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) size_t len, int advice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return ksys_fadvise64_64(fd, (u64)offset_high << 32 | offset_low, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) advice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) asmlinkage long compat_sys_sync_file_range2(int fd, unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned offset_hi, unsigned offset_lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned nbytes_hi, unsigned nbytes_lo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) loff_t offset = ((loff_t)offset_hi << 32) | offset_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) loff_t nbytes = ((loff_t)nbytes_hi << 32) | nbytes_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return ksys_sync_file_range(fd, offset, nbytes, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }