[MIPS] Always pass -msoft-float.
[linux-2.6/openmoko-kernel/knife-kernel.git] / arch / um / sys-x86_64 / signal.c
blobfe1d065332b11d33f215a8f4a43654be69aff7a9
1 /*
2 * Copyright (C) 2003 PathScale, Inc.
3 * Licensed under the GPL
4 */
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"
19 #ifdef CONFIG_MODE_SKAS
21 #include "skas.h"
23 static int copy_sc_from_user_skas(struct pt_regs *regs,
24 struct sigcontext *from)
26 int err = 0;
28 #define GETREG(regs, regno, sc, regname) \
29 __get_user((regs)->regs.skas.regs[(regno) / sizeof(unsigned long)], \
30 &(sc)->regname)
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);
52 #undef GETREG
54 return(err);
57 int copy_sc_to_user_skas(struct sigcontext *to, struct _fpstate *to_fp,
58 struct pt_regs *regs, unsigned long mask)
60 struct faultinfo * fi = &current->thread.arch.faultinfo;
61 int err = 0;
63 err |= __put_user(0, &to->gs);
64 err |= __put_user(0, &to->fs);
66 #define PUTREG(regs, regno, sc, regname) \
67 __put_user((regs)->regs.skas.regs[(regno) / sizeof(unsigned long)], \
68 &(sc)->regname)
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 */
88 err |= __put_user(fi->cr2, &to->cr2);
89 err |= __put_user(fi->error_code, &to->err);
90 err |= __put_user(fi->trap_no, &to->trapno);
92 err |= PUTREG(regs, RIP, to, rip);
93 err |= PUTREG(regs, EFLAGS, to, eflags);
94 #undef PUTREG
96 err |= __put_user(mask, &to->oldmask);
98 return(err);
101 #endif
103 #ifdef CONFIG_MODE_TT
104 int copy_sc_from_user_tt(struct sigcontext *to, struct sigcontext *from,
105 int fpsize)
107 struct _fpstate *to_fp, *from_fp;
108 unsigned long sigs;
109 int err;
111 to_fp = to->fpstate;
112 sigs = to->oldmask;
113 err = copy_from_user(to, from, sizeof(*to));
114 from_fp = to->fpstate;
115 to->fpstate = to_fp;
116 to->oldmask = sigs;
117 if(to_fp != NULL)
118 err |= copy_from_user(to_fp, from_fp, fpsize);
119 return(err);
122 int copy_sc_to_user_tt(struct sigcontext *to, struct _fpstate *fp,
123 struct sigcontext *from, int fpsize)
125 struct _fpstate *to_fp, *from_fp;
126 int err;
128 to_fp = (fp ? fp : (struct _fpstate *) (to + 1));
129 from_fp = from->fpstate;
130 err = copy_to_user(to, from, sizeof(*to));
131 if(from_fp != NULL){
132 err |= copy_to_user(&to->fpstate, &to_fp, sizeof(to->fpstate));
133 err |= copy_to_user(to_fp, from_fp, fpsize);
135 return(err);
138 #endif
140 static int copy_sc_from_user(struct pt_regs *to, void __user *from)
142 int ret;
144 ret = CHOOSE_MODE(copy_sc_from_user_tt(UPT_SC(&to->regs), from,
145 sizeof(struct _fpstate)),
146 copy_sc_from_user_skas(to, from));
147 return(ret);
150 static int copy_sc_to_user(struct sigcontext *to, struct _fpstate *fp,
151 struct pt_regs *from, unsigned long mask)
153 return(CHOOSE_MODE(copy_sc_to_user_tt(to, fp, UPT_SC(&from->regs),
154 sizeof(*fp)),
155 copy_sc_to_user_skas(to, fp, from, mask)));
158 struct rt_sigframe
160 char *pretcode;
161 struct ucontext uc;
162 struct siginfo info;
165 #define round_down(m, n) (((m) / (n)) * (n))
167 int setup_signal_stack_si(unsigned long stack_top, int sig,
168 struct k_sigaction *ka, struct pt_regs * regs,
169 siginfo_t *info, sigset_t *set)
171 struct rt_sigframe __user *frame;
172 struct _fpstate __user *fp = NULL;
173 int err = 0;
174 struct task_struct *me = current;
176 frame = (struct rt_sigframe __user *)
177 round_down(stack_top - sizeof(struct rt_sigframe), 16) - 8;
178 frame = (struct rt_sigframe *) ((unsigned long) frame - 128);
180 if (!access_ok(VERIFY_WRITE, fp, sizeof(struct _fpstate)))
181 goto out;
183 #if 0 /* XXX */
184 if (save_i387(fp) < 0)
185 err |= -1;
186 #endif
187 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
188 goto out;
190 if (ka->sa.sa_flags & SA_SIGINFO) {
191 err |= copy_siginfo_to_user(&frame->info, info);
192 if (err)
193 goto out;
196 /* Create the ucontext. */
197 err |= __put_user(0, &frame->uc.uc_flags);
198 err |= __put_user(0, &frame->uc.uc_link);
199 err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
200 err |= __put_user(sas_ss_flags(PT_REGS_SP(regs)),
201 &frame->uc.uc_stack.ss_flags);
202 err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
203 err |= copy_sc_to_user(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
204 err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate);
205 if (sizeof(*set) == 16) {
206 __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
207 __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
209 else
210 err |= __copy_to_user(&frame->uc.uc_sigmask, set,
211 sizeof(*set));
213 /* Set up to return from userspace. If provided, use a stub
214 already in userspace. */
215 /* x86-64 should always use SA_RESTORER. */
216 if (ka->sa.sa_flags & SA_RESTORER)
217 err |= __put_user(ka->sa.sa_restorer, &frame->pretcode);
218 else
219 /* could use a vstub here */
220 goto out;
222 if (err)
223 goto out;
225 /* Set up registers for signal handler */
227 struct exec_domain *ed = current_thread_info()->exec_domain;
228 if (unlikely(ed && ed->signal_invmap && sig < 32))
229 sig = ed->signal_invmap[sig];
232 PT_REGS_RDI(regs) = sig;
233 /* In case the signal handler was declared without prototypes */
234 PT_REGS_RAX(regs) = 0;
236 /* This also works for non SA_SIGINFO handlers because they expect the
237 next argument after the signal number on the stack. */
238 PT_REGS_RSI(regs) = (unsigned long) &frame->info;
239 PT_REGS_RDX(regs) = (unsigned long) &frame->uc;
240 PT_REGS_RIP(regs) = (unsigned long) ka->sa.sa_handler;
242 PT_REGS_RSP(regs) = (unsigned long) frame;
243 out:
244 return(err);
247 long sys_rt_sigreturn(struct pt_regs *regs)
249 unsigned long sp = PT_REGS_SP(&current->thread.regs);
250 struct rt_sigframe __user *frame =
251 (struct rt_sigframe __user *)(sp - 8);
252 struct ucontext __user *uc = &frame->uc;
253 sigset_t set;
255 if(copy_from_user(&set, &uc->uc_sigmask, sizeof(set)))
256 goto segfault;
258 sigdelsetmask(&set, ~_BLOCKABLE);
260 spin_lock_irq(&current->sighand->siglock);
261 current->blocked = set;
262 recalc_sigpending();
263 spin_unlock_irq(&current->sighand->siglock);
265 if(copy_sc_from_user(&current->thread.regs, &uc->uc_mcontext))
266 goto segfault;
268 /* Avoid ERESTART handling */
269 PT_REGS_SYSCALL_NR(&current->thread.regs) = -1;
270 return(PT_REGS_SYSCALL_RET(&current->thread.regs));
272 segfault:
273 force_sig(SIGSEGV, current);
274 return 0;
277 * Overrides for Emacs so that we follow Linus's tabbing style.
278 * Emacs will notice this stuff at the end of the file and automatically
279 * adjust the settings for this buffer only. This must remain at the end
280 * of the file.
281 * ---------------------------------------------------------------------------
282 * Local variables:
283 * c-file-style: "linux"
284 * End: