syscall.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
  4. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  5. * Copyright 2015 Regents of the University of California, Berkeley
  6. *
  7. * See asm-generic/syscall.h for descriptions of what we must do here.
  8. */
  9. #ifndef _ASM_RISCV_SYSCALL_H
  10. #define _ASM_RISCV_SYSCALL_H
  11. #include <uapi/linux/audit.h>
  12. #include <linux/sched.h>
  13. #include <linux/err.h>
  14. /* The array of function pointers for syscalls. */
  15. extern const void *sys_call_table[];
  16. #ifdef CONFIG_COMPAT
  17. extern const void *compat_sys_call_table[];
  18. #endif
  19. /*
  20. * Only the low 32 bits of orig_r0 are meaningful, so we return int.
  21. * This importantly ignores the high bits on 64-bit, so comparisons
  22. * sign-extend the low 32 bits.
  23. */
  24. static inline int syscall_get_nr(struct task_struct *task,
  25. struct pt_regs *regs)
  26. {
  27. return regs->a7;
  28. }
  29. static inline void syscall_rollback(struct task_struct *task,
  30. struct pt_regs *regs)
  31. {
  32. regs->a0 = regs->orig_a0;
  33. }
  34. static inline long syscall_get_error(struct task_struct *task,
  35. struct pt_regs *regs)
  36. {
  37. unsigned long error = regs->a0;
  38. return IS_ERR_VALUE(error) ? error : 0;
  39. }
  40. static inline long syscall_get_return_value(struct task_struct *task,
  41. struct pt_regs *regs)
  42. {
  43. return regs->a0;
  44. }
  45. static inline void syscall_set_return_value(struct task_struct *task,
  46. struct pt_regs *regs,
  47. int error, long val)
  48. {
  49. regs->a0 = (long) error ?: val;
  50. }
  51. static inline void syscall_get_arguments(struct task_struct *task,
  52. struct pt_regs *regs,
  53. unsigned long *args)
  54. {
  55. args[0] = regs->orig_a0;
  56. args++;
  57. memcpy(args, &regs->a1, 5 * sizeof(args[0]));
  58. }
  59. static inline void syscall_set_arguments(struct task_struct *task,
  60. struct pt_regs *regs,
  61. const unsigned long *args)
  62. {
  63. regs->orig_a0 = args[0];
  64. args++;
  65. memcpy(&regs->a1, args, 5 * sizeof(regs->a1));
  66. }
  67. static inline int syscall_get_arch(struct task_struct *task)
  68. {
  69. #ifdef CONFIG_64BIT
  70. return AUDIT_ARCH_RISCV64;
  71. #else
  72. return AUDIT_ARCH_RISCV32;
  73. #endif
  74. }
  75. #endif /* _ASM_RISCV_SYSCALL_H */