blob: 6acee5c4ada6fcdff56ddd95313865dd295df508 [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Paolo 'Blaisorblade' Giarrusso80f95072005-05-01 08:58:55 -070020asmlinkage long sys_uname64(struct new_utsname __user * name)
21{
22 int err;
23 down_read(&uts_sem);
24 err = copy_to_user(name, &system_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
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#ifdef CONFIG_MODE_TT
Linus Torvalds1da177e2005-04-16 15:20:36 -070032extern long arch_prctl(int code, unsigned long addr);
33
34static long arch_prctl_tt(int code, unsigned long addr)
35{
36 unsigned long tmp;
37 long ret;
38
39 switch(code){
40 case ARCH_SET_GS:
41 case ARCH_SET_FS:
42 ret = arch_prctl(code, addr);
43 break;
44 case ARCH_GET_FS:
45 case ARCH_GET_GS:
46 ret = arch_prctl(code, (unsigned long) &tmp);
47 if(!ret)
48 ret = put_user(tmp, &addr);
49 break;
50 default:
51 ret = -EINVAL;
52 break;
53 }
54
55 return(ret);
56}
57#endif
58
59#ifdef CONFIG_MODE_SKAS
60
Paolo 'Blaisorblade' Giarrussof767b022005-05-28 15:52:03 -070061/* XXX: Must also call arch_prctl in the host, beside saving the segment bases! */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062static long arch_prctl_skas(int code, unsigned long addr)
63{
64 long ret = 0;
65
66 switch(code){
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 case ARCH_SET_FS:
68 current->thread.regs.regs.skas.regs[FS_BASE / sizeof(unsigned long)] = addr;
69 break;
Paolo 'Blaisorblade' Giarrussof767b022005-05-28 15:52:03 -070070 case ARCH_SET_GS:
71 current->thread.regs.regs.skas.regs[GS_BASE / sizeof(unsigned long)] = addr;
72 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 case ARCH_GET_FS:
Paolo 'Blaisorblade' Giarrussof767b022005-05-28 15:52:03 -070074 ret = put_user(current->thread.regs.regs.skas.
75 regs[FS_BASE / sizeof(unsigned long)],
76 (unsigned long __user *)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 break;
78 case ARCH_GET_GS:
Paolo 'Blaisorblade' Giarrussof767b022005-05-28 15:52:03 -070079 ret = put_user(current->thread.regs.regs.skas.
80 regs[GS_BASE / sizeof(unsigned long)],
81 (unsigned long __user *)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 break;
83 default:
84 ret = -EINVAL;
85 break;
86 }
87
88 return(ret);
89}
90#endif
91
92long sys_arch_prctl(int code, unsigned long addr)
93{
94 return(CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, code, addr));
95}
96
97long sys_clone(unsigned long clone_flags, unsigned long newsp,
98 void __user *parent_tid, void __user *child_tid)
99{
100 long ret;
101
Jeff Dikee0877f02005-06-25 14:55:21 -0700102 if (!newsp)
103 newsp = UPT_SP(&current->thread.regs.regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 current->thread.forking = 1;
Jeff Dikee0877f02005-06-25 14:55:21 -0700105 ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
106 child_tid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 current->thread.forking = 0;
108 return(ret);
109}