syscalls.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Implementation of various system calls for Linux/PowerPC
  4. *
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * Derived from "arch/i386/kernel/sys_i386.c"
  8. * Adapted from the i386 version by Gary Thomas
  9. * Modified by Cort Dougan (cort@cs.nmt.edu)
  10. * and Paul Mackerras (paulus@cs.anu.edu.au).
  11. *
  12. * This file contains various random system calls that
  13. * have a non-standard calling sequence on the Linux/PPC
  14. * platform.
  15. */
  16. #include <linux/errno.h>
  17. #include <linux/sched.h>
  18. #include <linux/syscalls.h>
  19. #include <linux/mm.h>
  20. #include <linux/fs.h>
  21. #include <linux/smp.h>
  22. #include <linux/sem.h>
  23. #include <linux/msg.h>
  24. #include <linux/shm.h>
  25. #include <linux/stat.h>
  26. #include <linux/mman.h>
  27. #include <linux/sys.h>
  28. #include <linux/ipc.h>
  29. #include <linux/utsname.h>
  30. #include <linux/file.h>
  31. #include <linux/personality.h>
  32. #include <linux/uaccess.h>
  33. #include <asm/syscalls.h>
  34. #include <asm/time.h>
  35. #include <asm/unistd.h>
  36. #include <asm/asm-prototypes.h>
  37. static inline long do_mmap2(unsigned long addr, size_t len,
  38. unsigned long prot, unsigned long flags,
  39. unsigned long fd, unsigned long off, int shift)
  40. {
  41. long ret = -EINVAL;
  42. if (!arch_validate_prot(prot, addr))
  43. goto out;
  44. if (shift) {
  45. if (off & ((1 << shift) - 1))
  46. goto out;
  47. off >>= shift;
  48. }
  49. ret = ksys_mmap_pgoff(addr, len, prot, flags, fd, off);
  50. out:
  51. return ret;
  52. }
  53. SYSCALL_DEFINE6(mmap2, unsigned long, addr, size_t, len,
  54. unsigned long, prot, unsigned long, flags,
  55. unsigned long, fd, unsigned long, pgoff)
  56. {
  57. return do_mmap2(addr, len, prot, flags, fd, pgoff, PAGE_SHIFT-12);
  58. }
  59. SYSCALL_DEFINE6(mmap, unsigned long, addr, size_t, len,
  60. unsigned long, prot, unsigned long, flags,
  61. unsigned long, fd, off_t, offset)
  62. {
  63. return do_mmap2(addr, len, prot, flags, fd, offset, PAGE_SHIFT);
  64. }
  65. #ifdef CONFIG_PPC32
  66. /*
  67. * Due to some executables calling the wrong select we sometimes
  68. * get wrong args. This determines how the args are being passed
  69. * (a single ptr to them all args passed) then calls
  70. * sys_select() with the appropriate args. -- Cort
  71. */
  72. int
  73. ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct __kernel_old_timeval __user *tvp)
  74. {
  75. if ( (unsigned long)n >= 4096 )
  76. {
  77. unsigned long __user *buffer = (unsigned long __user *)n;
  78. if (!access_ok(buffer, 5*sizeof(unsigned long))
  79. || __get_user(n, buffer)
  80. || __get_user(inp, ((fd_set __user * __user *)(buffer+1)))
  81. || __get_user(outp, ((fd_set __user * __user *)(buffer+2)))
  82. || __get_user(exp, ((fd_set __user * __user *)(buffer+3)))
  83. || __get_user(tvp, ((struct __kernel_old_timeval __user * __user *)(buffer+4))))
  84. return -EFAULT;
  85. }
  86. return sys_select(n, inp, outp, exp, tvp);
  87. }
  88. #endif
  89. #ifdef CONFIG_PPC64
  90. long ppc64_personality(unsigned long personality)
  91. {
  92. long ret;
  93. if (personality(current->personality) == PER_LINUX32
  94. && personality(personality) == PER_LINUX)
  95. personality = (personality & ~PER_MASK) | PER_LINUX32;
  96. ret = sys_personality(personality);
  97. if (personality(ret) == PER_LINUX32)
  98. ret = (ret & ~PER_MASK) | PER_LINUX;
  99. return ret;
  100. }
  101. #endif
  102. long ppc_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
  103. u32 len_high, u32 len_low)
  104. {
  105. return ksys_fadvise64_64(fd, (u64)offset_high << 32 | offset_low,
  106. (u64)len_high << 32 | len_low, advice);
  107. }
  108. SYSCALL_DEFINE0(switch_endian)
  109. {
  110. struct thread_info *ti;
  111. current->thread.regs->msr ^= MSR_LE;
  112. /*
  113. * Set TIF_RESTOREALL so that r3 isn't clobbered on return to
  114. * userspace. That also has the effect of restoring the non-volatile
  115. * GPRs, so we saved them on the way in here.
  116. */
  117. ti = current_thread_info();
  118. ti->flags |= _TIF_RESTOREALL;
  119. return 0;
  120. }