syscalls.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 ([email protected])
  6. *
  7. * Derived from "arch/i386/kernel/sys_i386.c"
  8. * Adapted from the i386 version by Gary Thomas
  9. * Modified by Cort Dougan ([email protected])
  10. * and Paul Mackerras ([email protected]).
  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. static long do_mmap2(unsigned long addr, size_t len,
  37. unsigned long prot, unsigned long flags,
  38. unsigned long fd, unsigned long off, int shift)
  39. {
  40. if (!arch_validate_prot(prot, addr))
  41. return -EINVAL;
  42. if (!IS_ALIGNED(off, 1 << shift))
  43. return -EINVAL;
  44. return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> shift);
  45. }
  46. SYSCALL_DEFINE6(mmap2, unsigned long, addr, size_t, len,
  47. unsigned long, prot, unsigned long, flags,
  48. unsigned long, fd, unsigned long, pgoff)
  49. {
  50. return do_mmap2(addr, len, prot, flags, fd, pgoff, PAGE_SHIFT-12);
  51. }
  52. #ifdef CONFIG_COMPAT
  53. COMPAT_SYSCALL_DEFINE6(mmap2,
  54. unsigned long, addr, size_t, len,
  55. unsigned long, prot, unsigned long, flags,
  56. unsigned long, fd, unsigned long, off_4k)
  57. {
  58. return do_mmap2(addr, len, prot, flags, fd, off_4k, PAGE_SHIFT-12);
  59. }
  60. #endif
  61. SYSCALL_DEFINE6(mmap, unsigned long, addr, size_t, len,
  62. unsigned long, prot, unsigned long, flags,
  63. unsigned long, fd, off_t, offset)
  64. {
  65. return do_mmap2(addr, len, prot, flags, fd, offset, PAGE_SHIFT);
  66. }
  67. #ifdef CONFIG_PPC64
  68. static long do_ppc64_personality(unsigned long personality)
  69. {
  70. long ret;
  71. if (personality(current->personality) == PER_LINUX32
  72. && personality(personality) == PER_LINUX)
  73. personality = (personality & ~PER_MASK) | PER_LINUX32;
  74. ret = ksys_personality(personality);
  75. if (personality(ret) == PER_LINUX32)
  76. ret = (ret & ~PER_MASK) | PER_LINUX;
  77. return ret;
  78. }
  79. SYSCALL_DEFINE1(ppc64_personality, unsigned long, personality)
  80. {
  81. return do_ppc64_personality(personality);
  82. }
  83. #ifdef CONFIG_COMPAT
  84. COMPAT_SYSCALL_DEFINE1(ppc64_personality, unsigned long, personality)
  85. {
  86. return do_ppc64_personality(personality);
  87. }
  88. #endif /* CONFIG_COMPAT */
  89. #endif /* CONFIG_PPC64 */
  90. SYSCALL_DEFINE6(ppc_fadvise64_64,
  91. int, fd, int, advice, u32, offset_high, u32, offset_low,
  92. u32, len_high, u32, len_low)
  93. {
  94. return ksys_fadvise64_64(fd, merge_64(offset_high, offset_low),
  95. merge_64(len_high, len_low), advice);
  96. }
  97. SYSCALL_DEFINE0(switch_endian)
  98. {
  99. struct thread_info *ti;
  100. regs_set_return_msr(current->thread.regs,
  101. current->thread.regs->msr ^ MSR_LE);
  102. /*
  103. * Set TIF_RESTOREALL so that r3 isn't clobbered on return to
  104. * userspace. That also has the effect of restoring the non-volatile
  105. * GPRs, so we saved them on the way in here.
  106. */
  107. ti = current_thread_info();
  108. ti->flags |= _TIF_RESTOREALL;
  109. return 0;
  110. }