syscall.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <asm/ptrace.h>
  14. static inline long syscall_get_nr(struct task_struct *task,
  15. struct pt_regs *regs)
  16. {
  17. return regs->svcnr ? regs->svcnr : -1;
  18. }
  19. static inline void syscall_rollback(struct task_struct *task,
  20. struct pt_regs *regs)
  21. {
  22. regs->gprs[2] = regs->orig_gpr2;
  23. }
  24. static inline long syscall_get_error(struct task_struct *task,
  25. struct pt_regs *regs)
  26. {
  27. return (regs->gprs[2] >= -4096UL) ? -regs->gprs[2] : 0;
  28. }
  29. static inline long syscall_get_return_value(struct task_struct *task,
  30. struct pt_regs *regs)
  31. {
  32. return regs->gprs[2];
  33. }
  34. static inline void syscall_set_return_value(struct task_struct *task,
  35. struct pt_regs *regs,
  36. int error, long val)
  37. {
  38. regs->gprs[2] = error ? -error : val;
  39. }
  40. static inline void syscall_get_arguments(struct task_struct *task,
  41. struct pt_regs *regs,
  42. unsigned int i, unsigned int n,
  43. unsigned long *args)
  44. {
  45. unsigned long mask = -1UL;
  46. BUG_ON(i + n > 6);
  47. #ifdef CONFIG_COMPAT
  48. if (test_tsk_thread_flag(task, TIF_31BIT))
  49. mask = 0xffffffff;
  50. #endif
  51. if (i + n == 6)
  52. args[--n] = regs->args[0] & mask;
  53. while (n-- > 0)
  54. if (i + n > 0)
  55. args[n] = regs->gprs[2 + i + n] & mask;
  56. if (i == 0)
  57. args[0] = regs->orig_gpr2 & mask;
  58. }
  59. static inline void syscall_set_arguments(struct task_struct *task,
  60. struct pt_regs *regs,
  61. unsigned int i, unsigned int n,
  62. const unsigned long *args)
  63. {
  64. BUG_ON(i + n > 6);
  65. if (i + n == 6)
  66. regs->args[0] = args[--n];
  67. while (n-- > 0)
  68. if (i + n > 0)
  69. regs->gprs[2 + i + n] = args[n];
  70. if (i == 0)
  71. regs->orig_gpr2 = args[0];
  72. }
  73. #endif /* _ASM_SYSCALL_H */