syscall.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_rollback(struct task_struct *task, struct pt_regs *regs)
  23. {
  24. regs->r0 = regs->orig_r0;
  25. }
  26. static inline long
  27. syscall_get_error(struct task_struct *task, struct pt_regs *regs)
  28. {
  29. /* 0 if syscall succeeded, otherwise -Errorcode */
  30. return IS_ERR_VALUE(regs->r0) ? regs->r0 : 0;
  31. }
  32. static inline long
  33. syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
  34. {
  35. return regs->r0;
  36. }
  37. static inline void
  38. syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
  39. int error, long val)
  40. {
  41. regs->r0 = (long) error ?: val;
  42. }
  43. /*
  44. * @i: argument index [0,5]
  45. * @n: number of arguments; n+i must be [1,6].
  46. */
  47. static inline void
  48. syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
  49. unsigned long *args)
  50. {
  51. unsigned long *inside_ptregs = &(regs->r0);
  52. unsigned int n = 6;
  53. unsigned int i = 0;
  54. while (n--) {
  55. args[i++] = (*inside_ptregs);
  56. inside_ptregs--;
  57. }
  58. }
  59. static inline int
  60. syscall_get_arch(struct task_struct *task)
  61. {
  62. return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
  63. ? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
  64. ? AUDIT_ARCH_ARCOMPACTBE : AUDIT_ARCH_ARCOMPACT)
  65. : (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
  66. ? AUDIT_ARCH_ARCV2BE : AUDIT_ARCH_ARCV2);
  67. }
  68. #endif