syscall.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Access to user system call parameters and results
  3. *
  4. * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
  5. *
  6. * This copyrighted material is made available to anyone wishing to use,
  7. * modify, copy, or redistribute it subject to the terms and conditions
  8. * of the GNU General Public License v.2.
  9. *
  10. * See asm-generic/syscall.h for descriptions of what we must do here.
  11. */
  12. #ifndef _ASM_SYSCALL_H
  13. #define _ASM_SYSCALL_H 1
  14. #include <uapi/linux/audit.h>
  15. #include <linux/sched.h>
  16. #include <linux/thread_info.h>
  17. /* ftrace syscalls requires exporting the sys_call_table */
  18. #ifdef CONFIG_FTRACE_SYSCALLS
  19. extern const unsigned long sys_call_table[];
  20. #endif /* CONFIG_FTRACE_SYSCALLS */
  21. static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  22. {
  23. /*
  24. * Note that we are returning an int here. That means 0xffffffff, ie.
  25. * 32-bit negative 1, will be interpreted as -1 on a 64-bit kernel.
  26. * This is important for seccomp so that compat tasks can set r0 = -1
  27. * to reject the syscall.
  28. */
  29. return TRAP(regs) == 0xc00 ? regs->gpr[0] : -1;
  30. }
  31. static inline void syscall_rollback(struct task_struct *task,
  32. struct pt_regs *regs)
  33. {
  34. regs->gpr[3] = regs->orig_gpr3;
  35. }
  36. static inline long syscall_get_return_value(struct task_struct *task,
  37. struct pt_regs *regs)
  38. {
  39. return regs->gpr[3];
  40. }
  41. static inline void syscall_set_return_value(struct task_struct *task,
  42. struct pt_regs *regs,
  43. int error, long val)
  44. {
  45. /*
  46. * In the general case it's not obvious that we must deal with CCR
  47. * here, as the syscall exit path will also do that for us. However
  48. * there are some places, eg. the signal code, which check ccr to
  49. * decide if the value in r3 is actually an error.
  50. */
  51. if (error) {
  52. regs->ccr |= 0x10000000L;
  53. regs->gpr[3] = error;
  54. } else {
  55. regs->ccr &= ~0x10000000L;
  56. regs->gpr[3] = val;
  57. }
  58. }
  59. static inline void syscall_get_arguments(struct task_struct *task,
  60. struct pt_regs *regs,
  61. unsigned int i, unsigned int n,
  62. unsigned long *args)
  63. {
  64. unsigned long val, mask = -1UL;
  65. BUG_ON(i + n > 6);
  66. #ifdef CONFIG_COMPAT
  67. if (test_tsk_thread_flag(task, TIF_32BIT))
  68. mask = 0xffffffff;
  69. #endif
  70. while (n--) {
  71. if (n == 0 && i == 0)
  72. val = regs->orig_gpr3;
  73. else
  74. val = regs->gpr[3 + i + n];
  75. args[n] = val & mask;
  76. }
  77. }
  78. static inline void syscall_set_arguments(struct task_struct *task,
  79. struct pt_regs *regs,
  80. unsigned int i, unsigned int n,
  81. const unsigned long *args)
  82. {
  83. BUG_ON(i + n > 6);
  84. memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
  85. /* Also copy the first argument into orig_gpr3 */
  86. if (i == 0 && n > 0)
  87. regs->orig_gpr3 = args[0];
  88. }
  89. static inline int syscall_get_arch(void)
  90. {
  91. int arch = is_32bit_task() ? AUDIT_ARCH_PPC : AUDIT_ARCH_PPC64;
  92. #ifdef __LITTLE_ENDIAN__
  93. arch |= __AUDIT_ARCH_LE;
  94. #endif
  95. return arch;
  96. }
  97. #endif /* _ASM_SYSCALL_H */