syscalls.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright 2003 PathScale, Inc.
  3. *
  4. * Licensed under the GPL
  5. */
  6. #include "linux/linkage.h"
  7. #include "linux/slab.h"
  8. #include "linux/shm.h"
  9. #include "linux/utsname.h"
  10. #include "linux/personality.h"
  11. #include "asm/uaccess.h"
  12. #define __FRAME_OFFSETS
  13. #include "asm/ptrace.h"
  14. #include "asm/unistd.h"
  15. #include "asm/prctl.h" /* XXX This should get the constants from libc */
  16. #include "choose-mode.h"
  17. #include "kern.h"
  18. #include "os.h"
  19. asmlinkage long sys_uname64(struct new_utsname __user * name)
  20. {
  21. int err;
  22. down_read(&uts_sem);
  23. err = copy_to_user(name, utsname(), sizeof (*name));
  24. up_read(&uts_sem);
  25. if (personality(current->personality) == PER_LINUX32)
  26. err |= copy_to_user(&name->machine, "i686", 5);
  27. return err ? -EFAULT : 0;
  28. }
  29. #ifdef CONFIG_MODE_TT
  30. extern long arch_prctl(int code, unsigned long addr);
  31. static long arch_prctl_tt(int code, unsigned long addr)
  32. {
  33. unsigned long tmp;
  34. long ret;
  35. switch(code){
  36. case ARCH_SET_GS:
  37. case ARCH_SET_FS:
  38. ret = arch_prctl(code, addr);
  39. break;
  40. case ARCH_GET_FS:
  41. case ARCH_GET_GS:
  42. ret = arch_prctl(code, (unsigned long) &tmp);
  43. if(!ret)
  44. ret = put_user(tmp, (long __user *)addr);
  45. break;
  46. default:
  47. ret = -EINVAL;
  48. break;
  49. }
  50. return(ret);
  51. }
  52. #endif
  53. #ifdef CONFIG_MODE_SKAS
  54. long arch_prctl_skas(struct task_struct *task, int code,
  55. unsigned long __user *addr)
  56. {
  57. unsigned long *ptr = addr, tmp;
  58. long ret;
  59. int pid = task->mm->context.skas.id.u.pid;
  60. /*
  61. * With ARCH_SET_FS (and ARCH_SET_GS is treated similarly to
  62. * be safe), we need to call arch_prctl on the host because
  63. * setting %fs may result in something else happening (like a
  64. * GDT or thread.fs being set instead). So, we let the host
  65. * fiddle the registers and thread struct and restore the
  66. * registers afterwards.
  67. *
  68. * So, the saved registers are stored to the process (this
  69. * needed because a stub may have been the last thing to run),
  70. * arch_prctl is run on the host, then the registers are read
  71. * back.
  72. */
  73. switch(code){
  74. case ARCH_SET_FS:
  75. case ARCH_SET_GS:
  76. restore_registers(pid, &current->thread.regs.regs);
  77. break;
  78. case ARCH_GET_FS:
  79. case ARCH_GET_GS:
  80. /*
  81. * With these two, we read to a local pointer and
  82. * put_user it to the userspace pointer that we were
  83. * given. If addr isn't valid (because it hasn't been
  84. * faulted in or is just bogus), we want put_user to
  85. * fault it in (or return -EFAULT) instead of having
  86. * the host return -EFAULT.
  87. */
  88. ptr = &tmp;
  89. }
  90. ret = os_arch_prctl(pid, code, ptr);
  91. if(ret)
  92. return ret;
  93. switch(code){
  94. case ARCH_SET_FS:
  95. current->thread.arch.fs = (unsigned long) ptr;
  96. save_registers(pid, &current->thread.regs.regs);
  97. break;
  98. case ARCH_SET_GS:
  99. save_registers(pid, &current->thread.regs.regs);
  100. break;
  101. case ARCH_GET_FS:
  102. ret = put_user(tmp, addr);
  103. break;
  104. case ARCH_GET_GS:
  105. ret = put_user(tmp, addr);
  106. break;
  107. }
  108. return ret;
  109. }
  110. #endif
  111. long sys_arch_prctl(int code, unsigned long addr)
  112. {
  113. return CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, current, code,
  114. (unsigned long __user *) addr);
  115. }
  116. long sys_clone(unsigned long clone_flags, unsigned long newsp,
  117. void __user *parent_tid, void __user *child_tid)
  118. {
  119. long ret;
  120. if (!newsp)
  121. newsp = UPT_SP(&current->thread.regs.regs);
  122. current->thread.forking = 1;
  123. ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
  124. child_tid);
  125. current->thread.forking = 0;
  126. return ret;
  127. }
  128. void arch_switch_to_skas(struct task_struct *from, struct task_struct *to)
  129. {
  130. if((to->thread.arch.fs == 0) || (to->mm == NULL))
  131. return;
  132. arch_prctl_skas(to, ARCH_SET_FS, (void __user *) to->thread.arch.fs);
  133. }