syscall.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * S390 version
  4. * Copyright IBM Corp. 1999, 2000
  5. * Author(s): Martin Schwidefsky ([email protected]),
  6. * Thomas Spatzier ([email protected])
  7. *
  8. * Derived from "arch/i386/kernel/sys_i386.c"
  9. *
  10. * This file contains various random system calls that
  11. * have a non-standard calling sequence on the Linux/s390
  12. * platform.
  13. */
  14. #include <linux/errno.h>
  15. #include <linux/sched.h>
  16. #include <linux/mm.h>
  17. #include <linux/fs.h>
  18. #include <linux/smp.h>
  19. #include <linux/sem.h>
  20. #include <linux/msg.h>
  21. #include <linux/shm.h>
  22. #include <linux/stat.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/mman.h>
  25. #include <linux/file.h>
  26. #include <linux/utsname.h>
  27. #include <linux/personality.h>
  28. #include <linux/unistd.h>
  29. #include <linux/ipc.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/string.h>
  32. #include <linux/thread_info.h>
  33. #include <linux/entry-common.h>
  34. #include <asm/ptrace.h>
  35. #include <asm/vtime.h>
  36. #include "entry.h"
  37. /*
  38. * Perform the mmap() system call. Linux for S/390 isn't able to handle more
  39. * than 5 system call parameters, so this system call uses a memory block
  40. * for parameter passing.
  41. */
  42. struct s390_mmap_arg_struct {
  43. unsigned long addr;
  44. unsigned long len;
  45. unsigned long prot;
  46. unsigned long flags;
  47. unsigned long fd;
  48. unsigned long offset;
  49. };
  50. SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg)
  51. {
  52. struct s390_mmap_arg_struct a;
  53. int error = -EFAULT;
  54. if (copy_from_user(&a, arg, sizeof(a)))
  55. goto out;
  56. error = ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
  57. out:
  58. return error;
  59. }
  60. #ifdef CONFIG_SYSVIPC
  61. /*
  62. * sys_ipc() is the de-multiplexer for the SysV IPC calls.
  63. */
  64. SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
  65. unsigned long, third, void __user *, ptr)
  66. {
  67. if (call >> 16)
  68. return -EINVAL;
  69. /* The s390 sys_ipc variant has only five parameters instead of six
  70. * like the generic variant. The only difference is the handling of
  71. * the SEMTIMEDOP subcall where on s390 the third parameter is used
  72. * as a pointer to a struct timespec where the generic variant uses
  73. * the fifth parameter.
  74. * Therefore we can call the generic variant by simply passing the
  75. * third parameter also as fifth parameter.
  76. */
  77. return ksys_ipc(call, first, second, third, ptr, third);
  78. }
  79. #endif /* CONFIG_SYSVIPC */
  80. SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
  81. {
  82. unsigned int ret = current->personality;
  83. if (personality(current->personality) == PER_LINUX32 &&
  84. personality(personality) == PER_LINUX)
  85. personality |= PER_LINUX32;
  86. if (personality != 0xffffffff)
  87. set_personality(personality);
  88. if (personality(ret) == PER_LINUX32)
  89. ret &= ~PER_LINUX32;
  90. return ret;
  91. }
  92. SYSCALL_DEFINE0(ni_syscall)
  93. {
  94. return -ENOSYS;
  95. }
  96. static void do_syscall(struct pt_regs *regs)
  97. {
  98. unsigned long nr;
  99. nr = regs->int_code & 0xffff;
  100. if (!nr) {
  101. nr = regs->gprs[1] & 0xffff;
  102. regs->int_code &= ~0xffffUL;
  103. regs->int_code |= nr;
  104. }
  105. regs->gprs[2] = nr;
  106. if (nr == __NR_restart_syscall && !(current->restart_block.arch_data & 1)) {
  107. regs->psw.addr = current->restart_block.arch_data;
  108. current->restart_block.arch_data = 1;
  109. }
  110. nr = syscall_enter_from_user_mode_work(regs, nr);
  111. /*
  112. * In the s390 ptrace ABI, both the syscall number and the return value
  113. * use gpr2. However, userspace puts the syscall number either in the
  114. * svc instruction itself, or uses gpr1. To make at least skipping syscalls
  115. * work, the ptrace code sets PIF_SYSCALL_RET_SET, which is checked here
  116. * and if set, the syscall will be skipped.
  117. */
  118. if (unlikely(test_and_clear_pt_regs_flag(regs, PIF_SYSCALL_RET_SET)))
  119. goto out;
  120. regs->gprs[2] = -ENOSYS;
  121. if (likely(nr >= NR_syscalls))
  122. goto out;
  123. do {
  124. regs->gprs[2] = current->thread.sys_call_table[nr](regs);
  125. } while (test_and_clear_pt_regs_flag(regs, PIF_EXECVE_PGSTE_RESTART));
  126. out:
  127. syscall_exit_to_user_mode_work(regs);
  128. }
  129. void noinstr __do_syscall(struct pt_regs *regs, int per_trap)
  130. {
  131. add_random_kstack_offset();
  132. enter_from_user_mode(regs);
  133. regs->psw = S390_lowcore.svc_old_psw;
  134. regs->int_code = S390_lowcore.svc_int_code;
  135. update_timer_sys();
  136. if (static_branch_likely(&cpu_has_bear))
  137. current->thread.last_break = regs->last_break;
  138. local_irq_enable();
  139. regs->orig_gpr2 = regs->gprs[2];
  140. if (per_trap)
  141. set_thread_flag(TIF_PER_TRAP);
  142. regs->flags = 0;
  143. set_pt_regs_flag(regs, PIF_SYSCALL);
  144. do_syscall(regs);
  145. exit_to_user_mode();
  146. }