Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  Implementation of various system calls for Linux/PowerPC
0004  *
0005  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
0006  *
0007  * Derived from "arch/i386/kernel/sys_i386.c"
0008  * Adapted from the i386 version by Gary Thomas
0009  * Modified by Cort Dougan (cort@cs.nmt.edu)
0010  * and Paul Mackerras (paulus@cs.anu.edu.au).
0011  *
0012  * This file contains various random system calls that
0013  * have a non-standard calling sequence on the Linux/PPC
0014  * platform.
0015  */
0016 
0017 #include <linux/errno.h>
0018 #include <linux/sched.h>
0019 #include <linux/syscalls.h>
0020 #include <linux/mm.h>
0021 #include <linux/fs.h>
0022 #include <linux/smp.h>
0023 #include <linux/sem.h>
0024 #include <linux/msg.h>
0025 #include <linux/shm.h>
0026 #include <linux/stat.h>
0027 #include <linux/mman.h>
0028 #include <linux/sys.h>
0029 #include <linux/ipc.h>
0030 #include <linux/utsname.h>
0031 #include <linux/file.h>
0032 #include <linux/personality.h>
0033 
0034 #include <linux/uaccess.h>
0035 #include <asm/syscalls.h>
0036 #include <asm/time.h>
0037 #include <asm/unistd.h>
0038 
0039 static inline long do_mmap2(unsigned long addr, size_t len,
0040             unsigned long prot, unsigned long flags,
0041             unsigned long fd, unsigned long off, int shift)
0042 {
0043     if (!arch_validate_prot(prot, addr))
0044         return -EINVAL;
0045 
0046     if (!IS_ALIGNED(off, 1 << shift))
0047         return -EINVAL;
0048 
0049     return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> shift);
0050 }
0051 
0052 SYSCALL_DEFINE6(mmap2, unsigned long, addr, size_t, len,
0053         unsigned long, prot, unsigned long, flags,
0054         unsigned long, fd, unsigned long, pgoff)
0055 {
0056     return do_mmap2(addr, len, prot, flags, fd, pgoff, PAGE_SHIFT-12);
0057 }
0058 
0059 SYSCALL_DEFINE6(mmap, unsigned long, addr, size_t, len,
0060         unsigned long, prot, unsigned long, flags,
0061         unsigned long, fd, off_t, offset)
0062 {
0063     return do_mmap2(addr, len, prot, flags, fd, offset, PAGE_SHIFT);
0064 }
0065 
0066 #ifdef CONFIG_PPC32
0067 /*
0068  * Due to some executables calling the wrong select we sometimes
0069  * get wrong args.  This determines how the args are being passed
0070  * (a single ptr to them all args passed) then calls
0071  * sys_select() with the appropriate args. -- Cort
0072  */
0073 int
0074 ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct __kernel_old_timeval __user *tvp)
0075 {
0076     if ((unsigned long)n >= 4096)
0077         return sys_old_select((void __user *)n);
0078 
0079     return sys_select(n, inp, outp, exp, tvp);
0080 }
0081 #endif
0082 
0083 #ifdef CONFIG_PPC64
0084 long ppc64_personality(unsigned long personality)
0085 {
0086     long ret;
0087 
0088     if (personality(current->personality) == PER_LINUX32
0089         && personality(personality) == PER_LINUX)
0090         personality = (personality & ~PER_MASK) | PER_LINUX32;
0091     ret = sys_personality(personality);
0092     if (personality(ret) == PER_LINUX32)
0093         ret = (ret & ~PER_MASK) | PER_LINUX;
0094     return ret;
0095 }
0096 #endif
0097 
0098 long ppc_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
0099               u32 len_high, u32 len_low)
0100 {
0101     return ksys_fadvise64_64(fd, (u64)offset_high << 32 | offset_low,
0102                  (u64)len_high << 32 | len_low, advice);
0103 }
0104 
0105 SYSCALL_DEFINE0(switch_endian)
0106 {
0107     struct thread_info *ti;
0108 
0109     regs_set_return_msr(current->thread.regs,
0110                 current->thread.regs->msr ^ MSR_LE);
0111 
0112     /*
0113      * Set TIF_RESTOREALL so that r3 isn't clobbered on return to
0114      * userspace. That also has the effect of restoring the non-volatile
0115      * GPRs, so we saved them on the way in here.
0116      */
0117     ti = current_thread_info();
0118     ti->flags |= _TIF_RESTOREALL;
0119 
0120     return 0;
0121 }