syscalls.c 4.6 KB

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