Commit 9a81c16b527528ad307843be5571111aa8d35a80
Committed by
Linus Torvalds
1 parent
b68e9d4581
Exists in
master
and in
39 other branches
powerpc: fix double syscall restarts
Make sigreturn zero regs->trap, make do_signal() do the same on all paths. As it is, signal interrupting e.g. read() from fd 512 (== ERESTARTSYS) with another signal getting unblocked when the first handler finishes will lead to restart one insn earlier than it ought to. Same for multiple signals with in-kernel handlers interrupting that sucker at the same time. Same for multiple signals of any kind interrupting that sucker on 64bit... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Acked-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 3 changed files with 4 additions and 3 deletions Inline Diff
arch/powerpc/kernel/signal.c
1 | /* | 1 | /* |
2 | * Common signal handling code for both 32 and 64 bits | 2 | * Common signal handling code for both 32 and 64 bits |
3 | * | 3 | * |
4 | * Copyright (c) 2007 Benjamin Herrenschmidt, IBM Coproration | 4 | * Copyright (c) 2007 Benjamin Herrenschmidt, IBM Coproration |
5 | * Extracted from signal_32.c and signal_64.c | 5 | * Extracted from signal_32.c and signal_64.c |
6 | * | 6 | * |
7 | * This file is subject to the terms and conditions of the GNU General | 7 | * This file is subject to the terms and conditions of the GNU General |
8 | * Public License. See the file README.legal in the main directory of | 8 | * Public License. See the file README.legal in the main directory of |
9 | * this archive for more details. | 9 | * this archive for more details. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/tracehook.h> | 12 | #include <linux/tracehook.h> |
13 | #include <linux/signal.h> | 13 | #include <linux/signal.h> |
14 | #include <asm/hw_breakpoint.h> | 14 | #include <asm/hw_breakpoint.h> |
15 | #include <asm/uaccess.h> | 15 | #include <asm/uaccess.h> |
16 | #include <asm/unistd.h> | 16 | #include <asm/unistd.h> |
17 | 17 | ||
18 | #include "signal.h" | 18 | #include "signal.h" |
19 | 19 | ||
20 | /* Log an error when sending an unhandled signal to a process. Controlled | 20 | /* Log an error when sending an unhandled signal to a process. Controlled |
21 | * through debug.exception-trace sysctl. | 21 | * through debug.exception-trace sysctl. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | int show_unhandled_signals = 0; | 24 | int show_unhandled_signals = 0; |
25 | 25 | ||
26 | /* | 26 | /* |
27 | * Allocate space for the signal frame | 27 | * Allocate space for the signal frame |
28 | */ | 28 | */ |
29 | void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, | 29 | void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, |
30 | size_t frame_size, int is_32) | 30 | size_t frame_size, int is_32) |
31 | { | 31 | { |
32 | unsigned long oldsp, newsp; | 32 | unsigned long oldsp, newsp; |
33 | 33 | ||
34 | /* Default to using normal stack */ | 34 | /* Default to using normal stack */ |
35 | oldsp = get_clean_sp(regs, is_32); | 35 | oldsp = get_clean_sp(regs, is_32); |
36 | 36 | ||
37 | /* Check for alt stack */ | 37 | /* Check for alt stack */ |
38 | if ((ka->sa.sa_flags & SA_ONSTACK) && | 38 | if ((ka->sa.sa_flags & SA_ONSTACK) && |
39 | current->sas_ss_size && !on_sig_stack(oldsp)) | 39 | current->sas_ss_size && !on_sig_stack(oldsp)) |
40 | oldsp = (current->sas_ss_sp + current->sas_ss_size); | 40 | oldsp = (current->sas_ss_sp + current->sas_ss_size); |
41 | 41 | ||
42 | /* Get aligned frame */ | 42 | /* Get aligned frame */ |
43 | newsp = (oldsp - frame_size) & ~0xFUL; | 43 | newsp = (oldsp - frame_size) & ~0xFUL; |
44 | 44 | ||
45 | /* Check access */ | 45 | /* Check access */ |
46 | if (!access_ok(VERIFY_WRITE, (void __user *)newsp, oldsp - newsp)) | 46 | if (!access_ok(VERIFY_WRITE, (void __user *)newsp, oldsp - newsp)) |
47 | return NULL; | 47 | return NULL; |
48 | 48 | ||
49 | return (void __user *)newsp; | 49 | return (void __user *)newsp; |
50 | } | 50 | } |
51 | 51 | ||
52 | 52 | ||
53 | /* | 53 | /* |
54 | * Restore the user process's signal mask | 54 | * Restore the user process's signal mask |
55 | */ | 55 | */ |
56 | void restore_sigmask(sigset_t *set) | 56 | void restore_sigmask(sigset_t *set) |
57 | { | 57 | { |
58 | sigdelsetmask(set, ~_BLOCKABLE); | 58 | sigdelsetmask(set, ~_BLOCKABLE); |
59 | spin_lock_irq(¤t->sighand->siglock); | 59 | spin_lock_irq(¤t->sighand->siglock); |
60 | current->blocked = *set; | 60 | current->blocked = *set; |
61 | recalc_sigpending(); | 61 | recalc_sigpending(); |
62 | spin_unlock_irq(¤t->sighand->siglock); | 62 | spin_unlock_irq(¤t->sighand->siglock); |
63 | } | 63 | } |
64 | 64 | ||
65 | static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka, | 65 | static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka, |
66 | int has_handler) | 66 | int has_handler) |
67 | { | 67 | { |
68 | unsigned long ret = regs->gpr[3]; | 68 | unsigned long ret = regs->gpr[3]; |
69 | int restart = 1; | 69 | int restart = 1; |
70 | 70 | ||
71 | /* syscall ? */ | 71 | /* syscall ? */ |
72 | if (TRAP(regs) != 0x0C00) | 72 | if (TRAP(regs) != 0x0C00) |
73 | return; | 73 | return; |
74 | 74 | ||
75 | /* error signalled ? */ | 75 | /* error signalled ? */ |
76 | if (!(regs->ccr & 0x10000000)) | 76 | if (!(regs->ccr & 0x10000000)) |
77 | return; | 77 | return; |
78 | 78 | ||
79 | switch (ret) { | 79 | switch (ret) { |
80 | case ERESTART_RESTARTBLOCK: | 80 | case ERESTART_RESTARTBLOCK: |
81 | case ERESTARTNOHAND: | 81 | case ERESTARTNOHAND: |
82 | /* ERESTARTNOHAND means that the syscall should only be | 82 | /* ERESTARTNOHAND means that the syscall should only be |
83 | * restarted if there was no handler for the signal, and since | 83 | * restarted if there was no handler for the signal, and since |
84 | * we only get here if there is a handler, we dont restart. | 84 | * we only get here if there is a handler, we dont restart. |
85 | */ | 85 | */ |
86 | restart = !has_handler; | 86 | restart = !has_handler; |
87 | break; | 87 | break; |
88 | case ERESTARTSYS: | 88 | case ERESTARTSYS: |
89 | /* ERESTARTSYS means to restart the syscall if there is no | 89 | /* ERESTARTSYS means to restart the syscall if there is no |
90 | * handler or the handler was registered with SA_RESTART | 90 | * handler or the handler was registered with SA_RESTART |
91 | */ | 91 | */ |
92 | restart = !has_handler || (ka->sa.sa_flags & SA_RESTART) != 0; | 92 | restart = !has_handler || (ka->sa.sa_flags & SA_RESTART) != 0; |
93 | break; | 93 | break; |
94 | case ERESTARTNOINTR: | 94 | case ERESTARTNOINTR: |
95 | /* ERESTARTNOINTR means that the syscall should be | 95 | /* ERESTARTNOINTR means that the syscall should be |
96 | * called again after the signal handler returns. | 96 | * called again after the signal handler returns. |
97 | */ | 97 | */ |
98 | break; | 98 | break; |
99 | default: | 99 | default: |
100 | return; | 100 | return; |
101 | } | 101 | } |
102 | if (restart) { | 102 | if (restart) { |
103 | if (ret == ERESTART_RESTARTBLOCK) | 103 | if (ret == ERESTART_RESTARTBLOCK) |
104 | regs->gpr[0] = __NR_restart_syscall; | 104 | regs->gpr[0] = __NR_restart_syscall; |
105 | else | 105 | else |
106 | regs->gpr[3] = regs->orig_gpr3; | 106 | regs->gpr[3] = regs->orig_gpr3; |
107 | regs->nip -= 4; | 107 | regs->nip -= 4; |
108 | regs->result = 0; | 108 | regs->result = 0; |
109 | } else { | 109 | } else { |
110 | regs->result = -EINTR; | 110 | regs->result = -EINTR; |
111 | regs->gpr[3] = EINTR; | 111 | regs->gpr[3] = EINTR; |
112 | regs->ccr |= 0x10000000; | 112 | regs->ccr |= 0x10000000; |
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | static int do_signal_pending(sigset_t *oldset, struct pt_regs *regs) | 116 | static int do_signal_pending(sigset_t *oldset, struct pt_regs *regs) |
117 | { | 117 | { |
118 | siginfo_t info; | 118 | siginfo_t info; |
119 | int signr; | 119 | int signr; |
120 | struct k_sigaction ka; | 120 | struct k_sigaction ka; |
121 | int ret; | 121 | int ret; |
122 | int is32 = is_32bit_task(); | 122 | int is32 = is_32bit_task(); |
123 | 123 | ||
124 | if (current_thread_info()->local_flags & _TLF_RESTORE_SIGMASK) | 124 | if (current_thread_info()->local_flags & _TLF_RESTORE_SIGMASK) |
125 | oldset = ¤t->saved_sigmask; | 125 | oldset = ¤t->saved_sigmask; |
126 | else if (!oldset) | 126 | else if (!oldset) |
127 | oldset = ¤t->blocked; | 127 | oldset = ¤t->blocked; |
128 | 128 | ||
129 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | 129 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
130 | 130 | ||
131 | /* Is there any syscall restart business here ? */ | 131 | /* Is there any syscall restart business here ? */ |
132 | check_syscall_restart(regs, &ka, signr > 0); | 132 | check_syscall_restart(regs, &ka, signr > 0); |
133 | 133 | ||
134 | if (signr <= 0) { | 134 | if (signr <= 0) { |
135 | struct thread_info *ti = current_thread_info(); | 135 | struct thread_info *ti = current_thread_info(); |
136 | /* No signal to deliver -- put the saved sigmask back */ | 136 | /* No signal to deliver -- put the saved sigmask back */ |
137 | if (ti->local_flags & _TLF_RESTORE_SIGMASK) { | 137 | if (ti->local_flags & _TLF_RESTORE_SIGMASK) { |
138 | ti->local_flags &= ~_TLF_RESTORE_SIGMASK; | 138 | ti->local_flags &= ~_TLF_RESTORE_SIGMASK; |
139 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); | 139 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); |
140 | } | 140 | } |
141 | regs->trap = 0; | ||
141 | return 0; /* no signals delivered */ | 142 | return 0; /* no signals delivered */ |
142 | } | 143 | } |
143 | 144 | ||
144 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS | 145 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
145 | /* | 146 | /* |
146 | * Reenable the DABR before delivering the signal to | 147 | * Reenable the DABR before delivering the signal to |
147 | * user space. The DABR will have been cleared if it | 148 | * user space. The DABR will have been cleared if it |
148 | * triggered inside the kernel. | 149 | * triggered inside the kernel. |
149 | */ | 150 | */ |
150 | if (current->thread.dabr) | 151 | if (current->thread.dabr) |
151 | set_dabr(current->thread.dabr); | 152 | set_dabr(current->thread.dabr); |
152 | #endif | 153 | #endif |
153 | /* Re-enable the breakpoints for the signal stack */ | 154 | /* Re-enable the breakpoints for the signal stack */ |
154 | thread_change_pc(current, regs); | 155 | thread_change_pc(current, regs); |
155 | 156 | ||
156 | if (is32) { | 157 | if (is32) { |
157 | if (ka.sa.sa_flags & SA_SIGINFO) | 158 | if (ka.sa.sa_flags & SA_SIGINFO) |
158 | ret = handle_rt_signal32(signr, &ka, &info, oldset, | 159 | ret = handle_rt_signal32(signr, &ka, &info, oldset, |
159 | regs); | 160 | regs); |
160 | else | 161 | else |
161 | ret = handle_signal32(signr, &ka, &info, oldset, | 162 | ret = handle_signal32(signr, &ka, &info, oldset, |
162 | regs); | 163 | regs); |
163 | } else { | 164 | } else { |
164 | ret = handle_rt_signal64(signr, &ka, &info, oldset, regs); | 165 | ret = handle_rt_signal64(signr, &ka, &info, oldset, regs); |
165 | } | 166 | } |
166 | 167 | ||
168 | regs->trap = 0; | ||
167 | if (ret) { | 169 | if (ret) { |
168 | spin_lock_irq(¤t->sighand->siglock); | 170 | spin_lock_irq(¤t->sighand->siglock); |
169 | sigorsets(¤t->blocked, ¤t->blocked, | 171 | sigorsets(¤t->blocked, ¤t->blocked, |
170 | &ka.sa.sa_mask); | 172 | &ka.sa.sa_mask); |
171 | if (!(ka.sa.sa_flags & SA_NODEFER)) | 173 | if (!(ka.sa.sa_flags & SA_NODEFER)) |
172 | sigaddset(¤t->blocked, signr); | 174 | sigaddset(¤t->blocked, signr); |
173 | recalc_sigpending(); | 175 | recalc_sigpending(); |
174 | spin_unlock_irq(¤t->sighand->siglock); | 176 | spin_unlock_irq(¤t->sighand->siglock); |
175 | 177 | ||
176 | /* | 178 | /* |
177 | * A signal was successfully delivered; the saved sigmask is in | 179 | * A signal was successfully delivered; the saved sigmask is in |
178 | * its frame, and we can clear the TLF_RESTORE_SIGMASK flag. | 180 | * its frame, and we can clear the TLF_RESTORE_SIGMASK flag. |
179 | */ | 181 | */ |
180 | current_thread_info()->local_flags &= ~_TLF_RESTORE_SIGMASK; | 182 | current_thread_info()->local_flags &= ~_TLF_RESTORE_SIGMASK; |
181 | 183 | ||
182 | /* | 184 | /* |
183 | * Let tracing know that we've done the handler setup. | 185 | * Let tracing know that we've done the handler setup. |
184 | */ | 186 | */ |
185 | tracehook_signal_handler(signr, &info, &ka, regs, | 187 | tracehook_signal_handler(signr, &info, &ka, regs, |
186 | test_thread_flag(TIF_SINGLESTEP)); | 188 | test_thread_flag(TIF_SINGLESTEP)); |
187 | } | 189 | } |
188 | 190 | ||
189 | return ret; | 191 | return ret; |
190 | } | 192 | } |
191 | 193 | ||
192 | void do_signal(struct pt_regs *regs, unsigned long thread_info_flags) | 194 | void do_signal(struct pt_regs *regs, unsigned long thread_info_flags) |
193 | { | 195 | { |
194 | if (thread_info_flags & _TIF_SIGPENDING) | 196 | if (thread_info_flags & _TIF_SIGPENDING) |
195 | do_signal_pending(NULL, regs); | 197 | do_signal_pending(NULL, regs); |
196 | 198 | ||
197 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { | 199 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { |
198 | clear_thread_flag(TIF_NOTIFY_RESUME); | 200 | clear_thread_flag(TIF_NOTIFY_RESUME); |
199 | tracehook_notify_resume(regs); | 201 | tracehook_notify_resume(regs); |
200 | } | 202 | } |
201 | } | 203 | } |
202 | 204 | ||
203 | long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, | 205 | long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, |
204 | unsigned long r5, unsigned long r6, unsigned long r7, | 206 | unsigned long r5, unsigned long r6, unsigned long r7, |
205 | unsigned long r8, struct pt_regs *regs) | 207 | unsigned long r8, struct pt_regs *regs) |
206 | { | 208 | { |
207 | return do_sigaltstack(uss, uoss, regs->gpr[1]); | 209 | return do_sigaltstack(uss, uoss, regs->gpr[1]); |
208 | } | 210 | } |
209 | 211 |
arch/powerpc/kernel/signal_32.c
1 | /* | 1 | /* |
2 | * Signal handling for 32bit PPC and 32bit tasks on 64bit PPC | 2 | * Signal handling for 32bit PPC and 32bit tasks on 64bit PPC |
3 | * | 3 | * |
4 | * PowerPC version | 4 | * PowerPC version |
5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | 5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
6 | * Copyright (C) 2001 IBM | 6 | * Copyright (C) 2001 IBM |
7 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | 7 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
8 | * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) | 8 | * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) |
9 | * | 9 | * |
10 | * Derived from "arch/i386/kernel/signal.c" | 10 | * Derived from "arch/i386/kernel/signal.c" |
11 | * Copyright (C) 1991, 1992 Linus Torvalds | 11 | * Copyright (C) 1991, 1992 Linus Torvalds |
12 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson | 12 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
13 | * | 13 | * |
14 | * This program is free software; you can redistribute it and/or | 14 | * This program is free software; you can redistribute it and/or |
15 | * modify it under the terms of the GNU General Public License | 15 | * modify it under the terms of the GNU General Public License |
16 | * as published by the Free Software Foundation; either version | 16 | * as published by the Free Software Foundation; either version |
17 | * 2 of the License, or (at your option) any later version. | 17 | * 2 of the License, or (at your option) any later version. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
21 | #include <linux/mm.h> | 21 | #include <linux/mm.h> |
22 | #include <linux/smp.h> | 22 | #include <linux/smp.h> |
23 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
24 | #include <linux/signal.h> | 24 | #include <linux/signal.h> |
25 | #include <linux/errno.h> | 25 | #include <linux/errno.h> |
26 | #include <linux/elf.h> | 26 | #include <linux/elf.h> |
27 | #include <linux/ptrace.h> | 27 | #include <linux/ptrace.h> |
28 | #ifdef CONFIG_PPC64 | 28 | #ifdef CONFIG_PPC64 |
29 | #include <linux/syscalls.h> | 29 | #include <linux/syscalls.h> |
30 | #include <linux/compat.h> | 30 | #include <linux/compat.h> |
31 | #else | 31 | #else |
32 | #include <linux/wait.h> | 32 | #include <linux/wait.h> |
33 | #include <linux/unistd.h> | 33 | #include <linux/unistd.h> |
34 | #include <linux/stddef.h> | 34 | #include <linux/stddef.h> |
35 | #include <linux/tty.h> | 35 | #include <linux/tty.h> |
36 | #include <linux/binfmts.h> | 36 | #include <linux/binfmts.h> |
37 | #include <linux/freezer.h> | 37 | #include <linux/freezer.h> |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #include <asm/uaccess.h> | 40 | #include <asm/uaccess.h> |
41 | #include <asm/cacheflush.h> | 41 | #include <asm/cacheflush.h> |
42 | #include <asm/syscalls.h> | 42 | #include <asm/syscalls.h> |
43 | #include <asm/sigcontext.h> | 43 | #include <asm/sigcontext.h> |
44 | #include <asm/vdso.h> | 44 | #include <asm/vdso.h> |
45 | #ifdef CONFIG_PPC64 | 45 | #ifdef CONFIG_PPC64 |
46 | #include "ppc32.h" | 46 | #include "ppc32.h" |
47 | #include <asm/unistd.h> | 47 | #include <asm/unistd.h> |
48 | #else | 48 | #else |
49 | #include <asm/ucontext.h> | 49 | #include <asm/ucontext.h> |
50 | #include <asm/pgtable.h> | 50 | #include <asm/pgtable.h> |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | #include "signal.h" | 53 | #include "signal.h" |
54 | 54 | ||
55 | #undef DEBUG_SIG | 55 | #undef DEBUG_SIG |
56 | 56 | ||
57 | #ifdef CONFIG_PPC64 | 57 | #ifdef CONFIG_PPC64 |
58 | #define sys_sigsuspend compat_sys_sigsuspend | 58 | #define sys_sigsuspend compat_sys_sigsuspend |
59 | #define sys_rt_sigsuspend compat_sys_rt_sigsuspend | 59 | #define sys_rt_sigsuspend compat_sys_rt_sigsuspend |
60 | #define sys_rt_sigreturn compat_sys_rt_sigreturn | 60 | #define sys_rt_sigreturn compat_sys_rt_sigreturn |
61 | #define sys_sigaction compat_sys_sigaction | 61 | #define sys_sigaction compat_sys_sigaction |
62 | #define sys_swapcontext compat_sys_swapcontext | 62 | #define sys_swapcontext compat_sys_swapcontext |
63 | #define sys_sigreturn compat_sys_sigreturn | 63 | #define sys_sigreturn compat_sys_sigreturn |
64 | 64 | ||
65 | #define old_sigaction old_sigaction32 | 65 | #define old_sigaction old_sigaction32 |
66 | #define sigcontext sigcontext32 | 66 | #define sigcontext sigcontext32 |
67 | #define mcontext mcontext32 | 67 | #define mcontext mcontext32 |
68 | #define ucontext ucontext32 | 68 | #define ucontext ucontext32 |
69 | 69 | ||
70 | /* | 70 | /* |
71 | * Userspace code may pass a ucontext which doesn't include VSX added | 71 | * Userspace code may pass a ucontext which doesn't include VSX added |
72 | * at the end. We need to check for this case. | 72 | * at the end. We need to check for this case. |
73 | */ | 73 | */ |
74 | #define UCONTEXTSIZEWITHOUTVSX \ | 74 | #define UCONTEXTSIZEWITHOUTVSX \ |
75 | (sizeof(struct ucontext) - sizeof(elf_vsrreghalf_t32)) | 75 | (sizeof(struct ucontext) - sizeof(elf_vsrreghalf_t32)) |
76 | 76 | ||
77 | /* | 77 | /* |
78 | * Returning 0 means we return to userspace via | 78 | * Returning 0 means we return to userspace via |
79 | * ret_from_except and thus restore all user | 79 | * ret_from_except and thus restore all user |
80 | * registers from *regs. This is what we need | 80 | * registers from *regs. This is what we need |
81 | * to do when a signal has been delivered. | 81 | * to do when a signal has been delivered. |
82 | */ | 82 | */ |
83 | 83 | ||
84 | #define GP_REGS_SIZE min(sizeof(elf_gregset_t32), sizeof(struct pt_regs32)) | 84 | #define GP_REGS_SIZE min(sizeof(elf_gregset_t32), sizeof(struct pt_regs32)) |
85 | #undef __SIGNAL_FRAMESIZE | 85 | #undef __SIGNAL_FRAMESIZE |
86 | #define __SIGNAL_FRAMESIZE __SIGNAL_FRAMESIZE32 | 86 | #define __SIGNAL_FRAMESIZE __SIGNAL_FRAMESIZE32 |
87 | #undef ELF_NVRREG | 87 | #undef ELF_NVRREG |
88 | #define ELF_NVRREG ELF_NVRREG32 | 88 | #define ELF_NVRREG ELF_NVRREG32 |
89 | 89 | ||
90 | /* | 90 | /* |
91 | * Functions for flipping sigsets (thanks to brain dead generic | 91 | * Functions for flipping sigsets (thanks to brain dead generic |
92 | * implementation that makes things simple for little endian only) | 92 | * implementation that makes things simple for little endian only) |
93 | */ | 93 | */ |
94 | static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set) | 94 | static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set) |
95 | { | 95 | { |
96 | compat_sigset_t cset; | 96 | compat_sigset_t cset; |
97 | 97 | ||
98 | switch (_NSIG_WORDS) { | 98 | switch (_NSIG_WORDS) { |
99 | case 4: cset.sig[5] = set->sig[3] & 0xffffffffull; | 99 | case 4: cset.sig[5] = set->sig[3] & 0xffffffffull; |
100 | cset.sig[7] = set->sig[3] >> 32; | 100 | cset.sig[7] = set->sig[3] >> 32; |
101 | case 3: cset.sig[4] = set->sig[2] & 0xffffffffull; | 101 | case 3: cset.sig[4] = set->sig[2] & 0xffffffffull; |
102 | cset.sig[5] = set->sig[2] >> 32; | 102 | cset.sig[5] = set->sig[2] >> 32; |
103 | case 2: cset.sig[2] = set->sig[1] & 0xffffffffull; | 103 | case 2: cset.sig[2] = set->sig[1] & 0xffffffffull; |
104 | cset.sig[3] = set->sig[1] >> 32; | 104 | cset.sig[3] = set->sig[1] >> 32; |
105 | case 1: cset.sig[0] = set->sig[0] & 0xffffffffull; | 105 | case 1: cset.sig[0] = set->sig[0] & 0xffffffffull; |
106 | cset.sig[1] = set->sig[0] >> 32; | 106 | cset.sig[1] = set->sig[0] >> 32; |
107 | } | 107 | } |
108 | return copy_to_user(uset, &cset, sizeof(*uset)); | 108 | return copy_to_user(uset, &cset, sizeof(*uset)); |
109 | } | 109 | } |
110 | 110 | ||
111 | static inline int get_sigset_t(sigset_t *set, | 111 | static inline int get_sigset_t(sigset_t *set, |
112 | const compat_sigset_t __user *uset) | 112 | const compat_sigset_t __user *uset) |
113 | { | 113 | { |
114 | compat_sigset_t s32; | 114 | compat_sigset_t s32; |
115 | 115 | ||
116 | if (copy_from_user(&s32, uset, sizeof(*uset))) | 116 | if (copy_from_user(&s32, uset, sizeof(*uset))) |
117 | return -EFAULT; | 117 | return -EFAULT; |
118 | 118 | ||
119 | /* | 119 | /* |
120 | * Swap the 2 words of the 64-bit sigset_t (they are stored | 120 | * Swap the 2 words of the 64-bit sigset_t (they are stored |
121 | * in the "wrong" endian in 32-bit user storage). | 121 | * in the "wrong" endian in 32-bit user storage). |
122 | */ | 122 | */ |
123 | switch (_NSIG_WORDS) { | 123 | switch (_NSIG_WORDS) { |
124 | case 4: set->sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32); | 124 | case 4: set->sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32); |
125 | case 3: set->sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32); | 125 | case 3: set->sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32); |
126 | case 2: set->sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32); | 126 | case 2: set->sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32); |
127 | case 1: set->sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32); | 127 | case 1: set->sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32); |
128 | } | 128 | } |
129 | return 0; | 129 | return 0; |
130 | } | 130 | } |
131 | 131 | ||
132 | static inline int get_old_sigaction(struct k_sigaction *new_ka, | 132 | static inline int get_old_sigaction(struct k_sigaction *new_ka, |
133 | struct old_sigaction __user *act) | 133 | struct old_sigaction __user *act) |
134 | { | 134 | { |
135 | compat_old_sigset_t mask; | 135 | compat_old_sigset_t mask; |
136 | compat_uptr_t handler, restorer; | 136 | compat_uptr_t handler, restorer; |
137 | 137 | ||
138 | if (get_user(handler, &act->sa_handler) || | 138 | if (get_user(handler, &act->sa_handler) || |
139 | __get_user(restorer, &act->sa_restorer) || | 139 | __get_user(restorer, &act->sa_restorer) || |
140 | __get_user(new_ka->sa.sa_flags, &act->sa_flags) || | 140 | __get_user(new_ka->sa.sa_flags, &act->sa_flags) || |
141 | __get_user(mask, &act->sa_mask)) | 141 | __get_user(mask, &act->sa_mask)) |
142 | return -EFAULT; | 142 | return -EFAULT; |
143 | new_ka->sa.sa_handler = compat_ptr(handler); | 143 | new_ka->sa.sa_handler = compat_ptr(handler); |
144 | new_ka->sa.sa_restorer = compat_ptr(restorer); | 144 | new_ka->sa.sa_restorer = compat_ptr(restorer); |
145 | siginitset(&new_ka->sa.sa_mask, mask); | 145 | siginitset(&new_ka->sa.sa_mask, mask); |
146 | return 0; | 146 | return 0; |
147 | } | 147 | } |
148 | 148 | ||
149 | #define to_user_ptr(p) ptr_to_compat(p) | 149 | #define to_user_ptr(p) ptr_to_compat(p) |
150 | #define from_user_ptr(p) compat_ptr(p) | 150 | #define from_user_ptr(p) compat_ptr(p) |
151 | 151 | ||
152 | static inline int save_general_regs(struct pt_regs *regs, | 152 | static inline int save_general_regs(struct pt_regs *regs, |
153 | struct mcontext __user *frame) | 153 | struct mcontext __user *frame) |
154 | { | 154 | { |
155 | elf_greg_t64 *gregs = (elf_greg_t64 *)regs; | 155 | elf_greg_t64 *gregs = (elf_greg_t64 *)regs; |
156 | int i; | 156 | int i; |
157 | 157 | ||
158 | WARN_ON(!FULL_REGS(regs)); | 158 | WARN_ON(!FULL_REGS(regs)); |
159 | 159 | ||
160 | for (i = 0; i <= PT_RESULT; i ++) { | 160 | for (i = 0; i <= PT_RESULT; i ++) { |
161 | if (i == 14 && !FULL_REGS(regs)) | 161 | if (i == 14 && !FULL_REGS(regs)) |
162 | i = 32; | 162 | i = 32; |
163 | if (__put_user((unsigned int)gregs[i], &frame->mc_gregs[i])) | 163 | if (__put_user((unsigned int)gregs[i], &frame->mc_gregs[i])) |
164 | return -EFAULT; | 164 | return -EFAULT; |
165 | } | 165 | } |
166 | return 0; | 166 | return 0; |
167 | } | 167 | } |
168 | 168 | ||
169 | static inline int restore_general_regs(struct pt_regs *regs, | 169 | static inline int restore_general_regs(struct pt_regs *regs, |
170 | struct mcontext __user *sr) | 170 | struct mcontext __user *sr) |
171 | { | 171 | { |
172 | elf_greg_t64 *gregs = (elf_greg_t64 *)regs; | 172 | elf_greg_t64 *gregs = (elf_greg_t64 *)regs; |
173 | int i; | 173 | int i; |
174 | 174 | ||
175 | for (i = 0; i <= PT_RESULT; i++) { | 175 | for (i = 0; i <= PT_RESULT; i++) { |
176 | if ((i == PT_MSR) || (i == PT_SOFTE)) | 176 | if ((i == PT_MSR) || (i == PT_SOFTE)) |
177 | continue; | 177 | continue; |
178 | if (__get_user(gregs[i], &sr->mc_gregs[i])) | 178 | if (__get_user(gregs[i], &sr->mc_gregs[i])) |
179 | return -EFAULT; | 179 | return -EFAULT; |
180 | } | 180 | } |
181 | return 0; | 181 | return 0; |
182 | } | 182 | } |
183 | 183 | ||
184 | #else /* CONFIG_PPC64 */ | 184 | #else /* CONFIG_PPC64 */ |
185 | 185 | ||
186 | #define GP_REGS_SIZE min(sizeof(elf_gregset_t), sizeof(struct pt_regs)) | 186 | #define GP_REGS_SIZE min(sizeof(elf_gregset_t), sizeof(struct pt_regs)) |
187 | 187 | ||
188 | static inline int put_sigset_t(sigset_t __user *uset, sigset_t *set) | 188 | static inline int put_sigset_t(sigset_t __user *uset, sigset_t *set) |
189 | { | 189 | { |
190 | return copy_to_user(uset, set, sizeof(*uset)); | 190 | return copy_to_user(uset, set, sizeof(*uset)); |
191 | } | 191 | } |
192 | 192 | ||
193 | static inline int get_sigset_t(sigset_t *set, const sigset_t __user *uset) | 193 | static inline int get_sigset_t(sigset_t *set, const sigset_t __user *uset) |
194 | { | 194 | { |
195 | return copy_from_user(set, uset, sizeof(*uset)); | 195 | return copy_from_user(set, uset, sizeof(*uset)); |
196 | } | 196 | } |
197 | 197 | ||
198 | static inline int get_old_sigaction(struct k_sigaction *new_ka, | 198 | static inline int get_old_sigaction(struct k_sigaction *new_ka, |
199 | struct old_sigaction __user *act) | 199 | struct old_sigaction __user *act) |
200 | { | 200 | { |
201 | old_sigset_t mask; | 201 | old_sigset_t mask; |
202 | 202 | ||
203 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || | 203 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
204 | __get_user(new_ka->sa.sa_handler, &act->sa_handler) || | 204 | __get_user(new_ka->sa.sa_handler, &act->sa_handler) || |
205 | __get_user(new_ka->sa.sa_restorer, &act->sa_restorer)) | 205 | __get_user(new_ka->sa.sa_restorer, &act->sa_restorer)) |
206 | return -EFAULT; | 206 | return -EFAULT; |
207 | __get_user(new_ka->sa.sa_flags, &act->sa_flags); | 207 | __get_user(new_ka->sa.sa_flags, &act->sa_flags); |
208 | __get_user(mask, &act->sa_mask); | 208 | __get_user(mask, &act->sa_mask); |
209 | siginitset(&new_ka->sa.sa_mask, mask); | 209 | siginitset(&new_ka->sa.sa_mask, mask); |
210 | return 0; | 210 | return 0; |
211 | } | 211 | } |
212 | 212 | ||
213 | #define to_user_ptr(p) ((unsigned long)(p)) | 213 | #define to_user_ptr(p) ((unsigned long)(p)) |
214 | #define from_user_ptr(p) ((void __user *)(p)) | 214 | #define from_user_ptr(p) ((void __user *)(p)) |
215 | 215 | ||
216 | static inline int save_general_regs(struct pt_regs *regs, | 216 | static inline int save_general_regs(struct pt_regs *regs, |
217 | struct mcontext __user *frame) | 217 | struct mcontext __user *frame) |
218 | { | 218 | { |
219 | WARN_ON(!FULL_REGS(regs)); | 219 | WARN_ON(!FULL_REGS(regs)); |
220 | return __copy_to_user(&frame->mc_gregs, regs, GP_REGS_SIZE); | 220 | return __copy_to_user(&frame->mc_gregs, regs, GP_REGS_SIZE); |
221 | } | 221 | } |
222 | 222 | ||
223 | static inline int restore_general_regs(struct pt_regs *regs, | 223 | static inline int restore_general_regs(struct pt_regs *regs, |
224 | struct mcontext __user *sr) | 224 | struct mcontext __user *sr) |
225 | { | 225 | { |
226 | /* copy up to but not including MSR */ | 226 | /* copy up to but not including MSR */ |
227 | if (__copy_from_user(regs, &sr->mc_gregs, | 227 | if (__copy_from_user(regs, &sr->mc_gregs, |
228 | PT_MSR * sizeof(elf_greg_t))) | 228 | PT_MSR * sizeof(elf_greg_t))) |
229 | return -EFAULT; | 229 | return -EFAULT; |
230 | /* copy from orig_r3 (the word after the MSR) up to the end */ | 230 | /* copy from orig_r3 (the word after the MSR) up to the end */ |
231 | if (__copy_from_user(®s->orig_gpr3, &sr->mc_gregs[PT_ORIG_R3], | 231 | if (__copy_from_user(®s->orig_gpr3, &sr->mc_gregs[PT_ORIG_R3], |
232 | GP_REGS_SIZE - PT_ORIG_R3 * sizeof(elf_greg_t))) | 232 | GP_REGS_SIZE - PT_ORIG_R3 * sizeof(elf_greg_t))) |
233 | return -EFAULT; | 233 | return -EFAULT; |
234 | return 0; | 234 | return 0; |
235 | } | 235 | } |
236 | 236 | ||
237 | #endif /* CONFIG_PPC64 */ | 237 | #endif /* CONFIG_PPC64 */ |
238 | 238 | ||
239 | /* | 239 | /* |
240 | * Atomically swap in the new signal mask, and wait for a signal. | 240 | * Atomically swap in the new signal mask, and wait for a signal. |
241 | */ | 241 | */ |
242 | long sys_sigsuspend(old_sigset_t mask) | 242 | long sys_sigsuspend(old_sigset_t mask) |
243 | { | 243 | { |
244 | mask &= _BLOCKABLE; | 244 | mask &= _BLOCKABLE; |
245 | spin_lock_irq(¤t->sighand->siglock); | 245 | spin_lock_irq(¤t->sighand->siglock); |
246 | current->saved_sigmask = current->blocked; | 246 | current->saved_sigmask = current->blocked; |
247 | siginitset(¤t->blocked, mask); | 247 | siginitset(¤t->blocked, mask); |
248 | recalc_sigpending(); | 248 | recalc_sigpending(); |
249 | spin_unlock_irq(¤t->sighand->siglock); | 249 | spin_unlock_irq(¤t->sighand->siglock); |
250 | 250 | ||
251 | current->state = TASK_INTERRUPTIBLE; | 251 | current->state = TASK_INTERRUPTIBLE; |
252 | schedule(); | 252 | schedule(); |
253 | set_restore_sigmask(); | 253 | set_restore_sigmask(); |
254 | return -ERESTARTNOHAND; | 254 | return -ERESTARTNOHAND; |
255 | } | 255 | } |
256 | 256 | ||
257 | long sys_sigaction(int sig, struct old_sigaction __user *act, | 257 | long sys_sigaction(int sig, struct old_sigaction __user *act, |
258 | struct old_sigaction __user *oact) | 258 | struct old_sigaction __user *oact) |
259 | { | 259 | { |
260 | struct k_sigaction new_ka, old_ka; | 260 | struct k_sigaction new_ka, old_ka; |
261 | int ret; | 261 | int ret; |
262 | 262 | ||
263 | #ifdef CONFIG_PPC64 | 263 | #ifdef CONFIG_PPC64 |
264 | if (sig < 0) | 264 | if (sig < 0) |
265 | sig = -sig; | 265 | sig = -sig; |
266 | #endif | 266 | #endif |
267 | 267 | ||
268 | if (act) { | 268 | if (act) { |
269 | if (get_old_sigaction(&new_ka, act)) | 269 | if (get_old_sigaction(&new_ka, act)) |
270 | return -EFAULT; | 270 | return -EFAULT; |
271 | } | 271 | } |
272 | 272 | ||
273 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | 273 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
274 | if (!ret && oact) { | 274 | if (!ret && oact) { |
275 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || | 275 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
276 | __put_user(to_user_ptr(old_ka.sa.sa_handler), | 276 | __put_user(to_user_ptr(old_ka.sa.sa_handler), |
277 | &oact->sa_handler) || | 277 | &oact->sa_handler) || |
278 | __put_user(to_user_ptr(old_ka.sa.sa_restorer), | 278 | __put_user(to_user_ptr(old_ka.sa.sa_restorer), |
279 | &oact->sa_restorer) || | 279 | &oact->sa_restorer) || |
280 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || | 280 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || |
281 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask)) | 281 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask)) |
282 | return -EFAULT; | 282 | return -EFAULT; |
283 | } | 283 | } |
284 | 284 | ||
285 | return ret; | 285 | return ret; |
286 | } | 286 | } |
287 | 287 | ||
288 | /* | 288 | /* |
289 | * When we have signals to deliver, we set up on the | 289 | * When we have signals to deliver, we set up on the |
290 | * user stack, going down from the original stack pointer: | 290 | * user stack, going down from the original stack pointer: |
291 | * an ABI gap of 56 words | 291 | * an ABI gap of 56 words |
292 | * an mcontext struct | 292 | * an mcontext struct |
293 | * a sigcontext struct | 293 | * a sigcontext struct |
294 | * a gap of __SIGNAL_FRAMESIZE bytes | 294 | * a gap of __SIGNAL_FRAMESIZE bytes |
295 | * | 295 | * |
296 | * Each of these things must be a multiple of 16 bytes in size. The following | 296 | * Each of these things must be a multiple of 16 bytes in size. The following |
297 | * structure represent all of this except the __SIGNAL_FRAMESIZE gap | 297 | * structure represent all of this except the __SIGNAL_FRAMESIZE gap |
298 | * | 298 | * |
299 | */ | 299 | */ |
300 | struct sigframe { | 300 | struct sigframe { |
301 | struct sigcontext sctx; /* the sigcontext */ | 301 | struct sigcontext sctx; /* the sigcontext */ |
302 | struct mcontext mctx; /* all the register values */ | 302 | struct mcontext mctx; /* all the register values */ |
303 | /* | 303 | /* |
304 | * Programs using the rs6000/xcoff abi can save up to 19 gp | 304 | * Programs using the rs6000/xcoff abi can save up to 19 gp |
305 | * regs and 18 fp regs below sp before decrementing it. | 305 | * regs and 18 fp regs below sp before decrementing it. |
306 | */ | 306 | */ |
307 | int abigap[56]; | 307 | int abigap[56]; |
308 | }; | 308 | }; |
309 | 309 | ||
310 | /* We use the mc_pad field for the signal return trampoline. */ | 310 | /* We use the mc_pad field for the signal return trampoline. */ |
311 | #define tramp mc_pad | 311 | #define tramp mc_pad |
312 | 312 | ||
313 | /* | 313 | /* |
314 | * When we have rt signals to deliver, we set up on the | 314 | * When we have rt signals to deliver, we set up on the |
315 | * user stack, going down from the original stack pointer: | 315 | * user stack, going down from the original stack pointer: |
316 | * one rt_sigframe struct (siginfo + ucontext + ABI gap) | 316 | * one rt_sigframe struct (siginfo + ucontext + ABI gap) |
317 | * a gap of __SIGNAL_FRAMESIZE+16 bytes | 317 | * a gap of __SIGNAL_FRAMESIZE+16 bytes |
318 | * (the +16 is to get the siginfo and ucontext in the same | 318 | * (the +16 is to get the siginfo and ucontext in the same |
319 | * positions as in older kernels). | 319 | * positions as in older kernels). |
320 | * | 320 | * |
321 | * Each of these things must be a multiple of 16 bytes in size. | 321 | * Each of these things must be a multiple of 16 bytes in size. |
322 | * | 322 | * |
323 | */ | 323 | */ |
324 | struct rt_sigframe { | 324 | struct rt_sigframe { |
325 | #ifdef CONFIG_PPC64 | 325 | #ifdef CONFIG_PPC64 |
326 | compat_siginfo_t info; | 326 | compat_siginfo_t info; |
327 | #else | 327 | #else |
328 | struct siginfo info; | 328 | struct siginfo info; |
329 | #endif | 329 | #endif |
330 | struct ucontext uc; | 330 | struct ucontext uc; |
331 | /* | 331 | /* |
332 | * Programs using the rs6000/xcoff abi can save up to 19 gp | 332 | * Programs using the rs6000/xcoff abi can save up to 19 gp |
333 | * regs and 18 fp regs below sp before decrementing it. | 333 | * regs and 18 fp regs below sp before decrementing it. |
334 | */ | 334 | */ |
335 | int abigap[56]; | 335 | int abigap[56]; |
336 | }; | 336 | }; |
337 | 337 | ||
338 | #ifdef CONFIG_VSX | 338 | #ifdef CONFIG_VSX |
339 | unsigned long copy_fpr_to_user(void __user *to, | 339 | unsigned long copy_fpr_to_user(void __user *to, |
340 | struct task_struct *task) | 340 | struct task_struct *task) |
341 | { | 341 | { |
342 | double buf[ELF_NFPREG]; | 342 | double buf[ELF_NFPREG]; |
343 | int i; | 343 | int i; |
344 | 344 | ||
345 | /* save FPR copy to local buffer then write to the thread_struct */ | 345 | /* save FPR copy to local buffer then write to the thread_struct */ |
346 | for (i = 0; i < (ELF_NFPREG - 1) ; i++) | 346 | for (i = 0; i < (ELF_NFPREG - 1) ; i++) |
347 | buf[i] = task->thread.TS_FPR(i); | 347 | buf[i] = task->thread.TS_FPR(i); |
348 | memcpy(&buf[i], &task->thread.fpscr, sizeof(double)); | 348 | memcpy(&buf[i], &task->thread.fpscr, sizeof(double)); |
349 | return __copy_to_user(to, buf, ELF_NFPREG * sizeof(double)); | 349 | return __copy_to_user(to, buf, ELF_NFPREG * sizeof(double)); |
350 | } | 350 | } |
351 | 351 | ||
352 | unsigned long copy_fpr_from_user(struct task_struct *task, | 352 | unsigned long copy_fpr_from_user(struct task_struct *task, |
353 | void __user *from) | 353 | void __user *from) |
354 | { | 354 | { |
355 | double buf[ELF_NFPREG]; | 355 | double buf[ELF_NFPREG]; |
356 | int i; | 356 | int i; |
357 | 357 | ||
358 | if (__copy_from_user(buf, from, ELF_NFPREG * sizeof(double))) | 358 | if (__copy_from_user(buf, from, ELF_NFPREG * sizeof(double))) |
359 | return 1; | 359 | return 1; |
360 | for (i = 0; i < (ELF_NFPREG - 1) ; i++) | 360 | for (i = 0; i < (ELF_NFPREG - 1) ; i++) |
361 | task->thread.TS_FPR(i) = buf[i]; | 361 | task->thread.TS_FPR(i) = buf[i]; |
362 | memcpy(&task->thread.fpscr, &buf[i], sizeof(double)); | 362 | memcpy(&task->thread.fpscr, &buf[i], sizeof(double)); |
363 | 363 | ||
364 | return 0; | 364 | return 0; |
365 | } | 365 | } |
366 | 366 | ||
367 | unsigned long copy_vsx_to_user(void __user *to, | 367 | unsigned long copy_vsx_to_user(void __user *to, |
368 | struct task_struct *task) | 368 | struct task_struct *task) |
369 | { | 369 | { |
370 | double buf[ELF_NVSRHALFREG]; | 370 | double buf[ELF_NVSRHALFREG]; |
371 | int i; | 371 | int i; |
372 | 372 | ||
373 | /* save FPR copy to local buffer then write to the thread_struct */ | 373 | /* save FPR copy to local buffer then write to the thread_struct */ |
374 | for (i = 0; i < ELF_NVSRHALFREG; i++) | 374 | for (i = 0; i < ELF_NVSRHALFREG; i++) |
375 | buf[i] = task->thread.fpr[i][TS_VSRLOWOFFSET]; | 375 | buf[i] = task->thread.fpr[i][TS_VSRLOWOFFSET]; |
376 | return __copy_to_user(to, buf, ELF_NVSRHALFREG * sizeof(double)); | 376 | return __copy_to_user(to, buf, ELF_NVSRHALFREG * sizeof(double)); |
377 | } | 377 | } |
378 | 378 | ||
379 | unsigned long copy_vsx_from_user(struct task_struct *task, | 379 | unsigned long copy_vsx_from_user(struct task_struct *task, |
380 | void __user *from) | 380 | void __user *from) |
381 | { | 381 | { |
382 | double buf[ELF_NVSRHALFREG]; | 382 | double buf[ELF_NVSRHALFREG]; |
383 | int i; | 383 | int i; |
384 | 384 | ||
385 | if (__copy_from_user(buf, from, ELF_NVSRHALFREG * sizeof(double))) | 385 | if (__copy_from_user(buf, from, ELF_NVSRHALFREG * sizeof(double))) |
386 | return 1; | 386 | return 1; |
387 | for (i = 0; i < ELF_NVSRHALFREG ; i++) | 387 | for (i = 0; i < ELF_NVSRHALFREG ; i++) |
388 | task->thread.fpr[i][TS_VSRLOWOFFSET] = buf[i]; | 388 | task->thread.fpr[i][TS_VSRLOWOFFSET] = buf[i]; |
389 | return 0; | 389 | return 0; |
390 | } | 390 | } |
391 | #else | 391 | #else |
392 | inline unsigned long copy_fpr_to_user(void __user *to, | 392 | inline unsigned long copy_fpr_to_user(void __user *to, |
393 | struct task_struct *task) | 393 | struct task_struct *task) |
394 | { | 394 | { |
395 | return __copy_to_user(to, task->thread.fpr, | 395 | return __copy_to_user(to, task->thread.fpr, |
396 | ELF_NFPREG * sizeof(double)); | 396 | ELF_NFPREG * sizeof(double)); |
397 | } | 397 | } |
398 | 398 | ||
399 | inline unsigned long copy_fpr_from_user(struct task_struct *task, | 399 | inline unsigned long copy_fpr_from_user(struct task_struct *task, |
400 | void __user *from) | 400 | void __user *from) |
401 | { | 401 | { |
402 | return __copy_from_user(task->thread.fpr, from, | 402 | return __copy_from_user(task->thread.fpr, from, |
403 | ELF_NFPREG * sizeof(double)); | 403 | ELF_NFPREG * sizeof(double)); |
404 | } | 404 | } |
405 | #endif | 405 | #endif |
406 | 406 | ||
407 | /* | 407 | /* |
408 | * Save the current user registers on the user stack. | 408 | * Save the current user registers on the user stack. |
409 | * We only save the altivec/spe registers if the process has used | 409 | * We only save the altivec/spe registers if the process has used |
410 | * altivec/spe instructions at some point. | 410 | * altivec/spe instructions at some point. |
411 | */ | 411 | */ |
412 | static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame, | 412 | static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame, |
413 | int sigret, int ctx_has_vsx_region) | 413 | int sigret, int ctx_has_vsx_region) |
414 | { | 414 | { |
415 | unsigned long msr = regs->msr; | 415 | unsigned long msr = regs->msr; |
416 | 416 | ||
417 | /* Make sure floating point registers are stored in regs */ | 417 | /* Make sure floating point registers are stored in regs */ |
418 | flush_fp_to_thread(current); | 418 | flush_fp_to_thread(current); |
419 | 419 | ||
420 | /* save general registers */ | 420 | /* save general registers */ |
421 | if (save_general_regs(regs, frame)) | 421 | if (save_general_regs(regs, frame)) |
422 | return 1; | 422 | return 1; |
423 | 423 | ||
424 | #ifdef CONFIG_ALTIVEC | 424 | #ifdef CONFIG_ALTIVEC |
425 | /* save altivec registers */ | 425 | /* save altivec registers */ |
426 | if (current->thread.used_vr) { | 426 | if (current->thread.used_vr) { |
427 | flush_altivec_to_thread(current); | 427 | flush_altivec_to_thread(current); |
428 | if (__copy_to_user(&frame->mc_vregs, current->thread.vr, | 428 | if (__copy_to_user(&frame->mc_vregs, current->thread.vr, |
429 | ELF_NVRREG * sizeof(vector128))) | 429 | ELF_NVRREG * sizeof(vector128))) |
430 | return 1; | 430 | return 1; |
431 | /* set MSR_VEC in the saved MSR value to indicate that | 431 | /* set MSR_VEC in the saved MSR value to indicate that |
432 | frame->mc_vregs contains valid data */ | 432 | frame->mc_vregs contains valid data */ |
433 | msr |= MSR_VEC; | 433 | msr |= MSR_VEC; |
434 | } | 434 | } |
435 | /* else assert((regs->msr & MSR_VEC) == 0) */ | 435 | /* else assert((regs->msr & MSR_VEC) == 0) */ |
436 | 436 | ||
437 | /* We always copy to/from vrsave, it's 0 if we don't have or don't | 437 | /* We always copy to/from vrsave, it's 0 if we don't have or don't |
438 | * use altivec. Since VSCR only contains 32 bits saved in the least | 438 | * use altivec. Since VSCR only contains 32 bits saved in the least |
439 | * significant bits of a vector, we "cheat" and stuff VRSAVE in the | 439 | * significant bits of a vector, we "cheat" and stuff VRSAVE in the |
440 | * most significant bits of that same vector. --BenH | 440 | * most significant bits of that same vector. --BenH |
441 | */ | 441 | */ |
442 | if (__put_user(current->thread.vrsave, (u32 __user *)&frame->mc_vregs[32])) | 442 | if (__put_user(current->thread.vrsave, (u32 __user *)&frame->mc_vregs[32])) |
443 | return 1; | 443 | return 1; |
444 | #endif /* CONFIG_ALTIVEC */ | 444 | #endif /* CONFIG_ALTIVEC */ |
445 | if (copy_fpr_to_user(&frame->mc_fregs, current)) | 445 | if (copy_fpr_to_user(&frame->mc_fregs, current)) |
446 | return 1; | 446 | return 1; |
447 | #ifdef CONFIG_VSX | 447 | #ifdef CONFIG_VSX |
448 | /* | 448 | /* |
449 | * Copy VSR 0-31 upper half from thread_struct to local | 449 | * Copy VSR 0-31 upper half from thread_struct to local |
450 | * buffer, then write that to userspace. Also set MSR_VSX in | 450 | * buffer, then write that to userspace. Also set MSR_VSX in |
451 | * the saved MSR value to indicate that frame->mc_vregs | 451 | * the saved MSR value to indicate that frame->mc_vregs |
452 | * contains valid data | 452 | * contains valid data |
453 | */ | 453 | */ |
454 | if (current->thread.used_vsr && ctx_has_vsx_region) { | 454 | if (current->thread.used_vsr && ctx_has_vsx_region) { |
455 | __giveup_vsx(current); | 455 | __giveup_vsx(current); |
456 | if (copy_vsx_to_user(&frame->mc_vsregs, current)) | 456 | if (copy_vsx_to_user(&frame->mc_vsregs, current)) |
457 | return 1; | 457 | return 1; |
458 | msr |= MSR_VSX; | 458 | msr |= MSR_VSX; |
459 | } | 459 | } |
460 | #endif /* CONFIG_VSX */ | 460 | #endif /* CONFIG_VSX */ |
461 | #ifdef CONFIG_SPE | 461 | #ifdef CONFIG_SPE |
462 | /* save spe registers */ | 462 | /* save spe registers */ |
463 | if (current->thread.used_spe) { | 463 | if (current->thread.used_spe) { |
464 | flush_spe_to_thread(current); | 464 | flush_spe_to_thread(current); |
465 | if (__copy_to_user(&frame->mc_vregs, current->thread.evr, | 465 | if (__copy_to_user(&frame->mc_vregs, current->thread.evr, |
466 | ELF_NEVRREG * sizeof(u32))) | 466 | ELF_NEVRREG * sizeof(u32))) |
467 | return 1; | 467 | return 1; |
468 | /* set MSR_SPE in the saved MSR value to indicate that | 468 | /* set MSR_SPE in the saved MSR value to indicate that |
469 | frame->mc_vregs contains valid data */ | 469 | frame->mc_vregs contains valid data */ |
470 | msr |= MSR_SPE; | 470 | msr |= MSR_SPE; |
471 | } | 471 | } |
472 | /* else assert((regs->msr & MSR_SPE) == 0) */ | 472 | /* else assert((regs->msr & MSR_SPE) == 0) */ |
473 | 473 | ||
474 | /* We always copy to/from spefscr */ | 474 | /* We always copy to/from spefscr */ |
475 | if (__put_user(current->thread.spefscr, (u32 __user *)&frame->mc_vregs + ELF_NEVRREG)) | 475 | if (__put_user(current->thread.spefscr, (u32 __user *)&frame->mc_vregs + ELF_NEVRREG)) |
476 | return 1; | 476 | return 1; |
477 | #endif /* CONFIG_SPE */ | 477 | #endif /* CONFIG_SPE */ |
478 | 478 | ||
479 | if (__put_user(msr, &frame->mc_gregs[PT_MSR])) | 479 | if (__put_user(msr, &frame->mc_gregs[PT_MSR])) |
480 | return 1; | 480 | return 1; |
481 | if (sigret) { | 481 | if (sigret) { |
482 | /* Set up the sigreturn trampoline: li r0,sigret; sc */ | 482 | /* Set up the sigreturn trampoline: li r0,sigret; sc */ |
483 | if (__put_user(0x38000000UL + sigret, &frame->tramp[0]) | 483 | if (__put_user(0x38000000UL + sigret, &frame->tramp[0]) |
484 | || __put_user(0x44000002UL, &frame->tramp[1])) | 484 | || __put_user(0x44000002UL, &frame->tramp[1])) |
485 | return 1; | 485 | return 1; |
486 | flush_icache_range((unsigned long) &frame->tramp[0], | 486 | flush_icache_range((unsigned long) &frame->tramp[0], |
487 | (unsigned long) &frame->tramp[2]); | 487 | (unsigned long) &frame->tramp[2]); |
488 | } | 488 | } |
489 | 489 | ||
490 | return 0; | 490 | return 0; |
491 | } | 491 | } |
492 | 492 | ||
493 | /* | 493 | /* |
494 | * Restore the current user register values from the user stack, | 494 | * Restore the current user register values from the user stack, |
495 | * (except for MSR). | 495 | * (except for MSR). |
496 | */ | 496 | */ |
497 | static long restore_user_regs(struct pt_regs *regs, | 497 | static long restore_user_regs(struct pt_regs *regs, |
498 | struct mcontext __user *sr, int sig) | 498 | struct mcontext __user *sr, int sig) |
499 | { | 499 | { |
500 | long err; | 500 | long err; |
501 | unsigned int save_r2 = 0; | 501 | unsigned int save_r2 = 0; |
502 | unsigned long msr; | 502 | unsigned long msr; |
503 | #ifdef CONFIG_VSX | 503 | #ifdef CONFIG_VSX |
504 | int i; | 504 | int i; |
505 | #endif | 505 | #endif |
506 | 506 | ||
507 | /* | 507 | /* |
508 | * restore general registers but not including MSR or SOFTE. Also | 508 | * restore general registers but not including MSR or SOFTE. Also |
509 | * take care of keeping r2 (TLS) intact if not a signal | 509 | * take care of keeping r2 (TLS) intact if not a signal |
510 | */ | 510 | */ |
511 | if (!sig) | 511 | if (!sig) |
512 | save_r2 = (unsigned int)regs->gpr[2]; | 512 | save_r2 = (unsigned int)regs->gpr[2]; |
513 | err = restore_general_regs(regs, sr); | 513 | err = restore_general_regs(regs, sr); |
514 | regs->trap = 0; | ||
514 | err |= __get_user(msr, &sr->mc_gregs[PT_MSR]); | 515 | err |= __get_user(msr, &sr->mc_gregs[PT_MSR]); |
515 | if (!sig) | 516 | if (!sig) |
516 | regs->gpr[2] = (unsigned long) save_r2; | 517 | regs->gpr[2] = (unsigned long) save_r2; |
517 | if (err) | 518 | if (err) |
518 | return 1; | 519 | return 1; |
519 | 520 | ||
520 | /* if doing signal return, restore the previous little-endian mode */ | 521 | /* if doing signal return, restore the previous little-endian mode */ |
521 | if (sig) | 522 | if (sig) |
522 | regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE); | 523 | regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE); |
523 | 524 | ||
524 | /* | 525 | /* |
525 | * Do this before updating the thread state in | 526 | * Do this before updating the thread state in |
526 | * current->thread.fpr/vr/evr. That way, if we get preempted | 527 | * current->thread.fpr/vr/evr. That way, if we get preempted |
527 | * and another task grabs the FPU/Altivec/SPE, it won't be | 528 | * and another task grabs the FPU/Altivec/SPE, it won't be |
528 | * tempted to save the current CPU state into the thread_struct | 529 | * tempted to save the current CPU state into the thread_struct |
529 | * and corrupt what we are writing there. | 530 | * and corrupt what we are writing there. |
530 | */ | 531 | */ |
531 | discard_lazy_cpu_state(); | 532 | discard_lazy_cpu_state(); |
532 | 533 | ||
533 | #ifdef CONFIG_ALTIVEC | 534 | #ifdef CONFIG_ALTIVEC |
534 | /* | 535 | /* |
535 | * Force the process to reload the altivec registers from | 536 | * Force the process to reload the altivec registers from |
536 | * current->thread when it next does altivec instructions | 537 | * current->thread when it next does altivec instructions |
537 | */ | 538 | */ |
538 | regs->msr &= ~MSR_VEC; | 539 | regs->msr &= ~MSR_VEC; |
539 | if (msr & MSR_VEC) { | 540 | if (msr & MSR_VEC) { |
540 | /* restore altivec registers from the stack */ | 541 | /* restore altivec registers from the stack */ |
541 | if (__copy_from_user(current->thread.vr, &sr->mc_vregs, | 542 | if (__copy_from_user(current->thread.vr, &sr->mc_vregs, |
542 | sizeof(sr->mc_vregs))) | 543 | sizeof(sr->mc_vregs))) |
543 | return 1; | 544 | return 1; |
544 | } else if (current->thread.used_vr) | 545 | } else if (current->thread.used_vr) |
545 | memset(current->thread.vr, 0, ELF_NVRREG * sizeof(vector128)); | 546 | memset(current->thread.vr, 0, ELF_NVRREG * sizeof(vector128)); |
546 | 547 | ||
547 | /* Always get VRSAVE back */ | 548 | /* Always get VRSAVE back */ |
548 | if (__get_user(current->thread.vrsave, (u32 __user *)&sr->mc_vregs[32])) | 549 | if (__get_user(current->thread.vrsave, (u32 __user *)&sr->mc_vregs[32])) |
549 | return 1; | 550 | return 1; |
550 | #endif /* CONFIG_ALTIVEC */ | 551 | #endif /* CONFIG_ALTIVEC */ |
551 | if (copy_fpr_from_user(current, &sr->mc_fregs)) | 552 | if (copy_fpr_from_user(current, &sr->mc_fregs)) |
552 | return 1; | 553 | return 1; |
553 | 554 | ||
554 | #ifdef CONFIG_VSX | 555 | #ifdef CONFIG_VSX |
555 | /* | 556 | /* |
556 | * Force the process to reload the VSX registers from | 557 | * Force the process to reload the VSX registers from |
557 | * current->thread when it next does VSX instruction. | 558 | * current->thread when it next does VSX instruction. |
558 | */ | 559 | */ |
559 | regs->msr &= ~MSR_VSX; | 560 | regs->msr &= ~MSR_VSX; |
560 | if (msr & MSR_VSX) { | 561 | if (msr & MSR_VSX) { |
561 | /* | 562 | /* |
562 | * Restore altivec registers from the stack to a local | 563 | * Restore altivec registers from the stack to a local |
563 | * buffer, then write this out to the thread_struct | 564 | * buffer, then write this out to the thread_struct |
564 | */ | 565 | */ |
565 | if (copy_vsx_from_user(current, &sr->mc_vsregs)) | 566 | if (copy_vsx_from_user(current, &sr->mc_vsregs)) |
566 | return 1; | 567 | return 1; |
567 | } else if (current->thread.used_vsr) | 568 | } else if (current->thread.used_vsr) |
568 | for (i = 0; i < 32 ; i++) | 569 | for (i = 0; i < 32 ; i++) |
569 | current->thread.fpr[i][TS_VSRLOWOFFSET] = 0; | 570 | current->thread.fpr[i][TS_VSRLOWOFFSET] = 0; |
570 | #endif /* CONFIG_VSX */ | 571 | #endif /* CONFIG_VSX */ |
571 | /* | 572 | /* |
572 | * force the process to reload the FP registers from | 573 | * force the process to reload the FP registers from |
573 | * current->thread when it next does FP instructions | 574 | * current->thread when it next does FP instructions |
574 | */ | 575 | */ |
575 | regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1); | 576 | regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1); |
576 | 577 | ||
577 | #ifdef CONFIG_SPE | 578 | #ifdef CONFIG_SPE |
578 | /* force the process to reload the spe registers from | 579 | /* force the process to reload the spe registers from |
579 | current->thread when it next does spe instructions */ | 580 | current->thread when it next does spe instructions */ |
580 | regs->msr &= ~MSR_SPE; | 581 | regs->msr &= ~MSR_SPE; |
581 | if (msr & MSR_SPE) { | 582 | if (msr & MSR_SPE) { |
582 | /* restore spe registers from the stack */ | 583 | /* restore spe registers from the stack */ |
583 | if (__copy_from_user(current->thread.evr, &sr->mc_vregs, | 584 | if (__copy_from_user(current->thread.evr, &sr->mc_vregs, |
584 | ELF_NEVRREG * sizeof(u32))) | 585 | ELF_NEVRREG * sizeof(u32))) |
585 | return 1; | 586 | return 1; |
586 | } else if (current->thread.used_spe) | 587 | } else if (current->thread.used_spe) |
587 | memset(current->thread.evr, 0, ELF_NEVRREG * sizeof(u32)); | 588 | memset(current->thread.evr, 0, ELF_NEVRREG * sizeof(u32)); |
588 | 589 | ||
589 | /* Always get SPEFSCR back */ | 590 | /* Always get SPEFSCR back */ |
590 | if (__get_user(current->thread.spefscr, (u32 __user *)&sr->mc_vregs + ELF_NEVRREG)) | 591 | if (__get_user(current->thread.spefscr, (u32 __user *)&sr->mc_vregs + ELF_NEVRREG)) |
591 | return 1; | 592 | return 1; |
592 | #endif /* CONFIG_SPE */ | 593 | #endif /* CONFIG_SPE */ |
593 | 594 | ||
594 | return 0; | 595 | return 0; |
595 | } | 596 | } |
596 | 597 | ||
597 | #ifdef CONFIG_PPC64 | 598 | #ifdef CONFIG_PPC64 |
598 | long compat_sys_rt_sigaction(int sig, const struct sigaction32 __user *act, | 599 | long compat_sys_rt_sigaction(int sig, const struct sigaction32 __user *act, |
599 | struct sigaction32 __user *oact, size_t sigsetsize) | 600 | struct sigaction32 __user *oact, size_t sigsetsize) |
600 | { | 601 | { |
601 | struct k_sigaction new_ka, old_ka; | 602 | struct k_sigaction new_ka, old_ka; |
602 | int ret; | 603 | int ret; |
603 | 604 | ||
604 | /* XXX: Don't preclude handling different sized sigset_t's. */ | 605 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
605 | if (sigsetsize != sizeof(compat_sigset_t)) | 606 | if (sigsetsize != sizeof(compat_sigset_t)) |
606 | return -EINVAL; | 607 | return -EINVAL; |
607 | 608 | ||
608 | if (act) { | 609 | if (act) { |
609 | compat_uptr_t handler; | 610 | compat_uptr_t handler; |
610 | 611 | ||
611 | ret = get_user(handler, &act->sa_handler); | 612 | ret = get_user(handler, &act->sa_handler); |
612 | new_ka.sa.sa_handler = compat_ptr(handler); | 613 | new_ka.sa.sa_handler = compat_ptr(handler); |
613 | ret |= get_sigset_t(&new_ka.sa.sa_mask, &act->sa_mask); | 614 | ret |= get_sigset_t(&new_ka.sa.sa_mask, &act->sa_mask); |
614 | ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags); | 615 | ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags); |
615 | if (ret) | 616 | if (ret) |
616 | return -EFAULT; | 617 | return -EFAULT; |
617 | } | 618 | } |
618 | 619 | ||
619 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | 620 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
620 | if (!ret && oact) { | 621 | if (!ret && oact) { |
621 | ret = put_user(to_user_ptr(old_ka.sa.sa_handler), &oact->sa_handler); | 622 | ret = put_user(to_user_ptr(old_ka.sa.sa_handler), &oact->sa_handler); |
622 | ret |= put_sigset_t(&oact->sa_mask, &old_ka.sa.sa_mask); | 623 | ret |= put_sigset_t(&oact->sa_mask, &old_ka.sa.sa_mask); |
623 | ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); | 624 | ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
624 | } | 625 | } |
625 | return ret; | 626 | return ret; |
626 | } | 627 | } |
627 | 628 | ||
628 | /* | 629 | /* |
629 | * Note: it is necessary to treat how as an unsigned int, with the | 630 | * Note: it is necessary to treat how as an unsigned int, with the |
630 | * corresponding cast to a signed int to insure that the proper | 631 | * corresponding cast to a signed int to insure that the proper |
631 | * conversion (sign extension) between the register representation | 632 | * conversion (sign extension) between the register representation |
632 | * of a signed int (msr in 32-bit mode) and the register representation | 633 | * of a signed int (msr in 32-bit mode) and the register representation |
633 | * of a signed int (msr in 64-bit mode) is performed. | 634 | * of a signed int (msr in 64-bit mode) is performed. |
634 | */ | 635 | */ |
635 | long compat_sys_rt_sigprocmask(u32 how, compat_sigset_t __user *set, | 636 | long compat_sys_rt_sigprocmask(u32 how, compat_sigset_t __user *set, |
636 | compat_sigset_t __user *oset, size_t sigsetsize) | 637 | compat_sigset_t __user *oset, size_t sigsetsize) |
637 | { | 638 | { |
638 | sigset_t s; | 639 | sigset_t s; |
639 | sigset_t __user *up; | 640 | sigset_t __user *up; |
640 | int ret; | 641 | int ret; |
641 | mm_segment_t old_fs = get_fs(); | 642 | mm_segment_t old_fs = get_fs(); |
642 | 643 | ||
643 | if (set) { | 644 | if (set) { |
644 | if (get_sigset_t(&s, set)) | 645 | if (get_sigset_t(&s, set)) |
645 | return -EFAULT; | 646 | return -EFAULT; |
646 | } | 647 | } |
647 | 648 | ||
648 | set_fs(KERNEL_DS); | 649 | set_fs(KERNEL_DS); |
649 | /* This is valid because of the set_fs() */ | 650 | /* This is valid because of the set_fs() */ |
650 | up = (sigset_t __user *) &s; | 651 | up = (sigset_t __user *) &s; |
651 | ret = sys_rt_sigprocmask((int)how, set ? up : NULL, oset ? up : NULL, | 652 | ret = sys_rt_sigprocmask((int)how, set ? up : NULL, oset ? up : NULL, |
652 | sigsetsize); | 653 | sigsetsize); |
653 | set_fs(old_fs); | 654 | set_fs(old_fs); |
654 | if (ret) | 655 | if (ret) |
655 | return ret; | 656 | return ret; |
656 | if (oset) { | 657 | if (oset) { |
657 | if (put_sigset_t(oset, &s)) | 658 | if (put_sigset_t(oset, &s)) |
658 | return -EFAULT; | 659 | return -EFAULT; |
659 | } | 660 | } |
660 | return 0; | 661 | return 0; |
661 | } | 662 | } |
662 | 663 | ||
663 | long compat_sys_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize) | 664 | long compat_sys_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize) |
664 | { | 665 | { |
665 | sigset_t s; | 666 | sigset_t s; |
666 | int ret; | 667 | int ret; |
667 | mm_segment_t old_fs = get_fs(); | 668 | mm_segment_t old_fs = get_fs(); |
668 | 669 | ||
669 | set_fs(KERNEL_DS); | 670 | set_fs(KERNEL_DS); |
670 | /* The __user pointer cast is valid because of the set_fs() */ | 671 | /* The __user pointer cast is valid because of the set_fs() */ |
671 | ret = sys_rt_sigpending((sigset_t __user *) &s, sigsetsize); | 672 | ret = sys_rt_sigpending((sigset_t __user *) &s, sigsetsize); |
672 | set_fs(old_fs); | 673 | set_fs(old_fs); |
673 | if (!ret) { | 674 | if (!ret) { |
674 | if (put_sigset_t(set, &s)) | 675 | if (put_sigset_t(set, &s)) |
675 | return -EFAULT; | 676 | return -EFAULT; |
676 | } | 677 | } |
677 | return ret; | 678 | return ret; |
678 | } | 679 | } |
679 | 680 | ||
680 | 681 | ||
681 | int copy_siginfo_to_user32(struct compat_siginfo __user *d, siginfo_t *s) | 682 | int copy_siginfo_to_user32(struct compat_siginfo __user *d, siginfo_t *s) |
682 | { | 683 | { |
683 | int err; | 684 | int err; |
684 | 685 | ||
685 | if (!access_ok (VERIFY_WRITE, d, sizeof(*d))) | 686 | if (!access_ok (VERIFY_WRITE, d, sizeof(*d))) |
686 | return -EFAULT; | 687 | return -EFAULT; |
687 | 688 | ||
688 | /* If you change siginfo_t structure, please be sure | 689 | /* If you change siginfo_t structure, please be sure |
689 | * this code is fixed accordingly. | 690 | * this code is fixed accordingly. |
690 | * It should never copy any pad contained in the structure | 691 | * It should never copy any pad contained in the structure |
691 | * to avoid security leaks, but must copy the generic | 692 | * to avoid security leaks, but must copy the generic |
692 | * 3 ints plus the relevant union member. | 693 | * 3 ints plus the relevant union member. |
693 | * This routine must convert siginfo from 64bit to 32bit as well | 694 | * This routine must convert siginfo from 64bit to 32bit as well |
694 | * at the same time. | 695 | * at the same time. |
695 | */ | 696 | */ |
696 | err = __put_user(s->si_signo, &d->si_signo); | 697 | err = __put_user(s->si_signo, &d->si_signo); |
697 | err |= __put_user(s->si_errno, &d->si_errno); | 698 | err |= __put_user(s->si_errno, &d->si_errno); |
698 | err |= __put_user((short)s->si_code, &d->si_code); | 699 | err |= __put_user((short)s->si_code, &d->si_code); |
699 | if (s->si_code < 0) | 700 | if (s->si_code < 0) |
700 | err |= __copy_to_user(&d->_sifields._pad, &s->_sifields._pad, | 701 | err |= __copy_to_user(&d->_sifields._pad, &s->_sifields._pad, |
701 | SI_PAD_SIZE32); | 702 | SI_PAD_SIZE32); |
702 | else switch(s->si_code >> 16) { | 703 | else switch(s->si_code >> 16) { |
703 | case __SI_CHLD >> 16: | 704 | case __SI_CHLD >> 16: |
704 | err |= __put_user(s->si_pid, &d->si_pid); | 705 | err |= __put_user(s->si_pid, &d->si_pid); |
705 | err |= __put_user(s->si_uid, &d->si_uid); | 706 | err |= __put_user(s->si_uid, &d->si_uid); |
706 | err |= __put_user(s->si_utime, &d->si_utime); | 707 | err |= __put_user(s->si_utime, &d->si_utime); |
707 | err |= __put_user(s->si_stime, &d->si_stime); | 708 | err |= __put_user(s->si_stime, &d->si_stime); |
708 | err |= __put_user(s->si_status, &d->si_status); | 709 | err |= __put_user(s->si_status, &d->si_status); |
709 | break; | 710 | break; |
710 | case __SI_FAULT >> 16: | 711 | case __SI_FAULT >> 16: |
711 | err |= __put_user((unsigned int)(unsigned long)s->si_addr, | 712 | err |= __put_user((unsigned int)(unsigned long)s->si_addr, |
712 | &d->si_addr); | 713 | &d->si_addr); |
713 | break; | 714 | break; |
714 | case __SI_POLL >> 16: | 715 | case __SI_POLL >> 16: |
715 | err |= __put_user(s->si_band, &d->si_band); | 716 | err |= __put_user(s->si_band, &d->si_band); |
716 | err |= __put_user(s->si_fd, &d->si_fd); | 717 | err |= __put_user(s->si_fd, &d->si_fd); |
717 | break; | 718 | break; |
718 | case __SI_TIMER >> 16: | 719 | case __SI_TIMER >> 16: |
719 | err |= __put_user(s->si_tid, &d->si_tid); | 720 | err |= __put_user(s->si_tid, &d->si_tid); |
720 | err |= __put_user(s->si_overrun, &d->si_overrun); | 721 | err |= __put_user(s->si_overrun, &d->si_overrun); |
721 | err |= __put_user(s->si_int, &d->si_int); | 722 | err |= __put_user(s->si_int, &d->si_int); |
722 | break; | 723 | break; |
723 | case __SI_RT >> 16: /* This is not generated by the kernel as of now. */ | 724 | case __SI_RT >> 16: /* This is not generated by the kernel as of now. */ |
724 | case __SI_MESGQ >> 16: | 725 | case __SI_MESGQ >> 16: |
725 | err |= __put_user(s->si_int, &d->si_int); | 726 | err |= __put_user(s->si_int, &d->si_int); |
726 | /* fallthrough */ | 727 | /* fallthrough */ |
727 | case __SI_KILL >> 16: | 728 | case __SI_KILL >> 16: |
728 | default: | 729 | default: |
729 | err |= __put_user(s->si_pid, &d->si_pid); | 730 | err |= __put_user(s->si_pid, &d->si_pid); |
730 | err |= __put_user(s->si_uid, &d->si_uid); | 731 | err |= __put_user(s->si_uid, &d->si_uid); |
731 | break; | 732 | break; |
732 | } | 733 | } |
733 | return err; | 734 | return err; |
734 | } | 735 | } |
735 | 736 | ||
736 | #define copy_siginfo_to_user copy_siginfo_to_user32 | 737 | #define copy_siginfo_to_user copy_siginfo_to_user32 |
737 | 738 | ||
738 | int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from) | 739 | int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from) |
739 | { | 740 | { |
740 | memset(to, 0, sizeof *to); | 741 | memset(to, 0, sizeof *to); |
741 | 742 | ||
742 | if (copy_from_user(to, from, 3*sizeof(int)) || | 743 | if (copy_from_user(to, from, 3*sizeof(int)) || |
743 | copy_from_user(to->_sifields._pad, | 744 | copy_from_user(to->_sifields._pad, |
744 | from->_sifields._pad, SI_PAD_SIZE32)) | 745 | from->_sifields._pad, SI_PAD_SIZE32)) |
745 | return -EFAULT; | 746 | return -EFAULT; |
746 | 747 | ||
747 | return 0; | 748 | return 0; |
748 | } | 749 | } |
749 | 750 | ||
750 | /* | 751 | /* |
751 | * Note: it is necessary to treat pid and sig as unsigned ints, with the | 752 | * Note: it is necessary to treat pid and sig as unsigned ints, with the |
752 | * corresponding cast to a signed int to insure that the proper conversion | 753 | * corresponding cast to a signed int to insure that the proper conversion |
753 | * (sign extension) between the register representation of a signed int | 754 | * (sign extension) between the register representation of a signed int |
754 | * (msr in 32-bit mode) and the register representation of a signed int | 755 | * (msr in 32-bit mode) and the register representation of a signed int |
755 | * (msr in 64-bit mode) is performed. | 756 | * (msr in 64-bit mode) is performed. |
756 | */ | 757 | */ |
757 | long compat_sys_rt_sigqueueinfo(u32 pid, u32 sig, compat_siginfo_t __user *uinfo) | 758 | long compat_sys_rt_sigqueueinfo(u32 pid, u32 sig, compat_siginfo_t __user *uinfo) |
758 | { | 759 | { |
759 | siginfo_t info; | 760 | siginfo_t info; |
760 | int ret; | 761 | int ret; |
761 | mm_segment_t old_fs = get_fs(); | 762 | mm_segment_t old_fs = get_fs(); |
762 | 763 | ||
763 | ret = copy_siginfo_from_user32(&info, uinfo); | 764 | ret = copy_siginfo_from_user32(&info, uinfo); |
764 | if (unlikely(ret)) | 765 | if (unlikely(ret)) |
765 | return ret; | 766 | return ret; |
766 | 767 | ||
767 | set_fs (KERNEL_DS); | 768 | set_fs (KERNEL_DS); |
768 | /* The __user pointer cast is valid becasuse of the set_fs() */ | 769 | /* The __user pointer cast is valid becasuse of the set_fs() */ |
769 | ret = sys_rt_sigqueueinfo((int)pid, (int)sig, (siginfo_t __user *) &info); | 770 | ret = sys_rt_sigqueueinfo((int)pid, (int)sig, (siginfo_t __user *) &info); |
770 | set_fs (old_fs); | 771 | set_fs (old_fs); |
771 | return ret; | 772 | return ret; |
772 | } | 773 | } |
773 | /* | 774 | /* |
774 | * Start Alternate signal stack support | 775 | * Start Alternate signal stack support |
775 | * | 776 | * |
776 | * System Calls | 777 | * System Calls |
777 | * sigaltatck compat_sys_sigaltstack | 778 | * sigaltatck compat_sys_sigaltstack |
778 | */ | 779 | */ |
779 | 780 | ||
780 | int compat_sys_sigaltstack(u32 __new, u32 __old, int r5, | 781 | int compat_sys_sigaltstack(u32 __new, u32 __old, int r5, |
781 | int r6, int r7, int r8, struct pt_regs *regs) | 782 | int r6, int r7, int r8, struct pt_regs *regs) |
782 | { | 783 | { |
783 | stack_32_t __user * newstack = compat_ptr(__new); | 784 | stack_32_t __user * newstack = compat_ptr(__new); |
784 | stack_32_t __user * oldstack = compat_ptr(__old); | 785 | stack_32_t __user * oldstack = compat_ptr(__old); |
785 | stack_t uss, uoss; | 786 | stack_t uss, uoss; |
786 | int ret; | 787 | int ret; |
787 | mm_segment_t old_fs; | 788 | mm_segment_t old_fs; |
788 | unsigned long sp; | 789 | unsigned long sp; |
789 | compat_uptr_t ss_sp; | 790 | compat_uptr_t ss_sp; |
790 | 791 | ||
791 | /* | 792 | /* |
792 | * set sp to the user stack on entry to the system call | 793 | * set sp to the user stack on entry to the system call |
793 | * the system call router sets R9 to the saved registers | 794 | * the system call router sets R9 to the saved registers |
794 | */ | 795 | */ |
795 | sp = regs->gpr[1]; | 796 | sp = regs->gpr[1]; |
796 | 797 | ||
797 | /* Put new stack info in local 64 bit stack struct */ | 798 | /* Put new stack info in local 64 bit stack struct */ |
798 | if (newstack) { | 799 | if (newstack) { |
799 | if (get_user(ss_sp, &newstack->ss_sp) || | 800 | if (get_user(ss_sp, &newstack->ss_sp) || |
800 | __get_user(uss.ss_flags, &newstack->ss_flags) || | 801 | __get_user(uss.ss_flags, &newstack->ss_flags) || |
801 | __get_user(uss.ss_size, &newstack->ss_size)) | 802 | __get_user(uss.ss_size, &newstack->ss_size)) |
802 | return -EFAULT; | 803 | return -EFAULT; |
803 | uss.ss_sp = compat_ptr(ss_sp); | 804 | uss.ss_sp = compat_ptr(ss_sp); |
804 | } | 805 | } |
805 | 806 | ||
806 | old_fs = get_fs(); | 807 | old_fs = get_fs(); |
807 | set_fs(KERNEL_DS); | 808 | set_fs(KERNEL_DS); |
808 | /* The __user pointer casts are valid because of the set_fs() */ | 809 | /* The __user pointer casts are valid because of the set_fs() */ |
809 | ret = do_sigaltstack( | 810 | ret = do_sigaltstack( |
810 | newstack ? (stack_t __user *) &uss : NULL, | 811 | newstack ? (stack_t __user *) &uss : NULL, |
811 | oldstack ? (stack_t __user *) &uoss : NULL, | 812 | oldstack ? (stack_t __user *) &uoss : NULL, |
812 | sp); | 813 | sp); |
813 | set_fs(old_fs); | 814 | set_fs(old_fs); |
814 | /* Copy the stack information to the user output buffer */ | 815 | /* Copy the stack information to the user output buffer */ |
815 | if (!ret && oldstack && | 816 | if (!ret && oldstack && |
816 | (put_user(ptr_to_compat(uoss.ss_sp), &oldstack->ss_sp) || | 817 | (put_user(ptr_to_compat(uoss.ss_sp), &oldstack->ss_sp) || |
817 | __put_user(uoss.ss_flags, &oldstack->ss_flags) || | 818 | __put_user(uoss.ss_flags, &oldstack->ss_flags) || |
818 | __put_user(uoss.ss_size, &oldstack->ss_size))) | 819 | __put_user(uoss.ss_size, &oldstack->ss_size))) |
819 | return -EFAULT; | 820 | return -EFAULT; |
820 | return ret; | 821 | return ret; |
821 | } | 822 | } |
822 | #endif /* CONFIG_PPC64 */ | 823 | #endif /* CONFIG_PPC64 */ |
823 | 824 | ||
824 | /* | 825 | /* |
825 | * Set up a signal frame for a "real-time" signal handler | 826 | * Set up a signal frame for a "real-time" signal handler |
826 | * (one which gets siginfo). | 827 | * (one which gets siginfo). |
827 | */ | 828 | */ |
828 | int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka, | 829 | int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka, |
829 | siginfo_t *info, sigset_t *oldset, | 830 | siginfo_t *info, sigset_t *oldset, |
830 | struct pt_regs *regs) | 831 | struct pt_regs *regs) |
831 | { | 832 | { |
832 | struct rt_sigframe __user *rt_sf; | 833 | struct rt_sigframe __user *rt_sf; |
833 | struct mcontext __user *frame; | 834 | struct mcontext __user *frame; |
834 | void __user *addr; | 835 | void __user *addr; |
835 | unsigned long newsp = 0; | 836 | unsigned long newsp = 0; |
836 | 837 | ||
837 | /* Set up Signal Frame */ | 838 | /* Set up Signal Frame */ |
838 | /* Put a Real Time Context onto stack */ | 839 | /* Put a Real Time Context onto stack */ |
839 | rt_sf = get_sigframe(ka, regs, sizeof(*rt_sf), 1); | 840 | rt_sf = get_sigframe(ka, regs, sizeof(*rt_sf), 1); |
840 | addr = rt_sf; | 841 | addr = rt_sf; |
841 | if (unlikely(rt_sf == NULL)) | 842 | if (unlikely(rt_sf == NULL)) |
842 | goto badframe; | 843 | goto badframe; |
843 | 844 | ||
844 | /* Put the siginfo & fill in most of the ucontext */ | 845 | /* Put the siginfo & fill in most of the ucontext */ |
845 | if (copy_siginfo_to_user(&rt_sf->info, info) | 846 | if (copy_siginfo_to_user(&rt_sf->info, info) |
846 | || __put_user(0, &rt_sf->uc.uc_flags) | 847 | || __put_user(0, &rt_sf->uc.uc_flags) |
847 | || __put_user(0, &rt_sf->uc.uc_link) | 848 | || __put_user(0, &rt_sf->uc.uc_link) |
848 | || __put_user(current->sas_ss_sp, &rt_sf->uc.uc_stack.ss_sp) | 849 | || __put_user(current->sas_ss_sp, &rt_sf->uc.uc_stack.ss_sp) |
849 | || __put_user(sas_ss_flags(regs->gpr[1]), | 850 | || __put_user(sas_ss_flags(regs->gpr[1]), |
850 | &rt_sf->uc.uc_stack.ss_flags) | 851 | &rt_sf->uc.uc_stack.ss_flags) |
851 | || __put_user(current->sas_ss_size, &rt_sf->uc.uc_stack.ss_size) | 852 | || __put_user(current->sas_ss_size, &rt_sf->uc.uc_stack.ss_size) |
852 | || __put_user(to_user_ptr(&rt_sf->uc.uc_mcontext), | 853 | || __put_user(to_user_ptr(&rt_sf->uc.uc_mcontext), |
853 | &rt_sf->uc.uc_regs) | 854 | &rt_sf->uc.uc_regs) |
854 | || put_sigset_t(&rt_sf->uc.uc_sigmask, oldset)) | 855 | || put_sigset_t(&rt_sf->uc.uc_sigmask, oldset)) |
855 | goto badframe; | 856 | goto badframe; |
856 | 857 | ||
857 | /* Save user registers on the stack */ | 858 | /* Save user registers on the stack */ |
858 | frame = &rt_sf->uc.uc_mcontext; | 859 | frame = &rt_sf->uc.uc_mcontext; |
859 | addr = frame; | 860 | addr = frame; |
860 | if (vdso32_rt_sigtramp && current->mm->context.vdso_base) { | 861 | if (vdso32_rt_sigtramp && current->mm->context.vdso_base) { |
861 | if (save_user_regs(regs, frame, 0, 1)) | 862 | if (save_user_regs(regs, frame, 0, 1)) |
862 | goto badframe; | 863 | goto badframe; |
863 | regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp; | 864 | regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp; |
864 | } else { | 865 | } else { |
865 | if (save_user_regs(regs, frame, __NR_rt_sigreturn, 1)) | 866 | if (save_user_regs(regs, frame, __NR_rt_sigreturn, 1)) |
866 | goto badframe; | 867 | goto badframe; |
867 | regs->link = (unsigned long) frame->tramp; | 868 | regs->link = (unsigned long) frame->tramp; |
868 | } | 869 | } |
869 | 870 | ||
870 | current->thread.fpscr.val = 0; /* turn off all fp exceptions */ | 871 | current->thread.fpscr.val = 0; /* turn off all fp exceptions */ |
871 | 872 | ||
872 | /* create a stack frame for the caller of the handler */ | 873 | /* create a stack frame for the caller of the handler */ |
873 | newsp = ((unsigned long)rt_sf) - (__SIGNAL_FRAMESIZE + 16); | 874 | newsp = ((unsigned long)rt_sf) - (__SIGNAL_FRAMESIZE + 16); |
874 | addr = (void __user *)regs->gpr[1]; | 875 | addr = (void __user *)regs->gpr[1]; |
875 | if (put_user(regs->gpr[1], (u32 __user *)newsp)) | 876 | if (put_user(regs->gpr[1], (u32 __user *)newsp)) |
876 | goto badframe; | 877 | goto badframe; |
877 | 878 | ||
878 | /* Fill registers for signal handler */ | 879 | /* Fill registers for signal handler */ |
879 | regs->gpr[1] = newsp; | 880 | regs->gpr[1] = newsp; |
880 | regs->gpr[3] = sig; | 881 | regs->gpr[3] = sig; |
881 | regs->gpr[4] = (unsigned long) &rt_sf->info; | 882 | regs->gpr[4] = (unsigned long) &rt_sf->info; |
882 | regs->gpr[5] = (unsigned long) &rt_sf->uc; | 883 | regs->gpr[5] = (unsigned long) &rt_sf->uc; |
883 | regs->gpr[6] = (unsigned long) rt_sf; | 884 | regs->gpr[6] = (unsigned long) rt_sf; |
884 | regs->nip = (unsigned long) ka->sa.sa_handler; | 885 | regs->nip = (unsigned long) ka->sa.sa_handler; |
885 | /* enter the signal handler in big-endian mode */ | 886 | /* enter the signal handler in big-endian mode */ |
886 | regs->msr &= ~MSR_LE; | 887 | regs->msr &= ~MSR_LE; |
887 | regs->trap = 0; | ||
888 | return 1; | 888 | return 1; |
889 | 889 | ||
890 | badframe: | 890 | badframe: |
891 | #ifdef DEBUG_SIG | 891 | #ifdef DEBUG_SIG |
892 | printk("badframe in handle_rt_signal, regs=%p frame=%p newsp=%lx\n", | 892 | printk("badframe in handle_rt_signal, regs=%p frame=%p newsp=%lx\n", |
893 | regs, frame, newsp); | 893 | regs, frame, newsp); |
894 | #endif | 894 | #endif |
895 | if (show_unhandled_signals && printk_ratelimit()) | 895 | if (show_unhandled_signals && printk_ratelimit()) |
896 | printk(KERN_INFO "%s[%d]: bad frame in handle_rt_signal32: " | 896 | printk(KERN_INFO "%s[%d]: bad frame in handle_rt_signal32: " |
897 | "%p nip %08lx lr %08lx\n", | 897 | "%p nip %08lx lr %08lx\n", |
898 | current->comm, current->pid, | 898 | current->comm, current->pid, |
899 | addr, regs->nip, regs->link); | 899 | addr, regs->nip, regs->link); |
900 | 900 | ||
901 | force_sigsegv(sig, current); | 901 | force_sigsegv(sig, current); |
902 | return 0; | 902 | return 0; |
903 | } | 903 | } |
904 | 904 | ||
905 | static int do_setcontext(struct ucontext __user *ucp, struct pt_regs *regs, int sig) | 905 | static int do_setcontext(struct ucontext __user *ucp, struct pt_regs *regs, int sig) |
906 | { | 906 | { |
907 | sigset_t set; | 907 | sigset_t set; |
908 | struct mcontext __user *mcp; | 908 | struct mcontext __user *mcp; |
909 | 909 | ||
910 | if (get_sigset_t(&set, &ucp->uc_sigmask)) | 910 | if (get_sigset_t(&set, &ucp->uc_sigmask)) |
911 | return -EFAULT; | 911 | return -EFAULT; |
912 | #ifdef CONFIG_PPC64 | 912 | #ifdef CONFIG_PPC64 |
913 | { | 913 | { |
914 | u32 cmcp; | 914 | u32 cmcp; |
915 | 915 | ||
916 | if (__get_user(cmcp, &ucp->uc_regs)) | 916 | if (__get_user(cmcp, &ucp->uc_regs)) |
917 | return -EFAULT; | 917 | return -EFAULT; |
918 | mcp = (struct mcontext __user *)(u64)cmcp; | 918 | mcp = (struct mcontext __user *)(u64)cmcp; |
919 | /* no need to check access_ok(mcp), since mcp < 4GB */ | 919 | /* no need to check access_ok(mcp), since mcp < 4GB */ |
920 | } | 920 | } |
921 | #else | 921 | #else |
922 | if (__get_user(mcp, &ucp->uc_regs)) | 922 | if (__get_user(mcp, &ucp->uc_regs)) |
923 | return -EFAULT; | 923 | return -EFAULT; |
924 | if (!access_ok(VERIFY_READ, mcp, sizeof(*mcp))) | 924 | if (!access_ok(VERIFY_READ, mcp, sizeof(*mcp))) |
925 | return -EFAULT; | 925 | return -EFAULT; |
926 | #endif | 926 | #endif |
927 | restore_sigmask(&set); | 927 | restore_sigmask(&set); |
928 | if (restore_user_regs(regs, mcp, sig)) | 928 | if (restore_user_regs(regs, mcp, sig)) |
929 | return -EFAULT; | 929 | return -EFAULT; |
930 | 930 | ||
931 | return 0; | 931 | return 0; |
932 | } | 932 | } |
933 | 933 | ||
934 | long sys_swapcontext(struct ucontext __user *old_ctx, | 934 | long sys_swapcontext(struct ucontext __user *old_ctx, |
935 | struct ucontext __user *new_ctx, | 935 | struct ucontext __user *new_ctx, |
936 | int ctx_size, int r6, int r7, int r8, struct pt_regs *regs) | 936 | int ctx_size, int r6, int r7, int r8, struct pt_regs *regs) |
937 | { | 937 | { |
938 | unsigned char tmp; | 938 | unsigned char tmp; |
939 | int ctx_has_vsx_region = 0; | 939 | int ctx_has_vsx_region = 0; |
940 | 940 | ||
941 | #ifdef CONFIG_PPC64 | 941 | #ifdef CONFIG_PPC64 |
942 | unsigned long new_msr = 0; | 942 | unsigned long new_msr = 0; |
943 | 943 | ||
944 | if (new_ctx) { | 944 | if (new_ctx) { |
945 | struct mcontext __user *mcp; | 945 | struct mcontext __user *mcp; |
946 | u32 cmcp; | 946 | u32 cmcp; |
947 | 947 | ||
948 | /* | 948 | /* |
949 | * Get pointer to the real mcontext. No need for | 949 | * Get pointer to the real mcontext. No need for |
950 | * access_ok since we are dealing with compat | 950 | * access_ok since we are dealing with compat |
951 | * pointers. | 951 | * pointers. |
952 | */ | 952 | */ |
953 | if (__get_user(cmcp, &new_ctx->uc_regs)) | 953 | if (__get_user(cmcp, &new_ctx->uc_regs)) |
954 | return -EFAULT; | 954 | return -EFAULT; |
955 | mcp = (struct mcontext __user *)(u64)cmcp; | 955 | mcp = (struct mcontext __user *)(u64)cmcp; |
956 | if (__get_user(new_msr, &mcp->mc_gregs[PT_MSR])) | 956 | if (__get_user(new_msr, &mcp->mc_gregs[PT_MSR])) |
957 | return -EFAULT; | 957 | return -EFAULT; |
958 | } | 958 | } |
959 | /* | 959 | /* |
960 | * Check that the context is not smaller than the original | 960 | * Check that the context is not smaller than the original |
961 | * size (with VMX but without VSX) | 961 | * size (with VMX but without VSX) |
962 | */ | 962 | */ |
963 | if (ctx_size < UCONTEXTSIZEWITHOUTVSX) | 963 | if (ctx_size < UCONTEXTSIZEWITHOUTVSX) |
964 | return -EINVAL; | 964 | return -EINVAL; |
965 | /* | 965 | /* |
966 | * If the new context state sets the MSR VSX bits but | 966 | * If the new context state sets the MSR VSX bits but |
967 | * it doesn't provide VSX state. | 967 | * it doesn't provide VSX state. |
968 | */ | 968 | */ |
969 | if ((ctx_size < sizeof(struct ucontext)) && | 969 | if ((ctx_size < sizeof(struct ucontext)) && |
970 | (new_msr & MSR_VSX)) | 970 | (new_msr & MSR_VSX)) |
971 | return -EINVAL; | 971 | return -EINVAL; |
972 | /* Does the context have enough room to store VSX data? */ | 972 | /* Does the context have enough room to store VSX data? */ |
973 | if (ctx_size >= sizeof(struct ucontext)) | 973 | if (ctx_size >= sizeof(struct ucontext)) |
974 | ctx_has_vsx_region = 1; | 974 | ctx_has_vsx_region = 1; |
975 | #else | 975 | #else |
976 | /* Context size is for future use. Right now, we only make sure | 976 | /* Context size is for future use. Right now, we only make sure |
977 | * we are passed something we understand | 977 | * we are passed something we understand |
978 | */ | 978 | */ |
979 | if (ctx_size < sizeof(struct ucontext)) | 979 | if (ctx_size < sizeof(struct ucontext)) |
980 | return -EINVAL; | 980 | return -EINVAL; |
981 | #endif | 981 | #endif |
982 | if (old_ctx != NULL) { | 982 | if (old_ctx != NULL) { |
983 | struct mcontext __user *mctx; | 983 | struct mcontext __user *mctx; |
984 | 984 | ||
985 | /* | 985 | /* |
986 | * old_ctx might not be 16-byte aligned, in which | 986 | * old_ctx might not be 16-byte aligned, in which |
987 | * case old_ctx->uc_mcontext won't be either. | 987 | * case old_ctx->uc_mcontext won't be either. |
988 | * Because we have the old_ctx->uc_pad2 field | 988 | * Because we have the old_ctx->uc_pad2 field |
989 | * before old_ctx->uc_mcontext, we need to round down | 989 | * before old_ctx->uc_mcontext, we need to round down |
990 | * from &old_ctx->uc_mcontext to a 16-byte boundary. | 990 | * from &old_ctx->uc_mcontext to a 16-byte boundary. |
991 | */ | 991 | */ |
992 | mctx = (struct mcontext __user *) | 992 | mctx = (struct mcontext __user *) |
993 | ((unsigned long) &old_ctx->uc_mcontext & ~0xfUL); | 993 | ((unsigned long) &old_ctx->uc_mcontext & ~0xfUL); |
994 | if (!access_ok(VERIFY_WRITE, old_ctx, ctx_size) | 994 | if (!access_ok(VERIFY_WRITE, old_ctx, ctx_size) |
995 | || save_user_regs(regs, mctx, 0, ctx_has_vsx_region) | 995 | || save_user_regs(regs, mctx, 0, ctx_has_vsx_region) |
996 | || put_sigset_t(&old_ctx->uc_sigmask, ¤t->blocked) | 996 | || put_sigset_t(&old_ctx->uc_sigmask, ¤t->blocked) |
997 | || __put_user(to_user_ptr(mctx), &old_ctx->uc_regs)) | 997 | || __put_user(to_user_ptr(mctx), &old_ctx->uc_regs)) |
998 | return -EFAULT; | 998 | return -EFAULT; |
999 | } | 999 | } |
1000 | if (new_ctx == NULL) | 1000 | if (new_ctx == NULL) |
1001 | return 0; | 1001 | return 0; |
1002 | if (!access_ok(VERIFY_READ, new_ctx, ctx_size) | 1002 | if (!access_ok(VERIFY_READ, new_ctx, ctx_size) |
1003 | || __get_user(tmp, (u8 __user *) new_ctx) | 1003 | || __get_user(tmp, (u8 __user *) new_ctx) |
1004 | || __get_user(tmp, (u8 __user *) new_ctx + ctx_size - 1)) | 1004 | || __get_user(tmp, (u8 __user *) new_ctx + ctx_size - 1)) |
1005 | return -EFAULT; | 1005 | return -EFAULT; |
1006 | 1006 | ||
1007 | /* | 1007 | /* |
1008 | * If we get a fault copying the context into the kernel's | 1008 | * If we get a fault copying the context into the kernel's |
1009 | * image of the user's registers, we can't just return -EFAULT | 1009 | * image of the user's registers, we can't just return -EFAULT |
1010 | * because the user's registers will be corrupted. For instance | 1010 | * because the user's registers will be corrupted. For instance |
1011 | * the NIP value may have been updated but not some of the | 1011 | * the NIP value may have been updated but not some of the |
1012 | * other registers. Given that we have done the access_ok | 1012 | * other registers. Given that we have done the access_ok |
1013 | * and successfully read the first and last bytes of the region | 1013 | * and successfully read the first and last bytes of the region |
1014 | * above, this should only happen in an out-of-memory situation | 1014 | * above, this should only happen in an out-of-memory situation |
1015 | * or if another thread unmaps the region containing the context. | 1015 | * or if another thread unmaps the region containing the context. |
1016 | * We kill the task with a SIGSEGV in this situation. | 1016 | * We kill the task with a SIGSEGV in this situation. |
1017 | */ | 1017 | */ |
1018 | if (do_setcontext(new_ctx, regs, 0)) | 1018 | if (do_setcontext(new_ctx, regs, 0)) |
1019 | do_exit(SIGSEGV); | 1019 | do_exit(SIGSEGV); |
1020 | 1020 | ||
1021 | set_thread_flag(TIF_RESTOREALL); | 1021 | set_thread_flag(TIF_RESTOREALL); |
1022 | return 0; | 1022 | return 0; |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | long sys_rt_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8, | 1025 | long sys_rt_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8, |
1026 | struct pt_regs *regs) | 1026 | struct pt_regs *regs) |
1027 | { | 1027 | { |
1028 | struct rt_sigframe __user *rt_sf; | 1028 | struct rt_sigframe __user *rt_sf; |
1029 | 1029 | ||
1030 | /* Always make any pending restarted system calls return -EINTR */ | 1030 | /* Always make any pending restarted system calls return -EINTR */ |
1031 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | 1031 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
1032 | 1032 | ||
1033 | rt_sf = (struct rt_sigframe __user *) | 1033 | rt_sf = (struct rt_sigframe __user *) |
1034 | (regs->gpr[1] + __SIGNAL_FRAMESIZE + 16); | 1034 | (regs->gpr[1] + __SIGNAL_FRAMESIZE + 16); |
1035 | if (!access_ok(VERIFY_READ, rt_sf, sizeof(*rt_sf))) | 1035 | if (!access_ok(VERIFY_READ, rt_sf, sizeof(*rt_sf))) |
1036 | goto bad; | 1036 | goto bad; |
1037 | if (do_setcontext(&rt_sf->uc, regs, 1)) | 1037 | if (do_setcontext(&rt_sf->uc, regs, 1)) |
1038 | goto bad; | 1038 | goto bad; |
1039 | 1039 | ||
1040 | /* | 1040 | /* |
1041 | * It's not clear whether or why it is desirable to save the | 1041 | * It's not clear whether or why it is desirable to save the |
1042 | * sigaltstack setting on signal delivery and restore it on | 1042 | * sigaltstack setting on signal delivery and restore it on |
1043 | * signal return. But other architectures do this and we have | 1043 | * signal return. But other architectures do this and we have |
1044 | * always done it up until now so it is probably better not to | 1044 | * always done it up until now so it is probably better not to |
1045 | * change it. -- paulus | 1045 | * change it. -- paulus |
1046 | */ | 1046 | */ |
1047 | #ifdef CONFIG_PPC64 | 1047 | #ifdef CONFIG_PPC64 |
1048 | /* | 1048 | /* |
1049 | * We use the compat_sys_ version that does the 32/64 bits conversion | 1049 | * We use the compat_sys_ version that does the 32/64 bits conversion |
1050 | * and takes userland pointer directly. What about error checking ? | 1050 | * and takes userland pointer directly. What about error checking ? |
1051 | * nobody does any... | 1051 | * nobody does any... |
1052 | */ | 1052 | */ |
1053 | compat_sys_sigaltstack((u32)(u64)&rt_sf->uc.uc_stack, 0, 0, 0, 0, 0, regs); | 1053 | compat_sys_sigaltstack((u32)(u64)&rt_sf->uc.uc_stack, 0, 0, 0, 0, 0, regs); |
1054 | #else | 1054 | #else |
1055 | do_sigaltstack(&rt_sf->uc.uc_stack, NULL, regs->gpr[1]); | 1055 | do_sigaltstack(&rt_sf->uc.uc_stack, NULL, regs->gpr[1]); |
1056 | #endif | 1056 | #endif |
1057 | set_thread_flag(TIF_RESTOREALL); | 1057 | set_thread_flag(TIF_RESTOREALL); |
1058 | return 0; | 1058 | return 0; |
1059 | 1059 | ||
1060 | bad: | 1060 | bad: |
1061 | if (show_unhandled_signals && printk_ratelimit()) | 1061 | if (show_unhandled_signals && printk_ratelimit()) |
1062 | printk(KERN_INFO "%s[%d]: bad frame in sys_rt_sigreturn: " | 1062 | printk(KERN_INFO "%s[%d]: bad frame in sys_rt_sigreturn: " |
1063 | "%p nip %08lx lr %08lx\n", | 1063 | "%p nip %08lx lr %08lx\n", |
1064 | current->comm, current->pid, | 1064 | current->comm, current->pid, |
1065 | rt_sf, regs->nip, regs->link); | 1065 | rt_sf, regs->nip, regs->link); |
1066 | 1066 | ||
1067 | force_sig(SIGSEGV, current); | 1067 | force_sig(SIGSEGV, current); |
1068 | return 0; | 1068 | return 0; |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | #ifdef CONFIG_PPC32 | 1071 | #ifdef CONFIG_PPC32 |
1072 | int sys_debug_setcontext(struct ucontext __user *ctx, | 1072 | int sys_debug_setcontext(struct ucontext __user *ctx, |
1073 | int ndbg, struct sig_dbg_op __user *dbg, | 1073 | int ndbg, struct sig_dbg_op __user *dbg, |
1074 | int r6, int r7, int r8, | 1074 | int r6, int r7, int r8, |
1075 | struct pt_regs *regs) | 1075 | struct pt_regs *regs) |
1076 | { | 1076 | { |
1077 | struct sig_dbg_op op; | 1077 | struct sig_dbg_op op; |
1078 | int i; | 1078 | int i; |
1079 | unsigned char tmp; | 1079 | unsigned char tmp; |
1080 | unsigned long new_msr = regs->msr; | 1080 | unsigned long new_msr = regs->msr; |
1081 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS | 1081 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
1082 | unsigned long new_dbcr0 = current->thread.dbcr0; | 1082 | unsigned long new_dbcr0 = current->thread.dbcr0; |
1083 | #endif | 1083 | #endif |
1084 | 1084 | ||
1085 | for (i=0; i<ndbg; i++) { | 1085 | for (i=0; i<ndbg; i++) { |
1086 | if (copy_from_user(&op, dbg + i, sizeof(op))) | 1086 | if (copy_from_user(&op, dbg + i, sizeof(op))) |
1087 | return -EFAULT; | 1087 | return -EFAULT; |
1088 | switch (op.dbg_type) { | 1088 | switch (op.dbg_type) { |
1089 | case SIG_DBG_SINGLE_STEPPING: | 1089 | case SIG_DBG_SINGLE_STEPPING: |
1090 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS | 1090 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
1091 | if (op.dbg_value) { | 1091 | if (op.dbg_value) { |
1092 | new_msr |= MSR_DE; | 1092 | new_msr |= MSR_DE; |
1093 | new_dbcr0 |= (DBCR0_IDM | DBCR0_IC); | 1093 | new_dbcr0 |= (DBCR0_IDM | DBCR0_IC); |
1094 | } else { | 1094 | } else { |
1095 | new_dbcr0 &= ~DBCR0_IC; | 1095 | new_dbcr0 &= ~DBCR0_IC; |
1096 | if (!DBCR_ACTIVE_EVENTS(new_dbcr0, | 1096 | if (!DBCR_ACTIVE_EVENTS(new_dbcr0, |
1097 | current->thread.dbcr1)) { | 1097 | current->thread.dbcr1)) { |
1098 | new_msr &= ~MSR_DE; | 1098 | new_msr &= ~MSR_DE; |
1099 | new_dbcr0 &= ~DBCR0_IDM; | 1099 | new_dbcr0 &= ~DBCR0_IDM; |
1100 | } | 1100 | } |
1101 | } | 1101 | } |
1102 | #else | 1102 | #else |
1103 | if (op.dbg_value) | 1103 | if (op.dbg_value) |
1104 | new_msr |= MSR_SE; | 1104 | new_msr |= MSR_SE; |
1105 | else | 1105 | else |
1106 | new_msr &= ~MSR_SE; | 1106 | new_msr &= ~MSR_SE; |
1107 | #endif | 1107 | #endif |
1108 | break; | 1108 | break; |
1109 | case SIG_DBG_BRANCH_TRACING: | 1109 | case SIG_DBG_BRANCH_TRACING: |
1110 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS | 1110 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
1111 | return -EINVAL; | 1111 | return -EINVAL; |
1112 | #else | 1112 | #else |
1113 | if (op.dbg_value) | 1113 | if (op.dbg_value) |
1114 | new_msr |= MSR_BE; | 1114 | new_msr |= MSR_BE; |
1115 | else | 1115 | else |
1116 | new_msr &= ~MSR_BE; | 1116 | new_msr &= ~MSR_BE; |
1117 | #endif | 1117 | #endif |
1118 | break; | 1118 | break; |
1119 | 1119 | ||
1120 | default: | 1120 | default: |
1121 | return -EINVAL; | 1121 | return -EINVAL; |
1122 | } | 1122 | } |
1123 | } | 1123 | } |
1124 | 1124 | ||
1125 | /* We wait until here to actually install the values in the | 1125 | /* We wait until here to actually install the values in the |
1126 | registers so if we fail in the above loop, it will not | 1126 | registers so if we fail in the above loop, it will not |
1127 | affect the contents of these registers. After this point, | 1127 | affect the contents of these registers. After this point, |
1128 | failure is a problem, anyway, and it's very unlikely unless | 1128 | failure is a problem, anyway, and it's very unlikely unless |
1129 | the user is really doing something wrong. */ | 1129 | the user is really doing something wrong. */ |
1130 | regs->msr = new_msr; | 1130 | regs->msr = new_msr; |
1131 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS | 1131 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
1132 | current->thread.dbcr0 = new_dbcr0; | 1132 | current->thread.dbcr0 = new_dbcr0; |
1133 | #endif | 1133 | #endif |
1134 | 1134 | ||
1135 | if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx)) | 1135 | if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx)) |
1136 | || __get_user(tmp, (u8 __user *) ctx) | 1136 | || __get_user(tmp, (u8 __user *) ctx) |
1137 | || __get_user(tmp, (u8 __user *) (ctx + 1) - 1)) | 1137 | || __get_user(tmp, (u8 __user *) (ctx + 1) - 1)) |
1138 | return -EFAULT; | 1138 | return -EFAULT; |
1139 | 1139 | ||
1140 | /* | 1140 | /* |
1141 | * If we get a fault copying the context into the kernel's | 1141 | * If we get a fault copying the context into the kernel's |
1142 | * image of the user's registers, we can't just return -EFAULT | 1142 | * image of the user's registers, we can't just return -EFAULT |
1143 | * because the user's registers will be corrupted. For instance | 1143 | * because the user's registers will be corrupted. For instance |
1144 | * the NIP value may have been updated but not some of the | 1144 | * the NIP value may have been updated but not some of the |
1145 | * other registers. Given that we have done the access_ok | 1145 | * other registers. Given that we have done the access_ok |
1146 | * and successfully read the first and last bytes of the region | 1146 | * and successfully read the first and last bytes of the region |
1147 | * above, this should only happen in an out-of-memory situation | 1147 | * above, this should only happen in an out-of-memory situation |
1148 | * or if another thread unmaps the region containing the context. | 1148 | * or if another thread unmaps the region containing the context. |
1149 | * We kill the task with a SIGSEGV in this situation. | 1149 | * We kill the task with a SIGSEGV in this situation. |
1150 | */ | 1150 | */ |
1151 | if (do_setcontext(ctx, regs, 1)) { | 1151 | if (do_setcontext(ctx, regs, 1)) { |
1152 | if (show_unhandled_signals && printk_ratelimit()) | 1152 | if (show_unhandled_signals && printk_ratelimit()) |
1153 | printk(KERN_INFO "%s[%d]: bad frame in " | 1153 | printk(KERN_INFO "%s[%d]: bad frame in " |
1154 | "sys_debug_setcontext: %p nip %08lx " | 1154 | "sys_debug_setcontext: %p nip %08lx " |
1155 | "lr %08lx\n", | 1155 | "lr %08lx\n", |
1156 | current->comm, current->pid, | 1156 | current->comm, current->pid, |
1157 | ctx, regs->nip, regs->link); | 1157 | ctx, regs->nip, regs->link); |
1158 | 1158 | ||
1159 | force_sig(SIGSEGV, current); | 1159 | force_sig(SIGSEGV, current); |
1160 | goto out; | 1160 | goto out; |
1161 | } | 1161 | } |
1162 | 1162 | ||
1163 | /* | 1163 | /* |
1164 | * It's not clear whether or why it is desirable to save the | 1164 | * It's not clear whether or why it is desirable to save the |
1165 | * sigaltstack setting on signal delivery and restore it on | 1165 | * sigaltstack setting on signal delivery and restore it on |
1166 | * signal return. But other architectures do this and we have | 1166 | * signal return. But other architectures do this and we have |
1167 | * always done it up until now so it is probably better not to | 1167 | * always done it up until now so it is probably better not to |
1168 | * change it. -- paulus | 1168 | * change it. -- paulus |
1169 | */ | 1169 | */ |
1170 | do_sigaltstack(&ctx->uc_stack, NULL, regs->gpr[1]); | 1170 | do_sigaltstack(&ctx->uc_stack, NULL, regs->gpr[1]); |
1171 | 1171 | ||
1172 | set_thread_flag(TIF_RESTOREALL); | 1172 | set_thread_flag(TIF_RESTOREALL); |
1173 | out: | 1173 | out: |
1174 | return 0; | 1174 | return 0; |
1175 | } | 1175 | } |
1176 | #endif | 1176 | #endif |
1177 | 1177 | ||
1178 | /* | 1178 | /* |
1179 | * OK, we're invoking a handler | 1179 | * OK, we're invoking a handler |
1180 | */ | 1180 | */ |
1181 | int handle_signal32(unsigned long sig, struct k_sigaction *ka, | 1181 | int handle_signal32(unsigned long sig, struct k_sigaction *ka, |
1182 | siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) | 1182 | siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) |
1183 | { | 1183 | { |
1184 | struct sigcontext __user *sc; | 1184 | struct sigcontext __user *sc; |
1185 | struct sigframe __user *frame; | 1185 | struct sigframe __user *frame; |
1186 | unsigned long newsp = 0; | 1186 | unsigned long newsp = 0; |
1187 | 1187 | ||
1188 | /* Set up Signal Frame */ | 1188 | /* Set up Signal Frame */ |
1189 | frame = get_sigframe(ka, regs, sizeof(*frame), 1); | 1189 | frame = get_sigframe(ka, regs, sizeof(*frame), 1); |
1190 | if (unlikely(frame == NULL)) | 1190 | if (unlikely(frame == NULL)) |
1191 | goto badframe; | 1191 | goto badframe; |
1192 | sc = (struct sigcontext __user *) &frame->sctx; | 1192 | sc = (struct sigcontext __user *) &frame->sctx; |
1193 | 1193 | ||
1194 | #if _NSIG != 64 | 1194 | #if _NSIG != 64 |
1195 | #error "Please adjust handle_signal()" | 1195 | #error "Please adjust handle_signal()" |
1196 | #endif | 1196 | #endif |
1197 | if (__put_user(to_user_ptr(ka->sa.sa_handler), &sc->handler) | 1197 | if (__put_user(to_user_ptr(ka->sa.sa_handler), &sc->handler) |
1198 | || __put_user(oldset->sig[0], &sc->oldmask) | 1198 | || __put_user(oldset->sig[0], &sc->oldmask) |
1199 | #ifdef CONFIG_PPC64 | 1199 | #ifdef CONFIG_PPC64 |
1200 | || __put_user((oldset->sig[0] >> 32), &sc->_unused[3]) | 1200 | || __put_user((oldset->sig[0] >> 32), &sc->_unused[3]) |
1201 | #else | 1201 | #else |
1202 | || __put_user(oldset->sig[1], &sc->_unused[3]) | 1202 | || __put_user(oldset->sig[1], &sc->_unused[3]) |
1203 | #endif | 1203 | #endif |
1204 | || __put_user(to_user_ptr(&frame->mctx), &sc->regs) | 1204 | || __put_user(to_user_ptr(&frame->mctx), &sc->regs) |
1205 | || __put_user(sig, &sc->signal)) | 1205 | || __put_user(sig, &sc->signal)) |
1206 | goto badframe; | 1206 | goto badframe; |
1207 | 1207 | ||
1208 | if (vdso32_sigtramp && current->mm->context.vdso_base) { | 1208 | if (vdso32_sigtramp && current->mm->context.vdso_base) { |
1209 | if (save_user_regs(regs, &frame->mctx, 0, 1)) | 1209 | if (save_user_regs(regs, &frame->mctx, 0, 1)) |
1210 | goto badframe; | 1210 | goto badframe; |
1211 | regs->link = current->mm->context.vdso_base + vdso32_sigtramp; | 1211 | regs->link = current->mm->context.vdso_base + vdso32_sigtramp; |
1212 | } else { | 1212 | } else { |
1213 | if (save_user_regs(regs, &frame->mctx, __NR_sigreturn, 1)) | 1213 | if (save_user_regs(regs, &frame->mctx, __NR_sigreturn, 1)) |
1214 | goto badframe; | 1214 | goto badframe; |
1215 | regs->link = (unsigned long) frame->mctx.tramp; | 1215 | regs->link = (unsigned long) frame->mctx.tramp; |
1216 | } | 1216 | } |
1217 | 1217 | ||
1218 | current->thread.fpscr.val = 0; /* turn off all fp exceptions */ | 1218 | current->thread.fpscr.val = 0; /* turn off all fp exceptions */ |
1219 | 1219 | ||
1220 | /* create a stack frame for the caller of the handler */ | 1220 | /* create a stack frame for the caller of the handler */ |
1221 | newsp = ((unsigned long)frame) - __SIGNAL_FRAMESIZE; | 1221 | newsp = ((unsigned long)frame) - __SIGNAL_FRAMESIZE; |
1222 | if (put_user(regs->gpr[1], (u32 __user *)newsp)) | 1222 | if (put_user(regs->gpr[1], (u32 __user *)newsp)) |
1223 | goto badframe; | 1223 | goto badframe; |
1224 | 1224 | ||
1225 | regs->gpr[1] = newsp; | 1225 | regs->gpr[1] = newsp; |
1226 | regs->gpr[3] = sig; | 1226 | regs->gpr[3] = sig; |
1227 | regs->gpr[4] = (unsigned long) sc; | 1227 | regs->gpr[4] = (unsigned long) sc; |
1228 | regs->nip = (unsigned long) ka->sa.sa_handler; | 1228 | regs->nip = (unsigned long) ka->sa.sa_handler; |
1229 | /* enter the signal handler in big-endian mode */ | 1229 | /* enter the signal handler in big-endian mode */ |
1230 | regs->msr &= ~MSR_LE; | 1230 | regs->msr &= ~MSR_LE; |
1231 | regs->trap = 0; | ||
1232 | 1231 | ||
1233 | return 1; | 1232 | return 1; |
1234 | 1233 | ||
1235 | badframe: | 1234 | badframe: |
1236 | #ifdef DEBUG_SIG | 1235 | #ifdef DEBUG_SIG |
1237 | printk("badframe in handle_signal, regs=%p frame=%p newsp=%lx\n", | 1236 | printk("badframe in handle_signal, regs=%p frame=%p newsp=%lx\n", |
1238 | regs, frame, newsp); | 1237 | regs, frame, newsp); |
1239 | #endif | 1238 | #endif |
1240 | if (show_unhandled_signals && printk_ratelimit()) | 1239 | if (show_unhandled_signals && printk_ratelimit()) |
1241 | printk(KERN_INFO "%s[%d]: bad frame in handle_signal32: " | 1240 | printk(KERN_INFO "%s[%d]: bad frame in handle_signal32: " |
1242 | "%p nip %08lx lr %08lx\n", | 1241 | "%p nip %08lx lr %08lx\n", |
1243 | current->comm, current->pid, | 1242 | current->comm, current->pid, |
1244 | frame, regs->nip, regs->link); | 1243 | frame, regs->nip, regs->link); |
1245 | 1244 | ||
1246 | force_sigsegv(sig, current); | 1245 | force_sigsegv(sig, current); |
1247 | return 0; | 1246 | return 0; |
1248 | } | 1247 | } |
1249 | 1248 | ||
1250 | /* | 1249 | /* |
1251 | * Do a signal return; undo the signal stack. | 1250 | * Do a signal return; undo the signal stack. |
1252 | */ | 1251 | */ |
1253 | long sys_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8, | 1252 | long sys_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8, |
1254 | struct pt_regs *regs) | 1253 | struct pt_regs *regs) |
1255 | { | 1254 | { |
1256 | struct sigcontext __user *sc; | 1255 | struct sigcontext __user *sc; |
1257 | struct sigcontext sigctx; | 1256 | struct sigcontext sigctx; |
1258 | struct mcontext __user *sr; | 1257 | struct mcontext __user *sr; |
1259 | void __user *addr; | 1258 | void __user *addr; |
1260 | sigset_t set; | 1259 | sigset_t set; |
1261 | 1260 | ||
1262 | /* Always make any pending restarted system calls return -EINTR */ | 1261 | /* Always make any pending restarted system calls return -EINTR */ |
1263 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | 1262 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
1264 | 1263 | ||
1265 | sc = (struct sigcontext __user *)(regs->gpr[1] + __SIGNAL_FRAMESIZE); | 1264 | sc = (struct sigcontext __user *)(regs->gpr[1] + __SIGNAL_FRAMESIZE); |
1266 | addr = sc; | 1265 | addr = sc; |
1267 | if (copy_from_user(&sigctx, sc, sizeof(sigctx))) | 1266 | if (copy_from_user(&sigctx, sc, sizeof(sigctx))) |
1268 | goto badframe; | 1267 | goto badframe; |
1269 | 1268 | ||
1270 | #ifdef CONFIG_PPC64 | 1269 | #ifdef CONFIG_PPC64 |
1271 | /* | 1270 | /* |
1272 | * Note that PPC32 puts the upper 32 bits of the sigmask in the | 1271 | * Note that PPC32 puts the upper 32 bits of the sigmask in the |
1273 | * unused part of the signal stackframe | 1272 | * unused part of the signal stackframe |
1274 | */ | 1273 | */ |
1275 | set.sig[0] = sigctx.oldmask + ((long)(sigctx._unused[3]) << 32); | 1274 | set.sig[0] = sigctx.oldmask + ((long)(sigctx._unused[3]) << 32); |
1276 | #else | 1275 | #else |
1277 | set.sig[0] = sigctx.oldmask; | 1276 | set.sig[0] = sigctx.oldmask; |
1278 | set.sig[1] = sigctx._unused[3]; | 1277 | set.sig[1] = sigctx._unused[3]; |
1279 | #endif | 1278 | #endif |
1280 | restore_sigmask(&set); | 1279 | restore_sigmask(&set); |
1281 | 1280 | ||
1282 | sr = (struct mcontext __user *)from_user_ptr(sigctx.regs); | 1281 | sr = (struct mcontext __user *)from_user_ptr(sigctx.regs); |
1283 | addr = sr; | 1282 | addr = sr; |
1284 | if (!access_ok(VERIFY_READ, sr, sizeof(*sr)) | 1283 | if (!access_ok(VERIFY_READ, sr, sizeof(*sr)) |
1285 | || restore_user_regs(regs, sr, 1)) | 1284 | || restore_user_regs(regs, sr, 1)) |
1286 | goto badframe; | 1285 | goto badframe; |
1287 | 1286 | ||
1288 | set_thread_flag(TIF_RESTOREALL); | 1287 | set_thread_flag(TIF_RESTOREALL); |
1289 | return 0; | 1288 | return 0; |
1290 | 1289 | ||
1291 | badframe: | 1290 | badframe: |
1292 | if (show_unhandled_signals && printk_ratelimit()) | 1291 | if (show_unhandled_signals && printk_ratelimit()) |
1293 | printk(KERN_INFO "%s[%d]: bad frame in sys_sigreturn: " | 1292 | printk(KERN_INFO "%s[%d]: bad frame in sys_sigreturn: " |
1294 | "%p nip %08lx lr %08lx\n", | 1293 | "%p nip %08lx lr %08lx\n", |
1295 | current->comm, current->pid, | 1294 | current->comm, current->pid, |
1296 | addr, regs->nip, regs->link); | 1295 | addr, regs->nip, regs->link); |
1297 | 1296 | ||
1298 | force_sig(SIGSEGV, current); | 1297 | force_sig(SIGSEGV, current); |
1299 | return 0; | 1298 | return 0; |
1300 | } | 1299 | } |
arch/powerpc/kernel/signal_64.c
1 | /* | 1 | /* |
2 | * PowerPC version | 2 | * PowerPC version |
3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | 3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
4 | * | 4 | * |
5 | * Derived from "arch/i386/kernel/signal.c" | 5 | * Derived from "arch/i386/kernel/signal.c" |
6 | * Copyright (C) 1991, 1992 Linus Torvalds | 6 | * Copyright (C) 1991, 1992 Linus Torvalds |
7 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson | 7 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or | 9 | * This program is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU General Public License | 10 | * modify it under the terms of the GNU General Public License |
11 | * as published by the Free Software Foundation; either version | 11 | * as published by the Free Software Foundation; either version |
12 | * 2 of the License, or (at your option) any later version. | 12 | * 2 of the License, or (at your option) any later version. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/sched.h> | 15 | #include <linux/sched.h> |
16 | #include <linux/mm.h> | 16 | #include <linux/mm.h> |
17 | #include <linux/smp.h> | 17 | #include <linux/smp.h> |
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/signal.h> | 19 | #include <linux/signal.h> |
20 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
21 | #include <linux/wait.h> | 21 | #include <linux/wait.h> |
22 | #include <linux/unistd.h> | 22 | #include <linux/unistd.h> |
23 | #include <linux/stddef.h> | 23 | #include <linux/stddef.h> |
24 | #include <linux/elf.h> | 24 | #include <linux/elf.h> |
25 | #include <linux/ptrace.h> | 25 | #include <linux/ptrace.h> |
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | 27 | ||
28 | #include <asm/sigcontext.h> | 28 | #include <asm/sigcontext.h> |
29 | #include <asm/ucontext.h> | 29 | #include <asm/ucontext.h> |
30 | #include <asm/uaccess.h> | 30 | #include <asm/uaccess.h> |
31 | #include <asm/pgtable.h> | 31 | #include <asm/pgtable.h> |
32 | #include <asm/unistd.h> | 32 | #include <asm/unistd.h> |
33 | #include <asm/cacheflush.h> | 33 | #include <asm/cacheflush.h> |
34 | #include <asm/syscalls.h> | 34 | #include <asm/syscalls.h> |
35 | #include <asm/vdso.h> | 35 | #include <asm/vdso.h> |
36 | 36 | ||
37 | #include "signal.h" | 37 | #include "signal.h" |
38 | 38 | ||
39 | #define DEBUG_SIG 0 | 39 | #define DEBUG_SIG 0 |
40 | 40 | ||
41 | #define GP_REGS_SIZE min(sizeof(elf_gregset_t), sizeof(struct pt_regs)) | 41 | #define GP_REGS_SIZE min(sizeof(elf_gregset_t), sizeof(struct pt_regs)) |
42 | #define FP_REGS_SIZE sizeof(elf_fpregset_t) | 42 | #define FP_REGS_SIZE sizeof(elf_fpregset_t) |
43 | 43 | ||
44 | #define TRAMP_TRACEBACK 3 | 44 | #define TRAMP_TRACEBACK 3 |
45 | #define TRAMP_SIZE 6 | 45 | #define TRAMP_SIZE 6 |
46 | 46 | ||
47 | /* | 47 | /* |
48 | * When we have signals to deliver, we set up on the user stack, | 48 | * When we have signals to deliver, we set up on the user stack, |
49 | * going down from the original stack pointer: | 49 | * going down from the original stack pointer: |
50 | * 1) a rt_sigframe struct which contains the ucontext | 50 | * 1) a rt_sigframe struct which contains the ucontext |
51 | * 2) a gap of __SIGNAL_FRAMESIZE bytes which acts as a dummy caller | 51 | * 2) a gap of __SIGNAL_FRAMESIZE bytes which acts as a dummy caller |
52 | * frame for the signal handler. | 52 | * frame for the signal handler. |
53 | */ | 53 | */ |
54 | 54 | ||
55 | struct rt_sigframe { | 55 | struct rt_sigframe { |
56 | /* sys_rt_sigreturn requires the ucontext be the first field */ | 56 | /* sys_rt_sigreturn requires the ucontext be the first field */ |
57 | struct ucontext uc; | 57 | struct ucontext uc; |
58 | unsigned long _unused[2]; | 58 | unsigned long _unused[2]; |
59 | unsigned int tramp[TRAMP_SIZE]; | 59 | unsigned int tramp[TRAMP_SIZE]; |
60 | struct siginfo __user *pinfo; | 60 | struct siginfo __user *pinfo; |
61 | void __user *puc; | 61 | void __user *puc; |
62 | struct siginfo info; | 62 | struct siginfo info; |
63 | /* 64 bit ABI allows for 288 bytes below sp before decrementing it. */ | 63 | /* 64 bit ABI allows for 288 bytes below sp before decrementing it. */ |
64 | char abigap[288]; | 64 | char abigap[288]; |
65 | } __attribute__ ((aligned (16))); | 65 | } __attribute__ ((aligned (16))); |
66 | 66 | ||
67 | static const char fmt32[] = KERN_INFO \ | 67 | static const char fmt32[] = KERN_INFO \ |
68 | "%s[%d]: bad frame in %s: %08lx nip %08lx lr %08lx\n"; | 68 | "%s[%d]: bad frame in %s: %08lx nip %08lx lr %08lx\n"; |
69 | static const char fmt64[] = KERN_INFO \ | 69 | static const char fmt64[] = KERN_INFO \ |
70 | "%s[%d]: bad frame in %s: %016lx nip %016lx lr %016lx\n"; | 70 | "%s[%d]: bad frame in %s: %016lx nip %016lx lr %016lx\n"; |
71 | 71 | ||
72 | /* | 72 | /* |
73 | * Set up the sigcontext for the signal frame. | 73 | * Set up the sigcontext for the signal frame. |
74 | */ | 74 | */ |
75 | 75 | ||
76 | static long setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, | 76 | static long setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, |
77 | int signr, sigset_t *set, unsigned long handler, | 77 | int signr, sigset_t *set, unsigned long handler, |
78 | int ctx_has_vsx_region) | 78 | int ctx_has_vsx_region) |
79 | { | 79 | { |
80 | /* When CONFIG_ALTIVEC is set, we _always_ setup v_regs even if the | 80 | /* When CONFIG_ALTIVEC is set, we _always_ setup v_regs even if the |
81 | * process never used altivec yet (MSR_VEC is zero in pt_regs of | 81 | * process never used altivec yet (MSR_VEC is zero in pt_regs of |
82 | * the context). This is very important because we must ensure we | 82 | * the context). This is very important because we must ensure we |
83 | * don't lose the VRSAVE content that may have been set prior to | 83 | * don't lose the VRSAVE content that may have been set prior to |
84 | * the process doing its first vector operation | 84 | * the process doing its first vector operation |
85 | * Userland shall check AT_HWCAP to know wether it can rely on the | 85 | * Userland shall check AT_HWCAP to know wether it can rely on the |
86 | * v_regs pointer or not | 86 | * v_regs pointer or not |
87 | */ | 87 | */ |
88 | #ifdef CONFIG_ALTIVEC | 88 | #ifdef CONFIG_ALTIVEC |
89 | elf_vrreg_t __user *v_regs = (elf_vrreg_t __user *)(((unsigned long)sc->vmx_reserve + 15) & ~0xful); | 89 | elf_vrreg_t __user *v_regs = (elf_vrreg_t __user *)(((unsigned long)sc->vmx_reserve + 15) & ~0xful); |
90 | #endif | 90 | #endif |
91 | unsigned long msr = regs->msr; | 91 | unsigned long msr = regs->msr; |
92 | long err = 0; | 92 | long err = 0; |
93 | 93 | ||
94 | flush_fp_to_thread(current); | 94 | flush_fp_to_thread(current); |
95 | 95 | ||
96 | #ifdef CONFIG_ALTIVEC | 96 | #ifdef CONFIG_ALTIVEC |
97 | err |= __put_user(v_regs, &sc->v_regs); | 97 | err |= __put_user(v_regs, &sc->v_regs); |
98 | 98 | ||
99 | /* save altivec registers */ | 99 | /* save altivec registers */ |
100 | if (current->thread.used_vr) { | 100 | if (current->thread.used_vr) { |
101 | flush_altivec_to_thread(current); | 101 | flush_altivec_to_thread(current); |
102 | /* Copy 33 vec registers (vr0..31 and vscr) to the stack */ | 102 | /* Copy 33 vec registers (vr0..31 and vscr) to the stack */ |
103 | err |= __copy_to_user(v_regs, current->thread.vr, 33 * sizeof(vector128)); | 103 | err |= __copy_to_user(v_regs, current->thread.vr, 33 * sizeof(vector128)); |
104 | /* set MSR_VEC in the MSR value in the frame to indicate that sc->v_reg) | 104 | /* set MSR_VEC in the MSR value in the frame to indicate that sc->v_reg) |
105 | * contains valid data. | 105 | * contains valid data. |
106 | */ | 106 | */ |
107 | msr |= MSR_VEC; | 107 | msr |= MSR_VEC; |
108 | } | 108 | } |
109 | /* We always copy to/from vrsave, it's 0 if we don't have or don't | 109 | /* We always copy to/from vrsave, it's 0 if we don't have or don't |
110 | * use altivec. | 110 | * use altivec. |
111 | */ | 111 | */ |
112 | err |= __put_user(current->thread.vrsave, (u32 __user *)&v_regs[33]); | 112 | err |= __put_user(current->thread.vrsave, (u32 __user *)&v_regs[33]); |
113 | #else /* CONFIG_ALTIVEC */ | 113 | #else /* CONFIG_ALTIVEC */ |
114 | err |= __put_user(0, &sc->v_regs); | 114 | err |= __put_user(0, &sc->v_regs); |
115 | #endif /* CONFIG_ALTIVEC */ | 115 | #endif /* CONFIG_ALTIVEC */ |
116 | flush_fp_to_thread(current); | 116 | flush_fp_to_thread(current); |
117 | /* copy fpr regs and fpscr */ | 117 | /* copy fpr regs and fpscr */ |
118 | err |= copy_fpr_to_user(&sc->fp_regs, current); | 118 | err |= copy_fpr_to_user(&sc->fp_regs, current); |
119 | #ifdef CONFIG_VSX | 119 | #ifdef CONFIG_VSX |
120 | /* | 120 | /* |
121 | * Copy VSX low doubleword to local buffer for formatting, | 121 | * Copy VSX low doubleword to local buffer for formatting, |
122 | * then out to userspace. Update v_regs to point after the | 122 | * then out to userspace. Update v_regs to point after the |
123 | * VMX data. | 123 | * VMX data. |
124 | */ | 124 | */ |
125 | if (current->thread.used_vsr && ctx_has_vsx_region) { | 125 | if (current->thread.used_vsr && ctx_has_vsx_region) { |
126 | __giveup_vsx(current); | 126 | __giveup_vsx(current); |
127 | v_regs += ELF_NVRREG; | 127 | v_regs += ELF_NVRREG; |
128 | err |= copy_vsx_to_user(v_regs, current); | 128 | err |= copy_vsx_to_user(v_regs, current); |
129 | /* set MSR_VSX in the MSR value in the frame to | 129 | /* set MSR_VSX in the MSR value in the frame to |
130 | * indicate that sc->vs_reg) contains valid data. | 130 | * indicate that sc->vs_reg) contains valid data. |
131 | */ | 131 | */ |
132 | msr |= MSR_VSX; | 132 | msr |= MSR_VSX; |
133 | } | 133 | } |
134 | #endif /* CONFIG_VSX */ | 134 | #endif /* CONFIG_VSX */ |
135 | err |= __put_user(&sc->gp_regs, &sc->regs); | 135 | err |= __put_user(&sc->gp_regs, &sc->regs); |
136 | WARN_ON(!FULL_REGS(regs)); | 136 | WARN_ON(!FULL_REGS(regs)); |
137 | err |= __copy_to_user(&sc->gp_regs, regs, GP_REGS_SIZE); | 137 | err |= __copy_to_user(&sc->gp_regs, regs, GP_REGS_SIZE); |
138 | err |= __put_user(msr, &sc->gp_regs[PT_MSR]); | 138 | err |= __put_user(msr, &sc->gp_regs[PT_MSR]); |
139 | err |= __put_user(signr, &sc->signal); | 139 | err |= __put_user(signr, &sc->signal); |
140 | err |= __put_user(handler, &sc->handler); | 140 | err |= __put_user(handler, &sc->handler); |
141 | if (set != NULL) | 141 | if (set != NULL) |
142 | err |= __put_user(set->sig[0], &sc->oldmask); | 142 | err |= __put_user(set->sig[0], &sc->oldmask); |
143 | 143 | ||
144 | return err; | 144 | return err; |
145 | } | 145 | } |
146 | 146 | ||
147 | /* | 147 | /* |
148 | * Restore the sigcontext from the signal frame. | 148 | * Restore the sigcontext from the signal frame. |
149 | */ | 149 | */ |
150 | 150 | ||
151 | static long restore_sigcontext(struct pt_regs *regs, sigset_t *set, int sig, | 151 | static long restore_sigcontext(struct pt_regs *regs, sigset_t *set, int sig, |
152 | struct sigcontext __user *sc) | 152 | struct sigcontext __user *sc) |
153 | { | 153 | { |
154 | #ifdef CONFIG_ALTIVEC | 154 | #ifdef CONFIG_ALTIVEC |
155 | elf_vrreg_t __user *v_regs; | 155 | elf_vrreg_t __user *v_regs; |
156 | #endif | 156 | #endif |
157 | unsigned long err = 0; | 157 | unsigned long err = 0; |
158 | unsigned long save_r13 = 0; | 158 | unsigned long save_r13 = 0; |
159 | unsigned long msr; | 159 | unsigned long msr; |
160 | #ifdef CONFIG_VSX | 160 | #ifdef CONFIG_VSX |
161 | int i; | 161 | int i; |
162 | #endif | 162 | #endif |
163 | 163 | ||
164 | /* If this is not a signal return, we preserve the TLS in r13 */ | 164 | /* If this is not a signal return, we preserve the TLS in r13 */ |
165 | if (!sig) | 165 | if (!sig) |
166 | save_r13 = regs->gpr[13]; | 166 | save_r13 = regs->gpr[13]; |
167 | 167 | ||
168 | /* copy the GPRs */ | 168 | /* copy the GPRs */ |
169 | err |= __copy_from_user(regs->gpr, sc->gp_regs, sizeof(regs->gpr)); | 169 | err |= __copy_from_user(regs->gpr, sc->gp_regs, sizeof(regs->gpr)); |
170 | err |= __get_user(regs->nip, &sc->gp_regs[PT_NIP]); | 170 | err |= __get_user(regs->nip, &sc->gp_regs[PT_NIP]); |
171 | /* get MSR separately, transfer the LE bit if doing signal return */ | 171 | /* get MSR separately, transfer the LE bit if doing signal return */ |
172 | err |= __get_user(msr, &sc->gp_regs[PT_MSR]); | 172 | err |= __get_user(msr, &sc->gp_regs[PT_MSR]); |
173 | if (sig) | 173 | if (sig) |
174 | regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE); | 174 | regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE); |
175 | err |= __get_user(regs->orig_gpr3, &sc->gp_regs[PT_ORIG_R3]); | 175 | err |= __get_user(regs->orig_gpr3, &sc->gp_regs[PT_ORIG_R3]); |
176 | err |= __get_user(regs->ctr, &sc->gp_regs[PT_CTR]); | 176 | err |= __get_user(regs->ctr, &sc->gp_regs[PT_CTR]); |
177 | err |= __get_user(regs->link, &sc->gp_regs[PT_LNK]); | 177 | err |= __get_user(regs->link, &sc->gp_regs[PT_LNK]); |
178 | err |= __get_user(regs->xer, &sc->gp_regs[PT_XER]); | 178 | err |= __get_user(regs->xer, &sc->gp_regs[PT_XER]); |
179 | err |= __get_user(regs->ccr, &sc->gp_regs[PT_CCR]); | 179 | err |= __get_user(regs->ccr, &sc->gp_regs[PT_CCR]); |
180 | /* skip SOFTE */ | 180 | /* skip SOFTE */ |
181 | err |= __get_user(regs->trap, &sc->gp_regs[PT_TRAP]); | 181 | regs->trap = 0; |
182 | err |= __get_user(regs->dar, &sc->gp_regs[PT_DAR]); | 182 | err |= __get_user(regs->dar, &sc->gp_regs[PT_DAR]); |
183 | err |= __get_user(regs->dsisr, &sc->gp_regs[PT_DSISR]); | 183 | err |= __get_user(regs->dsisr, &sc->gp_regs[PT_DSISR]); |
184 | err |= __get_user(regs->result, &sc->gp_regs[PT_RESULT]); | 184 | err |= __get_user(regs->result, &sc->gp_regs[PT_RESULT]); |
185 | 185 | ||
186 | if (!sig) | 186 | if (!sig) |
187 | regs->gpr[13] = save_r13; | 187 | regs->gpr[13] = save_r13; |
188 | if (set != NULL) | 188 | if (set != NULL) |
189 | err |= __get_user(set->sig[0], &sc->oldmask); | 189 | err |= __get_user(set->sig[0], &sc->oldmask); |
190 | 190 | ||
191 | /* | 191 | /* |
192 | * Do this before updating the thread state in | 192 | * Do this before updating the thread state in |
193 | * current->thread.fpr/vr. That way, if we get preempted | 193 | * current->thread.fpr/vr. That way, if we get preempted |
194 | * and another task grabs the FPU/Altivec, it won't be | 194 | * and another task grabs the FPU/Altivec, it won't be |
195 | * tempted to save the current CPU state into the thread_struct | 195 | * tempted to save the current CPU state into the thread_struct |
196 | * and corrupt what we are writing there. | 196 | * and corrupt what we are writing there. |
197 | */ | 197 | */ |
198 | discard_lazy_cpu_state(); | 198 | discard_lazy_cpu_state(); |
199 | 199 | ||
200 | /* | 200 | /* |
201 | * Force reload of FP/VEC. | 201 | * Force reload of FP/VEC. |
202 | * This has to be done before copying stuff into current->thread.fpr/vr | 202 | * This has to be done before copying stuff into current->thread.fpr/vr |
203 | * for the reasons explained in the previous comment. | 203 | * for the reasons explained in the previous comment. |
204 | */ | 204 | */ |
205 | regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1 | MSR_VEC | MSR_VSX); | 205 | regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1 | MSR_VEC | MSR_VSX); |
206 | 206 | ||
207 | #ifdef CONFIG_ALTIVEC | 207 | #ifdef CONFIG_ALTIVEC |
208 | err |= __get_user(v_regs, &sc->v_regs); | 208 | err |= __get_user(v_regs, &sc->v_regs); |
209 | if (err) | 209 | if (err) |
210 | return err; | 210 | return err; |
211 | if (v_regs && !access_ok(VERIFY_READ, v_regs, 34 * sizeof(vector128))) | 211 | if (v_regs && !access_ok(VERIFY_READ, v_regs, 34 * sizeof(vector128))) |
212 | return -EFAULT; | 212 | return -EFAULT; |
213 | /* Copy 33 vec registers (vr0..31 and vscr) from the stack */ | 213 | /* Copy 33 vec registers (vr0..31 and vscr) from the stack */ |
214 | if (v_regs != 0 && (msr & MSR_VEC) != 0) | 214 | if (v_regs != 0 && (msr & MSR_VEC) != 0) |
215 | err |= __copy_from_user(current->thread.vr, v_regs, | 215 | err |= __copy_from_user(current->thread.vr, v_regs, |
216 | 33 * sizeof(vector128)); | 216 | 33 * sizeof(vector128)); |
217 | else if (current->thread.used_vr) | 217 | else if (current->thread.used_vr) |
218 | memset(current->thread.vr, 0, 33 * sizeof(vector128)); | 218 | memset(current->thread.vr, 0, 33 * sizeof(vector128)); |
219 | /* Always get VRSAVE back */ | 219 | /* Always get VRSAVE back */ |
220 | if (v_regs != 0) | 220 | if (v_regs != 0) |
221 | err |= __get_user(current->thread.vrsave, (u32 __user *)&v_regs[33]); | 221 | err |= __get_user(current->thread.vrsave, (u32 __user *)&v_regs[33]); |
222 | else | 222 | else |
223 | current->thread.vrsave = 0; | 223 | current->thread.vrsave = 0; |
224 | #endif /* CONFIG_ALTIVEC */ | 224 | #endif /* CONFIG_ALTIVEC */ |
225 | /* restore floating point */ | 225 | /* restore floating point */ |
226 | err |= copy_fpr_from_user(current, &sc->fp_regs); | 226 | err |= copy_fpr_from_user(current, &sc->fp_regs); |
227 | #ifdef CONFIG_VSX | 227 | #ifdef CONFIG_VSX |
228 | /* | 228 | /* |
229 | * Get additional VSX data. Update v_regs to point after the | 229 | * Get additional VSX data. Update v_regs to point after the |
230 | * VMX data. Copy VSX low doubleword from userspace to local | 230 | * VMX data. Copy VSX low doubleword from userspace to local |
231 | * buffer for formatting, then into the taskstruct. | 231 | * buffer for formatting, then into the taskstruct. |
232 | */ | 232 | */ |
233 | v_regs += ELF_NVRREG; | 233 | v_regs += ELF_NVRREG; |
234 | if ((msr & MSR_VSX) != 0) | 234 | if ((msr & MSR_VSX) != 0) |
235 | err |= copy_vsx_from_user(current, v_regs); | 235 | err |= copy_vsx_from_user(current, v_regs); |
236 | else | 236 | else |
237 | for (i = 0; i < 32 ; i++) | 237 | for (i = 0; i < 32 ; i++) |
238 | current->thread.fpr[i][TS_VSRLOWOFFSET] = 0; | 238 | current->thread.fpr[i][TS_VSRLOWOFFSET] = 0; |
239 | #endif | 239 | #endif |
240 | return err; | 240 | return err; |
241 | } | 241 | } |
242 | 242 | ||
243 | /* | 243 | /* |
244 | * Setup the trampoline code on the stack | 244 | * Setup the trampoline code on the stack |
245 | */ | 245 | */ |
246 | static long setup_trampoline(unsigned int syscall, unsigned int __user *tramp) | 246 | static long setup_trampoline(unsigned int syscall, unsigned int __user *tramp) |
247 | { | 247 | { |
248 | int i; | 248 | int i; |
249 | long err = 0; | 249 | long err = 0; |
250 | 250 | ||
251 | /* addi r1, r1, __SIGNAL_FRAMESIZE # Pop the dummy stackframe */ | 251 | /* addi r1, r1, __SIGNAL_FRAMESIZE # Pop the dummy stackframe */ |
252 | err |= __put_user(0x38210000UL | (__SIGNAL_FRAMESIZE & 0xffff), &tramp[0]); | 252 | err |= __put_user(0x38210000UL | (__SIGNAL_FRAMESIZE & 0xffff), &tramp[0]); |
253 | /* li r0, __NR_[rt_]sigreturn| */ | 253 | /* li r0, __NR_[rt_]sigreturn| */ |
254 | err |= __put_user(0x38000000UL | (syscall & 0xffff), &tramp[1]); | 254 | err |= __put_user(0x38000000UL | (syscall & 0xffff), &tramp[1]); |
255 | /* sc */ | 255 | /* sc */ |
256 | err |= __put_user(0x44000002UL, &tramp[2]); | 256 | err |= __put_user(0x44000002UL, &tramp[2]); |
257 | 257 | ||
258 | /* Minimal traceback info */ | 258 | /* Minimal traceback info */ |
259 | for (i=TRAMP_TRACEBACK; i < TRAMP_SIZE ;i++) | 259 | for (i=TRAMP_TRACEBACK; i < TRAMP_SIZE ;i++) |
260 | err |= __put_user(0, &tramp[i]); | 260 | err |= __put_user(0, &tramp[i]); |
261 | 261 | ||
262 | if (!err) | 262 | if (!err) |
263 | flush_icache_range((unsigned long) &tramp[0], | 263 | flush_icache_range((unsigned long) &tramp[0], |
264 | (unsigned long) &tramp[TRAMP_SIZE]); | 264 | (unsigned long) &tramp[TRAMP_SIZE]); |
265 | 265 | ||
266 | return err; | 266 | return err; |
267 | } | 267 | } |
268 | 268 | ||
269 | /* | 269 | /* |
270 | * Userspace code may pass a ucontext which doesn't include VSX added | 270 | * Userspace code may pass a ucontext which doesn't include VSX added |
271 | * at the end. We need to check for this case. | 271 | * at the end. We need to check for this case. |
272 | */ | 272 | */ |
273 | #define UCONTEXTSIZEWITHOUTVSX \ | 273 | #define UCONTEXTSIZEWITHOUTVSX \ |
274 | (sizeof(struct ucontext) - 32*sizeof(long)) | 274 | (sizeof(struct ucontext) - 32*sizeof(long)) |
275 | 275 | ||
276 | /* | 276 | /* |
277 | * Handle {get,set,swap}_context operations | 277 | * Handle {get,set,swap}_context operations |
278 | */ | 278 | */ |
279 | int sys_swapcontext(struct ucontext __user *old_ctx, | 279 | int sys_swapcontext(struct ucontext __user *old_ctx, |
280 | struct ucontext __user *new_ctx, | 280 | struct ucontext __user *new_ctx, |
281 | long ctx_size, long r6, long r7, long r8, struct pt_regs *regs) | 281 | long ctx_size, long r6, long r7, long r8, struct pt_regs *regs) |
282 | { | 282 | { |
283 | unsigned char tmp; | 283 | unsigned char tmp; |
284 | sigset_t set; | 284 | sigset_t set; |
285 | unsigned long new_msr = 0; | 285 | unsigned long new_msr = 0; |
286 | int ctx_has_vsx_region = 0; | 286 | int ctx_has_vsx_region = 0; |
287 | 287 | ||
288 | if (new_ctx && | 288 | if (new_ctx && |
289 | get_user(new_msr, &new_ctx->uc_mcontext.gp_regs[PT_MSR])) | 289 | get_user(new_msr, &new_ctx->uc_mcontext.gp_regs[PT_MSR])) |
290 | return -EFAULT; | 290 | return -EFAULT; |
291 | /* | 291 | /* |
292 | * Check that the context is not smaller than the original | 292 | * Check that the context is not smaller than the original |
293 | * size (with VMX but without VSX) | 293 | * size (with VMX but without VSX) |
294 | */ | 294 | */ |
295 | if (ctx_size < UCONTEXTSIZEWITHOUTVSX) | 295 | if (ctx_size < UCONTEXTSIZEWITHOUTVSX) |
296 | return -EINVAL; | 296 | return -EINVAL; |
297 | /* | 297 | /* |
298 | * If the new context state sets the MSR VSX bits but | 298 | * If the new context state sets the MSR VSX bits but |
299 | * it doesn't provide VSX state. | 299 | * it doesn't provide VSX state. |
300 | */ | 300 | */ |
301 | if ((ctx_size < sizeof(struct ucontext)) && | 301 | if ((ctx_size < sizeof(struct ucontext)) && |
302 | (new_msr & MSR_VSX)) | 302 | (new_msr & MSR_VSX)) |
303 | return -EINVAL; | 303 | return -EINVAL; |
304 | /* Does the context have enough room to store VSX data? */ | 304 | /* Does the context have enough room to store VSX data? */ |
305 | if (ctx_size >= sizeof(struct ucontext)) | 305 | if (ctx_size >= sizeof(struct ucontext)) |
306 | ctx_has_vsx_region = 1; | 306 | ctx_has_vsx_region = 1; |
307 | 307 | ||
308 | if (old_ctx != NULL) { | 308 | if (old_ctx != NULL) { |
309 | if (!access_ok(VERIFY_WRITE, old_ctx, ctx_size) | 309 | if (!access_ok(VERIFY_WRITE, old_ctx, ctx_size) |
310 | || setup_sigcontext(&old_ctx->uc_mcontext, regs, 0, NULL, 0, | 310 | || setup_sigcontext(&old_ctx->uc_mcontext, regs, 0, NULL, 0, |
311 | ctx_has_vsx_region) | 311 | ctx_has_vsx_region) |
312 | || __copy_to_user(&old_ctx->uc_sigmask, | 312 | || __copy_to_user(&old_ctx->uc_sigmask, |
313 | ¤t->blocked, sizeof(sigset_t))) | 313 | ¤t->blocked, sizeof(sigset_t))) |
314 | return -EFAULT; | 314 | return -EFAULT; |
315 | } | 315 | } |
316 | if (new_ctx == NULL) | 316 | if (new_ctx == NULL) |
317 | return 0; | 317 | return 0; |
318 | if (!access_ok(VERIFY_READ, new_ctx, ctx_size) | 318 | if (!access_ok(VERIFY_READ, new_ctx, ctx_size) |
319 | || __get_user(tmp, (u8 __user *) new_ctx) | 319 | || __get_user(tmp, (u8 __user *) new_ctx) |
320 | || __get_user(tmp, (u8 __user *) new_ctx + ctx_size - 1)) | 320 | || __get_user(tmp, (u8 __user *) new_ctx + ctx_size - 1)) |
321 | return -EFAULT; | 321 | return -EFAULT; |
322 | 322 | ||
323 | /* | 323 | /* |
324 | * If we get a fault copying the context into the kernel's | 324 | * If we get a fault copying the context into the kernel's |
325 | * image of the user's registers, we can't just return -EFAULT | 325 | * image of the user's registers, we can't just return -EFAULT |
326 | * because the user's registers will be corrupted. For instance | 326 | * because the user's registers will be corrupted. For instance |
327 | * the NIP value may have been updated but not some of the | 327 | * the NIP value may have been updated but not some of the |
328 | * other registers. Given that we have done the access_ok | 328 | * other registers. Given that we have done the access_ok |
329 | * and successfully read the first and last bytes of the region | 329 | * and successfully read the first and last bytes of the region |
330 | * above, this should only happen in an out-of-memory situation | 330 | * above, this should only happen in an out-of-memory situation |
331 | * or if another thread unmaps the region containing the context. | 331 | * or if another thread unmaps the region containing the context. |
332 | * We kill the task with a SIGSEGV in this situation. | 332 | * We kill the task with a SIGSEGV in this situation. |
333 | */ | 333 | */ |
334 | 334 | ||
335 | if (__copy_from_user(&set, &new_ctx->uc_sigmask, sizeof(set))) | 335 | if (__copy_from_user(&set, &new_ctx->uc_sigmask, sizeof(set))) |
336 | do_exit(SIGSEGV); | 336 | do_exit(SIGSEGV); |
337 | restore_sigmask(&set); | 337 | restore_sigmask(&set); |
338 | if (restore_sigcontext(regs, NULL, 0, &new_ctx->uc_mcontext)) | 338 | if (restore_sigcontext(regs, NULL, 0, &new_ctx->uc_mcontext)) |
339 | do_exit(SIGSEGV); | 339 | do_exit(SIGSEGV); |
340 | 340 | ||
341 | /* This returns like rt_sigreturn */ | 341 | /* This returns like rt_sigreturn */ |
342 | set_thread_flag(TIF_RESTOREALL); | 342 | set_thread_flag(TIF_RESTOREALL); |
343 | return 0; | 343 | return 0; |
344 | } | 344 | } |
345 | 345 | ||
346 | 346 | ||
347 | /* | 347 | /* |
348 | * Do a signal return; undo the signal stack. | 348 | * Do a signal return; undo the signal stack. |
349 | */ | 349 | */ |
350 | 350 | ||
351 | int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5, | 351 | int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5, |
352 | unsigned long r6, unsigned long r7, unsigned long r8, | 352 | unsigned long r6, unsigned long r7, unsigned long r8, |
353 | struct pt_regs *regs) | 353 | struct pt_regs *regs) |
354 | { | 354 | { |
355 | struct ucontext __user *uc = (struct ucontext __user *)regs->gpr[1]; | 355 | struct ucontext __user *uc = (struct ucontext __user *)regs->gpr[1]; |
356 | sigset_t set; | 356 | sigset_t set; |
357 | 357 | ||
358 | /* Always make any pending restarted system calls return -EINTR */ | 358 | /* Always make any pending restarted system calls return -EINTR */ |
359 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | 359 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
360 | 360 | ||
361 | if (!access_ok(VERIFY_READ, uc, sizeof(*uc))) | 361 | if (!access_ok(VERIFY_READ, uc, sizeof(*uc))) |
362 | goto badframe; | 362 | goto badframe; |
363 | 363 | ||
364 | if (__copy_from_user(&set, &uc->uc_sigmask, sizeof(set))) | 364 | if (__copy_from_user(&set, &uc->uc_sigmask, sizeof(set))) |
365 | goto badframe; | 365 | goto badframe; |
366 | restore_sigmask(&set); | 366 | restore_sigmask(&set); |
367 | if (restore_sigcontext(regs, NULL, 1, &uc->uc_mcontext)) | 367 | if (restore_sigcontext(regs, NULL, 1, &uc->uc_mcontext)) |
368 | goto badframe; | 368 | goto badframe; |
369 | 369 | ||
370 | /* do_sigaltstack expects a __user pointer and won't modify | 370 | /* do_sigaltstack expects a __user pointer and won't modify |
371 | * what's in there anyway | 371 | * what's in there anyway |
372 | */ | 372 | */ |
373 | do_sigaltstack(&uc->uc_stack, NULL, regs->gpr[1]); | 373 | do_sigaltstack(&uc->uc_stack, NULL, regs->gpr[1]); |
374 | 374 | ||
375 | set_thread_flag(TIF_RESTOREALL); | 375 | set_thread_flag(TIF_RESTOREALL); |
376 | return 0; | 376 | return 0; |
377 | 377 | ||
378 | badframe: | 378 | badframe: |
379 | #if DEBUG_SIG | 379 | #if DEBUG_SIG |
380 | printk("badframe in sys_rt_sigreturn, regs=%p uc=%p &uc->uc_mcontext=%p\n", | 380 | printk("badframe in sys_rt_sigreturn, regs=%p uc=%p &uc->uc_mcontext=%p\n", |
381 | regs, uc, &uc->uc_mcontext); | 381 | regs, uc, &uc->uc_mcontext); |
382 | #endif | 382 | #endif |
383 | if (show_unhandled_signals && printk_ratelimit()) | 383 | if (show_unhandled_signals && printk_ratelimit()) |
384 | printk(regs->msr & MSR_SF ? fmt64 : fmt32, | 384 | printk(regs->msr & MSR_SF ? fmt64 : fmt32, |
385 | current->comm, current->pid, "rt_sigreturn", | 385 | current->comm, current->pid, "rt_sigreturn", |
386 | (long)uc, regs->nip, regs->link); | 386 | (long)uc, regs->nip, regs->link); |
387 | 387 | ||
388 | force_sig(SIGSEGV, current); | 388 | force_sig(SIGSEGV, current); |
389 | return 0; | 389 | return 0; |
390 | } | 390 | } |
391 | 391 | ||
392 | int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info, | 392 | int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info, |
393 | sigset_t *set, struct pt_regs *regs) | 393 | sigset_t *set, struct pt_regs *regs) |
394 | { | 394 | { |
395 | /* Handler is *really* a pointer to the function descriptor for | 395 | /* Handler is *really* a pointer to the function descriptor for |
396 | * the signal routine. The first entry in the function | 396 | * the signal routine. The first entry in the function |
397 | * descriptor is the entry address of signal and the second | 397 | * descriptor is the entry address of signal and the second |
398 | * entry is the TOC value we need to use. | 398 | * entry is the TOC value we need to use. |
399 | */ | 399 | */ |
400 | func_descr_t __user *funct_desc_ptr; | 400 | func_descr_t __user *funct_desc_ptr; |
401 | struct rt_sigframe __user *frame; | 401 | struct rt_sigframe __user *frame; |
402 | unsigned long newsp = 0; | 402 | unsigned long newsp = 0; |
403 | long err = 0; | 403 | long err = 0; |
404 | 404 | ||
405 | frame = get_sigframe(ka, regs, sizeof(*frame), 0); | 405 | frame = get_sigframe(ka, regs, sizeof(*frame), 0); |
406 | if (unlikely(frame == NULL)) | 406 | if (unlikely(frame == NULL)) |
407 | goto badframe; | 407 | goto badframe; |
408 | 408 | ||
409 | err |= __put_user(&frame->info, &frame->pinfo); | 409 | err |= __put_user(&frame->info, &frame->pinfo); |
410 | err |= __put_user(&frame->uc, &frame->puc); | 410 | err |= __put_user(&frame->uc, &frame->puc); |
411 | err |= copy_siginfo_to_user(&frame->info, info); | 411 | err |= copy_siginfo_to_user(&frame->info, info); |
412 | if (err) | 412 | if (err) |
413 | goto badframe; | 413 | goto badframe; |
414 | 414 | ||
415 | /* Create the ucontext. */ | 415 | /* Create the ucontext. */ |
416 | err |= __put_user(0, &frame->uc.uc_flags); | 416 | err |= __put_user(0, &frame->uc.uc_flags); |
417 | err |= __put_user(0, &frame->uc.uc_link); | 417 | err |= __put_user(0, &frame->uc.uc_link); |
418 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); | 418 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
419 | err |= __put_user(sas_ss_flags(regs->gpr[1]), | 419 | err |= __put_user(sas_ss_flags(regs->gpr[1]), |
420 | &frame->uc.uc_stack.ss_flags); | 420 | &frame->uc.uc_stack.ss_flags); |
421 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); | 421 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
422 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, signr, NULL, | 422 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, signr, NULL, |
423 | (unsigned long)ka->sa.sa_handler, 1); | 423 | (unsigned long)ka->sa.sa_handler, 1); |
424 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); | 424 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
425 | if (err) | 425 | if (err) |
426 | goto badframe; | 426 | goto badframe; |
427 | 427 | ||
428 | /* Make sure signal handler doesn't get spurious FP exceptions */ | 428 | /* Make sure signal handler doesn't get spurious FP exceptions */ |
429 | current->thread.fpscr.val = 0; | 429 | current->thread.fpscr.val = 0; |
430 | 430 | ||
431 | /* Set up to return from userspace. */ | 431 | /* Set up to return from userspace. */ |
432 | if (vdso64_rt_sigtramp && current->mm->context.vdso_base) { | 432 | if (vdso64_rt_sigtramp && current->mm->context.vdso_base) { |
433 | regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp; | 433 | regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp; |
434 | } else { | 434 | } else { |
435 | err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]); | 435 | err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]); |
436 | if (err) | 436 | if (err) |
437 | goto badframe; | 437 | goto badframe; |
438 | regs->link = (unsigned long) &frame->tramp[0]; | 438 | regs->link = (unsigned long) &frame->tramp[0]; |
439 | } | 439 | } |
440 | funct_desc_ptr = (func_descr_t __user *) ka->sa.sa_handler; | 440 | funct_desc_ptr = (func_descr_t __user *) ka->sa.sa_handler; |
441 | 441 | ||
442 | /* Allocate a dummy caller frame for the signal handler. */ | 442 | /* Allocate a dummy caller frame for the signal handler. */ |
443 | newsp = ((unsigned long)frame) - __SIGNAL_FRAMESIZE; | 443 | newsp = ((unsigned long)frame) - __SIGNAL_FRAMESIZE; |
444 | err |= put_user(regs->gpr[1], (unsigned long __user *)newsp); | 444 | err |= put_user(regs->gpr[1], (unsigned long __user *)newsp); |
445 | 445 | ||
446 | /* Set up "regs" so we "return" to the signal handler. */ | 446 | /* Set up "regs" so we "return" to the signal handler. */ |
447 | err |= get_user(regs->nip, &funct_desc_ptr->entry); | 447 | err |= get_user(regs->nip, &funct_desc_ptr->entry); |
448 | /* enter the signal handler in big-endian mode */ | 448 | /* enter the signal handler in big-endian mode */ |
449 | regs->msr &= ~MSR_LE; | 449 | regs->msr &= ~MSR_LE; |
450 | regs->gpr[1] = newsp; | 450 | regs->gpr[1] = newsp; |
451 | err |= get_user(regs->gpr[2], &funct_desc_ptr->toc); | 451 | err |= get_user(regs->gpr[2], &funct_desc_ptr->toc); |
452 | regs->gpr[3] = signr; | 452 | regs->gpr[3] = signr; |
453 | regs->result = 0; | 453 | regs->result = 0; |
454 | if (ka->sa.sa_flags & SA_SIGINFO) { | 454 | if (ka->sa.sa_flags & SA_SIGINFO) { |
455 | err |= get_user(regs->gpr[4], (unsigned long __user *)&frame->pinfo); | 455 | err |= get_user(regs->gpr[4], (unsigned long __user *)&frame->pinfo); |
456 | err |= get_user(regs->gpr[5], (unsigned long __user *)&frame->puc); | 456 | err |= get_user(regs->gpr[5], (unsigned long __user *)&frame->puc); |
457 | regs->gpr[6] = (unsigned long) frame; | 457 | regs->gpr[6] = (unsigned long) frame; |
458 | } else { | 458 | } else { |
459 | regs->gpr[4] = (unsigned long)&frame->uc.uc_mcontext; | 459 | regs->gpr[4] = (unsigned long)&frame->uc.uc_mcontext; |
460 | } | 460 | } |
461 | if (err) | 461 | if (err) |
462 | goto badframe; | 462 | goto badframe; |
463 | 463 | ||
464 | return 1; | 464 | return 1; |
465 | 465 | ||
466 | badframe: | 466 | badframe: |
467 | #if DEBUG_SIG | 467 | #if DEBUG_SIG |
468 | printk("badframe in setup_rt_frame, regs=%p frame=%p newsp=%lx\n", | 468 | printk("badframe in setup_rt_frame, regs=%p frame=%p newsp=%lx\n", |
469 | regs, frame, newsp); | 469 | regs, frame, newsp); |
470 | #endif | 470 | #endif |
471 | if (show_unhandled_signals && printk_ratelimit()) | 471 | if (show_unhandled_signals && printk_ratelimit()) |
472 | printk(regs->msr & MSR_SF ? fmt64 : fmt32, | 472 | printk(regs->msr & MSR_SF ? fmt64 : fmt32, |
473 | current->comm, current->pid, "setup_rt_frame", | 473 | current->comm, current->pid, "setup_rt_frame", |
474 | (long)frame, regs->nip, regs->link); | 474 | (long)frame, regs->nip, regs->link); |
475 | 475 | ||
476 | force_sigsegv(signr, current); | 476 | force_sigsegv(signr, current); |
477 | return 0; | 477 | return 0; |
478 | } | 478 | } |
479 | 479 |