2 * Copyright 2003 PathScale, Inc.
4 * Licensed under the GPL
7 #include "linux/linkage.h"
8 #include "linux/slab.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"
21 asmlinkage long sys_uname64(struct new_utsname __user * name)
25 err = copy_to_user(name, utsname(), sizeof (*name));
27 if (personality(current->personality) == PER_LINUX32)
28 err |= copy_to_user(&name->machine, "i686", 5);
29 return err ? -EFAULT : 0;
33 extern long arch_prctl(int code, unsigned long addr);
35 static long arch_prctl_tt(int code, unsigned long addr)
43 ret = arch_prctl(code, addr);
47 ret = arch_prctl(code, (unsigned long) &tmp);
49 ret = put_user(tmp, (long __user *)addr);
60 #ifdef CONFIG_MODE_SKAS
62 static long arch_prctl_skas(int code, unsigned long __user *addr)
64 unsigned long *ptr = addr, tmp;
66 int pid = current->mm->context.skas.id.u.pid;
69 * With ARCH_SET_FS (and ARCH_SET_GS is treated similarly to
70 * be safe), we need to call arch_prctl on the host because
71 * setting %fs may result in something else happening (like a
72 * GDT being set instead). So, we let the host fiddle the
73 * registers and restore them afterwards.
75 * So, the saved registers are stored to the process (this
76 * needed because a stub may have been the last thing to run),
77 * arch_prctl is run on the host, then the registers are read
83 restore_registers(pid, ¤t->thread.regs.regs);
88 * With these two, we read to a local pointer and
89 * put_user it to the userspace pointer that we were
90 * given. If addr isn't valid (because it hasn't been
91 * faulted in or is just bogus), we want put_user to
92 * fault it in (or return -EFAULT) instead of having
93 * the host return -EFAULT.
98 ret = os_arch_prctl(pid, code, ptr);
104 current->thread.arch.fs = (unsigned long) ptr;
105 save_registers(pid, ¤t->thread.regs.regs);
108 save_registers(pid, ¤t->thread.regs.regs);
111 ret = put_user(tmp, addr);
114 ret = put_user(tmp, addr);
122 long sys_arch_prctl(int code, unsigned long addr)
124 return CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, code,
125 (unsigned long __user *) addr);
128 long sys_clone(unsigned long clone_flags, unsigned long newsp,
129 void __user *parent_tid, void __user *child_tid)
134 newsp = UPT_SP(¤t->thread.regs.regs);
135 current->thread.forking = 1;
136 ret = do_fork(clone_flags, newsp, ¤t->thread.regs, 0, parent_tid,
138 current->thread.forking = 0;
142 void arch_switch_to_skas(struct task_struct *from, struct task_struct *to)
144 if((to->thread.arch.fs == 0) || (to->mm == NULL))
147 arch_prctl_skas(ARCH_SET_FS, (void __user *) to->thread.arch.fs);