syscall.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if (i + n == 6)
  59. args[--n] = regs->args[0] & mask;
  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. if (i + n == 6)
  73. regs->args[0] = args[--n];
  74. while (n-- > 0)
  75. if (i + n > 0)
  76. regs->gprs[2 + i + n] = args[n];
  77. if (i == 0)
  78. regs->orig_gpr2 = args[0];
  79. }
  80. #endif /* _ASM_SYSCALL_H */