syscalls.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. asmlinkage long sys_uname64(struct new_utsname __user * name)
  19. {
  20. int err;
  21. down_read(&uts_sem);
  22. err = copy_to_user(name, &system_utsname, sizeof (*name));
  23. up_read(&uts_sem);
  24. if (personality(current->personality) == PER_LINUX32)
  25. err |= copy_to_user(&name->machine, "i686", 5);
  26. return err ? -EFAULT : 0;
  27. }
  28. #ifdef CONFIG_MODE_TT
  29. extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
  30. long sys_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
  31. {
  32. /* XXX This should check VERIFY_WRITE depending on func, check this
  33. * in i386 as well.
  34. */
  35. if (!access_ok(VERIFY_READ, ptr, bytecount))
  36. return -EFAULT;
  37. return(modify_ldt(func, ptr, bytecount));
  38. }
  39. #endif
  40. #ifdef CONFIG_MODE_SKAS
  41. extern int userspace_pid[];
  42. #include "skas_ptrace.h"
  43. long sys_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
  44. {
  45. struct ptrace_ldt ldt;
  46. void *buf;
  47. int res, n;
  48. buf = kmalloc(bytecount, GFP_KERNEL);
  49. if(buf == NULL)
  50. return(-ENOMEM);
  51. res = 0;
  52. switch(func){
  53. case 1:
  54. case 0x11:
  55. res = copy_from_user(buf, ptr, bytecount);
  56. break;
  57. }
  58. if(res != 0){
  59. res = -EFAULT;
  60. goto out;
  61. }
  62. ldt = ((struct ptrace_ldt) { .func = func,
  63. .ptr = buf,
  64. .bytecount = bytecount });
  65. #warning Need to look up userspace_pid by cpu
  66. res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
  67. if(res < 0)
  68. goto out;
  69. switch(func){
  70. case 0:
  71. case 2:
  72. n = res;
  73. res = copy_to_user(ptr, buf, n);
  74. if(res != 0)
  75. res = -EFAULT;
  76. else
  77. res = n;
  78. break;
  79. }
  80. out:
  81. kfree(buf);
  82. return(res);
  83. }
  84. #endif
  85. long sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
  86. {
  87. return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
  88. ptr, bytecount));
  89. }
  90. #ifdef CONFIG_MODE_TT
  91. extern long arch_prctl(int code, unsigned long addr);
  92. static long arch_prctl_tt(int code, unsigned long addr)
  93. {
  94. unsigned long tmp;
  95. long ret;
  96. switch(code){
  97. case ARCH_SET_GS:
  98. case ARCH_SET_FS:
  99. ret = arch_prctl(code, addr);
  100. break;
  101. case ARCH_GET_FS:
  102. case ARCH_GET_GS:
  103. ret = arch_prctl(code, (unsigned long) &tmp);
  104. if(!ret)
  105. ret = put_user(tmp, &addr);
  106. break;
  107. default:
  108. ret = -EINVAL;
  109. break;
  110. }
  111. return(ret);
  112. }
  113. #endif
  114. #ifdef CONFIG_MODE_SKAS
  115. /* XXX: Must also call arch_prctl in the host, beside saving the segment bases! */
  116. static long arch_prctl_skas(int code, unsigned long addr)
  117. {
  118. long ret = 0;
  119. switch(code){
  120. case ARCH_SET_FS:
  121. current->thread.regs.regs.skas.regs[FS_BASE / sizeof(unsigned long)] = addr;
  122. break;
  123. case ARCH_SET_GS:
  124. current->thread.regs.regs.skas.regs[GS_BASE / sizeof(unsigned long)] = addr;
  125. break;
  126. case ARCH_GET_FS:
  127. ret = put_user(current->thread.regs.regs.skas.
  128. regs[FS_BASE / sizeof(unsigned long)],
  129. (unsigned long __user *)addr);
  130. break;
  131. case ARCH_GET_GS:
  132. ret = put_user(current->thread.regs.regs.skas.
  133. regs[GS_BASE / sizeof(unsigned long)],
  134. (unsigned long __user *)addr);
  135. break;
  136. default:
  137. ret = -EINVAL;
  138. break;
  139. }
  140. return(ret);
  141. }
  142. #endif
  143. long sys_arch_prctl(int code, unsigned long addr)
  144. {
  145. return(CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, code, addr));
  146. }
  147. long sys_clone(unsigned long clone_flags, unsigned long newsp,
  148. void __user *parent_tid, void __user *child_tid)
  149. {
  150. long ret;
  151. if (!newsp)
  152. newsp = UPT_SP(&current->thread.regs.regs);
  153. current->thread.forking = 1;
  154. ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
  155. child_tid);
  156. current->thread.forking = 0;
  157. return(ret);
  158. }