syscalls.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "kern.h"
  17. #include "os.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, 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. long arch_prctl_skas(struct task_struct *task, int code,
  29. unsigned long __user *addr)
  30. {
  31. unsigned long *ptr = addr, tmp;
  32. long ret;
  33. int pid = task->mm->context.skas.id.u.pid;
  34. /*
  35. * With ARCH_SET_FS (and ARCH_SET_GS is treated similarly to
  36. * be safe), we need to call arch_prctl on the host because
  37. * setting %fs may result in something else happening (like a
  38. * GDT or thread.fs being set instead). So, we let the host
  39. * fiddle the registers and thread struct and restore the
  40. * registers afterwards.
  41. *
  42. * So, the saved registers are stored to the process (this
  43. * needed because a stub may have been the last thing to run),
  44. * arch_prctl is run on the host, then the registers are read
  45. * back.
  46. */
  47. switch(code){
  48. case ARCH_SET_FS:
  49. case ARCH_SET_GS:
  50. restore_registers(pid, &current->thread.regs.regs);
  51. break;
  52. case ARCH_GET_FS:
  53. case ARCH_GET_GS:
  54. /*
  55. * With these two, we read to a local pointer and
  56. * put_user it to the userspace pointer that we were
  57. * given. If addr isn't valid (because it hasn't been
  58. * faulted in or is just bogus), we want put_user to
  59. * fault it in (or return -EFAULT) instead of having
  60. * the host return -EFAULT.
  61. */
  62. ptr = &tmp;
  63. }
  64. ret = os_arch_prctl(pid, code, ptr);
  65. if(ret)
  66. return ret;
  67. switch(code){
  68. case ARCH_SET_FS:
  69. current->thread.arch.fs = (unsigned long) ptr;
  70. save_registers(pid, &current->thread.regs.regs);
  71. break;
  72. case ARCH_SET_GS:
  73. save_registers(pid, &current->thread.regs.regs);
  74. break;
  75. case ARCH_GET_FS:
  76. ret = put_user(tmp, addr);
  77. break;
  78. case ARCH_GET_GS:
  79. ret = put_user(tmp, addr);
  80. break;
  81. }
  82. return ret;
  83. }
  84. long sys_arch_prctl(int code, unsigned long addr)
  85. {
  86. return arch_prctl_skas(current, code, (unsigned long __user *) addr);
  87. }
  88. long sys_clone(unsigned long clone_flags, unsigned long newsp,
  89. void __user *parent_tid, void __user *child_tid)
  90. {
  91. long ret;
  92. if (!newsp)
  93. newsp = UPT_SP(&current->thread.regs.regs);
  94. current->thread.forking = 1;
  95. ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
  96. child_tid);
  97. current->thread.forking = 0;
  98. return ret;
  99. }
  100. void arch_switch_to_skas(struct task_struct *from, struct task_struct *to)
  101. {
  102. if((to->thread.arch.fs == 0) || (to->mm == NULL))
  103. return;
  104. arch_prctl_skas(to, ARCH_SET_FS, (void __user *) to->thread.arch.fs);
  105. }