syscall.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Access to user system call parameters and results
  3. *
  4. * Copyright (C) 2008-2009 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. #include <asm/asm-offsets.h> /* For NR_syscalls */
  17. extern const unsigned long sys_call_table[];
  18. /*
  19. * Only the low 32 bits of orig_ax are meaningful, so we return int.
  20. * This importantly ignores the high bits on 64-bit, so comparisons
  21. * sign-extend the low 32 bits.
  22. */
  23. static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  24. {
  25. return regs->orig_ax;
  26. }
  27. static inline void syscall_rollback(struct task_struct *task,
  28. struct pt_regs *regs)
  29. {
  30. regs->ax = regs->orig_ax;
  31. }
  32. static inline long syscall_get_error(struct task_struct *task,
  33. struct pt_regs *regs)
  34. {
  35. unsigned long error = regs->ax;
  36. #ifdef CONFIG_IA32_EMULATION
  37. /*
  38. * TS_COMPAT is set for 32-bit syscall entries and then
  39. * remains set until we return to user mode.
  40. */
  41. if (task_thread_info(task)->status & TS_COMPAT)
  42. /*
  43. * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
  44. * and will match correctly in comparisons.
  45. */
  46. error = (long) (int) error;
  47. #endif
  48. return IS_ERR_VALUE(error) ? error : 0;
  49. }
  50. static inline long syscall_get_return_value(struct task_struct *task,
  51. struct pt_regs *regs)
  52. {
  53. return regs->ax;
  54. }
  55. static inline void syscall_set_return_value(struct task_struct *task,
  56. struct pt_regs *regs,
  57. int error, long val)
  58. {
  59. regs->ax = (long) error ?: val;
  60. }
  61. #ifdef CONFIG_X86_32
  62. static inline void syscall_get_arguments(struct task_struct *task,
  63. struct pt_regs *regs,
  64. unsigned int i, unsigned int n,
  65. unsigned long *args)
  66. {
  67. BUG_ON(i + n > 6);
  68. memcpy(args, &regs->bx + i, n * sizeof(args[0]));
  69. }
  70. static inline void syscall_set_arguments(struct task_struct *task,
  71. struct pt_regs *regs,
  72. unsigned int i, unsigned int n,
  73. const unsigned long *args)
  74. {
  75. BUG_ON(i + n > 6);
  76. memcpy(&regs->bx + i, args, n * sizeof(args[0]));
  77. }
  78. #else /* CONFIG_X86_64 */
  79. static inline void syscall_get_arguments(struct task_struct *task,
  80. struct pt_regs *regs,
  81. unsigned int i, unsigned int n,
  82. unsigned long *args)
  83. {
  84. # ifdef CONFIG_IA32_EMULATION
  85. if (task_thread_info(task)->status & TS_COMPAT)
  86. switch (i) {
  87. case 0:
  88. if (!n--) break;
  89. *args++ = regs->bx;
  90. case 1:
  91. if (!n--) break;
  92. *args++ = regs->cx;
  93. case 2:
  94. if (!n--) break;
  95. *args++ = regs->dx;
  96. case 3:
  97. if (!n--) break;
  98. *args++ = regs->si;
  99. case 4:
  100. if (!n--) break;
  101. *args++ = regs->di;
  102. case 5:
  103. if (!n--) break;
  104. *args++ = regs->bp;
  105. case 6:
  106. if (!n--) break;
  107. default:
  108. BUG();
  109. break;
  110. }
  111. else
  112. # endif
  113. switch (i) {
  114. case 0:
  115. if (!n--) break;
  116. *args++ = regs->di;
  117. case 1:
  118. if (!n--) break;
  119. *args++ = regs->si;
  120. case 2:
  121. if (!n--) break;
  122. *args++ = regs->dx;
  123. case 3:
  124. if (!n--) break;
  125. *args++ = regs->r10;
  126. case 4:
  127. if (!n--) break;
  128. *args++ = regs->r8;
  129. case 5:
  130. if (!n--) break;
  131. *args++ = regs->r9;
  132. case 6:
  133. if (!n--) break;
  134. default:
  135. BUG();
  136. break;
  137. }
  138. }
  139. static inline void syscall_set_arguments(struct task_struct *task,
  140. struct pt_regs *regs,
  141. unsigned int i, unsigned int n,
  142. const unsigned long *args)
  143. {
  144. # ifdef CONFIG_IA32_EMULATION
  145. if (task_thread_info(task)->status & TS_COMPAT)
  146. switch (i) {
  147. case 0:
  148. if (!n--) break;
  149. regs->bx = *args++;
  150. case 1:
  151. if (!n--) break;
  152. regs->cx = *args++;
  153. case 2:
  154. if (!n--) break;
  155. regs->dx = *args++;
  156. case 3:
  157. if (!n--) break;
  158. regs->si = *args++;
  159. case 4:
  160. if (!n--) break;
  161. regs->di = *args++;
  162. case 5:
  163. if (!n--) break;
  164. regs->bp = *args++;
  165. case 6:
  166. if (!n--) break;
  167. default:
  168. BUG();
  169. break;
  170. }
  171. else
  172. # endif
  173. switch (i) {
  174. case 0:
  175. if (!n--) break;
  176. regs->di = *args++;
  177. case 1:
  178. if (!n--) break;
  179. regs->si = *args++;
  180. case 2:
  181. if (!n--) break;
  182. regs->dx = *args++;
  183. case 3:
  184. if (!n--) break;
  185. regs->r10 = *args++;
  186. case 4:
  187. if (!n--) break;
  188. regs->r8 = *args++;
  189. case 5:
  190. if (!n--) break;
  191. regs->r9 = *args++;
  192. case 6:
  193. if (!n--) break;
  194. default:
  195. BUG();
  196. break;
  197. }
  198. }
  199. #endif /* CONFIG_X86_32 */
  200. #endif /* _ASM_X86_SYSCALL_H */