syscall.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Access to user system call parameters and results
  4. *
  5. * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
  6. *
  7. * See asm-generic/syscall.h for descriptions of what we must do here.
  8. */
  9. #ifndef _ASM_X86_SYSCALL_H
  10. #define _ASM_X86_SYSCALL_H
  11. #include <uapi/linux/audit.h>
  12. #include <linux/sched.h>
  13. #include <linux/err.h>
  14. #include <asm/thread_info.h> /* for TS_COMPAT */
  15. #include <asm/unistd.h>
  16. typedef long (*sys_call_ptr_t)(const struct pt_regs *);
  17. extern const sys_call_ptr_t sys_call_table[];
  18. #if defined(CONFIG_X86_32)
  19. #define ia32_sys_call_table sys_call_table
  20. #else
  21. /*
  22. * These may not exist, but still put the prototypes in so we
  23. * can use IS_ENABLED().
  24. */
  25. extern const sys_call_ptr_t ia32_sys_call_table[];
  26. extern const sys_call_ptr_t x32_sys_call_table[];
  27. #endif
  28. /*
  29. * Only the low 32 bits of orig_ax are meaningful, so we return int.
  30. * This importantly ignores the high bits on 64-bit, so comparisons
  31. * sign-extend the low 32 bits.
  32. */
  33. static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  34. {
  35. return regs->orig_ax;
  36. }
  37. static inline void syscall_rollback(struct task_struct *task,
  38. struct pt_regs *regs)
  39. {
  40. regs->ax = regs->orig_ax;
  41. }
  42. static inline long syscall_get_error(struct task_struct *task,
  43. struct pt_regs *regs)
  44. {
  45. unsigned long error = regs->ax;
  46. #ifdef CONFIG_IA32_EMULATION
  47. /*
  48. * TS_COMPAT is set for 32-bit syscall entries and then
  49. * remains set until we return to user mode.
  50. */
  51. if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
  52. /*
  53. * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
  54. * and will match correctly in comparisons.
  55. */
  56. error = (long) (int) error;
  57. #endif
  58. return IS_ERR_VALUE(error) ? error : 0;
  59. }
  60. static inline long syscall_get_return_value(struct task_struct *task,
  61. struct pt_regs *regs)
  62. {
  63. return regs->ax;
  64. }
  65. static inline void syscall_set_return_value(struct task_struct *task,
  66. struct pt_regs *regs,
  67. int error, long val)
  68. {
  69. regs->ax = (long) error ?: val;
  70. }
  71. #ifdef CONFIG_X86_32
  72. static inline void syscall_get_arguments(struct task_struct *task,
  73. struct pt_regs *regs,
  74. unsigned long *args)
  75. {
  76. memcpy(args, &regs->bx, 6 * sizeof(args[0]));
  77. }
  78. static inline int syscall_get_arch(struct task_struct *task)
  79. {
  80. return AUDIT_ARCH_I386;
  81. }
  82. #else /* CONFIG_X86_64 */
  83. static inline void syscall_get_arguments(struct task_struct *task,
  84. struct pt_regs *regs,
  85. unsigned long *args)
  86. {
  87. # ifdef CONFIG_IA32_EMULATION
  88. if (task->thread_info.status & TS_COMPAT) {
  89. *args++ = regs->bx;
  90. *args++ = regs->cx;
  91. *args++ = regs->dx;
  92. *args++ = regs->si;
  93. *args++ = regs->di;
  94. *args = regs->bp;
  95. } else
  96. # endif
  97. {
  98. *args++ = regs->di;
  99. *args++ = regs->si;
  100. *args++ = regs->dx;
  101. *args++ = regs->r10;
  102. *args++ = regs->r8;
  103. *args = regs->r9;
  104. }
  105. }
  106. static inline int syscall_get_arch(struct task_struct *task)
  107. {
  108. /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
  109. return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
  110. task->thread_info.status & TS_COMPAT)
  111. ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
  112. }
  113. void do_syscall_64(struct pt_regs *regs, int nr);
  114. void do_int80_syscall_32(struct pt_regs *regs);
  115. long do_fast_syscall_32(struct pt_regs *regs);
  116. #endif /* CONFIG_X86_32 */
  117. #endif /* _ASM_X86_SYSCALL_H */