syscall.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Access to user system call parameters and results
  3. *
  4. * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
  5. *
  6. * This copyrighted material is made available to anyone wishing to use,
  7. * modify, copy, or redistribute it subject to the terms and conditions
  8. * of the GNU General Public License v.2.
  9. *
  10. * See asm-generic/syscall.h for descriptions of what we must do here.
  11. */
  12. #ifndef _ASM_X86_SYSCALL_H
  13. #define _ASM_X86_SYSCALL_H
  14. #include <linux/sched.h>
  15. #include <linux/err.h>
  16. static inline long syscall_get_nr(struct task_struct *task,
  17. struct pt_regs *regs)
  18. {
  19. /*
  20. * We always sign-extend a -1 value being set here,
  21. * so this is always either -1L or a syscall number.
  22. */
  23. return regs->orig_ax;
  24. }
  25. static inline void syscall_rollback(struct task_struct *task,
  26. struct pt_regs *regs)
  27. {
  28. regs->ax = regs->orig_ax;
  29. }
  30. static inline long syscall_get_error(struct task_struct *task,
  31. struct pt_regs *regs)
  32. {
  33. unsigned long error = regs->ax;
  34. #ifdef CONFIG_IA32_EMULATION
  35. /*
  36. * TS_COMPAT is set for 32-bit syscall entries and then
  37. * remains set until we return to user mode.
  38. */
  39. if (task_thread_info(task)->status & TS_COMPAT)
  40. /*
  41. * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
  42. * and will match correctly in comparisons.
  43. */
  44. error = (long) (int) error;
  45. #endif
  46. return IS_ERR_VALUE(error) ? error : 0;
  47. }
  48. static inline long syscall_get_return_value(struct task_struct *task,
  49. struct pt_regs *regs)
  50. {
  51. return regs->ax;
  52. }
  53. static inline void syscall_set_return_value(struct task_struct *task,
  54. struct pt_regs *regs,
  55. int error, long val)
  56. {
  57. regs->ax = (long) error ?: val;
  58. }
  59. #ifdef CONFIG_X86_32
  60. static inline void syscall_get_arguments(struct task_struct *task,
  61. struct pt_regs *regs,
  62. unsigned int i, unsigned int n,
  63. unsigned long *args)
  64. {
  65. BUG_ON(i + n > 6);
  66. memcpy(args, &regs->bx + i, n * sizeof(args[0]));
  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. memcpy(&regs->bx + i, args, n * sizeof(args[0]));
  75. }
  76. #else /* CONFIG_X86_64 */
  77. static inline void syscall_get_arguments(struct task_struct *task,
  78. struct pt_regs *regs,
  79. unsigned int i, unsigned int n,
  80. unsigned long *args)
  81. {
  82. # ifdef CONFIG_IA32_EMULATION
  83. if (task_thread_info(task)->status & TS_COMPAT)
  84. switch (i) {
  85. case 0:
  86. if (!n--) break;
  87. *args++ = regs->bx;
  88. case 1:
  89. if (!n--) break;
  90. *args++ = regs->cx;
  91. case 2:
  92. if (!n--) break;
  93. *args++ = regs->dx;
  94. case 3:
  95. if (!n--) break;
  96. *args++ = regs->si;
  97. case 4:
  98. if (!n--) break;
  99. *args++ = regs->di;
  100. case 5:
  101. if (!n--) break;
  102. *args++ = regs->bp;
  103. case 6:
  104. if (!n--) break;
  105. default:
  106. BUG();
  107. break;
  108. }
  109. else
  110. # endif
  111. switch (i) {
  112. case 0:
  113. if (!n--) break;
  114. *args++ = regs->di;
  115. case 1:
  116. if (!n--) break;
  117. *args++ = regs->si;
  118. case 2:
  119. if (!n--) break;
  120. *args++ = regs->dx;
  121. case 3:
  122. if (!n--) break;
  123. *args++ = regs->r10;
  124. case 4:
  125. if (!n--) break;
  126. *args++ = regs->r8;
  127. case 5:
  128. if (!n--) break;
  129. *args++ = regs->r9;
  130. case 6:
  131. if (!n--) break;
  132. default:
  133. BUG();
  134. break;
  135. }
  136. }
  137. static inline void syscall_set_arguments(struct task_struct *task,
  138. struct pt_regs *regs,
  139. unsigned int i, unsigned int n,
  140. const unsigned long *args)
  141. {
  142. # ifdef CONFIG_IA32_EMULATION
  143. if (task_thread_info(task)->status & TS_COMPAT)
  144. switch (i) {
  145. case 0:
  146. if (!n--) break;
  147. regs->bx = *args++;
  148. case 1:
  149. if (!n--) break;
  150. regs->cx = *args++;
  151. case 2:
  152. if (!n--) break;
  153. regs->dx = *args++;
  154. case 3:
  155. if (!n--) break;
  156. regs->si = *args++;
  157. case 4:
  158. if (!n--) break;
  159. regs->di = *args++;
  160. case 5:
  161. if (!n--) break;
  162. regs->bp = *args++;
  163. case 6:
  164. if (!n--) break;
  165. default:
  166. BUG();
  167. break;
  168. }
  169. else
  170. # endif
  171. switch (i) {
  172. case 0:
  173. if (!n--) break;
  174. regs->di = *args++;
  175. case 1:
  176. if (!n--) break;
  177. regs->si = *args++;
  178. case 2:
  179. if (!n--) break;
  180. regs->dx = *args++;
  181. case 3:
  182. if (!n--) break;
  183. regs->r10 = *args++;
  184. case 4:
  185. if (!n--) break;
  186. regs->r8 = *args++;
  187. case 5:
  188. if (!n--) break;
  189. regs->r9 = *args++;
  190. case 6:
  191. if (!n--) break;
  192. default:
  193. BUG();
  194. break;
  195. }
  196. }
  197. #endif /* CONFIG_X86_32 */
  198. #endif /* _ASM_X86_SYSCALL_H */