syscall.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <uapi/linux/audit.h>
  14. #include <linux/sched.h>
  15. #include <linux/err.h>
  16. #include <asm/ptrace.h>
  17. /*
  18. * The syscall table always contains 32 bit pointers since we know that the
  19. * address of the function to be called is (way) below 4GB. So the "int"
  20. * type here is what we want [need] for both 32 bit and 64 bit systems.
  21. */
  22. extern const unsigned int sys_call_table[];
  23. extern const unsigned int sys_call_table_emu[];
  24. static inline long syscall_get_nr(struct task_struct *task,
  25. struct pt_regs *regs)
  26. {
  27. return test_pt_regs_flag(regs, PIF_SYSCALL) ?
  28. (regs->int_code & 0xffff) : -1;
  29. }
  30. static inline void syscall_rollback(struct task_struct *task,
  31. struct pt_regs *regs)
  32. {
  33. regs->gprs[2] = regs->orig_gpr2;
  34. }
  35. static inline long syscall_get_error(struct task_struct *task,
  36. struct pt_regs *regs)
  37. {
  38. return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0;
  39. }
  40. static inline long syscall_get_return_value(struct task_struct *task,
  41. struct pt_regs *regs)
  42. {
  43. return regs->gprs[2];
  44. }
  45. static inline void syscall_set_return_value(struct task_struct *task,
  46. struct pt_regs *regs,
  47. int error, long val)
  48. {
  49. regs->gprs[2] = error ? error : val;
  50. }
  51. static inline void syscall_get_arguments(struct task_struct *task,
  52. struct pt_regs *regs,
  53. unsigned int i, unsigned int n,
  54. unsigned long *args)
  55. {
  56. unsigned long mask = -1UL;
  57. /*
  58. * No arguments for this syscall, there's nothing to do.
  59. */
  60. if (!n)
  61. return;
  62. BUG_ON(i + n > 6);
  63. #ifdef CONFIG_COMPAT
  64. if (test_tsk_thread_flag(task, TIF_31BIT))
  65. mask = 0xffffffff;
  66. #endif
  67. while (n-- > 0)
  68. if (i + n > 0)
  69. args[n] = regs->gprs[2 + i + n] & mask;
  70. if (i == 0)
  71. args[0] = regs->orig_gpr2 & mask;
  72. }
  73. static inline void syscall_set_arguments(struct task_struct *task,
  74. struct pt_regs *regs,
  75. unsigned int i, unsigned int n,
  76. const unsigned long *args)
  77. {
  78. BUG_ON(i + n > 6);
  79. while (n-- > 0)
  80. if (i + n > 0)
  81. regs->gprs[2 + i + n] = args[n];
  82. if (i == 0)
  83. regs->orig_gpr2 = args[0];
  84. }
  85. static inline int syscall_get_arch(void)
  86. {
  87. #ifdef CONFIG_COMPAT
  88. if (test_tsk_thread_flag(current, TIF_31BIT))
  89. return AUDIT_ARCH_S390;
  90. #endif
  91. return AUDIT_ARCH_S390X;
  92. }
  93. #endif /* _ASM_SYSCALL_H */