syscall.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <asm/ptrace.h>
  15. /*
  16. * The syscall table always contains 32 bit pointers since we know that the
  17. * address of the function to be called is (way) below 4GB. So the "int"
  18. * type here is what we want [need] for both 32 bit and 64 bit systems.
  19. */
  20. extern const unsigned int sys_call_table[];
  21. static inline long syscall_get_nr(struct task_struct *task,
  22. struct pt_regs *regs)
  23. {
  24. return regs->svcnr ? regs->svcnr : -1;
  25. }
  26. static inline void syscall_rollback(struct task_struct *task,
  27. struct pt_regs *regs)
  28. {
  29. regs->gprs[2] = regs->orig_gpr2;
  30. }
  31. static inline long syscall_get_error(struct task_struct *task,
  32. struct pt_regs *regs)
  33. {
  34. return (regs->gprs[2] >= -4096UL) ? -regs->gprs[2] : 0;
  35. }
  36. static inline long syscall_get_return_value(struct task_struct *task,
  37. struct pt_regs *regs)
  38. {
  39. return regs->gprs[2];
  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. regs->gprs[2] = error ? -error : val;
  46. }
  47. static inline void syscall_get_arguments(struct task_struct *task,
  48. struct pt_regs *regs,
  49. unsigned int i, unsigned int n,
  50. unsigned long *args)
  51. {
  52. unsigned long mask = -1UL;
  53. BUG_ON(i + n > 6);
  54. #ifdef CONFIG_COMPAT
  55. if (test_tsk_thread_flag(task, TIF_31BIT))
  56. mask = 0xffffffff;
  57. #endif
  58. while (n-- > 0)
  59. if (i + n > 0)
  60. args[n] = regs->gprs[2 + i + n] & mask;
  61. if (i == 0)
  62. args[0] = regs->orig_gpr2 & mask;
  63. }
  64. static inline void syscall_set_arguments(struct task_struct *task,
  65. struct pt_regs *regs,
  66. unsigned int i, unsigned int n,
  67. const unsigned long *args)
  68. {
  69. BUG_ON(i + n > 6);
  70. while (n-- > 0)
  71. if (i + n > 0)
  72. regs->gprs[2 + i + n] = args[n];
  73. if (i == 0)
  74. regs->orig_gpr2 = args[0];
  75. }
  76. #endif /* _ASM_SYSCALL_H */