syscall.h 1.9 KB

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