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_VM86_H
47 # include <sys/vm86.h>
50 #ifdef HAVE_SYS_SIGNAL_H
51 # include <sys/signal.h>
55 #define WIN32_NO_STATUS
58 #include "wine/library.h"
59 #include "wine/exception.h"
60 #include "ntdll_misc.h"
61 #include "wine/debug.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(seh
);
65 static pthread_key_t teb_key
;
67 /***********************************************************************
68 * signal context platform-specific definitions
72 /* All Registers access - only for local access */
73 # define REG_sig(reg_name, context) ((context)->uc_mcontext.regs->reg_name)
76 /* Gpr Registers access */
77 # define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context)
79 # define IAR_sig(context) REG_sig(nip, context) /* Program counter */
80 # define MSR_sig(context) REG_sig(msr, context) /* Machine State Register (Supervisor) */
81 # define CTR_sig(context) REG_sig(ctr, context) /* Count register */
83 # define XER_sig(context) REG_sig(xer, context) /* User's integer exception register */
84 # define LR_sig(context) REG_sig(link, context) /* Link register */
85 # define CR_sig(context) REG_sig(ccr, context) /* Condition register */
87 /* Float Registers access */
88 # define FLOAT_sig(reg_num, context) (((double*)((char*)((context)->uc_mcontext.regs+48*4)))[reg_num])
90 # define FPSCR_sig(context) (*(int*)((char*)((context)->uc_mcontext.regs+(48+32*2)*4)))
92 /* Exception Registers access */
93 # define DAR_sig(context) REG_sig(dar, context)
94 # define DSISR_sig(context) REG_sig(dsisr, context)
95 # define TRAP_sig(context) REG_sig(trap, context)
101 # include <sys/ucontext.h>
102 # include <sys/types.h>
104 /* All Registers access - only for local access */
105 # define REG_sig(reg_name, context) ((context)->uc_mcontext->ss.reg_name)
106 # define FLOATREG_sig(reg_name, context) ((context)->uc_mcontext->fs.reg_name)
107 # define EXCEPREG_sig(reg_name, context) ((context)->uc_mcontext->es.reg_name)
108 # define VECREG_sig(reg_name, context) ((context)->uc_mcontext->vs.reg_name)
110 /* Gpr Registers access */
111 # define GPR_sig(reg_num, context) REG_sig(r##reg_num, context)
113 # define IAR_sig(context) REG_sig(srr0, context) /* Program counter */
114 # define MSR_sig(context) REG_sig(srr1, context) /* Machine State Register (Supervisor) */
115 # define CTR_sig(context) REG_sig(ctr, context)
117 # define XER_sig(context) REG_sig(xer, context) /* Link register */
118 # define LR_sig(context) REG_sig(lr, context) /* User's integer exception register */
119 # define CR_sig(context) REG_sig(cr, context) /* Condition register */
121 /* Float Registers access */
122 # define FLOAT_sig(reg_num, context) FLOATREG_sig(fpregs[reg_num], context)
124 # define FPSCR_sig(context) FLOATREG_sig(fpscr, context)
126 /* Exception Registers access */
127 # define DAR_sig(context) EXCEPREG_sig(dar, context) /* Fault registers for coredump */
128 # define DSISR_sig(context) EXCEPREG_sig(dsisr, context)
129 # define TRAP_sig(context) EXCEPREG_sig(exception, context) /* number of powerpc exception taken */
131 /* Signal defs : Those are undefined on darwin
148 #endif /* __APPLE__ */
152 typedef int (*wine_signal_handler
)(unsigned int sig
);
154 static wine_signal_handler handlers
[256];
156 /***********************************************************************
159 static inline int dispatch_signal(unsigned int sig
)
161 if (handlers
[sig
] == NULL
) return 0;
162 return handlers
[sig
](sig
);
165 /***********************************************************************
168 * Set the register values from a sigcontext.
170 static void save_context( CONTEXT
*context
, const ucontext_t
*sigcontext
)
173 #define C(x) context->Gpr##x = GPR_sig(x,sigcontext)
174 /* Save Gpr registers */
175 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
176 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
177 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
181 context
->Iar
= IAR_sig(sigcontext
); /* Program Counter */
182 context
->Msr
= MSR_sig(sigcontext
); /* Machine State Register (Supervisor) */
183 context
->Ctr
= CTR_sig(sigcontext
);
185 context
->Xer
= XER_sig(sigcontext
);
186 context
->Lr
= LR_sig(sigcontext
);
187 context
->Cr
= CR_sig(sigcontext
);
189 /* Saving Exception regs */
190 context
->Dar
= DAR_sig(sigcontext
);
191 context
->Dsisr
= DSISR_sig(sigcontext
);
192 context
->Trap
= TRAP_sig(sigcontext
);
196 /***********************************************************************
199 * Build a sigcontext from the register values.
201 static void restore_context( const CONTEXT
*context
, ucontext_t
*sigcontext
)
204 #define C(x) GPR_sig(x,sigcontext) = context->Gpr##x
205 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
206 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
207 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
211 IAR_sig(sigcontext
) = context
->Iar
; /* Program Counter */
212 MSR_sig(sigcontext
) = context
->Msr
; /* Machine State Register (Supervisor) */
213 CTR_sig(sigcontext
) = context
->Ctr
;
215 XER_sig(sigcontext
) = context
->Xer
;
216 LR_sig(sigcontext
) = context
->Lr
;
217 CR_sig(sigcontext
) = context
->Cr
;
219 /* Setting Exception regs */
220 DAR_sig(sigcontext
) = context
->Dar
;
221 DSISR_sig(sigcontext
) = context
->Dsisr
;
222 TRAP_sig(sigcontext
) = context
->Trap
;
226 /***********************************************************************
229 * Set the FPU context from a sigcontext.
231 static inline void save_fpu( CONTEXT
*context
, const ucontext_t
*sigcontext
)
233 #define C(x) context->Fpr##x = FLOAT_sig(x,sigcontext)
234 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
235 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
236 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
239 context
->Fpscr
= FPSCR_sig(sigcontext
);
243 /***********************************************************************
246 * Restore the FPU context to a sigcontext.
248 static inline void restore_fpu( CONTEXT
*context
, const ucontext_t
*sigcontext
)
250 #define C(x) FLOAT_sig(x,sigcontext) = context->Fpr##x
251 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
252 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
253 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
256 FPSCR_sig(sigcontext
) = context
->Fpscr
;
260 /***********************************************************************
261 * RtlCaptureContext (NTDLL.@)
263 void WINAPI
RtlCaptureContext( CONTEXT
*context
)
265 FIXME("not implemented\n");
266 memset( context
, 0, sizeof(*context
) );
270 /***********************************************************************
273 * Set the new CPU context.
275 void set_cpu_context( const CONTEXT
*context
)
277 FIXME("not implemented\n");
281 /***********************************************************************
284 * Copy a register context according to the flags.
286 void copy_context( CONTEXT
*to
, const CONTEXT
*from
, DWORD flags
)
288 if (flags
& CONTEXT_CONTROL
)
295 to
->Dsisr
= from
->Dsisr
;
296 to
->Trap
= from
->Trap
;
298 if (flags
& CONTEXT_INTEGER
)
300 to
->Gpr0
= from
->Gpr0
;
301 to
->Gpr1
= from
->Gpr1
;
302 to
->Gpr2
= from
->Gpr2
;
303 to
->Gpr3
= from
->Gpr3
;
304 to
->Gpr4
= from
->Gpr4
;
305 to
->Gpr5
= from
->Gpr5
;
306 to
->Gpr6
= from
->Gpr6
;
307 to
->Gpr7
= from
->Gpr7
;
308 to
->Gpr8
= from
->Gpr8
;
309 to
->Gpr9
= from
->Gpr9
;
310 to
->Gpr10
= from
->Gpr10
;
311 to
->Gpr11
= from
->Gpr11
;
312 to
->Gpr12
= from
->Gpr12
;
313 to
->Gpr13
= from
->Gpr13
;
314 to
->Gpr14
= from
->Gpr14
;
315 to
->Gpr15
= from
->Gpr15
;
316 to
->Gpr16
= from
->Gpr16
;
317 to
->Gpr17
= from
->Gpr17
;
318 to
->Gpr18
= from
->Gpr18
;
319 to
->Gpr19
= from
->Gpr19
;
320 to
->Gpr20
= from
->Gpr20
;
321 to
->Gpr21
= from
->Gpr21
;
322 to
->Gpr22
= from
->Gpr22
;
323 to
->Gpr23
= from
->Gpr23
;
324 to
->Gpr24
= from
->Gpr24
;
325 to
->Gpr25
= from
->Gpr25
;
326 to
->Gpr26
= from
->Gpr26
;
327 to
->Gpr27
= from
->Gpr27
;
328 to
->Gpr28
= from
->Gpr28
;
329 to
->Gpr29
= from
->Gpr29
;
330 to
->Gpr30
= from
->Gpr30
;
331 to
->Gpr31
= from
->Gpr31
;
335 if (flags
& CONTEXT_FLOATING_POINT
)
337 to
->Fpr0
= from
->Fpr0
;
338 to
->Fpr1
= from
->Fpr1
;
339 to
->Fpr2
= from
->Fpr2
;
340 to
->Fpr3
= from
->Fpr3
;
341 to
->Fpr4
= from
->Fpr4
;
342 to
->Fpr5
= from
->Fpr5
;
343 to
->Fpr6
= from
->Fpr6
;
344 to
->Fpr7
= from
->Fpr7
;
345 to
->Fpr8
= from
->Fpr8
;
346 to
->Fpr9
= from
->Fpr9
;
347 to
->Fpr10
= from
->Fpr10
;
348 to
->Fpr11
= from
->Fpr11
;
349 to
->Fpr12
= from
->Fpr12
;
350 to
->Fpr13
= from
->Fpr13
;
351 to
->Fpr14
= from
->Fpr14
;
352 to
->Fpr15
= from
->Fpr15
;
353 to
->Fpr16
= from
->Fpr16
;
354 to
->Fpr17
= from
->Fpr17
;
355 to
->Fpr18
= from
->Fpr18
;
356 to
->Fpr19
= from
->Fpr19
;
357 to
->Fpr20
= from
->Fpr20
;
358 to
->Fpr21
= from
->Fpr21
;
359 to
->Fpr22
= from
->Fpr22
;
360 to
->Fpr23
= from
->Fpr23
;
361 to
->Fpr24
= from
->Fpr24
;
362 to
->Fpr25
= from
->Fpr25
;
363 to
->Fpr26
= from
->Fpr26
;
364 to
->Fpr27
= from
->Fpr27
;
365 to
->Fpr28
= from
->Fpr28
;
366 to
->Fpr29
= from
->Fpr29
;
367 to
->Fpr30
= from
->Fpr30
;
368 to
->Fpr31
= from
->Fpr31
;
369 to
->Fpscr
= from
->Fpscr
;
374 /***********************************************************************
377 * Convert a register context to the server format.
379 NTSTATUS
context_to_server( context_t
*to
, const CONTEXT
*from
)
381 DWORD flags
= from
->ContextFlags
; /* no CPU id? */
383 memset( to
, 0, sizeof(*to
) );
384 to
->cpu
= CPU_POWERPC
;
386 if (flags
& CONTEXT_CONTROL
)
388 to
->flags
|= SERVER_CTX_CONTROL
;
389 to
->ctl
.powerpc_regs
.iar
= from
->Iar
;
390 to
->ctl
.powerpc_regs
.msr
= from
->Msr
;
391 to
->ctl
.powerpc_regs
.ctr
= from
->Ctr
;
392 to
->ctl
.powerpc_regs
.lr
= from
->Lr
;
393 to
->ctl
.powerpc_regs
.dar
= from
->Dar
;
394 to
->ctl
.powerpc_regs
.dsisr
= from
->Dsisr
;
395 to
->ctl
.powerpc_regs
.trap
= from
->Trap
;
397 if (flags
& CONTEXT_INTEGER
)
399 to
->flags
|= SERVER_CTX_INTEGER
;
400 to
->integer
.powerpc_regs
.gpr
[0] = from
->Gpr0
;
401 to
->integer
.powerpc_regs
.gpr
[1] = from
->Gpr1
;
402 to
->integer
.powerpc_regs
.gpr
[2] = from
->Gpr2
;
403 to
->integer
.powerpc_regs
.gpr
[3] = from
->Gpr3
;
404 to
->integer
.powerpc_regs
.gpr
[4] = from
->Gpr4
;
405 to
->integer
.powerpc_regs
.gpr
[5] = from
->Gpr5
;
406 to
->integer
.powerpc_regs
.gpr
[6] = from
->Gpr6
;
407 to
->integer
.powerpc_regs
.gpr
[7] = from
->Gpr7
;
408 to
->integer
.powerpc_regs
.gpr
[8] = from
->Gpr8
;
409 to
->integer
.powerpc_regs
.gpr
[9] = from
->Gpr9
;
410 to
->integer
.powerpc_regs
.gpr
[10] = from
->Gpr10
;
411 to
->integer
.powerpc_regs
.gpr
[11] = from
->Gpr11
;
412 to
->integer
.powerpc_regs
.gpr
[12] = from
->Gpr12
;
413 to
->integer
.powerpc_regs
.gpr
[13] = from
->Gpr13
;
414 to
->integer
.powerpc_regs
.gpr
[14] = from
->Gpr14
;
415 to
->integer
.powerpc_regs
.gpr
[15] = from
->Gpr15
;
416 to
->integer
.powerpc_regs
.gpr
[16] = from
->Gpr16
;
417 to
->integer
.powerpc_regs
.gpr
[17] = from
->Gpr17
;
418 to
->integer
.powerpc_regs
.gpr
[18] = from
->Gpr18
;
419 to
->integer
.powerpc_regs
.gpr
[19] = from
->Gpr19
;
420 to
->integer
.powerpc_regs
.gpr
[20] = from
->Gpr20
;
421 to
->integer
.powerpc_regs
.gpr
[21] = from
->Gpr21
;
422 to
->integer
.powerpc_regs
.gpr
[22] = from
->Gpr22
;
423 to
->integer
.powerpc_regs
.gpr
[23] = from
->Gpr23
;
424 to
->integer
.powerpc_regs
.gpr
[24] = from
->Gpr24
;
425 to
->integer
.powerpc_regs
.gpr
[25] = from
->Gpr25
;
426 to
->integer
.powerpc_regs
.gpr
[26] = from
->Gpr26
;
427 to
->integer
.powerpc_regs
.gpr
[27] = from
->Gpr27
;
428 to
->integer
.powerpc_regs
.gpr
[28] = from
->Gpr28
;
429 to
->integer
.powerpc_regs
.gpr
[29] = from
->Gpr29
;
430 to
->integer
.powerpc_regs
.gpr
[30] = from
->Gpr30
;
431 to
->integer
.powerpc_regs
.gpr
[31] = from
->Gpr31
;
432 to
->integer
.powerpc_regs
.xer
= from
->Xer
;
433 to
->integer
.powerpc_regs
.cr
= from
->Cr
;
435 if (flags
& CONTEXT_FLOATING_POINT
)
437 to
->flags
|= SERVER_CTX_FLOATING_POINT
;
438 to
->fp
.powerpc_regs
.fpr
[0] = from
->Fpr0
;
439 to
->fp
.powerpc_regs
.fpr
[1] = from
->Fpr1
;
440 to
->fp
.powerpc_regs
.fpr
[2] = from
->Fpr2
;
441 to
->fp
.powerpc_regs
.fpr
[3] = from
->Fpr3
;
442 to
->fp
.powerpc_regs
.fpr
[4] = from
->Fpr4
;
443 to
->fp
.powerpc_regs
.fpr
[5] = from
->Fpr5
;
444 to
->fp
.powerpc_regs
.fpr
[6] = from
->Fpr6
;
445 to
->fp
.powerpc_regs
.fpr
[7] = from
->Fpr7
;
446 to
->fp
.powerpc_regs
.fpr
[8] = from
->Fpr8
;
447 to
->fp
.powerpc_regs
.fpr
[9] = from
->Fpr9
;
448 to
->fp
.powerpc_regs
.fpr
[10] = from
->Fpr10
;
449 to
->fp
.powerpc_regs
.fpr
[11] = from
->Fpr11
;
450 to
->fp
.powerpc_regs
.fpr
[12] = from
->Fpr12
;
451 to
->fp
.powerpc_regs
.fpr
[13] = from
->Fpr13
;
452 to
->fp
.powerpc_regs
.fpr
[14] = from
->Fpr14
;
453 to
->fp
.powerpc_regs
.fpr
[15] = from
->Fpr15
;
454 to
->fp
.powerpc_regs
.fpr
[16] = from
->Fpr16
;
455 to
->fp
.powerpc_regs
.fpr
[17] = from
->Fpr17
;
456 to
->fp
.powerpc_regs
.fpr
[18] = from
->Fpr18
;
457 to
->fp
.powerpc_regs
.fpr
[19] = from
->Fpr19
;
458 to
->fp
.powerpc_regs
.fpr
[20] = from
->Fpr20
;
459 to
->fp
.powerpc_regs
.fpr
[21] = from
->Fpr21
;
460 to
->fp
.powerpc_regs
.fpr
[22] = from
->Fpr22
;
461 to
->fp
.powerpc_regs
.fpr
[23] = from
->Fpr23
;
462 to
->fp
.powerpc_regs
.fpr
[24] = from
->Fpr24
;
463 to
->fp
.powerpc_regs
.fpr
[25] = from
->Fpr25
;
464 to
->fp
.powerpc_regs
.fpr
[26] = from
->Fpr26
;
465 to
->fp
.powerpc_regs
.fpr
[27] = from
->Fpr27
;
466 to
->fp
.powerpc_regs
.fpr
[28] = from
->Fpr28
;
467 to
->fp
.powerpc_regs
.fpr
[29] = from
->Fpr29
;
468 to
->fp
.powerpc_regs
.fpr
[30] = from
->Fpr30
;
469 to
->fp
.powerpc_regs
.fpr
[31] = from
->Fpr31
;
470 to
->fp
.powerpc_regs
.fpscr
= from
->Fpscr
;
472 return STATUS_SUCCESS
;
476 /***********************************************************************
477 * context_from_server
479 * Convert a register context from the server format.
481 NTSTATUS
context_from_server( CONTEXT
*to
, const context_t
*from
)
483 if (from
->cpu
!= CPU_POWERPC
) return STATUS_INVALID_PARAMETER
;
485 to
->ContextFlags
= 0; /* no CPU id? */
486 if (from
->flags
& SERVER_CTX_CONTROL
)
488 to
->ContextFlags
|= CONTEXT_CONTROL
;
489 to
->Msr
= from
->ctl
.powerpc_regs
.msr
;
490 to
->Ctr
= from
->ctl
.powerpc_regs
.ctr
;
491 to
->Iar
= from
->ctl
.powerpc_regs
.iar
;
492 to
->Lr
= from
->ctl
.powerpc_regs
.lr
;
493 to
->Dar
= from
->ctl
.powerpc_regs
.dar
;
494 to
->Dsisr
= from
->ctl
.powerpc_regs
.dsisr
;
495 to
->Trap
= from
->ctl
.powerpc_regs
.trap
;
497 if (from
->flags
& SERVER_CTX_INTEGER
)
499 to
->ContextFlags
|= CONTEXT_INTEGER
;
500 to
->Gpr0
= from
->integer
.powerpc_regs
.gpr
[0];
501 to
->Gpr1
= from
->integer
.powerpc_regs
.gpr
[1];
502 to
->Gpr2
= from
->integer
.powerpc_regs
.gpr
[2];
503 to
->Gpr3
= from
->integer
.powerpc_regs
.gpr
[3];
504 to
->Gpr4
= from
->integer
.powerpc_regs
.gpr
[4];
505 to
->Gpr5
= from
->integer
.powerpc_regs
.gpr
[5];
506 to
->Gpr6
= from
->integer
.powerpc_regs
.gpr
[6];
507 to
->Gpr7
= from
->integer
.powerpc_regs
.gpr
[7];
508 to
->Gpr8
= from
->integer
.powerpc_regs
.gpr
[8];
509 to
->Gpr9
= from
->integer
.powerpc_regs
.gpr
[9];
510 to
->Gpr10
= from
->integer
.powerpc_regs
.gpr
[10];
511 to
->Gpr11
= from
->integer
.powerpc_regs
.gpr
[11];
512 to
->Gpr12
= from
->integer
.powerpc_regs
.gpr
[12];
513 to
->Gpr13
= from
->integer
.powerpc_regs
.gpr
[13];
514 to
->Gpr14
= from
->integer
.powerpc_regs
.gpr
[14];
515 to
->Gpr15
= from
->integer
.powerpc_regs
.gpr
[15];
516 to
->Gpr16
= from
->integer
.powerpc_regs
.gpr
[16];
517 to
->Gpr17
= from
->integer
.powerpc_regs
.gpr
[17];
518 to
->Gpr18
= from
->integer
.powerpc_regs
.gpr
[18];
519 to
->Gpr19
= from
->integer
.powerpc_regs
.gpr
[19];
520 to
->Gpr20
= from
->integer
.powerpc_regs
.gpr
[20];
521 to
->Gpr21
= from
->integer
.powerpc_regs
.gpr
[21];
522 to
->Gpr22
= from
->integer
.powerpc_regs
.gpr
[22];
523 to
->Gpr23
= from
->integer
.powerpc_regs
.gpr
[23];
524 to
->Gpr24
= from
->integer
.powerpc_regs
.gpr
[24];
525 to
->Gpr25
= from
->integer
.powerpc_regs
.gpr
[25];
526 to
->Gpr26
= from
->integer
.powerpc_regs
.gpr
[26];
527 to
->Gpr27
= from
->integer
.powerpc_regs
.gpr
[27];
528 to
->Gpr28
= from
->integer
.powerpc_regs
.gpr
[28];
529 to
->Gpr29
= from
->integer
.powerpc_regs
.gpr
[29];
530 to
->Gpr30
= from
->integer
.powerpc_regs
.gpr
[30];
531 to
->Gpr31
= from
->integer
.powerpc_regs
.gpr
[31];
532 to
->Xer
= from
->integer
.powerpc_regs
.xer
;
533 to
->Cr
= from
->integer
.powerpc_regs
.cr
;
535 if (from
->flags
& SERVER_CTX_FLOATING_POINT
)
537 to
->ContextFlags
|= CONTEXT_FLOATING_POINT
;
538 to
->Fpr0
= from
->fp
.powerpc_regs
.fpr
[0];
539 to
->Fpr1
= from
->fp
.powerpc_regs
.fpr
[1];
540 to
->Fpr2
= from
->fp
.powerpc_regs
.fpr
[2];
541 to
->Fpr3
= from
->fp
.powerpc_regs
.fpr
[3];
542 to
->Fpr4
= from
->fp
.powerpc_regs
.fpr
[4];
543 to
->Fpr5
= from
->fp
.powerpc_regs
.fpr
[5];
544 to
->Fpr6
= from
->fp
.powerpc_regs
.fpr
[6];
545 to
->Fpr7
= from
->fp
.powerpc_regs
.fpr
[7];
546 to
->Fpr8
= from
->fp
.powerpc_regs
.fpr
[8];
547 to
->Fpr9
= from
->fp
.powerpc_regs
.fpr
[9];
548 to
->Fpr10
= from
->fp
.powerpc_regs
.fpr
[10];
549 to
->Fpr11
= from
->fp
.powerpc_regs
.fpr
[11];
550 to
->Fpr12
= from
->fp
.powerpc_regs
.fpr
[12];
551 to
->Fpr13
= from
->fp
.powerpc_regs
.fpr
[13];
552 to
->Fpr14
= from
->fp
.powerpc_regs
.fpr
[14];
553 to
->Fpr15
= from
->fp
.powerpc_regs
.fpr
[15];
554 to
->Fpr16
= from
->fp
.powerpc_regs
.fpr
[16];
555 to
->Fpr17
= from
->fp
.powerpc_regs
.fpr
[17];
556 to
->Fpr18
= from
->fp
.powerpc_regs
.fpr
[18];
557 to
->Fpr19
= from
->fp
.powerpc_regs
.fpr
[19];
558 to
->Fpr20
= from
->fp
.powerpc_regs
.fpr
[20];
559 to
->Fpr21
= from
->fp
.powerpc_regs
.fpr
[21];
560 to
->Fpr22
= from
->fp
.powerpc_regs
.fpr
[22];
561 to
->Fpr23
= from
->fp
.powerpc_regs
.fpr
[23];
562 to
->Fpr24
= from
->fp
.powerpc_regs
.fpr
[24];
563 to
->Fpr25
= from
->fp
.powerpc_regs
.fpr
[25];
564 to
->Fpr26
= from
->fp
.powerpc_regs
.fpr
[26];
565 to
->Fpr27
= from
->fp
.powerpc_regs
.fpr
[27];
566 to
->Fpr28
= from
->fp
.powerpc_regs
.fpr
[28];
567 to
->Fpr29
= from
->fp
.powerpc_regs
.fpr
[29];
568 to
->Fpr30
= from
->fp
.powerpc_regs
.fpr
[30];
569 to
->Fpr31
= from
->fp
.powerpc_regs
.fpr
[31];
570 to
->Fpscr
= from
->fp
.powerpc_regs
.fpscr
;
572 return STATUS_SUCCESS
;
576 /**********************************************************************
577 * call_stack_handlers
579 * Call the stack handlers chain.
581 static NTSTATUS
call_stack_handlers( EXCEPTION_RECORD
*rec
, CONTEXT
*context
)
583 EXCEPTION_POINTERS ptrs
;
585 FIXME( "not implemented on PowerPC\n" );
587 /* hack: call unhandled exception filter directly */
588 ptrs
.ExceptionRecord
= rec
;
589 ptrs
.ContextRecord
= context
;
590 unhandled_exception_filter( &ptrs
);
591 return STATUS_UNHANDLED_EXCEPTION
;
595 /*******************************************************************
598 * Implementation of NtRaiseException.
600 static NTSTATUS
raise_exception( EXCEPTION_RECORD
*rec
, CONTEXT
*context
, BOOL first_chance
)
608 TRACE( "code=%x flags=%x addr=%p ip=%x tid=%04x\n",
609 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
,
610 context
->Iar
, GetCurrentThreadId() );
611 for (c
= 0; c
< rec
->NumberParameters
; c
++)
612 TRACE( " info[%d]=%08lx\n", c
, rec
->ExceptionInformation
[c
] );
613 if (rec
->ExceptionCode
== EXCEPTION_WINE_STUB
)
615 if (rec
->ExceptionInformation
[1] >> 16)
616 MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
617 rec
->ExceptionAddress
,
618 (char*)rec
->ExceptionInformation
[0], (char*)rec
->ExceptionInformation
[1] );
620 MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
621 rec
->ExceptionAddress
,
622 (char*)rec
->ExceptionInformation
[0], rec
->ExceptionInformation
[1] );
626 /* FIXME: dump context */
629 status
= send_debug_event( rec
, TRUE
, context
);
630 if (status
== DBG_CONTINUE
|| status
== DBG_EXCEPTION_HANDLED
)
631 return STATUS_SUCCESS
;
633 if (call_vectored_handlers( rec
, context
) == EXCEPTION_CONTINUE_EXECUTION
)
634 return STATUS_SUCCESS
;
636 if ((status
= call_stack_handlers( rec
, context
)) != STATUS_UNHANDLED_EXCEPTION
)
640 /* last chance exception */
642 status
= send_debug_event( rec
, FALSE
, context
);
643 if (status
!= DBG_CONTINUE
)
645 if (rec
->ExceptionFlags
& EH_STACK_INVALID
)
646 ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
647 else if (rec
->ExceptionCode
== STATUS_NONCONTINUABLE_EXCEPTION
)
648 ERR("Process attempted to continue execution after noncontinuable exception.\n");
650 ERR("Unhandled exception code %x flags %x addr %p\n",
651 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
);
652 NtTerminateProcess( NtCurrentProcess(), rec
->ExceptionCode
);
654 return STATUS_SUCCESS
;
658 /**********************************************************************
661 * Handler for SIGSEGV and related errors.
663 static void segv_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
665 EXCEPTION_RECORD rec
;
669 save_context( &context
, sigcontext
);
671 rec
.ExceptionRecord
= NULL
;
672 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
673 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
674 rec
.NumberParameters
= 0;
679 switch (siginfo
->si_code
& 0xffff)
683 rec
.NumberParameters
= 2;
684 rec
.ExceptionInformation
[0] = 0; /* FIXME ? */
685 rec
.ExceptionInformation
[1] = (ULONG_PTR
)siginfo
->si_addr
;
686 if (!(rec
.ExceptionCode
= virtual_handle_fault(siginfo
->si_addr
, rec
.ExceptionInformation
[0])))
690 FIXME("Unhandled SIGSEGV/%x\n",siginfo
->si_code
);
695 switch (siginfo
->si_code
& 0xffff)
698 rec
.ExceptionCode
= EXCEPTION_DATATYPE_MISALIGNMENT
;
705 /* FIXME: correct for all cases ? */
706 rec
.NumberParameters
= 2;
707 rec
.ExceptionInformation
[0] = 0; /* FIXME ? */
708 rec
.ExceptionInformation
[1] = (ULONG_PTR
)siginfo
->si_addr
;
709 if (!(rec
.ExceptionCode
= virtual_handle_fault(siginfo
->si_addr
, rec
.ExceptionInformation
[0])))
714 FIXME("Unhandled SIGBUS/%x\n",siginfo
->si_code
);
719 switch (siginfo
->si_code
& 0xffff)
721 case ILL_ILLOPC
: /* illegal opcode */
723 case ILL_ILLOPN
: /* illegal operand */
726 case ILL_ILLADR
: /* illegal addressing mode */
729 case ILL_ILLTRP
: /* illegal trap */
732 case ILL_COPROC
: /* coprocessor error */
734 rec
.ExceptionCode
= EXCEPTION_ILLEGAL_INSTRUCTION
;
736 case ILL_PRVOPC
: /* privileged opcode */
738 case ILL_PRVREG
: /* privileged register */
740 rec
.ExceptionCode
= EXCEPTION_PRIV_INSTRUCTION
;
743 case ILL_BADSTK
: /* internal stack error */
744 rec
.ExceptionCode
= EXCEPTION_STACK_OVERFLOW
;
748 FIXME("Unhandled SIGILL/%x\n", siginfo
->si_code
);
753 status
= raise_exception( &rec
, &context
, TRUE
);
754 if (status
) raise_status( status
, &rec
);
756 restore_context( &context
, sigcontext
);
759 /**********************************************************************
762 * Handler for SIGTRAP.
764 static void trap_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
766 EXCEPTION_RECORD rec
;
770 save_context( &context
, sigcontext
);
772 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
773 rec
.ExceptionRecord
= NULL
;
774 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
775 rec
.NumberParameters
= 0;
777 /* FIXME: check if we might need to modify PC */
778 switch (siginfo
->si_code
& 0xffff)
782 rec
.ExceptionCode
= EXCEPTION_BREAKPOINT
;
787 rec
.ExceptionCode
= EXCEPTION_SINGLE_STEP
;
791 FIXME("Unhandled SIGTRAP/%x\n", siginfo
->si_code
);
794 status
= raise_exception( &rec
, &context
, TRUE
);
795 if (status
) raise_status( status
, &rec
);
796 restore_context( &context
, sigcontext
);
799 /**********************************************************************
802 * Handler for SIGFPE.
804 static void fpe_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
806 EXCEPTION_RECORD rec
;
810 save_fpu( &context
, sigcontext
);
811 save_context( &context
, sigcontext
);
813 switch (siginfo
->si_code
& 0xffff )
817 rec
.ExceptionCode
= EXCEPTION_ARRAY_BOUNDS_EXCEEDED
;
822 rec
.ExceptionCode
= EXCEPTION_INT_DIVIDE_BY_ZERO
;
827 rec
.ExceptionCode
= EXCEPTION_INT_OVERFLOW
;
832 rec
.ExceptionCode
= EXCEPTION_FLT_DIVIDE_BY_ZERO
;
837 rec
.ExceptionCode
= EXCEPTION_FLT_OVERFLOW
;
842 rec
.ExceptionCode
= EXCEPTION_FLT_UNDERFLOW
;
847 rec
.ExceptionCode
= EXCEPTION_FLT_INEXACT_RESULT
;
854 rec
.ExceptionCode
= EXCEPTION_FLT_INVALID_OPERATION
;
857 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
858 rec
.ExceptionRecord
= NULL
;
859 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
860 rec
.NumberParameters
= 0;
861 status
= raise_exception( &rec
, &context
, TRUE
);
862 if (status
) raise_status( status
, &rec
);
864 restore_context( &context
, sigcontext
);
865 restore_fpu( &context
, sigcontext
);
868 /**********************************************************************
871 * Handler for SIGINT.
873 static void int_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
875 if (!dispatch_signal(SIGINT
))
877 EXCEPTION_RECORD rec
;
881 save_context( &context
, sigcontext
);
882 rec
.ExceptionCode
= CONTROL_C_EXIT
;
883 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
884 rec
.ExceptionRecord
= NULL
;
885 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
886 rec
.NumberParameters
= 0;
887 status
= raise_exception( &rec
, &context
, TRUE
);
888 if (status
) raise_status( status
, &rec
);
889 restore_context( &context
, sigcontext
);
894 /**********************************************************************
897 * Handler for SIGABRT.
899 static void abrt_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
901 EXCEPTION_RECORD rec
;
905 save_context( &context
, sigcontext
);
906 rec
.ExceptionCode
= EXCEPTION_WINE_ASSERTION
;
907 rec
.ExceptionFlags
= EH_NONCONTINUABLE
;
908 rec
.ExceptionRecord
= NULL
;
909 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
910 rec
.NumberParameters
= 0;
911 status
= raise_exception( &rec
, &context
, TRUE
);
912 if (status
) raise_status( status
, &rec
);
913 restore_context( &context
, sigcontext
);
917 /**********************************************************************
920 * Handler for SIGQUIT.
922 static void quit_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
928 /**********************************************************************
931 * Handler for SIGUSR1, used to signal a thread that it got suspended.
933 static void usr1_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
937 save_context( &context
, sigcontext
);
938 wait_suspend( &context
);
939 restore_context( &context
, sigcontext
);
943 /***********************************************************************
944 * __wine_set_signal_handler (NTDLL.@)
946 int CDECL
__wine_set_signal_handler(unsigned int sig
, wine_signal_handler wsh
)
948 if (sig
> sizeof(handlers
) / sizeof(handlers
[0])) return -1;
949 if (handlers
[sig
] != NULL
) return -2;
955 /**********************************************************************
956 * signal_alloc_thread
958 NTSTATUS
signal_alloc_thread( TEB
**teb
)
960 static size_t sigstack_zero_bits
;
964 if (!sigstack_zero_bits
)
966 size_t min_size
= page_size
; /* this is just for the TEB, we don't use a signal stack yet */
967 /* find the first power of two not smaller than min_size */
968 while ((1u << sigstack_zero_bits
) < min_size
) sigstack_zero_bits
++;
969 assert( sizeof(TEB
) <= min_size
);
972 size
= 1 << sigstack_zero_bits
;
974 if (!(status
= NtAllocateVirtualMemory( NtCurrentProcess(), (void **)teb
, sigstack_zero_bits
,
975 &size
, MEM_COMMIT
| MEM_TOP_DOWN
, PAGE_READWRITE
)))
977 (*teb
)->Tib
.Self
= &(*teb
)->Tib
;
978 (*teb
)->Tib
.ExceptionList
= (void *)~0UL;
984 /**********************************************************************
987 void signal_free_thread( TEB
*teb
)
991 if (teb
->DeallocationStack
)
994 NtFreeVirtualMemory( GetCurrentProcess(), &teb
->DeallocationStack
, &size
, MEM_RELEASE
);
997 NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb
, &size
, MEM_RELEASE
);
1001 /**********************************************************************
1002 * signal_init_thread
1004 void signal_init_thread( TEB
*teb
)
1006 static int init_done
;
1010 pthread_key_create( &teb_key
, NULL
);
1013 pthread_setspecific( teb_key
, teb
);
1017 /**********************************************************************
1018 * signal_init_process
1020 void signal_init_process(void)
1022 struct sigaction sig_act
;
1024 sig_act
.sa_mask
= server_block_set
;
1025 sig_act
.sa_flags
= SA_RESTART
| SA_SIGINFO
;
1027 sig_act
.sa_sigaction
= int_handler
;
1028 if (sigaction( SIGINT
, &sig_act
, NULL
) == -1) goto error
;
1029 sig_act
.sa_sigaction
= fpe_handler
;
1030 if (sigaction( SIGFPE
, &sig_act
, NULL
) == -1) goto error
;
1031 sig_act
.sa_sigaction
= abrt_handler
;
1032 if (sigaction( SIGABRT
, &sig_act
, NULL
) == -1) goto error
;
1033 sig_act
.sa_sigaction
= quit_handler
;
1034 if (sigaction( SIGQUIT
, &sig_act
, NULL
) == -1) goto error
;
1035 sig_act
.sa_sigaction
= usr1_handler
;
1036 if (sigaction( SIGUSR1
, &sig_act
, NULL
) == -1) goto error
;
1038 sig_act
.sa_sigaction
= segv_handler
;
1039 if (sigaction( SIGSEGV
, &sig_act
, NULL
) == -1) goto error
;
1040 if (sigaction( SIGILL
, &sig_act
, NULL
) == -1) goto error
;
1042 if (sigaction( SIGBUS
, &sig_act
, NULL
) == -1) goto error
;
1046 sig_act
.sa_sigaction
= trap_handler
;
1047 if (sigaction( SIGTRAP
, &sig_act
, NULL
) == -1) goto error
;
1052 perror("sigaction");
1057 /**********************************************************************
1058 * __wine_enter_vm86 (NTDLL.@)
1060 void __wine_enter_vm86( CONTEXT
*context
)
1062 MESSAGE("vm86 mode not supported on this platform\n");
1065 /***********************************************************************
1066 * RtlUnwind (NTDLL.@)
1068 void WINAPI
RtlUnwind( PVOID pEndFrame
, PVOID targetIp
, PEXCEPTION_RECORD pRecord
, PVOID retval
)
1070 FIXME( "Not implemented on PowerPC\n" );
1073 /*******************************************************************
1074 * NtRaiseException (NTDLL.@)
1076 NTSTATUS WINAPI
NtRaiseException( EXCEPTION_RECORD
*rec
, CONTEXT
*context
, BOOL first_chance
)
1078 NTSTATUS status
= raise_exception( rec
, context
, first_chance
);
1079 if (status
== STATUS_SUCCESS
) NtSetContextThread( GetCurrentThread(), context
);
1083 /***********************************************************************
1084 * RtlRaiseException (NTDLL.@)
1086 void WINAPI
RtlRaiseException( EXCEPTION_RECORD
*rec
)
1091 RtlCaptureContext( &context
);
1092 rec
->ExceptionAddress
= (void *)context
.Iar
;
1093 status
= raise_exception( rec
, &context
, TRUE
);
1094 if (status
) raise_status( status
, rec
);
1097 /*************************************************************************
1098 * RtlCaptureStackBackTrace (NTDLL.@)
1100 USHORT WINAPI
RtlCaptureStackBackTrace( ULONG skip
, ULONG count
, PVOID
*buffer
, ULONG
*hash
)
1102 FIXME( "(%d, %d, %p, %p) stub!\n", skip
, count
, buffer
, hash
);
1106 /***********************************************************************
1107 * call_thread_entry_point
1109 void call_thread_entry_point( LPTHREAD_START_ROUTINE entry
, void *arg
)
1113 exit_thread( entry( arg
));
1115 __EXCEPT(unhandled_exception_filter
)
1117 NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
1120 abort(); /* should not be reached */
1123 /***********************************************************************
1124 * RtlExitUserThread (NTDLL.@)
1126 void WINAPI
RtlExitUserThread( ULONG status
)
1128 exit_thread( status
);
1131 /***********************************************************************
1134 void abort_thread( int status
)
1136 terminate_thread( status
);
1139 /**********************************************************************
1140 * DbgBreakPoint (NTDLL.@)
1142 void WINAPI
DbgBreakPoint(void)
1144 kill(getpid(), SIGTRAP
);
1147 /**********************************************************************
1148 * DbgUserBreakPoint (NTDLL.@)
1150 void WINAPI
DbgUserBreakPoint(void)
1152 kill(getpid(), SIGTRAP
);
1155 /**********************************************************************
1156 * NtCurrentTeb (NTDLL.@)
1158 TEB
* WINAPI
NtCurrentTeb(void)
1160 return pthread_getspecific( teb_key
);
1163 #endif /* __powerpc__ */