signal_powerpc.c 36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * PowerPC signal handling routines
 *
 * Copyright 2002 Marcus Meissner, SuSE Linux AG
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
19 20 21 22 23 24 25
 */

#ifdef __powerpc__

#include "config.h"
#include "wine/port.h"

26
#include <assert.h>
27 28
#include <signal.h>
#include <stdlib.h>
29
#include <stdarg.h>
30
#include <stdio.h>
31 32 33
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef HAVE_SYSCALL_H
# include <syscall.h>
#else
# ifdef HAVE_SYS_SYSCALL_H
#  include <sys/syscall.h>
# endif
#endif

#ifdef HAVE_SYS_VM86_H
# include <sys/vm86.h>
#endif

#ifdef HAVE_SYS_SIGNAL_H
# include <sys/signal.h>
#endif

54 55
#include "ntstatus.h"
#define WIN32_NO_STATUS
56
#include "windef.h"
57
#include "winternl.h"
58
#include "wine/library.h"
59
#include "wine/exception.h"
60
#include "ntdll_misc.h"
61 62 63 64
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(seh);

65
static pthread_key_t teb_key;
66 67 68 69

/***********************************************************************
 * signal context platform-specific definitions
 */
70
#ifdef linux
71

72 73 74 75 76
/* All Registers access - only for local access */
# define REG_sig(reg_name, context)		((context)->uc_mcontext.regs->reg_name)


/* Gpr Registers access  */
77
# define GPR_sig(reg_num, context)		REG_sig(gpr[reg_num], context)
78 79 80 81 82

# define IAR_sig(context)			REG_sig(nip, context)	/* Program counter */
# define MSR_sig(context)			REG_sig(msr, context)   /* Machine State Register (Supervisor) */
# define CTR_sig(context)			REG_sig(ctr, context)   /* Count register */

83 84 85
# define XER_sig(context)			REG_sig(xer, context) /* User's integer exception register */
# define LR_sig(context)			REG_sig(link, context) /* Link register */
# define CR_sig(context)			REG_sig(ccr, context) /* Condition register */
86 87

/* Float Registers access  */
88
# define FLOAT_sig(reg_num, context)		(((double*)((char*)((context)->uc_mcontext.regs+48*4)))[reg_num])
89

90
# define FPSCR_sig(context)			(*(int*)((char*)((context)->uc_mcontext.regs+(48+32*2)*4)))
91 92

/* Exception Registers access */
93 94 95
# define DAR_sig(context)			REG_sig(dar, context)
# define DSISR_sig(context)			REG_sig(dsisr, context)
# define TRAP_sig(context)			REG_sig(trap, context)
96 97 98

#endif /* linux */

99
#ifdef __APPLE__
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

# include <sys/ucontext.h>
# include <sys/types.h>

/* All Registers access - only for local access */
# define REG_sig(reg_name, context)		((context)->uc_mcontext->ss.reg_name)
# define FLOATREG_sig(reg_name, context)	((context)->uc_mcontext->fs.reg_name)
# define EXCEPREG_sig(reg_name, context)	((context)->uc_mcontext->es.reg_name)
# define VECREG_sig(reg_name, context)		((context)->uc_mcontext->vs.reg_name)

/* Gpr Registers access */
# define GPR_sig(reg_num, context)		REG_sig(r##reg_num, context)

# define IAR_sig(context)			REG_sig(srr0, context)	/* Program counter */
# define MSR_sig(context)			REG_sig(srr1, context)  /* Machine State Register (Supervisor) */
# define CTR_sig(context)			REG_sig(ctr, context)

# define XER_sig(context)			REG_sig(xer, context) /* Link register */
# define LR_sig(context)			REG_sig(lr, context)  /* User's integer exception register */
# define CR_sig(context)			REG_sig(cr, context)  /* Condition register */

/* Float Registers access */
# define FLOAT_sig(reg_num, context)		FLOATREG_sig(fpregs[reg_num], context)

124
# define FPSCR_sig(context)			FLOATREG_sig(fpscr, context)
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

/* Exception Registers access */
# define DAR_sig(context)			EXCEPREG_sig(dar, context)     /* Fault registers for coredump */
# define DSISR_sig(context)			EXCEPREG_sig(dsisr, context)
# define TRAP_sig(context)			EXCEPREG_sig(exception, context) /* number of powerpc exception taken */

/* Signal defs : Those are undefined on darwin
SIGBUS
#undef BUS_ADRERR
#undef BUS_OBJERR
SIGILL
#undef ILL_ILLOPN
#undef ILL_ILLTRP
#undef ILL_ILLADR
#undef ILL_COPROC
#undef ILL_PRVREG
#undef ILL_BADSTK
SIGTRAP
#undef TRAP_BRKPT
#undef TRAP_TRACE
SIGFPE
*/

148
#endif /* __APPLE__ */
149 150


151

152
typedef int (*wine_signal_handler)(unsigned int sig);
153 154 155 156 157 158

static wine_signal_handler handlers[256];

/***********************************************************************
 *           dispatch_signal
 */
159
static inline int dispatch_signal(unsigned int sig)
160 161 162 163 164 165 166 167 168 169
{
    if (handlers[sig] == NULL) return 0;
    return handlers[sig](sig);
}

/***********************************************************************
 *           save_context
 *
 * Set the register values from a sigcontext.
 */
170
static void save_context( CONTEXT *context, const ucontext_t *sigcontext )
171
{
172 173 174

#define C(x) context->Gpr##x = GPR_sig(x,sigcontext)
        /* Save Gpr registers */
175 176 177 178
	C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
	C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
	C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
	C(31);
179 180 181 182 183 184 185 186 187 188 189 190 191 192
#undef C

	context->Iar = IAR_sig(sigcontext);  /* Program Counter */
	context->Msr = MSR_sig(sigcontext);  /* Machine State Register (Supervisor) */
	context->Ctr = CTR_sig(sigcontext);
        
        context->Xer = XER_sig(sigcontext);
	context->Lr  = LR_sig(sigcontext);
	context->Cr  = CR_sig(sigcontext);
        
        /* Saving Exception regs */
        context->Dar   = DAR_sig(sigcontext);
        context->Dsisr = DSISR_sig(sigcontext);
        context->Trap  = TRAP_sig(sigcontext);
193 194 195 196 197 198 199 200
}


/***********************************************************************
 *           restore_context
 *
 * Build a sigcontext from the register values.
 */
201
static void restore_context( const CONTEXT *context, ucontext_t *sigcontext )
202
{
203 204

#define C(x)  GPR_sig(x,sigcontext) = context->Gpr##x
205 206 207 208
	C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
	C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
	C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
	C(31);
209 210 211 212 213 214 215 216 217 218 219 220 221 222
#undef C

        IAR_sig(sigcontext) = context->Iar;  /* Program Counter */
        MSR_sig(sigcontext) = context->Msr;  /* Machine State Register (Supervisor) */
        CTR_sig(sigcontext) = context->Ctr;
        
        XER_sig(sigcontext) = context->Xer;
        LR_sig(sigcontext) = context->Lr;
	CR_sig(sigcontext) = context->Cr;
        
        /* Setting Exception regs */
        DAR_sig(sigcontext) = context->Dar;
        DSISR_sig(sigcontext) = context->Dsisr;
        TRAP_sig(sigcontext) = context->Trap;
223 224 225 226 227 228 229 230
}


/***********************************************************************
 *           save_fpu
 *
 * Set the FPU context from a sigcontext.
 */
231
static inline void save_fpu( CONTEXT *context, const ucontext_t *sigcontext )
232
{
233 234 235 236 237 238 239
#define C(x)   context->Fpr##x = FLOAT_sig(x,sigcontext)
        C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
	C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
	C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
	C(31);
#undef C
        context->Fpscr = FPSCR_sig(sigcontext);
240 241 242 243 244 245 246 247
}


/***********************************************************************
 *           restore_fpu
 *
 * Restore the FPU context to a sigcontext.
 */
248
static inline void restore_fpu( CONTEXT *context, const ucontext_t *sigcontext )
249
{
250 251 252 253 254 255 256
#define C(x)  FLOAT_sig(x,sigcontext) = context->Fpr##x
        C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
	C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
	C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
	C(31);
#undef C
        FPSCR_sig(sigcontext) = context->Fpscr;
257 258 259
}


260
/***********************************************************************
261
 *		RtlCaptureContext (NTDLL.@)
262
 */
263
void WINAPI RtlCaptureContext( CONTEXT *context )
264 265
{
    FIXME("not implemented\n");
266
    memset( context, 0, sizeof(*context) );
267 268 269
}


270 271 272 273 274 275 276 277 278 279 280
/***********************************************************************
 *           set_cpu_context
 *
 * Set the new CPU context.
 */
void set_cpu_context( const CONTEXT *context )
{
    FIXME("not implemented\n");
}


281 282 283 284 285 286 287 288 289
/***********************************************************************
 *           copy_context
 *
 * Copy a register context according to the flags.
 */
void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags )
{
    if (flags & CONTEXT_CONTROL)
    {
290 291 292 293 294 295 296
        to->Msr   = from->Msr;
        to->Ctr   = from->Ctr;
        to->Iar   = from->Iar;
        to->Lr    = from->Lr;
        to->Dar   = from->Dar;
        to->Dsisr = from->Dsisr;
        to->Trap  = from->Trap;
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
    }
    if (flags & CONTEXT_INTEGER)
    {
        to->Gpr0  = from->Gpr0;
        to->Gpr1  = from->Gpr1;
        to->Gpr2  = from->Gpr2;
        to->Gpr3  = from->Gpr3;
        to->Gpr4  = from->Gpr4;
        to->Gpr5  = from->Gpr5;
        to->Gpr6  = from->Gpr6;
        to->Gpr7  = from->Gpr7;
        to->Gpr8  = from->Gpr8;
        to->Gpr9  = from->Gpr9;
        to->Gpr10 = from->Gpr10;
        to->Gpr11 = from->Gpr11;
        to->Gpr12 = from->Gpr12;
        to->Gpr13 = from->Gpr13;
        to->Gpr14 = from->Gpr14;
        to->Gpr15 = from->Gpr15;
        to->Gpr16 = from->Gpr16;
        to->Gpr17 = from->Gpr17;
        to->Gpr18 = from->Gpr18;
        to->Gpr19 = from->Gpr19;
        to->Gpr20 = from->Gpr20;
        to->Gpr21 = from->Gpr21;
        to->Gpr22 = from->Gpr22;
        to->Gpr23 = from->Gpr23;
        to->Gpr24 = from->Gpr24;
        to->Gpr25 = from->Gpr25;
        to->Gpr26 = from->Gpr26;
        to->Gpr27 = from->Gpr27;
        to->Gpr28 = from->Gpr28;
        to->Gpr29 = from->Gpr29;
        to->Gpr30 = from->Gpr30;
        to->Gpr31 = from->Gpr31;
        to->Xer   = from->Xer;
        to->Cr    = from->Cr;
    }
    if (flags & CONTEXT_FLOATING_POINT)
    {
        to->Fpr0  = from->Fpr0;
        to->Fpr1  = from->Fpr1;
        to->Fpr2  = from->Fpr2;
        to->Fpr3  = from->Fpr3;
        to->Fpr4  = from->Fpr4;
        to->Fpr5  = from->Fpr5;
        to->Fpr6  = from->Fpr6;
        to->Fpr7  = from->Fpr7;
        to->Fpr8  = from->Fpr8;
        to->Fpr9  = from->Fpr9;
        to->Fpr10 = from->Fpr10;
        to->Fpr11 = from->Fpr11;
        to->Fpr12 = from->Fpr12;
        to->Fpr13 = from->Fpr13;
        to->Fpr14 = from->Fpr14;
        to->Fpr15 = from->Fpr15;
        to->Fpr16 = from->Fpr16;
        to->Fpr17 = from->Fpr17;
        to->Fpr18 = from->Fpr18;
        to->Fpr19 = from->Fpr19;
        to->Fpr20 = from->Fpr20;
        to->Fpr21 = from->Fpr21;
        to->Fpr22 = from->Fpr22;
        to->Fpr23 = from->Fpr23;
        to->Fpr24 = from->Fpr24;
        to->Fpr25 = from->Fpr25;
        to->Fpr26 = from->Fpr26;
        to->Fpr27 = from->Fpr27;
        to->Fpr28 = from->Fpr28;
        to->Fpr29 = from->Fpr29;
        to->Fpr30 = from->Fpr30;
        to->Fpr31 = from->Fpr31;
        to->Fpscr = from->Fpscr;
    }
}


374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
/***********************************************************************
 *           context_to_server
 *
 * Convert a register context to the server format.
 */
NTSTATUS context_to_server( context_t *to, const CONTEXT *from )
{
    DWORD flags = from->ContextFlags;  /* no CPU id? */

    memset( to, 0, sizeof(*to) );
    to->cpu = CPU_POWERPC;

    if (flags & CONTEXT_CONTROL)
    {
        to->flags |= SERVER_CTX_CONTROL;
        to->ctl.powerpc_regs.iar   = from->Iar;
        to->ctl.powerpc_regs.msr   = from->Msr;
        to->ctl.powerpc_regs.ctr   = from->Ctr;
        to->ctl.powerpc_regs.lr    = from->Lr;
        to->ctl.powerpc_regs.dar   = from->Dar;
        to->ctl.powerpc_regs.dsisr = from->Dsisr;
        to->ctl.powerpc_regs.trap  = from->Trap;
    }
    if (flags & CONTEXT_INTEGER)
    {
        to->flags |= SERVER_CTX_INTEGER;
        to->integer.powerpc_regs.gpr[0]  = from->Gpr0;
        to->integer.powerpc_regs.gpr[1]  = from->Gpr1;
        to->integer.powerpc_regs.gpr[2]  = from->Gpr2;
        to->integer.powerpc_regs.gpr[3]  = from->Gpr3;
        to->integer.powerpc_regs.gpr[4]  = from->Gpr4;
        to->integer.powerpc_regs.gpr[5]  = from->Gpr5;
        to->integer.powerpc_regs.gpr[6]  = from->Gpr6;
        to->integer.powerpc_regs.gpr[7]  = from->Gpr7;
        to->integer.powerpc_regs.gpr[8]  = from->Gpr8;
        to->integer.powerpc_regs.gpr[9]  = from->Gpr9;
        to->integer.powerpc_regs.gpr[10] = from->Gpr10;
        to->integer.powerpc_regs.gpr[11] = from->Gpr11;
        to->integer.powerpc_regs.gpr[12] = from->Gpr12;
        to->integer.powerpc_regs.gpr[13] = from->Gpr13;
        to->integer.powerpc_regs.gpr[14] = from->Gpr14;
        to->integer.powerpc_regs.gpr[15] = from->Gpr15;
        to->integer.powerpc_regs.gpr[16] = from->Gpr16;
        to->integer.powerpc_regs.gpr[17] = from->Gpr17;
        to->integer.powerpc_regs.gpr[18] = from->Gpr18;
        to->integer.powerpc_regs.gpr[19] = from->Gpr19;
        to->integer.powerpc_regs.gpr[20] = from->Gpr20;
        to->integer.powerpc_regs.gpr[21] = from->Gpr21;
        to->integer.powerpc_regs.gpr[22] = from->Gpr22;
        to->integer.powerpc_regs.gpr[23] = from->Gpr23;
        to->integer.powerpc_regs.gpr[24] = from->Gpr24;
        to->integer.powerpc_regs.gpr[25] = from->Gpr25;
        to->integer.powerpc_regs.gpr[26] = from->Gpr26;
        to->integer.powerpc_regs.gpr[27] = from->Gpr27;
        to->integer.powerpc_regs.gpr[28] = from->Gpr28;
        to->integer.powerpc_regs.gpr[29] = from->Gpr29;
        to->integer.powerpc_regs.gpr[30] = from->Gpr30;
        to->integer.powerpc_regs.gpr[31] = from->Gpr31;
        to->integer.powerpc_regs.xer     = from->Xer;
        to->integer.powerpc_regs.cr      = from->Cr;
    }
    if (flags & CONTEXT_FLOATING_POINT)
    {
        to->flags |= SERVER_CTX_FLOATING_POINT;
        to->fp.powerpc_regs.fpr[0]  = from->Fpr0;
        to->fp.powerpc_regs.fpr[1]  = from->Fpr1;
        to->fp.powerpc_regs.fpr[2]  = from->Fpr2;
        to->fp.powerpc_regs.fpr[3]  = from->Fpr3;
        to->fp.powerpc_regs.fpr[4]  = from->Fpr4;
        to->fp.powerpc_regs.fpr[5]  = from->Fpr5;
        to->fp.powerpc_regs.fpr[6]  = from->Fpr6;
        to->fp.powerpc_regs.fpr[7]  = from->Fpr7;
        to->fp.powerpc_regs.fpr[8]  = from->Fpr8;
        to->fp.powerpc_regs.fpr[9]  = from->Fpr9;
        to->fp.powerpc_regs.fpr[10] = from->Fpr10;
        to->fp.powerpc_regs.fpr[11] = from->Fpr11;
        to->fp.powerpc_regs.fpr[12] = from->Fpr12;
        to->fp.powerpc_regs.fpr[13] = from->Fpr13;
        to->fp.powerpc_regs.fpr[14] = from->Fpr14;
        to->fp.powerpc_regs.fpr[15] = from->Fpr15;
        to->fp.powerpc_regs.fpr[16] = from->Fpr16;
        to->fp.powerpc_regs.fpr[17] = from->Fpr17;
        to->fp.powerpc_regs.fpr[18] = from->Fpr18;
        to->fp.powerpc_regs.fpr[19] = from->Fpr19;
        to->fp.powerpc_regs.fpr[20] = from->Fpr20;
        to->fp.powerpc_regs.fpr[21] = from->Fpr21;
        to->fp.powerpc_regs.fpr[22] = from->Fpr22;
        to->fp.powerpc_regs.fpr[23] = from->Fpr23;
        to->fp.powerpc_regs.fpr[24] = from->Fpr24;
        to->fp.powerpc_regs.fpr[25] = from->Fpr25;
        to->fp.powerpc_regs.fpr[26] = from->Fpr26;
        to->fp.powerpc_regs.fpr[27] = from->Fpr27;
        to->fp.powerpc_regs.fpr[28] = from->Fpr28;
        to->fp.powerpc_regs.fpr[29] = from->Fpr29;
        to->fp.powerpc_regs.fpr[30] = from->Fpr30;
        to->fp.powerpc_regs.fpr[31] = from->Fpr31;
        to->fp.powerpc_regs.fpscr   = from->Fpscr;
    }
    return STATUS_SUCCESS;
}


/***********************************************************************
 *           context_from_server
 *
 * Convert a register context from the server format.
 */
NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
{
    if (from->cpu != CPU_POWERPC) return STATUS_INVALID_PARAMETER;

    to->ContextFlags = 0;  /* no CPU id? */
    if (from->flags & SERVER_CTX_CONTROL)
    {
        to->ContextFlags |= CONTEXT_CONTROL;
        to->Msr   = from->ctl.powerpc_regs.msr;
        to->Ctr   = from->ctl.powerpc_regs.ctr;
        to->Iar   = from->ctl.powerpc_regs.iar;
        to->Lr    = from->ctl.powerpc_regs.lr;
        to->Dar   = from->ctl.powerpc_regs.dar;
        to->Dsisr = from->ctl.powerpc_regs.dsisr;
        to->Trap  = from->ctl.powerpc_regs.trap;
    }
    if (from->flags & SERVER_CTX_INTEGER)
    {
        to->ContextFlags |= CONTEXT_INTEGER;
        to->Gpr0  = from->integer.powerpc_regs.gpr[0];
        to->Gpr1  = from->integer.powerpc_regs.gpr[1];
        to->Gpr2  = from->integer.powerpc_regs.gpr[2];
        to->Gpr3  = from->integer.powerpc_regs.gpr[3];
        to->Gpr4  = from->integer.powerpc_regs.gpr[4];
        to->Gpr5  = from->integer.powerpc_regs.gpr[5];
        to->Gpr6  = from->integer.powerpc_regs.gpr[6];
        to->Gpr7  = from->integer.powerpc_regs.gpr[7];
        to->Gpr8  = from->integer.powerpc_regs.gpr[8];
        to->Gpr9  = from->integer.powerpc_regs.gpr[9];
        to->Gpr10 = from->integer.powerpc_regs.gpr[10];
        to->Gpr11 = from->integer.powerpc_regs.gpr[11];
        to->Gpr12 = from->integer.powerpc_regs.gpr[12];
        to->Gpr13 = from->integer.powerpc_regs.gpr[13];
        to->Gpr14 = from->integer.powerpc_regs.gpr[14];
        to->Gpr15 = from->integer.powerpc_regs.gpr[15];
        to->Gpr16 = from->integer.powerpc_regs.gpr[16];
        to->Gpr17 = from->integer.powerpc_regs.gpr[17];
        to->Gpr18 = from->integer.powerpc_regs.gpr[18];
        to->Gpr19 = from->integer.powerpc_regs.gpr[19];
        to->Gpr20 = from->integer.powerpc_regs.gpr[20];
        to->Gpr21 = from->integer.powerpc_regs.gpr[21];
        to->Gpr22 = from->integer.powerpc_regs.gpr[22];
        to->Gpr23 = from->integer.powerpc_regs.gpr[23];
        to->Gpr24 = from->integer.powerpc_regs.gpr[24];
        to->Gpr25 = from->integer.powerpc_regs.gpr[25];
        to->Gpr26 = from->integer.powerpc_regs.gpr[26];
        to->Gpr27 = from->integer.powerpc_regs.gpr[27];
        to->Gpr28 = from->integer.powerpc_regs.gpr[28];
        to->Gpr29 = from->integer.powerpc_regs.gpr[29];
        to->Gpr30 = from->integer.powerpc_regs.gpr[30];
        to->Gpr31 = from->integer.powerpc_regs.gpr[31];
        to->Xer   = from->integer.powerpc_regs.xer;
        to->Cr    = from->integer.powerpc_regs.cr;
    }
    if (from->flags & SERVER_CTX_FLOATING_POINT)
    {
        to->ContextFlags |= CONTEXT_FLOATING_POINT;
        to->Fpr0  = from->fp.powerpc_regs.fpr[0];
        to->Fpr1  = from->fp.powerpc_regs.fpr[1];
        to->Fpr2  = from->fp.powerpc_regs.fpr[2];
        to->Fpr3  = from->fp.powerpc_regs.fpr[3];
        to->Fpr4  = from->fp.powerpc_regs.fpr[4];
        to->Fpr5  = from->fp.powerpc_regs.fpr[5];
        to->Fpr6  = from->fp.powerpc_regs.fpr[6];
        to->Fpr7  = from->fp.powerpc_regs.fpr[7];
        to->Fpr8  = from->fp.powerpc_regs.fpr[8];
        to->Fpr9  = from->fp.powerpc_regs.fpr[9];
        to->Fpr10 = from->fp.powerpc_regs.fpr[10];
        to->Fpr11 = from->fp.powerpc_regs.fpr[11];
        to->Fpr12 = from->fp.powerpc_regs.fpr[12];
        to->Fpr13 = from->fp.powerpc_regs.fpr[13];
        to->Fpr14 = from->fp.powerpc_regs.fpr[14];
        to->Fpr15 = from->fp.powerpc_regs.fpr[15];
        to->Fpr16 = from->fp.powerpc_regs.fpr[16];
        to->Fpr17 = from->fp.powerpc_regs.fpr[17];
        to->Fpr18 = from->fp.powerpc_regs.fpr[18];
        to->Fpr19 = from->fp.powerpc_regs.fpr[19];
        to->Fpr20 = from->fp.powerpc_regs.fpr[20];
        to->Fpr21 = from->fp.powerpc_regs.fpr[21];
        to->Fpr22 = from->fp.powerpc_regs.fpr[22];
        to->Fpr23 = from->fp.powerpc_regs.fpr[23];
        to->Fpr24 = from->fp.powerpc_regs.fpr[24];
        to->Fpr25 = from->fp.powerpc_regs.fpr[25];
        to->Fpr26 = from->fp.powerpc_regs.fpr[26];
        to->Fpr27 = from->fp.powerpc_regs.fpr[27];
        to->Fpr28 = from->fp.powerpc_regs.fpr[28];
        to->Fpr29 = from->fp.powerpc_regs.fpr[29];
        to->Fpr30 = from->fp.powerpc_regs.fpr[30];
        to->Fpr31 = from->fp.powerpc_regs.fpr[31];
        to->Fpscr = from->fp.powerpc_regs.fpscr;
    }
    return STATUS_SUCCESS;
}


576 577 578 579 580 581 582
/**********************************************************************
 *		get_fpu_code
 *
 * Get the FPU exception code from the FPU status.
 */
static inline DWORD get_fpu_code( const CONTEXT *context )
{
583
    DWORD status  = context->Fpscr;
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599

    if (status & 0x01)  /* IE */
    {
        if (status & 0x40)  /* SF */
            return EXCEPTION_FLT_STACK_CHECK;
        else
            return EXCEPTION_FLT_INVALID_OPERATION;
    }
    if (status & 0x02) return EXCEPTION_FLT_DENORMAL_OPERAND;  /* DE flag */
    if (status & 0x04) return EXCEPTION_FLT_DIVIDE_BY_ZERO;    /* ZE flag */
    if (status & 0x08) return EXCEPTION_FLT_OVERFLOW;          /* OE flag */
    if (status & 0x10) return EXCEPTION_FLT_UNDERFLOW;         /* UE flag */
    if (status & 0x20) return EXCEPTION_FLT_INEXACT_RESULT;    /* PE flag */
    return EXCEPTION_FLT_INVALID_OPERATION;  /* generic error */
}

600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676

/**********************************************************************
 *           call_stack_handlers
 *
 * Call the stack handlers chain.
 */
static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
{
    EXCEPTION_POINTERS ptrs;

    FIXME( "not implemented on PowerPC\n" );

    /* hack: call unhandled exception filter directly */
    ptrs.ExceptionRecord = rec;
    ptrs.ContextRecord = context;
    unhandled_exception_filter( &ptrs );
    return STATUS_UNHANDLED_EXCEPTION;
}


/*******************************************************************
 *		raise_exception
 *
 * Implementation of NtRaiseException.
 */
static NTSTATUS raise_exception( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
{
    NTSTATUS status;

    if (first_chance)
    {
        DWORD c;

        TRACE( "code=%x flags=%x addr=%p ip=%x tid=%04x\n",
               rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
               context->Iar, GetCurrentThreadId() );
        for (c = 0; c < rec->NumberParameters; c++)
            TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] );
        if (rec->ExceptionCode == EXCEPTION_WINE_STUB)
        {
            if (rec->ExceptionInformation[1] >> 16)
                MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
                         rec->ExceptionAddress,
                         (char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] );
            else
                MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
                         rec->ExceptionAddress,
                         (char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] );
        }
        else
        {
            /* FIXME: dump context */
        }

        status = send_debug_event( rec, TRUE, context );
        if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
            return STATUS_SUCCESS;

        if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION)
            return STATUS_SUCCESS;

        if ((status = call_stack_handlers( rec, context )) != STATUS_UNHANDLED_EXCEPTION)
            return status;
    }

    /* last chance exception */

    status = send_debug_event( rec, FALSE, context );
    if (status != DBG_CONTINUE)
    {
        if (rec->ExceptionFlags & EH_STACK_INVALID)
            ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
        else if (rec->ExceptionCode == STATUS_NONCONTINUABLE_EXCEPTION)
            ERR("Process attempted to continue execution after noncontinuable exception.\n");
        else
            ERR("Unhandled exception code %x flags %x addr %p\n",
                rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
677
        NtTerminateProcess( NtCurrentProcess(), rec->ExceptionCode );
678 679 680 681 682
    }
    return STATUS_SUCCESS;
}


683
/**********************************************************************
684
 *		segv_handler
685
 *
686
 * Handler for SIGSEGV and related errors.
687
 */
688
static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext )
689 690
{
    EXCEPTION_RECORD rec;
691
    CONTEXT context;
692
    NTSTATUS status;
693

694 695
    save_context( &context, sigcontext );

696 697
    rec.ExceptionRecord  = NULL;
    rec.ExceptionFlags   = EXCEPTION_CONTINUABLE;
698
    rec.ExceptionAddress = (LPVOID)context.Iar;
699
    rec.NumberParameters = 0;
700 701 702

    switch (signal)
    {
703
    case SIGSEGV:
704 705
    	switch (siginfo->si_code & 0xffff)
        {
706 707
	case SEGV_MAPERR:
	case SEGV_ACCERR:
708 709 710 711 712 713 714 715 716
            rec.NumberParameters = 2;
            rec.ExceptionInformation[0] = 0; /* FIXME ? */
            rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
            if (!(rec.ExceptionCode = virtual_handle_fault(siginfo->si_addr, rec.ExceptionInformation[0])))
                goto done;
            break;
	default:
            FIXME("Unhandled SIGSEGV/%x\n",siginfo->si_code);
            break;
717 718 719
	}
    	break;
    case SIGBUS:
720 721
    	switch (siginfo->si_code & 0xffff)
        {
722
	case BUS_ADRALN:
723 724
            rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
            break;
725
#ifdef BUS_ADRERR
726
	case BUS_ADRERR:
727 728
#endif
#ifdef BUS_OBJERR
729
	case BUS_OBJERR:
730 731 732 733 734 735 736
            /* FIXME: correct for all cases ? */
            rec.NumberParameters = 2;
            rec.ExceptionInformation[0] = 0; /* FIXME ? */
            rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
            if (!(rec.ExceptionCode = virtual_handle_fault(siginfo->si_addr, rec.ExceptionInformation[0])))
                goto done;
            break;
737
#endif
738 739 740
	default:
            FIXME("Unhandled SIGBUS/%x\n",siginfo->si_code);
            break;
741 742 743
	}
    	break;
    case SIGILL:
744 745
    	switch (siginfo->si_code & 0xffff)
        {
746
	case ILL_ILLOPC: /* illegal opcode */
747
#ifdef ILL_ILLOPN
748
	case ILL_ILLOPN: /* illegal operand */
749 750
#endif
#ifdef ILL_ILLADR
751
	case ILL_ILLADR: /* illegal addressing mode */
752 753
#endif
#ifdef ILL_ILLTRP
754
	case ILL_ILLTRP: /* illegal trap */
755 756
#endif
#ifdef ILL_COPROC
757
	case ILL_COPROC: /* coprocessor error */
758
#endif
759 760
            rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
            break;
761
	case ILL_PRVOPC: /* privileged opcode */
762
#ifdef ILL_PRVREG
763
	case ILL_PRVREG: /* privileged register */
764
#endif
765 766
            rec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION;
            break;
767
#ifdef ILL_BADSTK
768
	case ILL_BADSTK: /* internal stack error */
769 770
            rec.ExceptionCode = EXCEPTION_STACK_OVERFLOW;
            break;
771
#endif
772 773 774
	default:
            FIXME("Unhandled SIGILL/%x\n", siginfo->si_code);
            break;
775 776 777
	}
    	break;
    }
778
    status = raise_exception( &rec, &context, TRUE );
779
    if (status) raise_status( status, &rec );
780 781
done:
    restore_context( &context, sigcontext );
782 783 784
}

/**********************************************************************
785
 *		trap_handler
786
 *
787
 * Handler for SIGTRAP.
788
 */
789
static void trap_handler( int signal, siginfo_t *siginfo, void *sigcontext )
790 791
{
    EXCEPTION_RECORD rec;
792
    CONTEXT context;
793
    NTSTATUS status;
794

795 796
    save_context( &context, sigcontext );

797 798
    rec.ExceptionFlags   = EXCEPTION_CONTINUABLE;
    rec.ExceptionRecord  = NULL;
799
    rec.ExceptionAddress = (LPVOID)context.Iar;
800 801 802
    rec.NumberParameters = 0;

    /* FIXME: check if we might need to modify PC */
803 804
    switch (siginfo->si_code & 0xffff)
    {
805
#ifdef TRAP_BRKPT
806 807 808
    case TRAP_BRKPT:
        rec.ExceptionCode = EXCEPTION_BREAKPOINT;
    	break;
809 810
#endif
#ifdef TRAP_TRACE
811 812 813
    case TRAP_TRACE:
        rec.ExceptionCode = EXCEPTION_SINGLE_STEP;
    	break;
814
#endif
815 816 817
    default:
        FIXME("Unhandled SIGTRAP/%x\n", siginfo->si_code);
        break;
818
    }
819
    status = raise_exception( &rec, &context, TRUE );
820
    if (status) raise_status( status, &rec );
821
    restore_context( &context, sigcontext );
822 823 824
}

/**********************************************************************
825
 *		fpe_handler
826
 *
827
 * Handler for SIGFPE.
828
 */
829
static void fpe_handler( int signal, siginfo_t *siginfo, void *sigcontext )
830 831
{
    EXCEPTION_RECORD rec;
832
    CONTEXT context;
833
    NTSTATUS status;
834

835 836 837 838 839
    save_fpu( &context, sigcontext );
    save_context( &context, sigcontext );

    switch (siginfo->si_code & 0xffff )
    {
840
#ifdef FPE_FLTSUB
841 842 843
    case FPE_FLTSUB:
        rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
        break;
844 845
#endif
#ifdef FPE_INTDIV
846 847 848
    case FPE_INTDIV:
        rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
        break;
849 850
#endif
#ifdef FPE_INTOVF
851 852 853
    case FPE_INTOVF:
        rec.ExceptionCode = EXCEPTION_INT_OVERFLOW;
        break;
854 855
#endif
#ifdef FPE_FLTDIV
856 857 858
    case FPE_FLTDIV:
        rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO;
        break;
859 860
#endif
#ifdef FPE_FLTOVF
861 862 863
    case FPE_FLTOVF:
        rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW;
        break;
864 865
#endif
#ifdef FPE_FLTUND
866 867 868
    case FPE_FLTUND:
        rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW;
        break;
869 870
#endif
#ifdef FPE_FLTRES
871 872 873
    case FPE_FLTRES:
        rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT;
        break;
874 875
#endif
#ifdef FPE_FLTINV
876
    case FPE_FLTINV:
877
#endif
878 879 880 881 882 883
    default:
        rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
        break;
    }
    rec.ExceptionFlags   = EXCEPTION_CONTINUABLE;
    rec.ExceptionRecord  = NULL;
884
    rec.ExceptionAddress = (LPVOID)context.Iar;
885
    rec.NumberParameters = 0;
886
    status = raise_exception( &rec, &context, TRUE );
887
    if (status) raise_status( status, &rec );
888

889 890
    restore_context( &context, sigcontext );
    restore_fpu( &context, sigcontext );
891
}
892 893 894 895 896 897

/**********************************************************************
 *		int_handler
 *
 * Handler for SIGINT.
 */
898
static void int_handler( int signal, siginfo_t *siginfo, void *sigcontext )
899 900 901 902 903
{
    if (!dispatch_signal(SIGINT))
    {
        EXCEPTION_RECORD rec;
        CONTEXT context;
904
        NTSTATUS status;
905

906
        save_context( &context, sigcontext );
907 908 909
        rec.ExceptionCode    = CONTROL_C_EXIT;
        rec.ExceptionFlags   = EXCEPTION_CONTINUABLE;
        rec.ExceptionRecord  = NULL;
910
        rec.ExceptionAddress = (LPVOID)context.Iar;
911
        rec.NumberParameters = 0;
912 913
        status = raise_exception( &rec, &context, TRUE );
        if (status) raise_status( status, &rec );
914
        restore_context( &context, sigcontext );
915 916 917
    }
}

918

919 920 921 922 923
/**********************************************************************
 *		abrt_handler
 *
 * Handler for SIGABRT.
 */
924
static void abrt_handler( int signal, siginfo_t *siginfo, void *sigcontext )
925 926 927
{
    EXCEPTION_RECORD rec;
    CONTEXT context;
928
    NTSTATUS status;
929

930
    save_context( &context, sigcontext );
931 932 933
    rec.ExceptionCode    = EXCEPTION_WINE_ASSERTION;
    rec.ExceptionFlags   = EH_NONCONTINUABLE;
    rec.ExceptionRecord  = NULL;
934
    rec.ExceptionAddress = (LPVOID)context.Iar;
935
    rec.NumberParameters = 0;
936 937
    status = raise_exception( &rec, &context, TRUE );
    if (status) raise_status( status, &rec );
938
    restore_context( &context, sigcontext );
939 940
}

941

942
/**********************************************************************
943
 *		quit_handler
944
 *
945
 * Handler for SIGQUIT.
946
 */
947
static void quit_handler( int signal, siginfo_t *siginfo, void *sigcontext )
948
{
949
    abort_thread(0);
950 951 952
}


953 954 955 956 957
/**********************************************************************
 *		usr1_handler
 *
 * Handler for SIGUSR1, used to signal a thread that it got suspended.
 */
958
static void usr1_handler( int signal, siginfo_t *siginfo, void *sigcontext )
959
{
960
    CONTEXT context;
961

962
    save_context( &context, sigcontext );
963
    wait_suspend( &context );
964
    restore_context( &context, sigcontext );
965 966 967
}


968 969 970 971 972 973 974 975 976 977 978 979 980
/**********************************************************************
 *		get_signal_stack_total_size
 *
 * Retrieve the size to allocate for the signal stack, including the TEB at the bottom.
 * Must be a power of two.
 */
size_t get_signal_stack_total_size(void)
{
    assert( sizeof(TEB) <= getpagesize() );
    return getpagesize();  /* this is just for the TEB, we don't need a signal stack */
}


981 982 983
/***********************************************************************
 *           __wine_set_signal_handler   (NTDLL.@)
 */
984
int CDECL __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh)
985 986 987 988 989 990 991 992 993
{
    if (sig > sizeof(handlers) / sizeof(handlers[0])) return -1;
    if (handlers[sig] != NULL) return -2;
    handlers[sig] = wsh;
    return 0;
}


/**********************************************************************
994
 *		signal_init_thread
995
 */
996
void signal_init_thread( TEB *teb )
997
{
998 999 1000 1001 1002 1003 1004 1005
    static int init_done;

    if (!init_done)
    {
        pthread_key_create( &teb_key, NULL );
        init_done = 1;
    }
    pthread_setspecific( teb_key, teb );
1006 1007
}

1008

1009 1010 1011 1012
/**********************************************************************
 *		signal_init_process
 */
void signal_init_process(void)
1013
{
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
    struct sigaction sig_act;

    sig_act.sa_mask = server_block_set;
    sig_act.sa_flags = SA_RESTART | SA_SIGINFO;

    sig_act.sa_sigaction = int_handler;
    if (sigaction( SIGINT, &sig_act, NULL ) == -1) goto error;
    sig_act.sa_sigaction = fpe_handler;
    if (sigaction( SIGFPE, &sig_act, NULL ) == -1) goto error;
    sig_act.sa_sigaction = abrt_handler;
    if (sigaction( SIGABRT, &sig_act, NULL ) == -1) goto error;
    sig_act.sa_sigaction = quit_handler;
    if (sigaction( SIGQUIT, &sig_act, NULL ) == -1) goto error;
    sig_act.sa_sigaction = usr1_handler;
    if (sigaction( SIGUSR1, &sig_act, NULL ) == -1) goto error;

    sig_act.sa_sigaction = segv_handler;
    if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error;
    if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error;
1033
#ifdef SIGBUS
1034
    if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error;
1035
#endif
1036

1037
#ifdef SIGTRAP
1038 1039
    sig_act.sa_sigaction = trap_handler;
    if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
1040
#endif
1041
    return;
1042 1043 1044

 error:
    perror("sigaction");
1045
    exit(1);
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
}


/**********************************************************************
 *              __wine_enter_vm86   (NTDLL.@)
 */
void __wine_enter_vm86( CONTEXT *context )
{
    MESSAGE("vm86 mode not supported on this platform\n");
}

1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
/***********************************************************************
 *            RtlUnwind  (NTDLL.@)
 */
void WINAPI RtlUnwind( PVOID pEndFrame, PVOID targetIp, PEXCEPTION_RECORD pRecord, PVOID retval )
{
    FIXME( "Not implemented on PowerPC\n" );
}

/*******************************************************************
 *		NtRaiseException (NTDLL.@)
 */
NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
{
    NTSTATUS status = raise_exception( rec, context, first_chance );
    if (status == STATUS_SUCCESS) NtSetContextThread( GetCurrentThread(), context );
    return status;
}

1075 1076 1077 1078 1079 1080 1081 1082 1083
/***********************************************************************
 *		RtlRaiseException (NTDLL.@)
 */
void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec )
{
    CONTEXT context;
    NTSTATUS status;

    RtlCaptureContext( &context );
1084
    rec->ExceptionAddress = (void *)context.Iar;
1085 1086 1087 1088
    status = raise_exception( rec, &context, TRUE );
    if (status) raise_status( status, rec );
}

1089 1090 1091 1092 1093 1094 1095
/***********************************************************************
 *           call_thread_entry_point
 */
void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg )
{
    __TRY
    {
1096
        exit_thread( entry( arg ));
1097 1098 1099 1100 1101 1102 1103 1104 1105
    }
    __EXCEPT(unhandled_exception_filter)
    {
        NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
    }
    __ENDTRY
    abort();  /* should not be reached */
}

1106 1107 1108 1109 1110 1111 1112 1113
/***********************************************************************
 *           RtlExitUserThread  (NTDLL.@)
 */
void WINAPI RtlExitUserThread( ULONG status )
{
    exit_thread( status );
}

1114 1115 1116 1117 1118 1119 1120 1121
/***********************************************************************
 *           abort_thread
 */
void abort_thread( int status )
{
    terminate_thread( status );
}

1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
/**********************************************************************
 *              DbgBreakPoint   (NTDLL.@)
 */
void WINAPI DbgBreakPoint(void)
{
     kill(getpid(), SIGTRAP);
}

/**********************************************************************
 *              DbgUserBreakPoint   (NTDLL.@)
 */
void WINAPI DbgUserBreakPoint(void)
{
     kill(getpid(), SIGTRAP);
}

1138 1139 1140 1141 1142 1143 1144 1145
/**********************************************************************
 *           NtCurrentTeb   (NTDLL.@)
 */
TEB * WINAPI NtCurrentTeb(void)
{
    return pthread_getspecific( teb_key );
}

1146
#endif  /* __powerpc__ */