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" |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 19 | #include "os.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Paolo 'Blaisorblade' Giarrusso | 80f9507 | 2005-05-01 08:58:55 -0700 | [diff] [blame] | 21 | asmlinkage long sys_uname64(struct new_utsname __user * name) |
| 22 | { |
| 23 | int err; |
| 24 | down_read(&uts_sem); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 25 | err = copy_to_user(name, utsname(), sizeof (*name)); |
Paolo 'Blaisorblade' Giarrusso | 80f9507 | 2005-05-01 08:58:55 -0700 | [diff] [blame] | 26 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #ifdef CONFIG_MODE_TT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | extern long arch_prctl(int code, unsigned long addr); |
| 34 | |
| 35 | static 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 Viro | ca34fb1 | 2006-06-04 02:51:47 -0700 | [diff] [blame] | 49 | ret = put_user(tmp, (long __user *)addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | break; |
| 51 | default: |
| 52 | ret = -EINVAL; |
| 53 | break; |
| 54 | } |
| 55 | |
| 56 | return(ret); |
| 57 | } |
| 58 | #endif |
| 59 | |
| 60 | #ifdef CONFIG_MODE_SKAS |
| 61 | |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 62 | static long arch_prctl_skas(int code, unsigned long __user *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 64 | unsigned long *ptr = addr, tmp; |
| 65 | long ret; |
| 66 | int pid = current->mm->context.skas.id.u.pid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 68 | /* |
| 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. |
| 74 | * |
| 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 |
| 78 | * back. |
| 79 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | switch(code){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | case ARCH_SET_FS: |
Paolo 'Blaisorblade' Giarrusso | f767b02 | 2005-05-28 15:52:03 -0700 | [diff] [blame] | 82 | case ARCH_SET_GS: |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 83 | restore_registers(pid, ¤t->thread.regs.regs); |
| 84 | break; |
| 85 | case ARCH_GET_FS: |
| 86 | case ARCH_GET_GS: |
| 87 | /* |
| 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. |
| 94 | */ |
| 95 | ptr = &tmp; |
| 96 | } |
| 97 | |
| 98 | ret = os_arch_prctl(pid, code, ptr); |
| 99 | if(ret) |
| 100 | return ret; |
| 101 | |
| 102 | switch(code){ |
| 103 | case ARCH_SET_FS: |
| 104 | case ARCH_SET_GS: |
| 105 | save_registers(pid, ¤t->thread.regs.regs); |
Paolo 'Blaisorblade' Giarrusso | f767b02 | 2005-05-28 15:52:03 -0700 | [diff] [blame] | 106 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | case ARCH_GET_FS: |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 108 | ret = put_user(tmp, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | break; |
| 110 | case ARCH_GET_GS: |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 111 | ret = put_user(tmp, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 115 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | #endif |
| 118 | |
| 119 | long sys_arch_prctl(int code, unsigned long addr) |
| 120 | { |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 121 | return CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, code, |
| 122 | (unsigned long __user *) addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | long sys_clone(unsigned long clone_flags, unsigned long newsp, |
| 126 | void __user *parent_tid, void __user *child_tid) |
| 127 | { |
| 128 | long ret; |
| 129 | |
Jeff Dike | e0877f0 | 2005-06-25 14:55:21 -0700 | [diff] [blame] | 130 | if (!newsp) |
| 131 | newsp = UPT_SP(¤t->thread.regs.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | current->thread.forking = 1; |
Jeff Dike | e0877f0 | 2005-06-25 14:55:21 -0700 | [diff] [blame] | 133 | ret = do_fork(clone_flags, newsp, ¤t->thread.regs, 0, parent_tid, |
| 134 | child_tid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | current->thread.forking = 0; |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 136 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
Jeff Dike | f355559 | 2007-02-10 01:44:29 -0800 | [diff] [blame^] | 138 | |
| 139 | void arch_switch_to_skas(struct task_struct *from, struct task_struct *to) |
| 140 | { |
| 141 | if(to->thread.arch.fs == 0) |
| 142 | return; |
| 143 | |
| 144 | arch_prctl_skas(ARCH_SET_FS, (void __user *) to->thread.arch.fs); |
| 145 | } |
| 146 | |