syscall.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/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_tsk_thread_flag(task, TIF_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. BUG_ON(i + n > 6);
  58. #ifdef CONFIG_COMPAT
  59. if (test_tsk_thread_flag(task, TIF_31BIT))
  60. mask = 0xffffffff;
  61. #endif
  62. while (n-- > 0)
  63. if (i + n > 0)
  64. args[n] = regs->gprs[2 + i + n] & mask;
  65. if (i == 0)
  66. args[0] = regs->orig_gpr2 & mask;
  67. }
  68. static inline void syscall_set_arguments(struct task_struct *task,
  69. struct pt_regs *regs,
  70. unsigned int i, unsigned int n,
  71. const unsigned long *args)
  72. {
  73. BUG_ON(i + n > 6);
  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. static inline int syscall_get_arch(struct task_struct *task,
  81. struct pt_regs *regs)
  82. {
  83. #ifdef CONFIG_COMPAT
  84. if (test_tsk_thread_flag(task, TIF_31BIT))
  85. return AUDIT_ARCH_S390;
  86. #endif
  87. return sizeof(long) == 8 ? AUDIT_ARCH_S390X : AUDIT_ARCH_S390;
  88. }
  89. #endif /* _ASM_SYSCALL_H */