aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/sys-x86_64/signal.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/sys-x86_64/signal.c')
-rw-r--r--arch/um/sys-x86_64/signal.c276
1 files changed, 276 insertions, 0 deletions
diff --git a/arch/um/sys-x86_64/signal.c b/arch/um/sys-x86_64/signal.c
new file mode 100644
index 000000000000..5bc5a0d796e5
--- /dev/null
+++ b/arch/um/sys-x86_64/signal.c
@@ -0,0 +1,276 @@
1/*
2 * Copyright (C) 2003 PathScale, Inc.
3 * Licensed under the GPL
4 */
5
6#include "linux/stddef.h"
7#include "linux/errno.h"
8#include "linux/personality.h"
9#include "linux/ptrace.h"
10#include "asm/current.h"
11#include "asm/uaccess.h"
12#include "asm/sigcontext.h"
13#include "asm/ptrace.h"
14#include "asm/arch/ucontext.h"
15#include "choose-mode.h"
16#include "sysdep/ptrace.h"
17#include "frame_kern.h"
18
19#ifdef CONFIG_MODE_SKAS
20
21#include "skas.h"
22
23static int copy_sc_from_user_skas(struct pt_regs *regs,
24 struct sigcontext *from)
25{
26 int err = 0;
27
28#define GETREG(regs, regno, sc, regname) \
29 __get_user((regs)->regs.skas.regs[(regno) / sizeof(unsigned long)], \
30 &(sc)->regname)
31
32 err |= GETREG(regs, R8, from, r8);
33 err |= GETREG(regs, R9, from, r9);
34 err |= GETREG(regs, R10, from, r10);
35 err |= GETREG(regs, R11, from, r11);
36 err |= GETREG(regs, R12, from, r12);
37 err |= GETREG(regs, R13, from, r13);
38 err |= GETREG(regs, R14, from, r14);
39 err |= GETREG(regs, R15, from, r15);
40 err |= GETREG(regs, RDI, from, rdi);
41 err |= GETREG(regs, RSI, from, rsi);
42 err |= GETREG(regs, RBP, from, rbp);
43 err |= GETREG(regs, RBX, from, rbx);
44 err |= GETREG(regs, RDX, from, rdx);
45 err |= GETREG(regs, RAX, from, rax);
46 err |= GETREG(regs, RCX, from, rcx);
47 err |= GETREG(regs, RSP, from, rsp);
48 err |= GETREG(regs, RIP, from, rip);
49 err |= GETREG(regs, EFLAGS, from, eflags);
50 err |= GETREG(regs, CS, from, cs);
51
52#undef GETREG
53
54 return(err);
55}
56
57int copy_sc_to_user_skas(struct sigcontext *to, struct _fpstate *to_fp,
58 struct pt_regs *regs, unsigned long mask)
59{
60 unsigned long eflags;
61 int err = 0;
62
63 err |= __put_user(0, &to->gs);
64 err |= __put_user(0, &to->fs);
65
66#define PUTREG(regs, regno, sc, regname) \
67 __put_user((regs)->regs.skas.regs[(regno) / sizeof(unsigned long)], \
68 &(sc)->regname)
69
70 err |= PUTREG(regs, RDI, to, rdi);
71 err |= PUTREG(regs, RSI, to, rsi);
72 err |= PUTREG(regs, RBP, to, rbp);
73 err |= PUTREG(regs, RSP, to, rsp);
74 err |= PUTREG(regs, RBX, to, rbx);
75 err |= PUTREG(regs, RDX, to, rdx);
76 err |= PUTREG(regs, RCX, to, rcx);
77 err |= PUTREG(regs, RAX, to, rax);
78 err |= PUTREG(regs, R8, to, r8);
79 err |= PUTREG(regs, R9, to, r9);
80 err |= PUTREG(regs, R10, to, r10);
81 err |= PUTREG(regs, R11, to, r11);
82 err |= PUTREG(regs, R12, to, r12);
83 err |= PUTREG(regs, R13, to, r13);
84 err |= PUTREG(regs, R14, to, r14);
85 err |= PUTREG(regs, R15, to, r15);
86 err |= PUTREG(regs, CS, to, cs); /* XXX x86_64 doesn't do this */
87 err |= __put_user(current->thread.err, &to->err);
88 err |= __put_user(current->thread.trap_no, &to->trapno);
89 err |= PUTREG(regs, RIP, to, rip);
90 err |= PUTREG(regs, EFLAGS, to, eflags);
91#undef PUTREG
92
93 err |= __put_user(mask, &to->oldmask);
94 err |= __put_user(current->thread.cr2, &to->cr2);
95
96 return(err);
97}
98
99#endif
100
101#ifdef CONFIG_MODE_TT
102int copy_sc_from_user_tt(struct sigcontext *to, struct sigcontext *from,
103 int fpsize)
104{
105 struct _fpstate *to_fp, *from_fp;
106 unsigned long sigs;
107 int err;
108
109 to_fp = to->fpstate;
110 from_fp = from->fpstate;
111 sigs = to->oldmask;
112 err = copy_from_user(to, from, sizeof(*to));
113 to->oldmask = sigs;
114 return(err);
115}
116
117int copy_sc_to_user_tt(struct sigcontext *to, struct _fpstate *fp,
118 struct sigcontext *from, int fpsize)
119{
120 struct _fpstate *to_fp, *from_fp;
121 int err;
122
123 to_fp = (fp ? fp : (struct _fpstate *) (to + 1));
124 from_fp = from->fpstate;
125 err = copy_to_user(to, from, sizeof(*to));
126 return(err);
127}
128
129#endif
130
131static int copy_sc_from_user(struct pt_regs *to, void __user *from)
132{
133 int ret;
134
135 ret = CHOOSE_MODE(copy_sc_from_user_tt(UPT_SC(&to->regs), from,
136 sizeof(struct _fpstate)),
137 copy_sc_from_user_skas(to, from));
138 return(ret);
139}
140
141static int copy_sc_to_user(struct sigcontext *to, struct _fpstate *fp,
142 struct pt_regs *from, unsigned long mask)
143{
144 return(CHOOSE_MODE(copy_sc_to_user_tt(to, fp, UPT_SC(&from->regs),
145 sizeof(*fp)),
146 copy_sc_to_user_skas(to, fp, from, mask)));
147}
148
149struct rt_sigframe
150{
151 char *pretcode;
152 struct ucontext uc;
153 struct siginfo info;
154};
155
156#define round_down(m, n) (((m) / (n)) * (n))
157
158int setup_signal_stack_si(unsigned long stack_top, int sig,
159 struct k_sigaction *ka, struct pt_regs * regs,
160 siginfo_t *info, sigset_t *set)
161{
162 struct rt_sigframe __user *frame;
163 struct _fpstate __user *fp = NULL;
164 int err = 0;
165 struct task_struct *me = current;
166
167 frame = (struct rt_sigframe __user *)
168 round_down(stack_top - sizeof(struct rt_sigframe), 16) - 8;
169 frame -= 128;
170
171 if (!access_ok(VERIFY_WRITE, fp, sizeof(struct _fpstate)))
172 goto out;
173
174#if 0 /* XXX */
175 if (save_i387(fp) < 0)
176 err |= -1;
177#endif
178 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
179 goto out;
180
181 if (ka->sa.sa_flags & SA_SIGINFO) {
182 err |= copy_siginfo_to_user(&frame->info, info);
183 if (err)
184 goto out;
185 }
186
187 /* Create the ucontext. */
188 err |= __put_user(0, &frame->uc.uc_flags);
189 err |= __put_user(0, &frame->uc.uc_link);
190 err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
191 err |= __put_user(sas_ss_flags(PT_REGS_SP(regs)),
192 &frame->uc.uc_stack.ss_flags);
193 err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
194 err |= copy_sc_to_user(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
195 err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate);
196 if (sizeof(*set) == 16) {
197 __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
198 __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
199 }
200 else
201 err |= __copy_to_user(&frame->uc.uc_sigmask, set,
202 sizeof(*set));
203
204 /* Set up to return from userspace. If provided, use a stub
205 already in userspace. */
206 /* x86-64 should always use SA_RESTORER. */
207 if (ka->sa.sa_flags & SA_RESTORER)
208 err |= __put_user(ka->sa.sa_restorer, &frame->pretcode);
209 else
210 /* could use a vstub here */
211 goto out;
212
213 if (err)
214 goto out;
215
216 /* Set up registers for signal handler */
217 {
218 struct exec_domain *ed = current_thread_info()->exec_domain;
219 if (unlikely(ed && ed->signal_invmap && sig < 32))
220 sig = ed->signal_invmap[sig];
221 }
222
223 PT_REGS_RDI(regs) = sig;
224 /* In case the signal handler was declared without prototypes */
225 PT_REGS_RAX(regs) = 0;
226
227 /* This also works for non SA_SIGINFO handlers because they expect the
228 next argument after the signal number on the stack. */
229 PT_REGS_RSI(regs) = (unsigned long) &frame->info;
230 PT_REGS_RDX(regs) = (unsigned long) &frame->uc;
231 PT_REGS_RIP(regs) = (unsigned long) ka->sa.sa_handler;
232
233 PT_REGS_RSP(regs) = (unsigned long) frame;
234 out:
235 return(err);
236}
237
238long sys_rt_sigreturn(struct pt_regs *regs)
239{
240 unsigned long sp = PT_REGS_SP(&current->thread.regs);
241 struct rt_sigframe __user *frame =
242 (struct rt_sigframe __user *)(sp - 8);
243 struct ucontext __user *uc = &frame->uc;
244 sigset_t set;
245
246 if(copy_from_user(&set, &uc->uc_sigmask, sizeof(set)))
247 goto segfault;
248
249 sigdelsetmask(&set, ~_BLOCKABLE);
250
251 spin_lock_irq(&current->sighand->siglock);
252 current->blocked = set;
253 recalc_sigpending();
254 spin_unlock_irq(&current->sighand->siglock);
255
256 if(copy_sc_from_user(&current->thread.regs, &uc->uc_mcontext))
257 goto segfault;
258
259 /* Avoid ERESTART handling */
260 PT_REGS_SYSCALL_NR(&current->thread.regs) = -1;
261 return(PT_REGS_SYSCALL_RET(&current->thread.regs));
262
263 segfault:
264 force_sig(SIGSEGV, current);
265 return 0;
266}
267/*
268 * Overrides for Emacs so that we follow Linus's tabbing style.
269 * Emacs will notice this stuff at the end of the file and automatically
270 * adjust the settings for this buffer only. This must remain at the end
271 * of the file.
272 * ---------------------------------------------------------------------------
273 * Local variables:
274 * c-file-style: "linux"
275 * End:
276 */