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"
31 #include <sys/types.h>
35 #ifdef HAVE_SYS_PARAM_H
36 # include <sys/param.h>
41 # ifdef HAVE_SYS_SYSCALL_H
42 # include <sys/syscall.h>
45 #ifdef HAVE_SYS_SIGNAL_H
46 # include <sys/signal.h>
48 #ifdef HAVE_SYS_UCONTEXT_H
49 # include <sys/ucontext.h>
53 #define WIN32_NO_STATUS
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
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)
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
143 #endif /* __APPLE__ */
147 typedef int (*wine_signal_handler
)(unsigned int sig
);
149 static wine_signal_handler handlers
[256];
151 /***********************************************************************
154 static inline int dispatch_signal(unsigned int sig
)
156 if (handlers
[sig
] == NULL
) return 0;
157 return handlers
[sig
](sig
);
160 /***********************************************************************
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);
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 /***********************************************************************
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);
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 /***********************************************************************
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);
234 context
->Fpscr
= FPSCR_sig(sigcontext
);
238 /***********************************************************************
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);
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 /***********************************************************************
268 * Set the new CPU context.
270 static void set_cpu_context( const CONTEXT
*context
)
272 FIXME("not implemented\n");
276 /***********************************************************************
279 * Copy a register context according to the flags.
281 static void copy_context( CONTEXT
*to
, const CONTEXT
*from
, DWORD flags
)
283 if (flags
& CONTEXT_CONTROL
)
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
;
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 /***********************************************************************
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 * NtSetContextThread (NTDLL.@)
573 * ZwSetContextThread (NTDLL.@)
575 NTSTATUS WINAPI
NtSetContextThread( HANDLE handle
, const CONTEXT
*context
)
580 ret
= set_thread_context( handle
, context
, &self
);
581 if (self
&& ret
== STATUS_SUCCESS
) set_cpu_context( context
);
586 /***********************************************************************
587 * NtGetContextThread (NTDLL.@)
588 * ZwGetContextThread (NTDLL.@)
590 NTSTATUS WINAPI
NtGetContextThread( HANDLE handle
, CONTEXT
*context
)
593 DWORD needed_flags
= context
->ContextFlags
;
594 BOOL self
= (handle
== GetCurrentThread());
598 if ((ret
= get_thread_context( handle
, context
, &self
))) return ret
;
599 needed_flags
&= ~context
->ContextFlags
;
602 if (self
&& needed_flags
)
605 RtlCaptureContext( &ctx
);
606 copy_context( context
, &ctx
, ctx
.ContextFlags
& needed_flags
);
607 context
->ContextFlags
|= ctx
.ContextFlags
& needed_flags
;
609 return STATUS_SUCCESS
;
613 /**********************************************************************
614 * call_stack_handlers
616 * Call the stack handlers chain.
618 static NTSTATUS
call_stack_handlers( EXCEPTION_RECORD
*rec
, CONTEXT
*context
)
620 EXCEPTION_POINTERS ptrs
;
622 FIXME( "not implemented on PowerPC\n" );
624 /* hack: call unhandled exception filter directly */
625 ptrs
.ExceptionRecord
= rec
;
626 ptrs
.ContextRecord
= context
;
627 unhandled_exception_filter( &ptrs
);
628 return STATUS_UNHANDLED_EXCEPTION
;
632 /*******************************************************************
635 * Implementation of NtRaiseException.
637 static NTSTATUS
raise_exception( EXCEPTION_RECORD
*rec
, CONTEXT
*context
, BOOL first_chance
)
645 TRACE( "code=%x flags=%x addr=%p ip=%x tid=%04x\n",
646 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
,
647 context
->Iar
, GetCurrentThreadId() );
648 for (c
= 0; c
< rec
->NumberParameters
; c
++)
649 TRACE( " info[%d]=%08lx\n", c
, rec
->ExceptionInformation
[c
] );
650 if (rec
->ExceptionCode
== EXCEPTION_WINE_STUB
)
652 if (rec
->ExceptionInformation
[1] >> 16)
653 MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
654 rec
->ExceptionAddress
,
655 (char*)rec
->ExceptionInformation
[0], (char*)rec
->ExceptionInformation
[1] );
657 MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
658 rec
->ExceptionAddress
,
659 (char*)rec
->ExceptionInformation
[0], rec
->ExceptionInformation
[1] );
663 /* FIXME: dump context */
666 status
= send_debug_event( rec
, TRUE
, context
);
667 if (status
== DBG_CONTINUE
|| status
== DBG_EXCEPTION_HANDLED
)
668 return STATUS_SUCCESS
;
670 if (call_vectored_handlers( rec
, context
) == EXCEPTION_CONTINUE_EXECUTION
)
671 return STATUS_SUCCESS
;
673 if ((status
= call_stack_handlers( rec
, context
)) != STATUS_UNHANDLED_EXCEPTION
)
677 /* last chance exception */
679 status
= send_debug_event( rec
, FALSE
, context
);
680 if (status
!= DBG_CONTINUE
)
682 if (rec
->ExceptionFlags
& EH_STACK_INVALID
)
683 ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
684 else if (rec
->ExceptionCode
== STATUS_NONCONTINUABLE_EXCEPTION
)
685 ERR("Process attempted to continue execution after noncontinuable exception.\n");
687 ERR("Unhandled exception code %x flags %x addr %p\n",
688 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
);
689 NtTerminateProcess( NtCurrentProcess(), rec
->ExceptionCode
);
691 return STATUS_SUCCESS
;
695 /**********************************************************************
698 * Handler for SIGSEGV and related errors.
700 static void segv_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
702 EXCEPTION_RECORD rec
;
706 save_context( &context
, sigcontext
);
708 rec
.ExceptionRecord
= NULL
;
709 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
710 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
711 rec
.NumberParameters
= 0;
716 switch (siginfo
->si_code
& 0xffff)
720 rec
.NumberParameters
= 2;
721 rec
.ExceptionInformation
[0] = 0; /* FIXME ? */
722 rec
.ExceptionInformation
[1] = (ULONG_PTR
)siginfo
->si_addr
;
723 if (!(rec
.ExceptionCode
= virtual_handle_fault(siginfo
->si_addr
, rec
.ExceptionInformation
[0], FALSE
)))
727 FIXME("Unhandled SIGSEGV/%x\n",siginfo
->si_code
);
732 switch (siginfo
->si_code
& 0xffff)
735 rec
.ExceptionCode
= EXCEPTION_DATATYPE_MISALIGNMENT
;
742 /* FIXME: correct for all cases ? */
743 rec
.NumberParameters
= 2;
744 rec
.ExceptionInformation
[0] = 0; /* FIXME ? */
745 rec
.ExceptionInformation
[1] = (ULONG_PTR
)siginfo
->si_addr
;
746 if (!(rec
.ExceptionCode
= virtual_handle_fault(siginfo
->si_addr
, rec
.ExceptionInformation
[0], FALSE
)))
751 FIXME("Unhandled SIGBUS/%x\n",siginfo
->si_code
);
756 switch (siginfo
->si_code
& 0xffff)
758 case ILL_ILLOPC
: /* illegal opcode */
760 case ILL_ILLOPN
: /* illegal operand */
763 case ILL_ILLADR
: /* illegal addressing mode */
766 case ILL_ILLTRP
: /* illegal trap */
769 case ILL_COPROC
: /* coprocessor error */
771 rec
.ExceptionCode
= EXCEPTION_ILLEGAL_INSTRUCTION
;
773 case ILL_PRVOPC
: /* privileged opcode */
775 case ILL_PRVREG
: /* privileged register */
777 rec
.ExceptionCode
= EXCEPTION_PRIV_INSTRUCTION
;
780 case ILL_BADSTK
: /* internal stack error */
781 rec
.ExceptionCode
= EXCEPTION_STACK_OVERFLOW
;
785 FIXME("Unhandled SIGILL/%x\n", siginfo
->si_code
);
790 status
= raise_exception( &rec
, &context
, TRUE
);
791 if (status
) raise_status( status
, &rec
);
793 restore_context( &context
, sigcontext
);
796 /**********************************************************************
799 * Handler for SIGTRAP.
801 static void trap_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
803 EXCEPTION_RECORD rec
;
807 save_context( &context
, sigcontext
);
809 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
810 rec
.ExceptionRecord
= NULL
;
811 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
812 rec
.NumberParameters
= 0;
814 /* FIXME: check if we might need to modify PC */
815 switch (siginfo
->si_code
& 0xffff)
819 rec
.ExceptionCode
= EXCEPTION_BREAKPOINT
;
824 rec
.ExceptionCode
= EXCEPTION_SINGLE_STEP
;
828 FIXME("Unhandled SIGTRAP/%x\n", siginfo
->si_code
);
831 status
= raise_exception( &rec
, &context
, TRUE
);
832 if (status
) raise_status( status
, &rec
);
833 restore_context( &context
, sigcontext
);
836 /**********************************************************************
839 * Handler for SIGFPE.
841 static void fpe_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
843 EXCEPTION_RECORD rec
;
847 save_fpu( &context
, sigcontext
);
848 save_context( &context
, sigcontext
);
850 switch (siginfo
->si_code
& 0xffff )
854 rec
.ExceptionCode
= EXCEPTION_ARRAY_BOUNDS_EXCEEDED
;
859 rec
.ExceptionCode
= EXCEPTION_INT_DIVIDE_BY_ZERO
;
864 rec
.ExceptionCode
= EXCEPTION_INT_OVERFLOW
;
869 rec
.ExceptionCode
= EXCEPTION_FLT_DIVIDE_BY_ZERO
;
874 rec
.ExceptionCode
= EXCEPTION_FLT_OVERFLOW
;
879 rec
.ExceptionCode
= EXCEPTION_FLT_UNDERFLOW
;
884 rec
.ExceptionCode
= EXCEPTION_FLT_INEXACT_RESULT
;
891 rec
.ExceptionCode
= EXCEPTION_FLT_INVALID_OPERATION
;
894 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
895 rec
.ExceptionRecord
= NULL
;
896 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
897 rec
.NumberParameters
= 0;
898 status
= raise_exception( &rec
, &context
, TRUE
);
899 if (status
) raise_status( status
, &rec
);
901 restore_context( &context
, sigcontext
);
902 restore_fpu( &context
, sigcontext
);
905 /**********************************************************************
908 * Handler for SIGINT.
910 static void int_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
912 if (!dispatch_signal(SIGINT
))
914 EXCEPTION_RECORD rec
;
918 save_context( &context
, sigcontext
);
919 rec
.ExceptionCode
= CONTROL_C_EXIT
;
920 rec
.ExceptionFlags
= EXCEPTION_CONTINUABLE
;
921 rec
.ExceptionRecord
= NULL
;
922 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
923 rec
.NumberParameters
= 0;
924 status
= raise_exception( &rec
, &context
, TRUE
);
925 if (status
) raise_status( status
, &rec
);
926 restore_context( &context
, sigcontext
);
931 /**********************************************************************
934 * Handler for SIGABRT.
936 static void abrt_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
938 EXCEPTION_RECORD rec
;
942 save_context( &context
, sigcontext
);
943 rec
.ExceptionCode
= EXCEPTION_WINE_ASSERTION
;
944 rec
.ExceptionFlags
= EH_NONCONTINUABLE
;
945 rec
.ExceptionRecord
= NULL
;
946 rec
.ExceptionAddress
= (LPVOID
)context
.Iar
;
947 rec
.NumberParameters
= 0;
948 status
= raise_exception( &rec
, &context
, TRUE
);
949 if (status
) raise_status( status
, &rec
);
950 restore_context( &context
, sigcontext
);
954 /**********************************************************************
957 * Handler for SIGQUIT.
959 static void quit_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
965 /**********************************************************************
968 * Handler for SIGUSR1, used to signal a thread that it got suspended.
970 static void usr1_handler( int signal
, siginfo_t
*siginfo
, void *sigcontext
)
974 save_context( &context
, sigcontext
);
975 wait_suspend( &context
);
976 restore_context( &context
, sigcontext
);
980 /***********************************************************************
981 * __wine_set_signal_handler (NTDLL.@)
983 int CDECL
__wine_set_signal_handler(unsigned int sig
, wine_signal_handler wsh
)
985 if (sig
>= sizeof(handlers
) / sizeof(handlers
[0])) return -1;
986 if (handlers
[sig
] != NULL
) return -2;
992 /**********************************************************************
993 * signal_alloc_thread
995 NTSTATUS
signal_alloc_thread( TEB
**teb
)
997 static size_t sigstack_zero_bits
;
1001 if (!sigstack_zero_bits
)
1003 size_t min_size
= page_size
; /* this is just for the TEB, we don't use a signal stack yet */
1004 /* find the first power of two not smaller than min_size */
1005 while ((1u << sigstack_zero_bits
) < min_size
) sigstack_zero_bits
++;
1006 assert( sizeof(TEB
) <= min_size
);
1009 size
= 1 << sigstack_zero_bits
;
1011 if (!(status
= NtAllocateVirtualMemory( NtCurrentProcess(), (void **)teb
, sigstack_zero_bits
,
1012 &size
, MEM_COMMIT
| MEM_TOP_DOWN
, PAGE_READWRITE
)))
1014 (*teb
)->Tib
.Self
= &(*teb
)->Tib
;
1015 (*teb
)->Tib
.ExceptionList
= (void *)~0UL;
1021 /**********************************************************************
1022 * signal_free_thread
1024 void signal_free_thread( TEB
*teb
)
1028 if (teb
->DeallocationStack
)
1031 NtFreeVirtualMemory( GetCurrentProcess(), &teb
->DeallocationStack
, &size
, MEM_RELEASE
);
1034 NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb
, &size
, MEM_RELEASE
);
1038 /**********************************************************************
1039 * signal_init_thread
1041 void signal_init_thread( TEB
*teb
)
1043 static BOOL init_done
;
1047 pthread_key_create( &teb_key
, NULL
);
1050 pthread_setspecific( teb_key
, teb
);
1054 /**********************************************************************
1055 * signal_init_process
1057 void signal_init_process( CONTEXT
*context
, LPTHREAD_START_ROUTINE entry
)
1059 struct sigaction sig_act
;
1061 sig_act
.sa_mask
= server_block_set
;
1062 sig_act
.sa_flags
= SA_RESTART
| SA_SIGINFO
;
1064 sig_act
.sa_sigaction
= int_handler
;
1065 if (sigaction( SIGINT
, &sig_act
, NULL
) == -1) goto error
;
1066 sig_act
.sa_sigaction
= fpe_handler
;
1067 if (sigaction( SIGFPE
, &sig_act
, NULL
) == -1) goto error
;
1068 sig_act
.sa_sigaction
= abrt_handler
;
1069 if (sigaction( SIGABRT
, &sig_act
, NULL
) == -1) goto error
;
1070 sig_act
.sa_sigaction
= quit_handler
;
1071 if (sigaction( SIGQUIT
, &sig_act
, NULL
) == -1) goto error
;
1072 sig_act
.sa_sigaction
= usr1_handler
;
1073 if (sigaction( SIGUSR1
, &sig_act
, NULL
) == -1) goto error
;
1075 sig_act
.sa_sigaction
= segv_handler
;
1076 if (sigaction( SIGSEGV
, &sig_act
, NULL
) == -1) goto error
;
1077 if (sigaction( SIGILL
, &sig_act
, NULL
) == -1) goto error
;
1079 if (sigaction( SIGBUS
, &sig_act
, NULL
) == -1) goto error
;
1083 sig_act
.sa_sigaction
= trap_handler
;
1084 if (sigaction( SIGTRAP
, &sig_act
, NULL
) == -1) goto error
;
1087 /* FIXME: set the initial context */
1091 perror("sigaction");
1096 /**********************************************************************
1097 * __wine_enter_vm86 (NTDLL.@)
1099 void __wine_enter_vm86( CONTEXT
*context
)
1101 MESSAGE("vm86 mode not supported on this platform\n");
1104 /***********************************************************************
1105 * RtlUnwind (NTDLL.@)
1107 void WINAPI
RtlUnwind( PVOID pEndFrame
, PVOID targetIp
, PEXCEPTION_RECORD pRecord
, PVOID retval
)
1109 FIXME( "Not implemented on PowerPC\n" );
1112 /*******************************************************************
1113 * NtRaiseException (NTDLL.@)
1115 NTSTATUS WINAPI
NtRaiseException( EXCEPTION_RECORD
*rec
, CONTEXT
*context
, BOOL first_chance
)
1117 NTSTATUS status
= raise_exception( rec
, context
, first_chance
);
1118 if (status
== STATUS_SUCCESS
) NtSetContextThread( GetCurrentThread(), context
);
1122 /***********************************************************************
1123 * RtlRaiseException (NTDLL.@)
1125 void WINAPI
RtlRaiseException( EXCEPTION_RECORD
*rec
)
1130 RtlCaptureContext( &context
);
1131 rec
->ExceptionAddress
= (void *)context
.Iar
;
1132 status
= raise_exception( rec
, &context
, TRUE
);
1133 if (status
) raise_status( status
, rec
);
1136 /*************************************************************************
1137 * RtlCaptureStackBackTrace (NTDLL.@)
1139 USHORT WINAPI
RtlCaptureStackBackTrace( ULONG skip
, ULONG count
, PVOID
*buffer
, ULONG
*hash
)
1141 FIXME( "(%d, %d, %p, %p) stub!\n", skip
, count
, buffer
, hash
);
1145 /***********************************************************************
1146 * call_thread_entry_point
1148 void call_thread_entry_point( LPTHREAD_START_ROUTINE entry
, void *arg
)
1152 exit_thread( entry( arg
));
1154 __EXCEPT(unhandled_exception_filter
)
1156 NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
1159 abort(); /* should not be reached */
1162 /***********************************************************************
1163 * RtlExitUserThread (NTDLL.@)
1165 void WINAPI
RtlExitUserThread( ULONG status
)
1167 exit_thread( status
);
1170 /***********************************************************************
1173 void abort_thread( int status
)
1175 terminate_thread( status
);
1178 /**********************************************************************
1179 * DbgBreakPoint (NTDLL.@)
1181 void WINAPI
DbgBreakPoint(void)
1183 kill(getpid(), SIGTRAP
);
1186 /**********************************************************************
1187 * DbgUserBreakPoint (NTDLL.@)
1189 void WINAPI
DbgUserBreakPoint(void)
1191 kill(getpid(), SIGTRAP
);
1194 /**********************************************************************
1195 * NtCurrentTeb (NTDLL.@)
1197 TEB
* WINAPI
NtCurrentTeb(void)
1199 return pthread_getspecific( teb_key
);
1202 #endif /* __powerpc__ */