2 * PowerPC signal handling routines
4 * Copyright 2002 Marcus Meissner, SuSE Linux AG
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
35 #ifdef HAVE_SYS_PARAM_H
36 # include <sys/param.h>
41 # ifdef HAVE_SYS_SYSCALL_H
42 # include <sys/syscall.h>
46 #ifdef HAVE_SYS_SIGNAL_H
47 # include <sys/signal.h>
51 #define WIN32_NO_STATUS
54 #include "wine/library.h"
55 #include "wine/exception.h"
56 #include "ntdll_misc.h"
57 #include "wine/debug.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(seh
);
61 static pthread_key_t teb_key
;
63 /***********************************************************************
64 * signal context platform-specific definitions
68 /* All Registers access - only for local access */
69 # define REG_sig(reg_name, context) ((context)->uc_mcontext.regs->reg_name)
72 /* Gpr Registers access */
73 # define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context)
75 # define IAR_sig(context) REG_sig(nip, context) /* Program counter */
76 # define MSR_sig(context) REG_sig(msr, context) /* Machine State Register (Supervisor) */
77 # define CTR_sig(context) REG_sig(ctr, context) /* Count register */
79 # define XER_sig(context) REG_sig(xer, context) /* User's integer exception register */
80 # define LR_sig(context) REG_sig(link, context) /* Link register */
81 # define CR_sig(context) REG_sig(ccr, context) /* Condition register */
83 /* Float Registers access */
84 # define FLOAT_sig(reg_num, context) (((double*)((char*)((context)->uc_mcontext.regs+48*4)))[reg_num])
86 # define FPSCR_sig(context) (*(int*)((char*)((context)->uc_mcontext.regs+(48+32*2)*4)))
88 /* Exception Registers access */
89 # define DAR_sig(context) REG_sig(dar, context)
90 # define DSISR_sig(context) REG_sig(dsisr, context)
91 # define TRAP_sig(context) REG_sig(trap, context)
97 # include <sys/ucontext.h>
98 # include <sys/types.h>
100 /* All Registers access - only for local access */
101 # define REG_sig(reg_name, context) ((context)->uc_mcontext->ss.reg_name)
102 # define FLOATREG_sig(reg_name, context) ((context)->uc_mcontext->fs.reg_name)
103 # define EXCEPREG_sig(reg_name, context) ((context)->uc_mcontext->es.reg_name)
104 # define VECREG_sig(reg_name, context) ((context)->uc_mcontext->vs.reg_name)
106 /* Gpr Registers access */
107 # define GPR_sig(reg_num, context) REG_sig(r##reg_num, context)
109 # define IAR_sig(context) REG_sig(srr0, context) /* Program counter */
110 # define MSR_sig(context) REG_sig(srr1, context) /* Machine State Register (Supervisor) */
111 # define CTR_sig(context) REG_sig(ctr, context)
113 # define XER_sig(context) REG_sig(xer, context) /* Link register */
114 # define LR_sig(context) REG_sig(lr, context) /* User's integer exception register */
115 # define CR_sig(context) REG_sig(cr, context) /* Condition register */
117 /* Float Registers access */
118 # define FLOAT_sig(reg_num, context) FLOATREG_sig(fpregs[reg_num], context)
120 # define FPSCR_sig(context) FLOATREG_sig(fpscr, context)
122 /* Exception Registers access */
123 # define DAR_sig(context) EXCEPREG_sig(dar, context) /* Fault registers for coredump */
124 # define DSISR_sig(context) EXCEPREG_sig(dsisr, context)
125 # define TRAP_sig(context) EXCEPREG_sig(exception, context) /* number of powerpc exception taken */
127 /* Signal defs : Those are undefined on darwin
144 #endif /* __APPLE__ */
148 typedef int (*wine_signal_handler
)(unsigned int sig
);
150 static wine_signal_handler handlers
[256];
152 /***********************************************************************
155 static inline int dispatch_signal(unsigned int sig
)
157 if (handlers
[sig
] == NULL
) return 0;
158 return handlers
[sig
](sig
);
161 /***********************************************************************
164 * Set the register values from a sigcontext.
166 static void save_context( CONTEXT
*context
, const ucontext_t
*sigcontext
)
169 #define C(x) context->Gpr##x = GPR_sig(x,sigcontext)
170 /* Save Gpr registers */
171 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
172 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
173 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
177 context
->Iar
= IAR_sig(sigcontext
); /* Program Counter */
178 context
->Msr
= MSR_sig(sigcontext
); /* Machine State Register (Supervisor) */
179 context
->Ctr
= CTR_sig(sigcontext
);
181 context
->Xer
= XER_sig(sigcontext
);
182 context
->Lr
= LR_sig(sigcontext
);
183 context
->Cr
= CR_sig(sigcontext
);
185 /* Saving Exception regs */
186 context
->Dar
= DAR_sig(sigcontext
);
187 context
->Dsisr
= DSISR_sig(sigcontext
);
188 context
->Trap
= TRAP_sig(sigcontext
);
192 /***********************************************************************
195 * Build a sigcontext from the register values.
197 static void restore_context( const CONTEXT
*context
, ucontext_t
*sigcontext
)
200 #define C(x) GPR_sig(x,sigcontext) = context->Gpr##x
201 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
202 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
203 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
207 IAR_sig(sigcontext
) = context
->Iar
; /* Program Counter */
208 MSR_sig(sigcontext
) = context
->Msr
; /* Machine State Register (Supervisor) */
209 CTR_sig(sigcontext
) = context
->Ctr
;
211 XER_sig(sigcontext
) = context
->Xer
;
212 LR_sig(sigcontext
) = context
->Lr
;
213 CR_sig(sigcontext
) = context
->Cr
;
215 /* Setting Exception regs */
216 DAR_sig(sigcontext
) = context
->Dar
;
217 DSISR_sig(sigcontext
) = context
->Dsisr
;
218 TRAP_sig(sigcontext
) = context
->Trap
;
222 /***********************************************************************
225 * Set the FPU context from a sigcontext.
227 static inline void save_fpu( CONTEXT
*context
, const ucontext_t
*sigcontext
)
229 #define C(x) context->Fpr##x = FLOAT_sig(x,sigcontext)
230 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
231 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
232 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
235 context
->Fpscr
= FPSCR_sig(sigcontext
);
239 /***********************************************************************
242 * Restore the FPU context to a sigcontext.
244 static inline void restore_fpu( CONTEXT
*context
, const ucontext_t
*sigcontext
)
246 #define C(x) FLOAT_sig(x,sigcontext) = context->Fpr##x
247 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
248 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
249 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
252 FPSCR_sig(sigcontext
) = context
->Fpscr
;
256 /***********************************************************************
257 * RtlCaptureContext (NTDLL.@)
259 void WINAPI
RtlCaptureContext( CONTEXT
*context
)
261 FIXME("not implemented\n");
262 memset( context
, 0, sizeof(*context
) );
266 /***********************************************************************
269 * Set the new CPU context.
271 void set_cpu_context( const CONTEXT
*context
)
273 FIXME("not implemented\n");
277 /***********************************************************************
280 * Copy a register context according to the flags.
282 void copy_context( CONTEXT
*to
, const CONTEXT
*from
, DWORD flags
)
284 if (flags
& CONTEXT_CONTROL
)
291 to
->Dsisr
= from
->Dsisr
;
292 to
->Trap
= from
->Trap
;
294 if (flags
& CONTEXT_INTEGER
)
296 to
->Gpr0
= from
->Gpr0
;
297 to
->Gpr1
= from
->Gpr1
;
298 to
->Gpr2
= from
->Gpr2
;
299 to
->Gpr3
= from
->Gpr3
;
300 to
->Gpr4
= from
->Gpr4
;
301 to
->Gpr5
= from
->Gpr5
;
302 to
->Gpr6
= from
->Gpr6
;
303 to
->Gpr7
= from
->Gpr7
;
304 to
->Gpr8
= from
->Gpr8
;
305 to
->Gpr9
= from
->Gpr9
;
306 to
->Gpr10
= from
->Gpr10
;
307 to
->Gpr11
= from
->Gpr11
;
308 to
->Gpr12
= from
->Gpr12
;
309 to
->Gpr13
= from
->Gpr13
;
310 to
->Gpr14
= from
->Gpr14
;
311 to
->Gpr15
= from
->Gpr15
;
312 to
->Gpr16
= from
->Gpr16
;
313 to
->Gpr17
= from
->Gpr17
;
314 to
->Gpr18
= from
->Gpr18
;
315 to
->Gpr19
= from
->Gpr19
;
316 to
->Gpr20
= from
->Gpr20
;
317 to
->Gpr21
= from
->Gpr21
;
318 to
->Gpr22
= from
->Gpr22
;
319 to
->Gpr23
= from
->Gpr23
;
320 to
->Gpr24
= from
->Gpr24
;
321 to
->Gpr25
= from
->Gpr25
;
322 to
->Gpr26
= from
->Gpr26
;
323 to
->Gpr27
= from
->Gpr27
;
324 to
->Gpr28
= from
->Gpr28
;
325 to
->Gpr29
= from
->Gpr29
;
326 to
->Gpr30
= from
->Gpr30
;
327 to
->Gpr31
= from
->Gpr31
;
331 if (flags
& CONTEXT_FLOATING_POINT
)
333 to
->Fpr0
= from
->Fpr0
;
334 to
->Fpr1
= from
->Fpr1
;
335 to
->Fpr2
= from
->Fpr2
;
336 to
->Fpr3
= from
->Fpr3
;
337 to
->Fpr4
= from
->Fpr4
;
338 to
->Fpr5
= from
->Fpr5
;
339 to
->Fpr6
= from
->Fpr6
;
340 to
->Fpr7
= from
->Fpr7
;
341 to
->Fpr8
= from
->Fpr8
;
342 to
->Fpr9
= from
->Fpr9
;
343 to
->Fpr10
= from
->Fpr10
;
344 to
->Fpr11
= from
->Fpr11
;
345 to
->Fpr12
= from
->Fpr12
;
346 to
->Fpr13
= from
->Fpr13
;
347 to
->Fpr14
= from
->Fpr14
;
348 to
->Fpr15
= from
->Fpr15
;
349 to
->Fpr16
= from
->Fpr16
;
350 to
->Fpr17
= from
->Fpr17
;
351 to
->Fpr18
= from
->Fpr18
;
352 to
->Fpr19
= from
->Fpr19
;
353 to
->Fpr20
= from
->Fpr20
;
354 to
->Fpr21
= from
->Fpr21
;
355 to
->Fpr22
= from
->Fpr22
;
356 to
->Fpr23
= from
->Fpr23
;
357 to
->Fpr24
= from
->Fpr24
;
358 to
->Fpr25
= from
->Fpr25
;
359 to
->Fpr26
= from
->Fpr26
;
360 to
->Fpr27
= from
->Fpr27
;
361 to
->Fpr28
= from
->Fpr28
;
362 to
->Fpr29
= from
->Fpr29
;
363 to
->Fpr30
= from
->Fpr30
;
364 to
->Fpr31
= from
->Fpr31
;
365 to
->Fpscr
= from
->Fpscr
;
370 /***********************************************************************
373 * Convert a register context to the server format.
375 NTSTATUS
context_to_server( context_t
*to
, const CONTEXT
*from
)
377 DWORD flags
= from
->ContextFlags
; /* no CPU id? */
379 memset( to
, 0, sizeof(*to
) );
380 to
->cpu
= CPU_POWERPC
;
382 if (flags
& CONTEXT_CONTROL
)
384 to
->flags
|= SERVER_CTX_CONTROL
;
385 to
->ctl
.powerpc_regs
.iar
= from
->Iar
;
386 to
->ctl
.powerpc_regs
.msr
= from
->Msr
;
387 to
->ctl
.powerpc_regs
.ctr
= from
->Ctr
;
388 to
->ctl
.powerpc_regs
.lr
= from
->Lr
;
389 to
->ctl
.powerpc_regs
.dar
= from
->Dar
;
390 to
->ctl
.powerpc_regs
.dsisr
= from
->Dsisr
;
391 to
->ctl
.powerpc_regs
.trap
= from
->Trap
;
393 if (flags
& CONTEXT_INTEGER
)
395 to
->flags
|= SERVER_CTX_INTEGER
;
396 to
->integer
.powerpc_regs
.gpr
[0] = from
->Gpr0
;
397 to
->integer
.powerpc_regs
.gpr
[1] = from
->Gpr1
;
398 to
->integer
.powerpc_regs
.gpr
[2] = from
->Gpr2
;
399 to
->integer
.powerpc_regs
.gpr
[3] = from
->Gpr3
;
400 to
->integer
.powerpc_regs
.gpr
[4] = from
->Gpr4
;
401 to
->integer
.powerpc_regs
.gpr
[5] = from
->Gpr5
;
402 to
->integer
.powerpc_regs
.gpr
[6] = from
->Gpr6
;
403 to
->integer
.powerpc_regs
.gpr
[7] = from
->Gpr7
;
404 to
->integer
.powerpc_regs
.gpr
[8] = from
->Gpr8
;
405 to
->integer
.powerpc_regs
.gpr
[9] = from
->Gpr9
;
406 to
->integer
.powerpc_regs
.gpr
[10] = from
->Gpr10
;
407 to
->integer
.powerpc_regs
.gpr
[11] = from
->Gpr11
;
408 to
->integer
.powerpc_regs
.gpr
[12] = from
->Gpr12
;
409 to
->integer
.powerpc_regs
.gpr
[13] = from
->Gpr13
;
410 to
->integer
.powerpc_regs
.gpr
[14] = from
->Gpr14
;
411 to
->integer
.powerpc_regs
.gpr
[15] = from
->Gpr15
;
412 to
->integer
.powerpc_regs
.gpr
[16] = from
->Gpr16
;
413 to
->integer
.powerpc_regs
.gpr
[17] = from
->Gpr17
;
414 to
->integer
.powerpc_regs
.gpr
[18] = from
->Gpr18
;
415 to
->integer
.powerpc_regs
.gpr
[19] = from
->Gpr19
;
416 to
->integer
.powerpc_regs
.gpr
[20] = from
->Gpr20
;
417 to
->integer
.powerpc_regs
.gpr
[21] = from
->Gpr21
;
418 to
->integer
.powerpc_regs
.gpr
[22] = from
->Gpr22
;
419 to
->integer
.powerpc_regs
.gpr
[23] = from
->Gpr23
;
420 to
->integer
.powerpc_regs
.gpr
[24] = from
->Gpr24
;
421 to
->integer
.powerpc_regs
.gpr
[25] = from
->Gpr25
;
422 to
->integer
.powerpc_regs
.gpr
[26] = from
->Gpr26
;
423 to
->integer
.powerpc_regs
.gpr
[27] = from
->Gpr27
;
424 to
->integer
.powerpc_regs
.gpr
[28] = from
->Gpr28
;
425 to
->integer
.powerpc_regs
.gpr
[29] = from
->Gpr29
;
426 to
->integer
.powerpc_regs
.gpr
[30] = from
->Gpr30
;
427 to
->integer
.powerpc_regs
.gpr
[31] = from
->Gpr31
;
428 to
->integer
.powerpc_regs
.xer
= from
->Xer
;
429 to
->integer
.powerpc_regs
.cr
= from
->Cr
;
431 if (flags
& CONTEXT_FLOATING_POINT
)
433 to
->flags
|= SERVER_CTX_FLOATING_POINT
;
434 to
->fp
.powerpc_regs
.fpr
[0] = from
->Fpr0
;
435 to
->fp
.powerpc_regs
.fpr
[1] = from
->Fpr1
;
436 to
->fp
.powerpc_regs
.fpr
[2] = from
->Fpr2
;
437 to
->fp
.powerpc_regs
.fpr
[3] = from
->Fpr3
;
438 to
->fp
.powerpc_regs
.fpr
[4] = from
->Fpr4
;
439 to
->fp
.powerpc_regs
.fpr
[5] = from
->Fpr5
;
440 to
->fp
.powerpc_regs
.fpr
[6] = from
->Fpr6
;
441 to
->fp
.powerpc_regs
.fpr
[7] = from
->Fpr7
;
442 to
->fp
.powerpc_regs
.fpr
[8] = from
->Fpr8
;
443 to
->fp
.powerpc_regs
.fpr
[9] = from
->Fpr9
;
444 to
->fp
.powerpc_regs
.fpr
[10] = from
->Fpr10
;
445 to
->fp
.powerpc_regs
.fpr
[11] = from
->Fpr11
;
446 to
->fp
.powerpc_regs
.fpr
[12] = from
->Fpr12
;
447 to
->fp
.powerpc_regs
.fpr
[13] = from
->Fpr13
;
448 to
->fp
.powerpc_regs
.fpr
[14] = from
->Fpr14
;
449 to
->fp
.powerpc_regs
.fpr
[15] = from
->Fpr15
;
450 to
->fp
.powerpc_regs
.fpr
[16] = from
->Fpr16
;
451 to
->fp
.powerpc_regs
.fpr
[17] = from
->Fpr17
;
452 to
->fp
.powerpc_regs
.fpr
[18] = from
->Fpr18
;
453 to
->fp
.powerpc_regs
.fpr
[19] = from
->Fpr19
;
454 to
->fp
.powerpc_regs
.fpr
[20] = from
->Fpr20
;
455 to
->fp
.powerpc_regs
.fpr
[21] = from
->Fpr21
;
456 to
->fp
.powerpc_regs
.fpr
[22] = from
->Fpr22
;
457 to
->fp
.powerpc_regs
.fpr
[23] = from
->Fpr23
;
458 to
->fp
.powerpc_regs
.fpr
[24] = from
->Fpr24
;
459 to
->fp
.powerpc_regs
.fpr
[25] = from
->Fpr25
;
460 to
->fp
.powerpc_regs
.fpr
[26] = from
->Fpr26
;
461 to
->fp
.powerpc_regs
.fpr
[27] = from
->Fpr27
;
462 to
->fp
.powerpc_regs
.fpr
[28] = from
->Fpr28
;
463 to
->fp
.powerpc_regs
.fpr
[29] = from
->Fpr29
;
464 to
->fp
.powerpc_regs
.fpr
[30] = from
->Fpr30
;
465 to
->fp
.powerpc_regs
.fpr
[31] = from
->Fpr31
;
466 to
->fp
.powerpc_regs
.fpscr
= from
->Fpscr
;
468 return STATUS_SUCCESS
;
472 /***********************************************************************
473 * context_from_server
475 * Convert a register context from the server format.
477 NTSTATUS
context_from_server( CONTEXT
*to
, const context_t
*from
)
479 if (from
->cpu
!= CPU_POWERPC
) return STATUS_INVALID_PARAMETER
;
481 to
->ContextFlags
= 0; /* no CPU id? */
482 if (from
->flags
& SERVER_CTX_CONTROL
)
484 to
->ContextFlags
|= CONTEXT_CONTROL
;
485 to
->Msr
= from
->ctl
.powerpc_regs
.msr
;
486 to
->Ctr
= from
->ctl
.powerpc_regs
.ctr
;
487 to
->Iar
= from
->ctl
.powerpc_regs
.iar
;
488 to
->Lr
= from
->ctl
.powerpc_regs
.lr
;
489 to
->Dar
= from
->ctl
.powerpc_regs
.dar
;
490 to
->Dsisr
= from
->ctl
.powerpc_regs
.dsisr
;
491 to
->Trap
= from
->ctl
.powerpc_regs
.trap
;
493 if (from
->flags
& SERVER_CTX_INTEGER
)
495 to
->ContextFlags
|= CONTEXT_INTEGER
;
496 to
->Gpr0
= from
->integer
.powerpc_regs
.gpr
[0];
497 to
->Gpr1
= from
->integer
.powerpc_regs
.gpr
[1];
498 to
->Gpr2
= from
->integer
.powerpc_regs
.gpr
[2];
499 to
->Gpr3
= from
->integer
.powerpc_regs
.gpr
[3];
500 to
->Gpr4
= from
->integer
.powerpc_regs
.gpr
[4];
501 to
->Gpr5
= from
->integer
.powerpc_regs
.gpr
[5];
502 to
->Gpr6
= from
->integer
.powerpc_regs
.gpr
[6];
503 to
->Gpr7
= from
->integer
.powerpc_regs
.gpr
[7];
504 to
->Gpr8
= from
->integer
.powerpc_regs
.gpr
[8];
505 to
->Gpr9
= from
->integer
.powerpc_regs
.gpr
[9];
506 to
->Gpr10
= from
->integer
.powerpc_regs
.gpr
[10];
507 to
->Gpr11
= from
->integer
.powerpc_regs
.gpr
[11];
508 to
->Gpr12
= from
->integer
.powerpc_regs
.gpr
[12];
509 to
->Gpr13
= from
->integer
.powerpc_regs
.gpr
[13];
510 to
->Gpr14
= from
->integer
.powerpc_regs
.gpr
[14];
511 to
->Gpr15
= from
->integer
.powerpc_regs
.gpr
[15];
512 to
->Gpr16
= from
->integer
.powerpc_regs
.gpr
[16];
513 to
->Gpr17
= from
->integer
.powerpc_regs
.gpr
[17];
514 to
->Gpr18
= from
->integer
.powerpc_regs
.gpr
[18];
515 to
->Gpr19
= from
->integer
.powerpc_regs
.gpr
[19];
516 to
->Gpr20
= from
->integer
.powerpc_regs
.gpr
[20];
517 to
->Gpr21
= from
->integer
.powerpc_regs
.gpr
[21];
518 to
->Gpr22
= from
->integer
.powerpc_regs
.gpr
[22];
519 to
->Gpr23
= from
->integer
.powerpc_regs
.gpr
[23];
520 to
->Gpr24
= from
->integer
.powerpc_regs
.gpr
[24];
521 to
->Gpr25
= from
->integer
.powerpc_regs
.gpr
[25];
522 to
->Gpr26
= from
->integer
.powerpc_regs
.gpr
[26];
523 to
->Gpr27
= from
->integer
.powerpc_regs
.gpr
[27];
524 to
->Gpr28
= from
->integer
.powerpc_regs
.gpr
[28];
525 to
->Gpr29
= from
->integer
.powerpc_regs
.gpr
[29];
526 to
->Gpr30
= from
->integer
.powerpc_regs
.gpr
[30];
527 to
->Gpr31
= from
->integer
.powerpc_regs
.gpr
[31];
528 to
->Xer
= from
->integer
.powerpc_regs
.xer
;
529 to
->Cr
= from
->integer
.powerpc_regs
.cr
;
531 if (from
->flags
& SERVER_CTX_FLOATING_POINT
)
533 to
->ContextFlags
|= CONTEXT_FLOATING_POINT
;
534 to
->Fpr0
= from
->fp
.powerpc_regs
.fpr
[0];
535 to
->Fpr1
= from
->fp
.powerpc_regs
.fpr
[1];
536 to
->Fpr2
= from
->fp
.powerpc_regs
.fpr
[2];
537 to
->Fpr3
= from
->fp
.powerpc_regs
.fpr
[3];
538 to
->Fpr4
= from
->fp
.powerpc_regs
.fpr
[4];
539 to
->Fpr5
= from
->fp
.powerpc_regs
.fpr
[5];
540 to
->Fpr6
= from
->fp
.powerpc_regs
.fpr
[6];
541 to
->Fpr7
= from
->fp
.powerpc_regs
.fpr
[7];
542 to
->Fpr8
= from
->fp
.powerpc_regs
.fpr
[8];
543 to
->Fpr9
= from
->fp
.powerpc_regs
.fpr
[9];
544 to
->Fpr10
= from
->fp
.powerpc_regs
.fpr
[10];
545 to
->Fpr11
= from
->fp
.powerpc_regs
.fpr
[11];
546 to
->Fpr12
= from
->fp
.powerpc_regs
.fpr
[12];
547 to
->Fpr13
= from
->fp
.powerpc_regs
.fpr
[13];
548 to
->Fpr14
= from
->fp
.powerpc_regs
.fpr
[14];
549 to
->Fpr15
= from
->fp
.powerpc_regs
.fpr
[15];
550 to
->Fpr16
= from
->fp
.powerpc_regs
.fpr
[16];
551 to
->Fpr17
= from
->fp
.powerpc_regs
.fpr
[17];
552 to
->Fpr18
= from
->fp
.powerpc_regs
.fpr
[18];
553 to
->Fpr19
= from
->fp
.powerpc_regs
.fpr
[19];
554 to
->Fpr20
= from
->fp
.powerpc_regs
.fpr
[20];
555 to
->Fpr21
= from
->fp
.powerpc_regs
.fpr
[21];
556 to
->Fpr22
= from
->fp
.powerpc_regs
.fpr
[22];
557 to
->Fpr23
= from
->fp
.powerpc_regs
.fpr
[23];
558 to
->Fpr24
= from
->fp
.powerpc_regs
.fpr
[24];
559 to
->Fpr25
= from
->fp
.powerpc_regs
.fpr
[25];
560 to
->Fpr26
= from
->fp
.powerpc_regs
.fpr
[26];
561 to
->Fpr27
= from
->fp
.powerpc_regs
.fpr
[27];
562 to
->Fpr28
= from
->fp
.powerpc_regs
.fpr
[28];
563 to
->Fpr29
= from
->fp
.powerpc_regs
.fpr
[29];
564 to
->Fpr30
= from
->fp
.powerpc_regs
.fpr
[30];
565 to
->Fpr31
= from
->fp
.powerpc_regs
.fpr
[31];
566 to
->Fpscr
= from
->fp
.powerpc_regs
.fpscr
;
568 return STATUS_SUCCESS
;
572 /**********************************************************************
573 * call_stack_handlers
575 * Call the stack handlers chain.
577 static NTSTATUS
call_stack_handlers( EXCEPTION_RECORD
*rec
, CONTEXT
*context
)
579 EXCEPTION_POINTERS ptrs
;
581 FIXME( "not implemented on PowerPC\n" );
583 /* hack: call unhandled exception filter directly */
584 ptrs
.ExceptionRecord
= rec
;
585 ptrs
.ContextRecord
= context
;
586 unhandled_exception_filter( &ptrs
);
587 return STATUS_UNHANDLED_EXCEPTION
;
591 /*******************************************************************
594 * Implementation of NtRaiseException.
596 static NTSTATUS
raise_exception( EXCEPTION_RECORD
*rec
, CONTEXT
*context
, BOOL first_chance
)
604 TRACE( "code=%x flags=%x addr=%p ip=%x tid=%04x\n",
605 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
,
606 context
->Iar
, GetCurrentThreadId() );
607 for (c
= 0; c
< rec
->NumberParameters
; c
++)
608 TRACE( " info[%d]=%08lx\n", c
, rec
->ExceptionInformation
[c
] );
609 if (rec
->ExceptionCode
== EXCEPTION_WINE_STUB
)
611 if (rec
->ExceptionInformation
[1] >> 16)
612 MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
613 rec
->ExceptionAddress
,
614 (char*)rec
->ExceptionInformation
[0], (char*)rec
->ExceptionInformation
[1] );
616 MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
617 rec
->ExceptionAddress
,
618 (char*)rec
->ExceptionInformation
[0], rec
->ExceptionInformation
[1] );
622 /* FIXME: dump context */
625 status
= send_debug_event( rec
, TRUE
, context
);
626 if (status
== DBG_CONTINUE
|| status
== DBG_EXCEPTION_HANDLED
)
627 return STATUS_SUCCESS
;
629 if (call_vectored_handlers( rec
, context
) == EXCEPTION_CONTINUE_EXECUTION
)
630 return STATUS_SUCCESS
;
632 if ((status
= call_stack_handlers( rec
, context
)) != STATUS_UNHANDLED_EXCEPTION
)
636 /* last chance exception */
638 status
= send_debug_event( rec
, FALSE
, context
);
639 if (status
!= DBG_CONTINUE
)
641 if (rec
->ExceptionFlags
& EH_STACK_INVALID
)
642 ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
643 else if (rec
->ExceptionCode
== STATUS_NONCONTINUABLE_EXCEPTION
)
644 ERR("Process attempted to continue execution after noncontinuable exception.\n");
646 ERR("Unhandled exception code %x flags %x addr %p\n",
647 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
);
648 NtTerminateProcess( NtCurrentProcess(), rec
->ExceptionCode
);
650 return STATUS_SUCCESS
;
654 /**********************************************************************
657 * Handler for SIGSEGV and related errors.
659 static void segv_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
661 EXCEPTION_RECORD rec
;
665 save_context( &context
, sigcontext
);
667 rec
.ExceptionRecord
= NULL
;
668 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
669 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
670 rec
.NumberParameters
= 0;
675 switch (siginfo
->si_code
& 0xffff)
679 rec
.NumberParameters
= 2;
680 rec
.ExceptionInformation
[0] = 0; /* FIXME ? */
681 rec
.ExceptionInformation
[1] = (ULONG_PTR
)siginfo
->si_addr
;
682 if (!(rec
.ExceptionCode
= virtual_handle_fault(siginfo
->si_addr
, rec
.ExceptionInformation
[0])))
686 FIXME("Unhandled SIGSEGV/%x\n",siginfo
->si_code
);
691 switch (siginfo
->si_code
& 0xffff)
694 rec
.ExceptionCode
= EXCEPTION_DATATYPE_MISALIGNMENT
;
701 /* FIXME: correct for all cases ? */
702 rec
.NumberParameters
= 2;
703 rec
.ExceptionInformation
[0] = 0; /* FIXME ? */
704 rec
.ExceptionInformation
[1] = (ULONG_PTR
)siginfo
->si_addr
;
705 if (!(rec
.ExceptionCode
= virtual_handle_fault(siginfo
->si_addr
, rec
.ExceptionInformation
[0])))
710 FIXME("Unhandled SIGBUS/%x\n",siginfo
->si_code
);
715 switch (siginfo
->si_code
& 0xffff)
717 case ILL_ILLOPC
: /* illegal opcode */
719 case ILL_ILLOPN
: /* illegal operand */
722 case ILL_ILLADR
: /* illegal addressing mode */
725 case ILL_ILLTRP
: /* illegal trap */
728 case ILL_COPROC
: /* coprocessor error */
730 rec
.ExceptionCode
= EXCEPTION_ILLEGAL_INSTRUCTION
;
732 case ILL_PRVOPC
: /* privileged opcode */
734 case ILL_PRVREG
: /* privileged register */
736 rec
.ExceptionCode
= EXCEPTION_PRIV_INSTRUCTION
;
739 case ILL_BADSTK
: /* internal stack error */
740 rec
.ExceptionCode
= EXCEPTION_STACK_OVERFLOW
;
744 FIXME("Unhandled SIGILL/%x\n", siginfo
->si_code
);
749 status
= raise_exception( &rec
, &context
, TRUE
);
750 if (status
) raise_status( status
, &rec
);
752 restore_context( &context
, sigcontext
);
755 /**********************************************************************
758 * Handler for SIGTRAP.
760 static void trap_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
762 EXCEPTION_RECORD rec
;
766 save_context( &context
, sigcontext
);
768 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
769 rec
.ExceptionRecord
= NULL
;
770 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
771 rec
.NumberParameters
= 0;
773 /* FIXME: check if we might need to modify PC */
774 switch (siginfo
->si_code
& 0xffff)
778 rec
.ExceptionCode
= EXCEPTION_BREAKPOINT
;
783 rec
.ExceptionCode
= EXCEPTION_SINGLE_STEP
;
787 FIXME("Unhandled SIGTRAP/%x\n", siginfo
->si_code
);
790 status
= raise_exception( &rec
, &context
, TRUE
);
791 if (status
) raise_status( status
, &rec
);
792 restore_context( &context
, sigcontext
);
795 /**********************************************************************
798 * Handler for SIGFPE.
800 static void fpe_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
802 EXCEPTION_RECORD rec
;
806 save_fpu( &context
, sigcontext
);
807 save_context( &context
, sigcontext
);
809 switch (siginfo
->si_code
& 0xffff )
813 rec
.ExceptionCode
= EXCEPTION_ARRAY_BOUNDS_EXCEEDED
;
818 rec
.ExceptionCode
= EXCEPTION_INT_DIVIDE_BY_ZERO
;
823 rec
.ExceptionCode
= EXCEPTION_INT_OVERFLOW
;
828 rec
.ExceptionCode
= EXCEPTION_FLT_DIVIDE_BY_ZERO
;
833 rec
.ExceptionCode
= EXCEPTION_FLT_OVERFLOW
;
838 rec
.ExceptionCode
= EXCEPTION_FLT_UNDERFLOW
;
843 rec
.ExceptionCode
= EXCEPTION_FLT_INEXACT_RESULT
;
850 rec
.ExceptionCode
= EXCEPTION_FLT_INVALID_OPERATION
;
853 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
854 rec
.ExceptionRecord
= NULL
;
855 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
856 rec
.NumberParameters
= 0;
857 status
= raise_exception( &rec
, &context
, TRUE
);
858 if (status
) raise_status( status
, &rec
);
860 restore_context( &context
, sigcontext
);
861 restore_fpu( &context
, sigcontext
);
864 /**********************************************************************
867 * Handler for SIGINT.
869 static void int_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
871 if (!dispatch_signal(SIGINT
))
873 EXCEPTION_RECORD rec
;
877 save_context( &context
, sigcontext
);
878 rec
.ExceptionCode
= CONTROL_C_EXIT
;
879 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
880 rec
.ExceptionRecord
= NULL
;
881 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
882 rec
.NumberParameters
= 0;
883 status
= raise_exception( &rec
, &context
, TRUE
);
884 if (status
) raise_status( status
, &rec
);
885 restore_context( &context
, sigcontext
);
890 /**********************************************************************
893 * Handler for SIGABRT.
895 static void abrt_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
897 EXCEPTION_RECORD rec
;
901 save_context( &context
, sigcontext
);
902 rec
.ExceptionCode
= EXCEPTION_WINE_ASSERTION
;
903 rec
.ExceptionFlags
= EH_NONCONTINUABLE
;
904 rec
.ExceptionRecord
= NULL
;
905 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
906 rec
.NumberParameters
= 0;
907 status
= raise_exception( &rec
, &context
, TRUE
);
908 if (status
) raise_status( status
, &rec
);
909 restore_context( &context
, sigcontext
);
913 /**********************************************************************
916 * Handler for SIGQUIT.
918 static void quit_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
924 /**********************************************************************
927 * Handler for SIGUSR1, used to signal a thread that it got suspended.
929 static void usr1_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
933 save_context( &context
, sigcontext
);
934 wait_suspend( &context
);
935 restore_context( &context
, sigcontext
);
939 /***********************************************************************
940 * __wine_set_signal_handler (NTDLL.@)
942 int CDECL
__wine_set_signal_handler(unsigned int sig
, wine_signal_handler wsh
)
944 if (sig
> sizeof(handlers
) / sizeof(handlers
[0])) return -1;
945 if (handlers
[sig
] != NULL
) return -2;
951 /**********************************************************************
952 * signal_alloc_thread
954 NTSTATUS
signal_alloc_thread( TEB
**teb
)
956 static size_t sigstack_zero_bits
;
960 if (!sigstack_zero_bits
)
962 size_t min_size
= page_size
; /* this is just for the TEB, we don't use a signal stack yet */
963 /* find the first power of two not smaller than min_size */
964 while ((1u << sigstack_zero_bits
) < min_size
) sigstack_zero_bits
++;
965 assert( sizeof(TEB
) <= min_size
);
968 size
= 1 << sigstack_zero_bits
;
970 if (!(status
= NtAllocateVirtualMemory( NtCurrentProcess(), (void **)teb
, sigstack_zero_bits
,
971 &size
, MEM_COMMIT
| MEM_TOP_DOWN
, PAGE_READWRITE
)))
973 (*teb
)->Tib
.Self
= &(*teb
)->Tib
;
974 (*teb
)->Tib
.ExceptionList
= (void *)~0UL;
980 /**********************************************************************
983 void signal_free_thread( TEB
*teb
)
987 if (teb
->DeallocationStack
)
990 NtFreeVirtualMemory( GetCurrentProcess(), &teb
->DeallocationStack
, &size
, MEM_RELEASE
);
993 NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb
, &size
, MEM_RELEASE
);
997 /**********************************************************************
1000 void signal_init_thread( TEB
*teb
)
1002 static BOOL init_done
;
1006 pthread_key_create( &teb_key
, NULL
);
1009 pthread_setspecific( teb_key
, teb
);
1013 /**********************************************************************
1014 * signal_init_process
1016 void signal_init_process(void)
1018 struct sigaction sig_act
;
1020 sig_act
.sa_mask
= server_block_set
;
1021 sig_act
.sa_flags
= SA_RESTART
| SA_SIGINFO
;
1023 sig_act
.sa_sigaction
= int_handler
;
1024 if (sigaction( SIGINT
, &sig_act
, NULL
) == -1) goto error
;
1025 sig_act
.sa_sigaction
= fpe_handler
;
1026 if (sigaction( SIGFPE
, &sig_act
, NULL
) == -1) goto error
;
1027 sig_act
.sa_sigaction
= abrt_handler
;
1028 if (sigaction( SIGABRT
, &sig_act
, NULL
) == -1) goto error
;
1029 sig_act
.sa_sigaction
= quit_handler
;
1030 if (sigaction( SIGQUIT
, &sig_act
, NULL
) == -1) goto error
;
1031 sig_act
.sa_sigaction
= usr1_handler
;
1032 if (sigaction( SIGUSR1
, &sig_act
, NULL
) == -1) goto error
;
1034 sig_act
.sa_sigaction
= segv_handler
;
1035 if (sigaction( SIGSEGV
, &sig_act
, NULL
) == -1) goto error
;
1036 if (sigaction( SIGILL
, &sig_act
, NULL
) == -1) goto error
;
1038 if (sigaction( SIGBUS
, &sig_act
, NULL
) == -1) goto error
;
1042 sig_act
.sa_sigaction
= trap_handler
;
1043 if (sigaction( SIGTRAP
, &sig_act
, NULL
) == -1) goto error
;
1048 perror("sigaction");
1053 /**********************************************************************
1054 * __wine_enter_vm86 (NTDLL.@)
1056 void __wine_enter_vm86( CONTEXT
*context
)
1058 MESSAGE("vm86 mode not supported on this platform\n");
1061 /***********************************************************************
1062 * RtlUnwind (NTDLL.@)
1064 void WINAPI
RtlUnwind( PVOID pEndFrame
, PVOID targetIp
, PEXCEPTION_RECORD pRecord
, PVOID retval
)
1066 FIXME( "Not implemented on PowerPC\n" );
1069 /*******************************************************************
1070 * NtRaiseException (NTDLL.@)
1072 NTSTATUS WINAPI
NtRaiseException( EXCEPTION_RECORD
*rec
, CONTEXT
*context
, BOOL first_chance
)
1074 NTSTATUS status
= raise_exception( rec
, context
, first_chance
);
1075 if (status
== STATUS_SUCCESS
) NtSetContextThread( GetCurrentThread(), context
);
1079 /***********************************************************************
1080 * RtlRaiseException (NTDLL.@)
1082 void WINAPI
RtlRaiseException( EXCEPTION_RECORD
*rec
)
1087 RtlCaptureContext( &context
);
1088 rec
->ExceptionAddress
= (void *)context
.Iar
;
1089 status
= raise_exception( rec
, &context
, TRUE
);
1090 if (status
) raise_status( status
, rec
);
1093 /*************************************************************************
1094 * RtlCaptureStackBackTrace (NTDLL.@)
1096 USHORT WINAPI
RtlCaptureStackBackTrace( ULONG skip
, ULONG count
, PVOID
*buffer
, ULONG
*hash
)
1098 FIXME( "(%d, %d, %p, %p) stub!\n", skip
, count
, buffer
, hash
);
1102 /***********************************************************************
1103 * call_thread_entry_point
1105 void call_thread_entry_point( LPTHREAD_START_ROUTINE entry
, void *arg
)
1109 exit_thread( entry( arg
));
1111 __EXCEPT(unhandled_exception_filter
)
1113 NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
1116 abort(); /* should not be reached */
1119 /***********************************************************************
1120 * RtlExitUserThread (NTDLL.@)
1122 void WINAPI
RtlExitUserThread( ULONG status
)
1124 exit_thread( status
);
1127 /***********************************************************************
1130 void abort_thread( int status
)
1132 terminate_thread( status
);
1135 /**********************************************************************
1136 * DbgBreakPoint (NTDLL.@)
1138 void WINAPI
DbgBreakPoint(void)
1140 kill(getpid(), SIGTRAP
);
1143 /**********************************************************************
1144 * DbgUserBreakPoint (NTDLL.@)
1146 void WINAPI
DbgUserBreakPoint(void)
1148 kill(getpid(), SIGTRAP
);
1151 /**********************************************************************
1152 * NtCurrentTeb (NTDLL.@)
1154 TEB
* WINAPI
NtCurrentTeb(void)
1156 return pthread_getspecific( teb_key
);
1159 #endif /* __powerpc__ */