syscall.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. static inline long syscall_get_nr(struct task_struct *task,
  24. struct pt_regs *regs)
  25. {
  26. return test_tsk_thread_flag(task, TIF_SYSCALL) ?
  27. (regs->int_code & 0xffff) : -1;
  28. }
  29. static inline void syscall_rollback(struct task_struct *task,
  30. struct pt_regs *regs)
  31. {
  32. regs->gprs[2] = regs->orig_gpr2;
  33. }
  34. static inline long syscall_get_error(struct task_struct *task,
  35. struct pt_regs *regs)
  36. {
  37. return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0;
  38. }
  39. static inline long syscall_get_return_value(struct task_struct *task,
  40. struct pt_regs *regs)
  41. {
  42. return regs->gprs[2];
  43. }
  44. static inline void syscall_set_return_value(struct task_struct *task,
  45. struct pt_regs *regs,
  46. int error, long val)
  47. {
  48. regs->gprs[2] = error ? -error : val;
  49. }
  50. static inline void syscall_get_arguments(struct task_struct *task,
  51. struct pt_regs *regs,
  52. unsigned int i, unsigned int n,
  53. unsigned long *args)
  54. {
  55. unsigned long mask = -1UL;
  56. BUG_ON(i + n > 6);
  57. #ifdef CONFIG_COMPAT
  58. if (test_tsk_thread_flag(task, TIF_31BIT))
  59. mask = 0xffffffff;
  60. #endif
  61. while (n-- > 0)
  62. if (i + n > 0)
  63. args[n] = regs->gprs[2 + i + n] & mask;
  64. if (i == 0)
  65. args[0] = regs->orig_gpr2 & mask;
  66. }
  67. static inline void syscall_set_arguments(struct task_struct *task,
  68. struct pt_regs *regs,
  69. unsigned int i, unsigned int n,
  70. const unsigned long *args)
  71. {
  72. BUG_ON(i + n > 6);
  73. while (n-- > 0)
  74. if (i + n > 0)
  75. regs->gprs[2 + i + n] = args[n];
  76. if (i == 0)
  77. regs->orig_gpr2 = args[0];
  78. }
  79. static inline int syscall_get_arch(struct task_struct *task,
  80. struct pt_regs *regs)
  81. {
  82. #ifdef CONFIG_COMPAT
  83. if (test_tsk_thread_flag(task, TIF_31BIT))
  84. return AUDIT_ARCH_S390;
  85. #endif
  86. return sizeof(long) == 8 ? AUDIT_ARCH_S390X : AUDIT_ARCH_S390;
  87. }
  88. #endif /* _ASM_SYSCALL_H */