Advertisement
Guest User

Untitled

a guest
Sep 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.92 KB | None | 0 0
  1. diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c
  2. index e9dafbd8fe3..5f7dc9adfe0 100644
  3. --- a/sys/amd64/amd64/trap.c
  4. +++ b/sys/amd64/amd64/trap.c
  5. @@ -963,48 +963,67 @@ cpu_fetch_syscall_args(struct thread *td)
  6.     register_t *argp;
  7.     struct syscall_args *sa;
  8.     caddr_t params;
  9. -   int reg, regcnt, error;
  10. +   int regoff, regcnt, error;
  11. +   u_int abi;
  12.  
  13.     p = td->td_proc;
  14. -   frame = td->td_frame;
  15. -   sa = &td->td_sa;
  16. -   reg = 0;
  17. -   regcnt = 6;
  18. +   abi = SV_PROC_ABI(p);
  19. +
  20. +   KASSERT(abi == SV_ABI_FREEBSD ||
  21. +       abi == SV_ABI_LINUX ||
  22. +       abi == SV_ABI_CLOUDABI,
  23. +       ("Unknown ABI. cpu_fetch_syscall_args is unimplemented."));
  24.  
  25. -   sa->code = frame->tf_rax;
  26.  
  27. -   if (sa->code == SYS_syscall || sa->code == SYS___syscall) {
  28. -       sa->code = frame->tf_rdi;
  29. -       reg++;
  30. -       regcnt--;
  31. +   frame = td->td_frame;
  32. +   regoff = 0;
  33. +   if (__predict_true(abi == SV_ABI_FREEBSD)) {
  34. +       regoff = frame->tf_rax == SYS_syscall ||
  35. +           frame->tf_rax == SYS___syscall;
  36.     }
  37. -   if (p->p_sysent->sv_mask)
  38. -       sa->code &= p->p_sysent->sv_mask;
  39.  
  40. -   if (sa->code >= p->p_sysent->sv_size)
  41. -       sa->callp = &p->p_sysent->sv_table[0];
  42. -   else
  43. -       sa->callp = &p->p_sysent->sv_table[sa->code];
  44. +   sa = &td->td_sa;
  45. +   regcnt = 6 - regoff;
  46. +
  47. +   sa->code = regoff ? frame->tf_rdi : frame->tf_rax;
  48. +   if (__predict_false(sa->code >= p->p_sysent->sv_size)) {
  49. +       switch (abi) {
  50. +       case SV_ABI_CLOUDABI:
  51. +           return (ENOSYS);
  52. +       case SV_ABI_LINUX:
  53. +           sa->code = p->p_sysent->sv_size - 1;
  54. +           break;
  55. +       case SV_ABI_FREEBSD:
  56. +           sa->code = 0;
  57. +           break;
  58. +       }
  59. +   }
  60. +   sa->callp = &p->p_sysent->sv_table[sa->code];
  61. +   if (p->p_sysent->sv_mask)
  62. +       sa->code &= p->p_sysent->sv_mask;
  63.  
  64.     sa->narg = sa->callp->sy_narg;
  65.     KASSERT(sa->narg <= sizeof(sa->args) / sizeof(sa->args[0]),
  66.         ("Too many syscall arguments!"));
  67.     error = 0;
  68.     argp = &frame->tf_rdi;
  69. -   argp += reg;
  70. +   argp += regoff;
  71.     memcpy(sa->args, argp, sizeof(sa->args[0]) * 6);
  72. +   /* Other ABIs than FreeBSD has maximum 6 arguments per syscall. */
  73.     if (sa->narg > regcnt) {
  74.         params = (caddr_t)frame->tf_rsp + sizeof(register_t);
  75.         error = copyin(params, &sa->args[regcnt],
  76.                 (sa->narg - regcnt) * sizeof(sa->args[0]));
  77.     }
  78.  
  79. -   if (error == 0) {
  80. -       td->td_retval[0] = 0;
  81. +   if (error != 0)
  82. +       return (error);
  83. +
  84. +   td->td_retval[0] = 0;
  85. +   if (SV_PROC_ABI(p) != SV_ABI_LINUX)
  86.         td->td_retval[1] = frame->tf_rdx;
  87. -   }
  88.  
  89. -   return (error);
  90. +   return (0);
  91.  }
  92.  
  93.  #include "../../kern/subr_syscall.c"
  94. diff --git a/sys/amd64/cloudabi64/cloudabi64_sysvec.c b/sys/amd64/cloudabi64/cloudabi64_sysvec.c
  95. index dca9f568463..50af59cf790 100644
  96. --- a/sys/amd64/cloudabi64/cloudabi64_sysvec.c
  97. +++ b/sys/amd64/cloudabi64/cloudabi64_sysvec.c
  98. @@ -86,36 +86,6 @@ cloudabi64_proc_setregs(struct thread *td, struct image_params *imgp,
  99.     (void)cpu_set_user_tls(td, TO_PTR(stack));
  100.  }
  101.  
  102. -static int
  103. -cloudabi64_fetch_syscall_args(struct thread *td)
  104. -{
  105. -   struct trapframe *frame;
  106. -   struct syscall_args *sa;
  107. -
  108. -   frame = td->td_frame;
  109. -   sa = &td->td_sa;
  110. -
  111. -   /* Obtain system call number. */
  112. -   sa->code = frame->tf_rax;
  113. -   if (sa->code >= CLOUDABI64_SYS_MAXSYSCALL)
  114. -       return (ENOSYS);
  115. -   sa->callp = &cloudabi64_sysent[sa->code];
  116. -   sa->narg = sa->callp->sy_narg;
  117. -
  118. -   /* Fetch system call arguments. */
  119. -   sa->args[0] = frame->tf_rdi;
  120. -   sa->args[1] = frame->tf_rsi;
  121. -   sa->args[2] = frame->tf_rdx;
  122. -   sa->args[3] = frame->tf_rcx; /* Actually %r10. */
  123. -   sa->args[4] = frame->tf_r8;
  124. -   sa->args[5] = frame->tf_r9;
  125. -
  126. -   /* Default system call return values. */
  127. -   td->td_retval[0] = 0;
  128. -   td->td_retval[1] = frame->tf_rdx;
  129. -   return (0);
  130. -}
  131. -
  132.  static void
  133.  cloudabi64_set_syscall_retval(struct thread *td, int error)
  134.  {
  135. @@ -206,7 +176,7 @@ static struct sysentvec cloudabi64_elf_sysvec = {
  136.     .sv_setregs     = cloudabi64_proc_setregs,
  137.     .sv_flags       = SV_ABI_CLOUDABI | SV_CAPSICUM | SV_LP64,
  138.     .sv_set_syscall_retval  = cloudabi64_set_syscall_retval,
  139. -   .sv_fetch_syscall_args  = cloudabi64_fetch_syscall_args,
  140. +   .sv_fetch_syscall_args  = cpu_fetch_syscall_args,
  141.     .sv_syscallnames    = cloudabi64_syscallnames,
  142.     .sv_schedtail       = cloudabi64_schedtail,
  143.  };
  144. diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
  145. index afa06bb415c..8e3882767a5 100644
  146. --- a/sys/amd64/linux/linux_sysvec.c
  147. +++ b/sys/amd64/linux/linux_sysvec.c
  148. @@ -118,7 +118,6 @@ static bool linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
  149.  static void    linux_vdso_install(void *param);
  150.  static void    linux_vdso_deinstall(void *param);
  151.  static void    linux_set_syscall_retval(struct thread *td, int error);
  152. -static int linux_fetch_syscall_args(struct thread *td);
  153.  static void    linux_exec_setregs(struct thread *td, struct image_params *imgp,
  154.             u_long stack);
  155.  static int linux_vsyscall(struct thread *td);
  156. @@ -188,36 +187,6 @@ linux_translate_traps(int signal, int trap_code)
  157.     }
  158.  }
  159.  
  160. -static int
  161. -linux_fetch_syscall_args(struct thread *td)
  162. -{
  163. -   struct proc *p;
  164. -   struct trapframe *frame;
  165. -   struct syscall_args *sa;
  166. -
  167. -   p = td->td_proc;
  168. -   frame = td->td_frame;
  169. -   sa = &td->td_sa;
  170. -
  171. -   sa->args[0] = frame->tf_rdi;
  172. -   sa->args[1] = frame->tf_rsi;
  173. -   sa->args[2] = frame->tf_rdx;
  174. -   sa->args[3] = frame->tf_rcx;
  175. -   sa->args[4] = frame->tf_r8;
  176. -   sa->args[5] = frame->tf_r9;
  177. -   sa->code = frame->tf_rax;
  178. -
  179. -   if (sa->code >= p->p_sysent->sv_size)
  180. -       /* nosys */
  181. -       sa->callp = &p->p_sysent->sv_table[p->p_sysent->sv_size - 1];
  182. -   else
  183. -       sa->callp = &p->p_sysent->sv_table[sa->code];
  184. -   sa->narg = sa->callp->sy_narg;
  185. -
  186. -   td->td_retval[0] = 0;
  187. -   return (0);
  188. -}
  189. -
  190.  static void
  191.  linux_set_syscall_retval(struct thread *td, int error)
  192.  {
  193. @@ -735,7 +704,7 @@ struct sysentvec elf_linux_sysvec = {
  194.     .sv_maxssiz = NULL,
  195.     .sv_flags   = SV_ABI_LINUX | SV_LP64 | SV_SHP,
  196.     .sv_set_syscall_retval = linux_set_syscall_retval,
  197. -   .sv_fetch_syscall_args = linux_fetch_syscall_args,
  198. +   .sv_fetch_syscall_args = cpu_fetch_syscall_args,
  199.     .sv_syscallnames = NULL,
  200.     .sv_shared_page_base = SHAREDPAGE,
  201.     .sv_shared_page_len = PAGE_SIZE,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement