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