oledb32: Add version resource.
[wine.git] / dlls / ntdll / signal_powerpc.c
blob507490a526492546332659c1deab289ef60c8e35
1 /*
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
21 #ifdef __powerpc__
23 #include "config.h"
24 #include "wine/port.h"
26 #include <assert.h>
27 #include <signal.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <sys/types.h>
32 #ifdef HAVE_UNISTD_H
33 # include <unistd.h>
34 #endif
35 #ifdef HAVE_SYS_PARAM_H
36 # include <sys/param.h>
37 #endif
38 #ifdef HAVE_SYSCALL_H
39 # include <syscall.h>
40 #else
41 # ifdef HAVE_SYS_SYSCALL_H
42 # include <sys/syscall.h>
43 # endif
44 #endif
45 #ifdef HAVE_SYS_SIGNAL_H
46 # include <sys/signal.h>
47 #endif
48 #ifdef HAVE_SYS_UCONTEXT_H
49 # include <sys/ucontext.h>
50 #endif
52 #include "ntstatus.h"
53 #define WIN32_NO_STATUS
54 #include "windef.h"
55 #include "winternl.h"
56 #include "wine/library.h"
57 #include "wine/exception.h"
58 #include "ntdll_misc.h"
59 #include "wine/debug.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(seh);
63 static pthread_key_t teb_key;
65 /***********************************************************************
66 * signal context platform-specific definitions
68 #ifdef linux
70 /* All Registers access - only for local access */
71 # define REG_sig(reg_name, context) ((context)->uc_mcontext.regs->reg_name)
74 /* Gpr Registers access */
75 # define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context)
77 # define IAR_sig(context) REG_sig(nip, context) /* Program counter */
78 # define MSR_sig(context) REG_sig(msr, context) /* Machine State Register (Supervisor) */
79 # define CTR_sig(context) REG_sig(ctr, context) /* Count register */
81 # define XER_sig(context) REG_sig(xer, context) /* User's integer exception register */
82 # define LR_sig(context) REG_sig(link, context) /* Link register */
83 # define CR_sig(context) REG_sig(ccr, context) /* Condition register */
85 /* Float Registers access */
86 # define FLOAT_sig(reg_num, context) (((double*)((char*)((context)->uc_mcontext.regs+48*4)))[reg_num])
88 # define FPSCR_sig(context) (*(int*)((char*)((context)->uc_mcontext.regs+(48+32*2)*4)))
90 /* Exception Registers access */
91 # define DAR_sig(context) REG_sig(dar, context)
92 # define DSISR_sig(context) REG_sig(dsisr, context)
93 # define TRAP_sig(context) REG_sig(trap, context)
95 #endif /* linux */
97 #ifdef __APPLE__
99 /* All Registers access - only for local access */
100 # define REG_sig(reg_name, context) ((context)->uc_mcontext->ss.reg_name)
101 # define FLOATREG_sig(reg_name, context) ((context)->uc_mcontext->fs.reg_name)
102 # define EXCEPREG_sig(reg_name, context) ((context)->uc_mcontext->es.reg_name)
103 # define VECREG_sig(reg_name, context) ((context)->uc_mcontext->vs.reg_name)
105 /* Gpr Registers access */
106 # define GPR_sig(reg_num, context) REG_sig(r##reg_num, context)
108 # define IAR_sig(context) REG_sig(srr0, context) /* Program counter */
109 # define MSR_sig(context) REG_sig(srr1, context) /* Machine State Register (Supervisor) */
110 # define CTR_sig(context) REG_sig(ctr, context)
112 # define XER_sig(context) REG_sig(xer, context) /* Link register */
113 # define LR_sig(context) REG_sig(lr, context) /* User's integer exception register */
114 # define CR_sig(context) REG_sig(cr, context) /* Condition register */
116 /* Float Registers access */
117 # define FLOAT_sig(reg_num, context) FLOATREG_sig(fpregs[reg_num], context)
119 # define FPSCR_sig(context) FLOATREG_sig(fpscr, context)
121 /* Exception Registers access */
122 # define DAR_sig(context) EXCEPREG_sig(dar, context) /* Fault registers for coredump */
123 # define DSISR_sig(context) EXCEPREG_sig(dsisr, context)
124 # define TRAP_sig(context) EXCEPREG_sig(exception, context) /* number of powerpc exception taken */
126 /* Signal defs : Those are undefined on darwin
127 SIGBUS
128 #undef BUS_ADRERR
129 #undef BUS_OBJERR
130 SIGILL
131 #undef ILL_ILLOPN
132 #undef ILL_ILLTRP
133 #undef ILL_ILLADR
134 #undef ILL_COPROC
135 #undef ILL_PRVREG
136 #undef ILL_BADSTK
137 SIGTRAP
138 #undef TRAP_BRKPT
139 #undef TRAP_TRACE
140 SIGFPE
143 #endif /* __APPLE__ */
147 typedef int (*wine_signal_handler)(unsigned int sig);
149 static wine_signal_handler handlers[256];
151 /***********************************************************************
152 * dispatch_signal
154 static inline int dispatch_signal(unsigned int sig)
156 if (handlers[sig] == NULL) return 0;
157 return handlers[sig](sig);
160 /***********************************************************************
161 * save_context
163 * Set the register values from a sigcontext.
165 static void save_context( CONTEXT *context, const ucontext_t *sigcontext )
168 #define C(x) context->Gpr##x = GPR_sig(x,sigcontext)
169 /* Save Gpr registers */
170 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
171 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
172 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
173 C(31);
174 #undef C
176 context->Iar = IAR_sig(sigcontext); /* Program Counter */
177 context->Msr = MSR_sig(sigcontext); /* Machine State Register (Supervisor) */
178 context->Ctr = CTR_sig(sigcontext);
180 context->Xer = XER_sig(sigcontext);
181 context->Lr = LR_sig(sigcontext);
182 context->Cr = CR_sig(sigcontext);
184 /* Saving Exception regs */
185 context->Dar = DAR_sig(sigcontext);
186 context->Dsisr = DSISR_sig(sigcontext);
187 context->Trap = TRAP_sig(sigcontext);
191 /***********************************************************************
192 * restore_context
194 * Build a sigcontext from the register values.
196 static void restore_context( const CONTEXT *context, ucontext_t *sigcontext )
199 #define C(x) GPR_sig(x,sigcontext) = context->Gpr##x
200 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
201 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
202 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
203 C(31);
204 #undef C
206 IAR_sig(sigcontext) = context->Iar; /* Program Counter */
207 MSR_sig(sigcontext) = context->Msr; /* Machine State Register (Supervisor) */
208 CTR_sig(sigcontext) = context->Ctr;
210 XER_sig(sigcontext) = context->Xer;
211 LR_sig(sigcontext) = context->Lr;
212 CR_sig(sigcontext) = context->Cr;
214 /* Setting Exception regs */
215 DAR_sig(sigcontext) = context->Dar;
216 DSISR_sig(sigcontext) = context->Dsisr;
217 TRAP_sig(sigcontext) = context->Trap;
221 /***********************************************************************
222 * save_fpu
224 * Set the FPU context from a sigcontext.
226 static inline void save_fpu( CONTEXT *context, const ucontext_t *sigcontext )
228 #define C(x) context->Fpr##x = FLOAT_sig(x,sigcontext)
229 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
230 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
231 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
232 C(31);
233 #undef C
234 context->Fpscr = FPSCR_sig(sigcontext);
238 /***********************************************************************
239 * restore_fpu
241 * Restore the FPU context to a sigcontext.
243 static inline void restore_fpu( CONTEXT *context, const ucontext_t *sigcontext )
245 #define C(x) FLOAT_sig(x,sigcontext) = context->Fpr##x
246 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
247 C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
248 C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
249 C(31);
250 #undef C
251 FPSCR_sig(sigcontext) = context->Fpscr;
255 /***********************************************************************
256 * RtlCaptureContext (NTDLL.@)
258 void WINAPI RtlCaptureContext( CONTEXT *context )
260 FIXME("not implemented\n");
261 memset( context, 0, sizeof(*context) );
265 /***********************************************************************
266 * set_cpu_context
268 * Set the new CPU context.
270 void set_cpu_context( const CONTEXT *context )
272 FIXME("not implemented\n");
276 /***********************************************************************
277 * copy_context
279 * Copy a register context according to the flags.
281 void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags )
283 if (flags & CONTEXT_CONTROL)
285 to->Msr = from->Msr;
286 to->Ctr = from->Ctr;
287 to->Iar = from->Iar;
288 to->Lr = from->Lr;
289 to->Dar = from->Dar;
290 to->Dsisr = from->Dsisr;
291 to->Trap = from->Trap;
293 if (flags & CONTEXT_INTEGER)
295 to->Gpr0 = from->Gpr0;
296 to->Gpr1 = from->Gpr1;
297 to->Gpr2 = from->Gpr2;
298 to->Gpr3 = from->Gpr3;
299 to->Gpr4 = from->Gpr4;
300 to->Gpr5 = from->Gpr5;
301 to->Gpr6 = from->Gpr6;
302 to->Gpr7 = from->Gpr7;
303 to->Gpr8 = from->Gpr8;
304 to->Gpr9 = from->Gpr9;
305 to->Gpr10 = from->Gpr10;
306 to->Gpr11 = from->Gpr11;
307 to->Gpr12 = from->Gpr12;
308 to->Gpr13 = from->Gpr13;
309 to->Gpr14 = from->Gpr14;
310 to->Gpr15 = from->Gpr15;
311 to->Gpr16 = from->Gpr16;
312 to->Gpr17 = from->Gpr17;
313 to->Gpr18 = from->Gpr18;
314 to->Gpr19 = from->Gpr19;
315 to->Gpr20 = from->Gpr20;
316 to->Gpr21 = from->Gpr21;
317 to->Gpr22 = from->Gpr22;
318 to->Gpr23 = from->Gpr23;
319 to->Gpr24 = from->Gpr24;
320 to->Gpr25 = from->Gpr25;
321 to->Gpr26 = from->Gpr26;
322 to->Gpr27 = from->Gpr27;
323 to->Gpr28 = from->Gpr28;
324 to->Gpr29 = from->Gpr29;
325 to->Gpr30 = from->Gpr30;
326 to->Gpr31 = from->Gpr31;
327 to->Xer = from->Xer;
328 to->Cr = from->Cr;
330 if (flags & CONTEXT_FLOATING_POINT)
332 to->Fpr0 = from->Fpr0;
333 to->Fpr1 = from->Fpr1;
334 to->Fpr2 = from->Fpr2;
335 to->Fpr3 = from->Fpr3;
336 to->Fpr4 = from->Fpr4;
337 to->Fpr5 = from->Fpr5;
338 to->Fpr6 = from->Fpr6;
339 to->Fpr7 = from->Fpr7;
340 to->Fpr8 = from->Fpr8;
341 to->Fpr9 = from->Fpr9;
342 to->Fpr10 = from->Fpr10;
343 to->Fpr11 = from->Fpr11;
344 to->Fpr12 = from->Fpr12;
345 to->Fpr13 = from->Fpr13;
346 to->Fpr14 = from->Fpr14;
347 to->Fpr15 = from->Fpr15;
348 to->Fpr16 = from->Fpr16;
349 to->Fpr17 = from->Fpr17;
350 to->Fpr18 = from->Fpr18;
351 to->Fpr19 = from->Fpr19;
352 to->Fpr20 = from->Fpr20;
353 to->Fpr21 = from->Fpr21;
354 to->Fpr22 = from->Fpr22;
355 to->Fpr23 = from->Fpr23;
356 to->Fpr24 = from->Fpr24;
357 to->Fpr25 = from->Fpr25;
358 to->Fpr26 = from->Fpr26;
359 to->Fpr27 = from->Fpr27;
360 to->Fpr28 = from->Fpr28;
361 to->Fpr29 = from->Fpr29;
362 to->Fpr30 = from->Fpr30;
363 to->Fpr31 = from->Fpr31;
364 to->Fpscr = from->Fpscr;
369 /***********************************************************************
370 * context_to_server
372 * Convert a register context to the server format.
374 NTSTATUS context_to_server( context_t *to, const CONTEXT *from )
376 DWORD flags = from->ContextFlags; /* no CPU id? */
378 memset( to, 0, sizeof(*to) );
379 to->cpu = CPU_POWERPC;
381 if (flags & CONTEXT_CONTROL)
383 to->flags |= SERVER_CTX_CONTROL;
384 to->ctl.powerpc_regs.iar = from->Iar;
385 to->ctl.powerpc_regs.msr = from->Msr;
386 to->ctl.powerpc_regs.ctr = from->Ctr;
387 to->ctl.powerpc_regs.lr = from->Lr;
388 to->ctl.powerpc_regs.dar = from->Dar;
389 to->ctl.powerpc_regs.dsisr = from->Dsisr;
390 to->ctl.powerpc_regs.trap = from->Trap;
392 if (flags & CONTEXT_INTEGER)
394 to->flags |= SERVER_CTX_INTEGER;
395 to->integer.powerpc_regs.gpr[0] = from->Gpr0;
396 to->integer.powerpc_regs.gpr[1] = from->Gpr1;
397 to->integer.powerpc_regs.gpr[2] = from->Gpr2;
398 to->integer.powerpc_regs.gpr[3] = from->Gpr3;
399 to->integer.powerpc_regs.gpr[4] = from->Gpr4;
400 to->integer.powerpc_regs.gpr[5] = from->Gpr5;
401 to->integer.powerpc_regs.gpr[6] = from->Gpr6;
402 to->integer.powerpc_regs.gpr[7] = from->Gpr7;
403 to->integer.powerpc_regs.gpr[8] = from->Gpr8;
404 to->integer.powerpc_regs.gpr[9] = from->Gpr9;
405 to->integer.powerpc_regs.gpr[10] = from->Gpr10;
406 to->integer.powerpc_regs.gpr[11] = from->Gpr11;
407 to->integer.powerpc_regs.gpr[12] = from->Gpr12;
408 to->integer.powerpc_regs.gpr[13] = from->Gpr13;
409 to->integer.powerpc_regs.gpr[14] = from->Gpr14;
410 to->integer.powerpc_regs.gpr[15] = from->Gpr15;
411 to->integer.powerpc_regs.gpr[16] = from->Gpr16;
412 to->integer.powerpc_regs.gpr[17] = from->Gpr17;
413 to->integer.powerpc_regs.gpr[18] = from->Gpr18;
414 to->integer.powerpc_regs.gpr[19] = from->Gpr19;
415 to->integer.powerpc_regs.gpr[20] = from->Gpr20;
416 to->integer.powerpc_regs.gpr[21] = from->Gpr21;
417 to->integer.powerpc_regs.gpr[22] = from->Gpr22;
418 to->integer.powerpc_regs.gpr[23] = from->Gpr23;
419 to->integer.powerpc_regs.gpr[24] = from->Gpr24;
420 to->integer.powerpc_regs.gpr[25] = from->Gpr25;
421 to->integer.powerpc_regs.gpr[26] = from->Gpr26;
422 to->integer.powerpc_regs.gpr[27] = from->Gpr27;
423 to->integer.powerpc_regs.gpr[28] = from->Gpr28;
424 to->integer.powerpc_regs.gpr[29] = from->Gpr29;
425 to->integer.powerpc_regs.gpr[30] = from->Gpr30;
426 to->integer.powerpc_regs.gpr[31] = from->Gpr31;
427 to->integer.powerpc_regs.xer = from->Xer;
428 to->integer.powerpc_regs.cr = from->Cr;
430 if (flags & CONTEXT_FLOATING_POINT)
432 to->flags |= SERVER_CTX_FLOATING_POINT;
433 to->fp.powerpc_regs.fpr[0] = from->Fpr0;
434 to->fp.powerpc_regs.fpr[1] = from->Fpr1;
435 to->fp.powerpc_regs.fpr[2] = from->Fpr2;
436 to->fp.powerpc_regs.fpr[3] = from->Fpr3;
437 to->fp.powerpc_regs.fpr[4] = from->Fpr4;
438 to->fp.powerpc_regs.fpr[5] = from->Fpr5;
439 to->fp.powerpc_regs.fpr[6] = from->Fpr6;
440 to->fp.powerpc_regs.fpr[7] = from->Fpr7;
441 to->fp.powerpc_regs.fpr[8] = from->Fpr8;
442 to->fp.powerpc_regs.fpr[9] = from->Fpr9;
443 to->fp.powerpc_regs.fpr[10] = from->Fpr10;
444 to->fp.powerpc_regs.fpr[11] = from->Fpr11;
445 to->fp.powerpc_regs.fpr[12] = from->Fpr12;
446 to->fp.powerpc_regs.fpr[13] = from->Fpr13;
447 to->fp.powerpc_regs.fpr[14] = from->Fpr14;
448 to->fp.powerpc_regs.fpr[15] = from->Fpr15;
449 to->fp.powerpc_regs.fpr[16] = from->Fpr16;
450 to->fp.powerpc_regs.fpr[17] = from->Fpr17;
451 to->fp.powerpc_regs.fpr[18] = from->Fpr18;
452 to->fp.powerpc_regs.fpr[19] = from->Fpr19;
453 to->fp.powerpc_regs.fpr[20] = from->Fpr20;
454 to->fp.powerpc_regs.fpr[21] = from->Fpr21;
455 to->fp.powerpc_regs.fpr[22] = from->Fpr22;
456 to->fp.powerpc_regs.fpr[23] = from->Fpr23;
457 to->fp.powerpc_regs.fpr[24] = from->Fpr24;
458 to->fp.powerpc_regs.fpr[25] = from->Fpr25;
459 to->fp.powerpc_regs.fpr[26] = from->Fpr26;
460 to->fp.powerpc_regs.fpr[27] = from->Fpr27;
461 to->fp.powerpc_regs.fpr[28] = from->Fpr28;
462 to->fp.powerpc_regs.fpr[29] = from->Fpr29;
463 to->fp.powerpc_regs.fpr[30] = from->Fpr30;
464 to->fp.powerpc_regs.fpr[31] = from->Fpr31;
465 to->fp.powerpc_regs.fpscr = from->Fpscr;
467 return STATUS_SUCCESS;
471 /***********************************************************************
472 * context_from_server
474 * Convert a register context from the server format.
476 NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
478 if (from->cpu != CPU_POWERPC) return STATUS_INVALID_PARAMETER;
480 to->ContextFlags = 0; /* no CPU id? */
481 if (from->flags & SERVER_CTX_CONTROL)
483 to->ContextFlags |= CONTEXT_CONTROL;
484 to->Msr = from->ctl.powerpc_regs.msr;
485 to->Ctr = from->ctl.powerpc_regs.ctr;
486 to->Iar = from->ctl.powerpc_regs.iar;
487 to->Lr = from->ctl.powerpc_regs.lr;
488 to->Dar = from->ctl.powerpc_regs.dar;
489 to->Dsisr = from->ctl.powerpc_regs.dsisr;
490 to->Trap = from->ctl.powerpc_regs.trap;
492 if (from->flags & SERVER_CTX_INTEGER)
494 to->ContextFlags |= CONTEXT_INTEGER;
495 to->Gpr0 = from->integer.powerpc_regs.gpr[0];
496 to->Gpr1 = from->integer.powerpc_regs.gpr[1];
497 to->Gpr2 = from->integer.powerpc_regs.gpr[2];
498 to->Gpr3 = from->integer.powerpc_regs.gpr[3];
499 to->Gpr4 = from->integer.powerpc_regs.gpr[4];
500 to->Gpr5 = from->integer.powerpc_regs.gpr[5];
501 to->Gpr6 = from->integer.powerpc_regs.gpr[6];
502 to->Gpr7 = from->integer.powerpc_regs.gpr[7];
503 to->Gpr8 = from->integer.powerpc_regs.gpr[8];
504 to->Gpr9 = from->integer.powerpc_regs.gpr[9];
505 to->Gpr10 = from->integer.powerpc_regs.gpr[10];
506 to->Gpr11 = from->integer.powerpc_regs.gpr[11];
507 to->Gpr12 = from->integer.powerpc_regs.gpr[12];
508 to->Gpr13 = from->integer.powerpc_regs.gpr[13];
509 to->Gpr14 = from->integer.powerpc_regs.gpr[14];
510 to->Gpr15 = from->integer.powerpc_regs.gpr[15];
511 to->Gpr16 = from->integer.powerpc_regs.gpr[16];
512 to->Gpr17 = from->integer.powerpc_regs.gpr[17];
513 to->Gpr18 = from->integer.powerpc_regs.gpr[18];
514 to->Gpr19 = from->integer.powerpc_regs.gpr[19];
515 to->Gpr20 = from->integer.powerpc_regs.gpr[20];
516 to->Gpr21 = from->integer.powerpc_regs.gpr[21];
517 to->Gpr22 = from->integer.powerpc_regs.gpr[22];
518 to->Gpr23 = from->integer.powerpc_regs.gpr[23];
519 to->Gpr24 = from->integer.powerpc_regs.gpr[24];
520 to->Gpr25 = from->integer.powerpc_regs.gpr[25];
521 to->Gpr26 = from->integer.powerpc_regs.gpr[26];
522 to->Gpr27 = from->integer.powerpc_regs.gpr[27];
523 to->Gpr28 = from->integer.powerpc_regs.gpr[28];
524 to->Gpr29 = from->integer.powerpc_regs.gpr[29];
525 to->Gpr30 = from->integer.powerpc_regs.gpr[30];
526 to->Gpr31 = from->integer.powerpc_regs.gpr[31];
527 to->Xer = from->integer.powerpc_regs.xer;
528 to->Cr = from->integer.powerpc_regs.cr;
530 if (from->flags & SERVER_CTX_FLOATING_POINT)
532 to->ContextFlags |= CONTEXT_FLOATING_POINT;
533 to->Fpr0 = from->fp.powerpc_regs.fpr[0];
534 to->Fpr1 = from->fp.powerpc_regs.fpr[1];
535 to->Fpr2 = from->fp.powerpc_regs.fpr[2];
536 to->Fpr3 = from->fp.powerpc_regs.fpr[3];
537 to->Fpr4 = from->fp.powerpc_regs.fpr[4];
538 to->Fpr5 = from->fp.powerpc_regs.fpr[5];
539 to->Fpr6 = from->fp.powerpc_regs.fpr[6];
540 to->Fpr7 = from->fp.powerpc_regs.fpr[7];
541 to->Fpr8 = from->fp.powerpc_regs.fpr[8];
542 to->Fpr9 = from->fp.powerpc_regs.fpr[9];
543 to->Fpr10 = from->fp.powerpc_regs.fpr[10];
544 to->Fpr11 = from->fp.powerpc_regs.fpr[11];
545 to->Fpr12 = from->fp.powerpc_regs.fpr[12];
546 to->Fpr13 = from->fp.powerpc_regs.fpr[13];
547 to->Fpr14 = from->fp.powerpc_regs.fpr[14];
548 to->Fpr15 = from->fp.powerpc_regs.fpr[15];
549 to->Fpr16 = from->fp.powerpc_regs.fpr[16];
550 to->Fpr17 = from->fp.powerpc_regs.fpr[17];
551 to->Fpr18 = from->fp.powerpc_regs.fpr[18];
552 to->Fpr19 = from->fp.powerpc_regs.fpr[19];
553 to->Fpr20 = from->fp.powerpc_regs.fpr[20];
554 to->Fpr21 = from->fp.powerpc_regs.fpr[21];
555 to->Fpr22 = from->fp.powerpc_regs.fpr[22];
556 to->Fpr23 = from->fp.powerpc_regs.fpr[23];
557 to->Fpr24 = from->fp.powerpc_regs.fpr[24];
558 to->Fpr25 = from->fp.powerpc_regs.fpr[25];
559 to->Fpr26 = from->fp.powerpc_regs.fpr[26];
560 to->Fpr27 = from->fp.powerpc_regs.fpr[27];
561 to->Fpr28 = from->fp.powerpc_regs.fpr[28];
562 to->Fpr29 = from->fp.powerpc_regs.fpr[29];
563 to->Fpr30 = from->fp.powerpc_regs.fpr[30];
564 to->Fpr31 = from->fp.powerpc_regs.fpr[31];
565 to->Fpscr = from->fp.powerpc_regs.fpscr;
567 return STATUS_SUCCESS;
571 /**********************************************************************
572 * call_stack_handlers
574 * Call the stack handlers chain.
576 static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
578 EXCEPTION_POINTERS ptrs;
580 FIXME( "not implemented on PowerPC\n" );
582 /* hack: call unhandled exception filter directly */
583 ptrs.ExceptionRecord = rec;
584 ptrs.ContextRecord = context;
585 unhandled_exception_filter( &ptrs );
586 return STATUS_UNHANDLED_EXCEPTION;
590 /*******************************************************************
591 * raise_exception
593 * Implementation of NtRaiseException.
595 static NTSTATUS raise_exception( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
597 NTSTATUS status;
599 if (first_chance)
601 DWORD c;
603 TRACE( "code=%x flags=%x addr=%p ip=%x tid=%04x\n",
604 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
605 context->Iar, GetCurrentThreadId() );
606 for (c = 0; c < rec->NumberParameters; c++)
607 TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] );
608 if (rec->ExceptionCode == EXCEPTION_WINE_STUB)
610 if (rec->ExceptionInformation[1] >> 16)
611 MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
612 rec->ExceptionAddress,
613 (char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] );
614 else
615 MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
616 rec->ExceptionAddress,
617 (char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] );
619 else
621 /* FIXME: dump context */
624 status = send_debug_event( rec, TRUE, context );
625 if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
626 return STATUS_SUCCESS;
628 if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION)
629 return STATUS_SUCCESS;
631 if ((status = call_stack_handlers( rec, context )) != STATUS_UNHANDLED_EXCEPTION)
632 return status;
635 /* last chance exception */
637 status = send_debug_event( rec, FALSE, context );
638 if (status != DBG_CONTINUE)
640 if (rec->ExceptionFlags & EH_STACK_INVALID)
641 ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
642 else if (rec->ExceptionCode == STATUS_NONCONTINUABLE_EXCEPTION)
643 ERR("Process attempted to continue execution after noncontinuable exception.\n");
644 else
645 ERR("Unhandled exception code %x flags %x addr %p\n",
646 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
647 NtTerminateProcess( NtCurrentProcess(), rec->ExceptionCode );
649 return STATUS_SUCCESS;
653 /**********************************************************************
654 * segv_handler
656 * Handler for SIGSEGV and related errors.
658 static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext )
660 EXCEPTION_RECORD rec;
661 CONTEXT context;
662 NTSTATUS status;
664 save_context( &context, sigcontext );
666 rec.ExceptionRecord = NULL;
667 rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
668 rec.ExceptionAddress = (LPVOID)context.Iar;
669 rec.NumberParameters = 0;
671 switch (signal)
673 case SIGSEGV:
674 switch (siginfo->si_code & 0xffff)
676 case SEGV_MAPERR:
677 case SEGV_ACCERR:
678 rec.NumberParameters = 2;
679 rec.ExceptionInformation[0] = 0; /* FIXME ? */
680 rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
681 if (!(rec.ExceptionCode = virtual_handle_fault(siginfo->si_addr, rec.ExceptionInformation[0], FALSE)))
682 goto done;
683 break;
684 default:
685 FIXME("Unhandled SIGSEGV/%x\n",siginfo->si_code);
686 break;
688 break;
689 case SIGBUS:
690 switch (siginfo->si_code & 0xffff)
692 case BUS_ADRALN:
693 rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
694 break;
695 #ifdef BUS_ADRERR
696 case BUS_ADRERR:
697 #endif
698 #ifdef BUS_OBJERR
699 case BUS_OBJERR:
700 /* FIXME: correct for all cases ? */
701 rec.NumberParameters = 2;
702 rec.ExceptionInformation[0] = 0; /* FIXME ? */
703 rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
704 if (!(rec.ExceptionCode = virtual_handle_fault(siginfo->si_addr, rec.ExceptionInformation[0], FALSE)))
705 goto done;
706 break;
707 #endif
708 default:
709 FIXME("Unhandled SIGBUS/%x\n",siginfo->si_code);
710 break;
712 break;
713 case SIGILL:
714 switch (siginfo->si_code & 0xffff)
716 case ILL_ILLOPC: /* illegal opcode */
717 #ifdef ILL_ILLOPN
718 case ILL_ILLOPN: /* illegal operand */
719 #endif
720 #ifdef ILL_ILLADR
721 case ILL_ILLADR: /* illegal addressing mode */
722 #endif
723 #ifdef ILL_ILLTRP
724 case ILL_ILLTRP: /* illegal trap */
725 #endif
726 #ifdef ILL_COPROC
727 case ILL_COPROC: /* coprocessor error */
728 #endif
729 rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
730 break;
731 case ILL_PRVOPC: /* privileged opcode */
732 #ifdef ILL_PRVREG
733 case ILL_PRVREG: /* privileged register */
734 #endif
735 rec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION;
736 break;
737 #ifdef ILL_BADSTK
738 case ILL_BADSTK: /* internal stack error */
739 rec.ExceptionCode = EXCEPTION_STACK_OVERFLOW;
740 break;
741 #endif
742 default:
743 FIXME("Unhandled SIGILL/%x\n", siginfo->si_code);
744 break;
746 break;
748 status = raise_exception( &rec, &context, TRUE );
749 if (status) raise_status( status, &rec );
750 done:
751 restore_context( &context, sigcontext );
754 /**********************************************************************
755 * trap_handler
757 * Handler for SIGTRAP.
759 static void trap_handler( int signal, siginfo_t *siginfo, void *sigcontext )
761 EXCEPTION_RECORD rec;
762 CONTEXT context;
763 NTSTATUS status;
765 save_context( &context, sigcontext );
767 rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
768 rec.ExceptionRecord = NULL;
769 rec.ExceptionAddress = (LPVOID)context.Iar;
770 rec.NumberParameters = 0;
772 /* FIXME: check if we might need to modify PC */
773 switch (siginfo->si_code & 0xffff)
775 #ifdef TRAP_BRKPT
776 case TRAP_BRKPT:
777 rec.ExceptionCode = EXCEPTION_BREAKPOINT;
778 break;
779 #endif
780 #ifdef TRAP_TRACE
781 case TRAP_TRACE:
782 rec.ExceptionCode = EXCEPTION_SINGLE_STEP;
783 break;
784 #endif
785 default:
786 FIXME("Unhandled SIGTRAP/%x\n", siginfo->si_code);
787 break;
789 status = raise_exception( &rec, &context, TRUE );
790 if (status) raise_status( status, &rec );
791 restore_context( &context, sigcontext );
794 /**********************************************************************
795 * fpe_handler
797 * Handler for SIGFPE.
799 static void fpe_handler( int signal, siginfo_t *siginfo, void *sigcontext )
801 EXCEPTION_RECORD rec;
802 CONTEXT context;
803 NTSTATUS status;
805 save_fpu( &context, sigcontext );
806 save_context( &context, sigcontext );
808 switch (siginfo->si_code & 0xffff )
810 #ifdef FPE_FLTSUB
811 case FPE_FLTSUB:
812 rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
813 break;
814 #endif
815 #ifdef FPE_INTDIV
816 case FPE_INTDIV:
817 rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
818 break;
819 #endif
820 #ifdef FPE_INTOVF
821 case FPE_INTOVF:
822 rec.ExceptionCode = EXCEPTION_INT_OVERFLOW;
823 break;
824 #endif
825 #ifdef FPE_FLTDIV
826 case FPE_FLTDIV:
827 rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO;
828 break;
829 #endif
830 #ifdef FPE_FLTOVF
831 case FPE_FLTOVF:
832 rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW;
833 break;
834 #endif
835 #ifdef FPE_FLTUND
836 case FPE_FLTUND:
837 rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW;
838 break;
839 #endif
840 #ifdef FPE_FLTRES
841 case FPE_FLTRES:
842 rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT;
843 break;
844 #endif
845 #ifdef FPE_FLTINV
846 case FPE_FLTINV:
847 #endif
848 default:
849 rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
850 break;
852 rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
853 rec.ExceptionRecord = NULL;
854 rec.ExceptionAddress = (LPVOID)context.Iar;
855 rec.NumberParameters = 0;
856 status = raise_exception( &rec, &context, TRUE );
857 if (status) raise_status( status, &rec );
859 restore_context( &context, sigcontext );
860 restore_fpu( &context, sigcontext );
863 /**********************************************************************
864 * int_handler
866 * Handler for SIGINT.
868 static void int_handler( int signal, siginfo_t *siginfo, void *sigcontext )
870 if (!dispatch_signal(SIGINT))
872 EXCEPTION_RECORD rec;
873 CONTEXT context;
874 NTSTATUS status;
876 save_context( &context, sigcontext );
877 rec.ExceptionCode = CONTROL_C_EXIT;
878 rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
879 rec.ExceptionRecord = NULL;
880 rec.ExceptionAddress = (LPVOID)context.Iar;
881 rec.NumberParameters = 0;
882 status = raise_exception( &rec, &context, TRUE );
883 if (status) raise_status( status, &rec );
884 restore_context( &context, sigcontext );
889 /**********************************************************************
890 * abrt_handler
892 * Handler for SIGABRT.
894 static void abrt_handler( int signal, siginfo_t *siginfo, void *sigcontext )
896 EXCEPTION_RECORD rec;
897 CONTEXT context;
898 NTSTATUS status;
900 save_context( &context, sigcontext );
901 rec.ExceptionCode = EXCEPTION_WINE_ASSERTION;
902 rec.ExceptionFlags = EH_NONCONTINUABLE;
903 rec.ExceptionRecord = NULL;
904 rec.ExceptionAddress = (LPVOID)context.Iar;
905 rec.NumberParameters = 0;
906 status = raise_exception( &rec, &context, TRUE );
907 if (status) raise_status( status, &rec );
908 restore_context( &context, sigcontext );
912 /**********************************************************************
913 * quit_handler
915 * Handler for SIGQUIT.
917 static void quit_handler( int signal, siginfo_t *siginfo, void *sigcontext )
919 abort_thread(0);
923 /**********************************************************************
924 * usr1_handler
926 * Handler for SIGUSR1, used to signal a thread that it got suspended.
928 static void usr1_handler( int signal, siginfo_t *siginfo, void *sigcontext )
930 CONTEXT context;
932 save_context( &context, sigcontext );
933 wait_suspend( &context );
934 restore_context( &context, sigcontext );
938 /***********************************************************************
939 * __wine_set_signal_handler (NTDLL.@)
941 int CDECL __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh)
943 if (sig >= sizeof(handlers) / sizeof(handlers[0])) return -1;
944 if (handlers[sig] != NULL) return -2;
945 handlers[sig] = wsh;
946 return 0;
950 /**********************************************************************
951 * signal_alloc_thread
953 NTSTATUS signal_alloc_thread( TEB **teb )
955 static size_t sigstack_zero_bits;
956 SIZE_T size;
957 NTSTATUS status;
959 if (!sigstack_zero_bits)
961 size_t min_size = page_size; /* this is just for the TEB, we don't use a signal stack yet */
962 /* find the first power of two not smaller than min_size */
963 while ((1u << sigstack_zero_bits) < min_size) sigstack_zero_bits++;
964 assert( sizeof(TEB) <= min_size );
967 size = 1 << sigstack_zero_bits;
968 *teb = NULL;
969 if (!(status = NtAllocateVirtualMemory( NtCurrentProcess(), (void **)teb, sigstack_zero_bits,
970 &size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE )))
972 (*teb)->Tib.Self = &(*teb)->Tib;
973 (*teb)->Tib.ExceptionList = (void *)~0UL;
975 return status;
979 /**********************************************************************
980 * signal_free_thread
982 void signal_free_thread( TEB *teb )
984 SIZE_T size;
986 if (teb->DeallocationStack)
988 size = 0;
989 NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE );
991 size = 0;
992 NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
996 /**********************************************************************
997 * signal_init_thread
999 void signal_init_thread( TEB *teb )
1001 static BOOL init_done;
1003 if (!init_done)
1005 pthread_key_create( &teb_key, NULL );
1006 init_done = TRUE;
1008 pthread_setspecific( teb_key, teb );
1012 /**********************************************************************
1013 * signal_init_process
1015 void signal_init_process(void)
1017 struct sigaction sig_act;
1019 sig_act.sa_mask = server_block_set;
1020 sig_act.sa_flags = SA_RESTART | SA_SIGINFO;
1022 sig_act.sa_sigaction = int_handler;
1023 if (sigaction( SIGINT, &sig_act, NULL ) == -1) goto error;
1024 sig_act.sa_sigaction = fpe_handler;
1025 if (sigaction( SIGFPE, &sig_act, NULL ) == -1) goto error;
1026 sig_act.sa_sigaction = abrt_handler;
1027 if (sigaction( SIGABRT, &sig_act, NULL ) == -1) goto error;
1028 sig_act.sa_sigaction = quit_handler;
1029 if (sigaction( SIGQUIT, &sig_act, NULL ) == -1) goto error;
1030 sig_act.sa_sigaction = usr1_handler;
1031 if (sigaction( SIGUSR1, &sig_act, NULL ) == -1) goto error;
1033 sig_act.sa_sigaction = segv_handler;
1034 if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error;
1035 if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error;
1036 #ifdef SIGBUS
1037 if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error;
1038 #endif
1040 #ifdef SIGTRAP
1041 sig_act.sa_sigaction = trap_handler;
1042 if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
1043 #endif
1044 return;
1046 error:
1047 perror("sigaction");
1048 exit(1);
1052 /**********************************************************************
1053 * __wine_enter_vm86 (NTDLL.@)
1055 void __wine_enter_vm86( CONTEXT *context )
1057 MESSAGE("vm86 mode not supported on this platform\n");
1060 /***********************************************************************
1061 * RtlUnwind (NTDLL.@)
1063 void WINAPI RtlUnwind( PVOID pEndFrame, PVOID targetIp, PEXCEPTION_RECORD pRecord, PVOID retval )
1065 FIXME( "Not implemented on PowerPC\n" );
1068 /*******************************************************************
1069 * NtRaiseException (NTDLL.@)
1071 NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
1073 NTSTATUS status = raise_exception( rec, context, first_chance );
1074 if (status == STATUS_SUCCESS) NtSetContextThread( GetCurrentThread(), context );
1075 return status;
1078 /***********************************************************************
1079 * RtlRaiseException (NTDLL.@)
1081 void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec )
1083 CONTEXT context;
1084 NTSTATUS status;
1086 RtlCaptureContext( &context );
1087 rec->ExceptionAddress = (void *)context.Iar;
1088 status = raise_exception( rec, &context, TRUE );
1089 if (status) raise_status( status, rec );
1092 /*************************************************************************
1093 * RtlCaptureStackBackTrace (NTDLL.@)
1095 USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
1097 FIXME( "(%d, %d, %p, %p) stub!\n", skip, count, buffer, hash );
1098 return 0;
1101 /***********************************************************************
1102 * call_thread_entry_point
1104 void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg )
1106 __TRY
1108 exit_thread( entry( arg ));
1110 __EXCEPT(unhandled_exception_filter)
1112 NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
1114 __ENDTRY
1115 abort(); /* should not be reached */
1118 /***********************************************************************
1119 * RtlExitUserThread (NTDLL.@)
1121 void WINAPI RtlExitUserThread( ULONG status )
1123 exit_thread( status );
1126 /***********************************************************************
1127 * abort_thread
1129 void abort_thread( int status )
1131 terminate_thread( status );
1134 /**********************************************************************
1135 * DbgBreakPoint (NTDLL.@)
1137 void WINAPI DbgBreakPoint(void)
1139 kill(getpid(), SIGTRAP);
1142 /**********************************************************************
1143 * DbgUserBreakPoint (NTDLL.@)
1145 void WINAPI DbgUserBreakPoint(void)
1147 kill(getpid(), SIGTRAP);
1150 /**********************************************************************
1151 * NtCurrentTeb (NTDLL.@)
1153 TEB * WINAPI NtCurrentTeb(void)
1155 return pthread_getspecific( teb_key );
1158 #endif /* __powerpc__ */