syscall.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  4. */
  5. #ifndef _ASM_ARC_SYSCALL_H
  6. #define _ASM_ARC_SYSCALL_H 1
  7. #include <uapi/linux/audit.h>
  8. #include <linux/err.h>
  9. #include <linux/sched.h>
  10. #include <asm/unistd.h>
  11. #include <asm/ptrace.h> /* in_syscall() */
  12. extern void *sys_call_table[];
  13. static inline long
  14. syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  15. {
  16. if (user_mode(regs) && in_syscall(regs))
  17. return regs->r8;
  18. else
  19. return -1;
  20. }
  21. static inline void
  22. syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)
  23. {
  24. /*
  25. * Unlike syscall_get_nr(), syscall_set_nr() can be called only when
  26. * the target task is stopped for tracing on entering syscall, so
  27. * there is no need to have the same check syscall_get_nr() has.
  28. */
  29. regs->r8 = nr;
  30. }
  31. static inline void
  32. syscall_rollback(struct task_struct *task, struct pt_regs *regs)
  33. {
  34. regs->r0 = regs->orig_r0;
  35. }
  36. static inline long
  37. syscall_get_error(struct task_struct *task, struct pt_regs *regs)
  38. {
  39. /* 0 if syscall succeeded, otherwise -Errorcode */
  40. return IS_ERR_VALUE(regs->r0) ? regs->r0 : 0;
  41. }
  42. static inline long
  43. syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
  44. {
  45. return regs->r0;
  46. }
  47. static inline void
  48. syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
  49. int error, long val)
  50. {
  51. regs->r0 = (long) error ?: val;
  52. }
  53. /*
  54. * @i: argument index [0,5]
  55. * @n: number of arguments; n+i must be [1,6].
  56. */
  57. static inline void
  58. syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
  59. unsigned long *args)
  60. {
  61. unsigned long *inside_ptregs = &(regs->r0);
  62. unsigned int n = 6;
  63. unsigned int i = 0;
  64. while (n--) {
  65. args[i++] = (*inside_ptregs);
  66. inside_ptregs--;
  67. }
  68. }
  69. static inline void
  70. syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
  71. unsigned long *args)
  72. {
  73. unsigned long *inside_ptregs = &regs->r0;
  74. unsigned int n = 6;
  75. unsigned int i = 0;
  76. while (n--) {
  77. *inside_ptregs = args[i++];
  78. inside_ptregs--;
  79. }
  80. }
  81. static inline int
  82. syscall_get_arch(struct task_struct *task)
  83. {
  84. return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
  85. ? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
  86. ? AUDIT_ARCH_ARCOMPACTBE : AUDIT_ARCH_ARCOMPACT)
  87. : (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
  88. ? AUDIT_ARCH_ARCV2BE : AUDIT_ARCH_ARCV2);
  89. }
  90. #endif