syscall.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 long syscall_get_nr(struct task_struct *task,
  22. struct pt_regs *regs)
  23. {
  24. return TRAP(regs) == 0xc00 ? regs->gpr[0] : -1L;
  25. }
  26. static inline void syscall_rollback(struct task_struct *task,
  27. struct pt_regs *regs)
  28. {
  29. regs->gpr[3] = regs->orig_gpr3;
  30. }
  31. static inline long syscall_get_error(struct task_struct *task,
  32. struct pt_regs *regs)
  33. {
  34. return (regs->ccr & 0x10000000) ? -regs->gpr[3] : 0;
  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. if (error) {
  46. regs->ccr |= 0x10000000L;
  47. regs->gpr[3] = -error;
  48. } else {
  49. regs->ccr &= ~0x10000000L;
  50. regs->gpr[3] = val;
  51. }
  52. }
  53. static inline void syscall_get_arguments(struct task_struct *task,
  54. struct pt_regs *regs,
  55. unsigned int i, unsigned int n,
  56. unsigned long *args)
  57. {
  58. BUG_ON(i + n > 6);
  59. #ifdef CONFIG_PPC64
  60. if (test_tsk_thread_flag(task, TIF_32BIT)) {
  61. /*
  62. * Zero-extend 32-bit argument values. The high bits are
  63. * garbage ignored by the actual syscall dispatch.
  64. */
  65. while (n-- > 0)
  66. args[n] = (u32) regs->gpr[3 + i + n];
  67. return;
  68. }
  69. #endif
  70. memcpy(args, &regs->gpr[3 + i], n * sizeof(args[0]));
  71. }
  72. static inline void syscall_set_arguments(struct task_struct *task,
  73. struct pt_regs *regs,
  74. unsigned int i, unsigned int n,
  75. const unsigned long *args)
  76. {
  77. BUG_ON(i + n > 6);
  78. memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
  79. }
  80. static inline int syscall_get_arch(void)
  81. {
  82. int arch = is_32bit_task() ? AUDIT_ARCH_PPC : AUDIT_ARCH_PPC64;
  83. #ifdef __LITTLE_ENDIAN__
  84. arch |= __AUDIT_ARCH_LE;
  85. #endif
  86. return arch;
  87. }
  88. #endif /* _ASM_SYSCALL_H */