syscall.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * S390 version
  4. * Copyright IBM Corp. 1999, 2000
  5. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  6. * Thomas Spatzier (tspat@de.ibm.com)
  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. #ifdef CONFIG_SYSVIPC
  38. /*
  39. * sys_ipc() is the de-multiplexer for the SysV IPC calls.
  40. */
  41. SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
  42. unsigned long, third, void __user *, ptr)
  43. {
  44. if (call >> 16)
  45. return -EINVAL;
  46. /* The s390 sys_ipc variant has only five parameters instead of six
  47. * like the generic variant. The only difference is the handling of
  48. * the SEMTIMEDOP subcall where on s390 the third parameter is used
  49. * as a pointer to a struct timespec where the generic variant uses
  50. * the fifth parameter.
  51. * Therefore we can call the generic variant by simply passing the
  52. * third parameter also as fifth parameter.
  53. */
  54. return ksys_ipc(call, first, second, third, ptr, third);
  55. }
  56. #endif /* CONFIG_SYSVIPC */
  57. SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
  58. {
  59. unsigned int ret = current->personality;
  60. if (personality(current->personality) == PER_LINUX32 &&
  61. personality(personality) == PER_LINUX)
  62. personality |= PER_LINUX32;
  63. if (personality != 0xffffffff)
  64. set_personality(personality);
  65. if (personality(ret) == PER_LINUX32)
  66. ret &= ~PER_LINUX32;
  67. return ret;
  68. }
  69. SYSCALL_DEFINE0(ni_syscall)
  70. {
  71. return -ENOSYS;
  72. }
  73. static void do_syscall(struct pt_regs *regs)
  74. {
  75. unsigned long nr;
  76. nr = regs->int_code & 0xffff;
  77. if (!nr) {
  78. nr = regs->gprs[1] & 0xffff;
  79. regs->int_code &= ~0xffffUL;
  80. regs->int_code |= nr;
  81. }
  82. regs->gprs[2] = nr;
  83. if (nr == __NR_restart_syscall && !(current->restart_block.arch_data & 1)) {
  84. regs->psw.addr = current->restart_block.arch_data;
  85. current->restart_block.arch_data = 1;
  86. }
  87. nr = syscall_enter_from_user_mode_work(regs, nr);
  88. /*
  89. * In the s390 ptrace ABI, both the syscall number and the return value
  90. * use gpr2. However, userspace puts the syscall number either in the
  91. * svc instruction itself, or uses gpr1. To make at least skipping syscalls
  92. * work, the ptrace code sets PIF_SYSCALL_RET_SET, which is checked here
  93. * and if set, the syscall will be skipped.
  94. */
  95. if (unlikely(test_and_clear_pt_regs_flag(regs, PIF_SYSCALL_RET_SET)))
  96. goto out;
  97. regs->gprs[2] = -ENOSYS;
  98. if (likely(nr >= NR_syscalls))
  99. goto out;
  100. do {
  101. regs->gprs[2] = current->thread.sys_call_table[nr](regs);
  102. } while (test_and_clear_pt_regs_flag(regs, PIF_EXECVE_PGSTE_RESTART));
  103. out:
  104. syscall_exit_to_user_mode_work(regs);
  105. }
  106. void noinstr __do_syscall(struct pt_regs *regs, int per_trap)
  107. {
  108. add_random_kstack_offset();
  109. enter_from_user_mode(regs);
  110. regs->psw = get_lowcore()->svc_old_psw;
  111. regs->int_code = get_lowcore()->svc_int_code;
  112. update_timer_sys();
  113. if (static_branch_likely(&cpu_has_bear))
  114. current->thread.last_break = regs->last_break;
  115. local_irq_enable();
  116. regs->orig_gpr2 = regs->gprs[2];
  117. if (per_trap)
  118. set_thread_flag(TIF_PER_TRAP);
  119. regs->flags = 0;
  120. set_pt_regs_flag(regs, PIF_SYSCALL);
  121. do_syscall(regs);
  122. exit_to_user_mode();
  123. }