blob: 01b91f9fa7893647454f2a843f22a729197d78cb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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"
Paolo 'Blaisorblade' Giarrussof7fe8782005-05-05 16:15:15 -070010#include "linux/utsname.h"
11#include "linux/personality.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#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"
Jeff Dikeba9950c2005-05-20 13:59:07 -070018#include "kern.h"
Jeff Dikef3555592007-02-10 01:44:29 -080019#include "os.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Paolo 'Blaisorblade' Giarrusso80f95072005-05-01 08:58:55 -070021asmlinkage long sys_uname64(struct new_utsname __user * name)
22{
23 int err;
24 down_read(&uts_sem);
Serge E. Hallyne9ff3992006-10-02 02:18:11 -070025 err = copy_to_user(name, utsname(), sizeof (*name));
Paolo 'Blaisorblade' Giarrusso80f95072005-05-01 08:58:55 -070026 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;
30}
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#ifdef CONFIG_MODE_TT
Linus Torvalds1da177e2005-04-16 15:20:36 -070033extern long arch_prctl(int code, unsigned long addr);
34
35static long arch_prctl_tt(int code, unsigned long addr)
36{
37 unsigned long tmp;
38 long ret;
39
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)
Al Viroca34fb12006-06-04 02:51:47 -070049 ret = put_user(tmp, (long __user *)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 break;
51 default:
52 ret = -EINVAL;
53 break;
54 }
55
56 return(ret);
57}
58#endif
59
60#ifdef CONFIG_MODE_SKAS
61
Jeff Dike6e6d74c2007-02-10 01:44:30 -080062long arch_prctl_skas(struct task_struct *task, int code,
63 unsigned long __user *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Jeff Dikef3555592007-02-10 01:44:29 -080065 unsigned long *ptr = addr, tmp;
66 long ret;
Jeff Dike6e6d74c2007-02-10 01:44:30 -080067 int pid = task->mm->context.skas.id.u.pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Jeff Dikef3555592007-02-10 01:44:29 -080069 /*
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
Jeff Dike6e6d74c2007-02-10 01:44:30 -080073 * 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.
Jeff Dikef3555592007-02-10 01:44:29 -080076 *
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.
81 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 switch(code){
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 case ARCH_SET_FS:
Paolo 'Blaisorblade' Giarrussof767b022005-05-28 15:52:03 -070084 case ARCH_SET_GS:
Jeff Dikef3555592007-02-10 01:44:29 -080085 restore_registers(pid, &current->thread.regs.regs);
86 break;
87 case ARCH_GET_FS:
88 case ARCH_GET_GS:
89 /*
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.
96 */
97 ptr = &tmp;
98 }
99
100 ret = os_arch_prctl(pid, code, ptr);
101 if(ret)
102 return ret;
103
104 switch(code){
105 case ARCH_SET_FS:
106 case ARCH_SET_GS:
107 save_registers(pid, &current->thread.regs.regs);
Paolo 'Blaisorblade' Giarrussof767b022005-05-28 15:52:03 -0700108 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 case ARCH_GET_FS:
Jeff Dikef3555592007-02-10 01:44:29 -0800110 ret = put_user(tmp, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 break;
112 case ARCH_GET_GS:
Jeff Dikef3555592007-02-10 01:44:29 -0800113 ret = put_user(tmp, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
116
Jeff Dikef3555592007-02-10 01:44:29 -0800117 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119#endif
120
121long sys_arch_prctl(int code, unsigned long addr)
122{
Jeff Dike6e6d74c2007-02-10 01:44:30 -0800123 return CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, current, code,
Jeff Dikef3555592007-02-10 01:44:29 -0800124 (unsigned long __user *) addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126
127long sys_clone(unsigned long clone_flags, unsigned long newsp,
128 void __user *parent_tid, void __user *child_tid)
129{
130 long ret;
131
Jeff Dikee0877f02005-06-25 14:55:21 -0700132 if (!newsp)
133 newsp = UPT_SP(&current->thread.regs.regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 current->thread.forking = 1;
Jeff Dikee0877f02005-06-25 14:55:21 -0700135 ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
136 child_tid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 current->thread.forking = 0;
Jeff Dikef3555592007-02-10 01:44:29 -0800138 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
Jeff Dikef3555592007-02-10 01:44:29 -0800140
141void arch_switch_to_skas(struct task_struct *from, struct task_struct *to)
142{
143 if(to->thread.arch.fs == 0)
144 return;
145
Jeff Dike6e6d74c2007-02-10 01:44:30 -0800146 arch_prctl_skas(to, ARCH_SET_FS, (void __user *) to->thread.arch.fs);
Jeff Dikef3555592007-02-10 01:44:29 -0800147}
148