syscall-generic.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Access to user system call parameters and results
  3. *
  4. * See asm-generic/syscall.h for function descriptions.
  5. *
  6. * Copyright (C) 2015 Mickaël Salaün <mic@digikod.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __UM_SYSCALL_GENERIC_H
  13. #define __UM_SYSCALL_GENERIC_H
  14. #include <asm/ptrace.h>
  15. #include <linux/err.h>
  16. #include <linux/sched.h>
  17. #include <sysdep/ptrace.h>
  18. static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  19. {
  20. return PT_REGS_SYSCALL_NR(regs);
  21. }
  22. static inline void syscall_rollback(struct task_struct *task,
  23. struct pt_regs *regs)
  24. {
  25. /* do nothing */
  26. }
  27. static inline long syscall_get_error(struct task_struct *task,
  28. struct pt_regs *regs)
  29. {
  30. const long error = regs_return_value(regs);
  31. return IS_ERR_VALUE(error) ? error : 0;
  32. }
  33. static inline long syscall_get_return_value(struct task_struct *task,
  34. struct pt_regs *regs)
  35. {
  36. return regs_return_value(regs);
  37. }
  38. static inline void syscall_set_return_value(struct task_struct *task,
  39. struct pt_regs *regs,
  40. int error, long val)
  41. {
  42. PT_REGS_SET_SYSCALL_RETURN(regs, (long) error ?: val);
  43. }
  44. static inline void syscall_get_arguments(struct task_struct *task,
  45. struct pt_regs *regs,
  46. unsigned int i, unsigned int n,
  47. unsigned long *args)
  48. {
  49. const struct uml_pt_regs *r = &regs->regs;
  50. switch (i) {
  51. case 0:
  52. if (!n--)
  53. break;
  54. *args++ = UPT_SYSCALL_ARG1(r);
  55. case 1:
  56. if (!n--)
  57. break;
  58. *args++ = UPT_SYSCALL_ARG2(r);
  59. case 2:
  60. if (!n--)
  61. break;
  62. *args++ = UPT_SYSCALL_ARG3(r);
  63. case 3:
  64. if (!n--)
  65. break;
  66. *args++ = UPT_SYSCALL_ARG4(r);
  67. case 4:
  68. if (!n--)
  69. break;
  70. *args++ = UPT_SYSCALL_ARG5(r);
  71. case 5:
  72. if (!n--)
  73. break;
  74. *args++ = UPT_SYSCALL_ARG6(r);
  75. case 6:
  76. if (!n--)
  77. break;
  78. default:
  79. BUG();
  80. break;
  81. }
  82. }
  83. static inline void syscall_set_arguments(struct task_struct *task,
  84. struct pt_regs *regs,
  85. unsigned int i, unsigned int n,
  86. const unsigned long *args)
  87. {
  88. struct uml_pt_regs *r = &regs->regs;
  89. switch (i) {
  90. case 0:
  91. if (!n--)
  92. break;
  93. UPT_SYSCALL_ARG1(r) = *args++;
  94. case 1:
  95. if (!n--)
  96. break;
  97. UPT_SYSCALL_ARG2(r) = *args++;
  98. case 2:
  99. if (!n--)
  100. break;
  101. UPT_SYSCALL_ARG3(r) = *args++;
  102. case 3:
  103. if (!n--)
  104. break;
  105. UPT_SYSCALL_ARG4(r) = *args++;
  106. case 4:
  107. if (!n--)
  108. break;
  109. UPT_SYSCALL_ARG5(r) = *args++;
  110. case 5:
  111. if (!n--)
  112. break;
  113. UPT_SYSCALL_ARG6(r) = *args++;
  114. case 6:
  115. if (!n--)
  116. break;
  117. default:
  118. BUG();
  119. break;
  120. }
  121. }
  122. /* See arch/x86/um/asm/syscall.h for syscall_get_arch() definition. */
  123. #endif /* __UM_SYSCALL_GENERIC_H */