syscall.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Access to user system call parameters and results
  3. *
  4. * Copyright IBM Corp. 2008
  5. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License (version 2 only)
  9. * as published by the Free Software Foundation.
  10. */
  11. #ifndef _ASM_SYSCALL_H
  12. #define _ASM_SYSCALL_H 1
  13. #include <linux/sched.h>
  14. #include <linux/err.h>
  15. #include <asm/ptrace.h>
  16. /*
  17. * The syscall table always contains 32 bit pointers since we know that the
  18. * address of the function to be called is (way) below 4GB. So the "int"
  19. * type here is what we want [need] for both 32 bit and 64 bit systems.
  20. */
  21. extern const unsigned int sys_call_table[];
  22. static inline long syscall_get_nr(struct task_struct *task,
  23. struct pt_regs *regs)
  24. {
  25. return test_tsk_thread_flag(task, TIF_SYSCALL) ?
  26. (regs->int_code & 0xffff) : -1;
  27. }
  28. static inline void syscall_rollback(struct task_struct *task,
  29. struct pt_regs *regs)
  30. {
  31. regs->gprs[2] = regs->orig_gpr2;
  32. }
  33. static inline long syscall_get_error(struct task_struct *task,
  34. struct pt_regs *regs)
  35. {
  36. return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0;
  37. }
  38. static inline long syscall_get_return_value(struct task_struct *task,
  39. struct pt_regs *regs)
  40. {
  41. return regs->gprs[2];
  42. }
  43. static inline void syscall_set_return_value(struct task_struct *task,
  44. struct pt_regs *regs,
  45. int error, long val)
  46. {
  47. regs->gprs[2] = error ? -error : val;
  48. }
  49. static inline void syscall_get_arguments(struct task_struct *task,
  50. struct pt_regs *regs,
  51. unsigned int i, unsigned int n,
  52. unsigned long *args)
  53. {
  54. unsigned long mask = -1UL;
  55. BUG_ON(i + n > 6);
  56. #ifdef CONFIG_COMPAT
  57. if (test_tsk_thread_flag(task, TIF_31BIT))
  58. mask = 0xffffffff;
  59. #endif
  60. while (n-- > 0)
  61. if (i + n > 0)
  62. args[n] = regs->gprs[2 + i + n] & mask;
  63. if (i == 0)
  64. args[0] = regs->orig_gpr2 & mask;
  65. }
  66. static inline void syscall_set_arguments(struct task_struct *task,
  67. struct pt_regs *regs,
  68. unsigned int i, unsigned int n,
  69. const unsigned long *args)
  70. {
  71. BUG_ON(i + n > 6);
  72. while (n-- > 0)
  73. if (i + n > 0)
  74. regs->gprs[2 + i + n] = args[n];
  75. if (i == 0)
  76. regs->orig_gpr2 = args[0];
  77. }
  78. #endif /* _ASM_SYSCALL_H */