syscalls.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. asmlinkage long sys_uname64(struct new_utsname __user * name)
  18. {
  19. int err;
  20. down_read(&uts_sem);
  21. err = copy_to_user(name, &system_utsname, sizeof (*name));
  22. up_read(&uts_sem);
  23. if (personality(current->personality) == PER_LINUX32)
  24. err |= copy_to_user(&name->machine, "i686", 5);
  25. return err ? -EFAULT : 0;
  26. }
  27. #ifdef CONFIG_MODE_TT
  28. extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
  29. long sys_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
  30. {
  31. /* XXX This should check VERIFY_WRITE depending on func, check this
  32. * in i386 as well.
  33. */
  34. if (!access_ok(VERIFY_READ, ptr, bytecount))
  35. return -EFAULT;
  36. return(modify_ldt(func, ptr, bytecount));
  37. }
  38. #endif
  39. #ifdef CONFIG_MODE_SKAS
  40. extern int userspace_pid[];
  41. long sys_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
  42. {
  43. struct ptrace_ldt ldt;
  44. void *buf;
  45. int res, n;
  46. buf = kmalloc(bytecount, GFP_KERNEL);
  47. if(buf == NULL)
  48. return(-ENOMEM);
  49. res = 0;
  50. switch(func){
  51. case 1:
  52. case 0x11:
  53. res = copy_from_user(buf, ptr, bytecount);
  54. break;
  55. }
  56. if(res != 0){
  57. res = -EFAULT;
  58. goto out;
  59. }
  60. ldt = ((struct ptrace_ldt) { .func = func,
  61. .ptr = buf,
  62. .bytecount = bytecount });
  63. #warning Need to look up userspace_pid by cpu
  64. res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
  65. if(res < 0)
  66. goto out;
  67. switch(func){
  68. case 0:
  69. case 2:
  70. n = res;
  71. res = copy_to_user(ptr, buf, n);
  72. if(res != 0)
  73. res = -EFAULT;
  74. else
  75. res = n;
  76. break;
  77. }
  78. out:
  79. kfree(buf);
  80. return(res);
  81. }
  82. #endif
  83. long sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
  84. {
  85. return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
  86. ptr, bytecount));
  87. }
  88. #ifdef CONFIG_MODE_TT
  89. extern long arch_prctl(int code, unsigned long addr);
  90. static long arch_prctl_tt(int code, unsigned long addr)
  91. {
  92. unsigned long tmp;
  93. long ret;
  94. switch(code){
  95. case ARCH_SET_GS:
  96. case ARCH_SET_FS:
  97. ret = arch_prctl(code, addr);
  98. break;
  99. case ARCH_GET_FS:
  100. case ARCH_GET_GS:
  101. ret = arch_prctl(code, (unsigned long) &tmp);
  102. if(!ret)
  103. ret = put_user(tmp, &addr);
  104. break;
  105. default:
  106. ret = -EINVAL;
  107. break;
  108. }
  109. return(ret);
  110. }
  111. #endif
  112. #ifdef CONFIG_MODE_SKAS
  113. static long arch_prctl_skas(int code, unsigned long addr)
  114. {
  115. long ret = 0;
  116. switch(code){
  117. case ARCH_SET_GS:
  118. current->thread.regs.regs.skas.regs[GS_BASE / sizeof(unsigned long)] = addr;
  119. break;
  120. case ARCH_SET_FS:
  121. current->thread.regs.regs.skas.regs[FS_BASE / sizeof(unsigned long)] = addr;
  122. break;
  123. case ARCH_GET_FS:
  124. ret = put_user(current->thread.regs.regs.skas.regs[GS / sizeof(unsigned long)], &addr);
  125. break;
  126. case ARCH_GET_GS:
  127. ret = put_user(current->thread.regs.regs.skas.regs[FS / sizeof(unsigned \
  128. long)], &addr);
  129. break;
  130. default:
  131. ret = -EINVAL;
  132. break;
  133. }
  134. return(ret);
  135. }
  136. #endif
  137. long sys_arch_prctl(int code, unsigned long addr)
  138. {
  139. return(CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, code, addr));
  140. }
  141. long sys_clone(unsigned long clone_flags, unsigned long newsp,
  142. void __user *parent_tid, void __user *child_tid)
  143. {
  144. long ret;
  145. /* XXX: normal arch do here this pass, and also pass the regs to
  146. * do_fork, instead of NULL. Currently the arch-independent code
  147. * ignores these values, while the UML code (actually it's
  148. * copy_thread) does the right thing. But this should change,
  149. probably. */
  150. /*if (!newsp)
  151. newsp = UPT_SP(current->thread.regs);*/
  152. current->thread.forking = 1;
  153. ret = do_fork(clone_flags, newsp, NULL, 0, parent_tid, child_tid);
  154. current->thread.forking = 0;
  155. return(ret);
  156. }
  157. /*
  158. * Overrides for Emacs so that we follow Linus's tabbing style.
  159. * Emacs will notice this stuff at the end of the file and automatically
  160. * adjust the settings for this buffer only. This must remain at the end
  161. * of the file.
  162. * ---------------------------------------------------------------------------
  163. * Local variables:
  164. * c-file-style: "linux"
  165. * End:
  166. */