]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/um/sys-x86_64/syscalls.c
uml: throw out CHOOSE_MODE
[linux-2.6-omap-h63xx.git] / arch / um / sys-x86_64 / syscalls.c
1 /*
2  * Copyright 2003 PathScale, Inc.
3  *
4  * Licensed under the GPL
5  */
6
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 "kern.h"
18 #include "os.h"
19
20 asmlinkage long sys_uname64(struct new_utsname __user * name)
21 {
22         int err;
23         down_read(&uts_sem);
24         err = copy_to_user(name, utsname(), sizeof (*name));
25         up_read(&uts_sem);
26         if (personality(current->personality) == PER_LINUX32)
27                 err |= copy_to_user(&name->machine, "i686", 5);
28         return err ? -EFAULT : 0;
29 }
30
31 long arch_prctl_skas(struct task_struct *task, int code,
32                      unsigned long __user *addr)
33 {
34         unsigned long *ptr = addr, tmp;
35         long ret;
36         int pid = task->mm->context.skas.id.u.pid;
37
38         /*
39          * With ARCH_SET_FS (and ARCH_SET_GS is treated similarly to
40          * be safe), we need to call arch_prctl on the host because
41          * setting %fs may result in something else happening (like a
42          * GDT or thread.fs being set instead).  So, we let the host
43          * fiddle the registers and thread struct and restore the
44          * registers afterwards.
45          *
46          * So, the saved registers are stored to the process (this
47          * needed because a stub may have been the last thing to run),
48          * arch_prctl is run on the host, then the registers are read
49          * back.
50          */
51         switch(code){
52         case ARCH_SET_FS:
53         case ARCH_SET_GS:
54                 restore_registers(pid, &current->thread.regs.regs);
55                 break;
56         case ARCH_GET_FS:
57         case ARCH_GET_GS:
58                 /*
59                  * With these two, we read to a local pointer and
60                  * put_user it to the userspace pointer that we were
61                  * given.  If addr isn't valid (because it hasn't been
62                  * faulted in or is just bogus), we want put_user to
63                  * fault it in (or return -EFAULT) instead of having
64                  * the host return -EFAULT.
65                  */
66                 ptr = &tmp;
67         }
68
69         ret = os_arch_prctl(pid, code, ptr);
70         if(ret)
71                 return ret;
72
73         switch(code){
74         case ARCH_SET_FS:
75                 current->thread.arch.fs = (unsigned long) ptr;
76                 save_registers(pid, &current->thread.regs.regs);
77                 break;
78         case ARCH_SET_GS:
79                 save_registers(pid, &current->thread.regs.regs);
80                 break;
81         case ARCH_GET_FS:
82                 ret = put_user(tmp, addr);
83                 break;
84         case ARCH_GET_GS:
85                 ret = put_user(tmp, addr);
86                 break;
87         }
88
89         return ret;
90 }
91
92 long sys_arch_prctl(int code, unsigned long addr)
93 {
94         return arch_prctl_skas(current, code, (unsigned long __user *) addr);
95 }
96
97 long sys_clone(unsigned long clone_flags, unsigned long newsp,
98                void __user *parent_tid, void __user *child_tid)
99 {
100         long ret;
101
102         if (!newsp)
103                 newsp = UPT_SP(&current->thread.regs.regs);
104         current->thread.forking = 1;
105         ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
106                       child_tid);
107         current->thread.forking = 0;
108         return ret;
109 }
110
111 void arch_switch_to_skas(struct task_struct *from, struct task_struct *to)
112 {
113         if((to->thread.arch.fs == 0) || (to->mm == NULL))
114                 return;
115
116         arch_prctl_skas(to, ARCH_SET_FS, (void __user *) to->thread.arch.fs);
117 }