syscall.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <linux/sched.h>
  15. /* ftrace syscalls requires exporting the sys_call_table */
  16. #ifdef CONFIG_FTRACE_SYSCALLS
  17. extern const unsigned long *sys_call_table;
  18. #endif /* CONFIG_FTRACE_SYSCALLS */
  19. static inline long syscall_get_nr(struct task_struct *task,
  20. struct pt_regs *regs)
  21. {
  22. return TRAP(regs) == 0xc00 ? regs->gpr[0] : -1L;
  23. }
  24. static inline void syscall_rollback(struct task_struct *task,
  25. struct pt_regs *regs)
  26. {
  27. regs->gpr[3] = regs->orig_gpr3;
  28. }
  29. static inline long syscall_get_error(struct task_struct *task,
  30. struct pt_regs *regs)
  31. {
  32. return (regs->ccr & 0x10000000) ? -regs->gpr[3] : 0;
  33. }
  34. static inline long syscall_get_return_value(struct task_struct *task,
  35. struct pt_regs *regs)
  36. {
  37. return regs->gpr[3];
  38. }
  39. static inline void syscall_set_return_value(struct task_struct *task,
  40. struct pt_regs *regs,
  41. int error, long val)
  42. {
  43. if (error) {
  44. regs->ccr |= 0x10000000L;
  45. regs->gpr[3] = -error;
  46. } else {
  47. regs->ccr &= ~0x10000000L;
  48. regs->gpr[3] = val;
  49. }
  50. }
  51. static inline void syscall_get_arguments(struct task_struct *task,
  52. struct pt_regs *regs,
  53. unsigned int i, unsigned int n,
  54. unsigned long *args)
  55. {
  56. BUG_ON(i + n > 6);
  57. #ifdef CONFIG_PPC64
  58. if (test_tsk_thread_flag(task, TIF_32BIT)) {
  59. /*
  60. * Zero-extend 32-bit argument values. The high bits are
  61. * garbage ignored by the actual syscall dispatch.
  62. */
  63. while (n-- > 0)
  64. args[n] = (u32) regs->gpr[3 + i + n];
  65. return;
  66. }
  67. #endif
  68. memcpy(args, &regs->gpr[3 + i], n * sizeof(args[0]));
  69. }
  70. static inline void syscall_set_arguments(struct task_struct *task,
  71. struct pt_regs *regs,
  72. unsigned int i, unsigned int n,
  73. const unsigned long *args)
  74. {
  75. BUG_ON(i + n > 6);
  76. memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
  77. }
  78. #endif /* _ASM_SYSCALL_H */