Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" |
Paolo 'Blaisorblade' Giarrusso | f7fe878 | 2005-05-05 16:15:15 -0700 | [diff] [blame] | 10 | #include "linux/utsname.h" |
| 11 | #include "linux/personality.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" |
Jeff Dike | ba9950c | 2005-05-20 13:59:07 -0700 | [diff] [blame] | 18 | #include "kern.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Paolo 'Blaisorblade' Giarrusso | 80f9507 | 2005-05-01 08:58:55 -0700 | [diff] [blame] | 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, &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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #ifdef CONFIG_MODE_TT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | extern long arch_prctl(int code, unsigned long addr); |
| 33 | |
| 34 | static 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) |
Al Viro | ca34fb1 | 2006-06-04 02:51:47 -0700 | [diff] [blame] | 48 | ret = put_user(tmp, (long __user *)addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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' Giarrusso | f767b02 | 2005-05-28 15:52:03 -0700 | [diff] [blame] | 61 | /* XXX: Must also call arch_prctl in the host, beside saving the segment bases! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static long arch_prctl_skas(int code, unsigned long addr) |
| 63 | { |
| 64 | long ret = 0; |
| 65 | |
| 66 | switch(code){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | case ARCH_SET_FS: |
| 68 | current->thread.regs.regs.skas.regs[FS_BASE / sizeof(unsigned long)] = addr; |
| 69 | break; |
Paolo 'Blaisorblade' Giarrusso | f767b02 | 2005-05-28 15:52:03 -0700 | [diff] [blame] | 70 | case ARCH_SET_GS: |
| 71 | current->thread.regs.regs.skas.regs[GS_BASE / sizeof(unsigned long)] = addr; |
| 72 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | case ARCH_GET_FS: |
Paolo 'Blaisorblade' Giarrusso | f767b02 | 2005-05-28 15:52:03 -0700 | [diff] [blame] | 74 | ret = put_user(current->thread.regs.regs.skas. |
| 75 | regs[FS_BASE / sizeof(unsigned long)], |
| 76 | (unsigned long __user *)addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | break; |
| 78 | case ARCH_GET_GS: |
Paolo 'Blaisorblade' Giarrusso | f767b02 | 2005-05-28 15:52:03 -0700 | [diff] [blame] | 79 | ret = put_user(current->thread.regs.regs.skas. |
| 80 | regs[GS_BASE / sizeof(unsigned long)], |
| 81 | (unsigned long __user *)addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | break; |
| 83 | default: |
| 84 | ret = -EINVAL; |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | return(ret); |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | long sys_arch_prctl(int code, unsigned long addr) |
| 93 | { |
| 94 | return(CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, code, 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 | |
Jeff Dike | e0877f0 | 2005-06-25 14:55:21 -0700 | [diff] [blame] | 102 | if (!newsp) |
| 103 | newsp = UPT_SP(¤t->thread.regs.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | current->thread.forking = 1; |
Jeff Dike | e0877f0 | 2005-06-25 14:55:21 -0700 | [diff] [blame] | 105 | ret = do_fork(clone_flags, newsp, ¤t->thread.regs, 0, parent_tid, |
| 106 | child_tid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | current->thread.forking = 0; |
| 108 | return(ret); |
| 109 | } |