ntdll: Add stub for RtlInstallFunctionTableCallback on ARM/ARM64.
[wine.git] / dlls / ntdll / signal_arm.c
blob32205ea39c3146d93838633cef322212db38e900
1 /*
2 * ARM signal handling routines
4 * Copyright 2002 Marcus Meissner, SuSE Linux AG
5 * Copyright 2010-2013, 2015 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifdef __arm__
24 #include "config.h"
25 #include "wine/port.h"
27 #include <assert.h>
28 #include <signal.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <stdio.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 #define NONAMELESSUNION
53 #define NONAMELESSSTRUCT
54 #include "ntstatus.h"
55 #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 #include "wine/debug.h"
62 #include "winnt.h"
64 WINE_DEFAULT_DEBUG_CHANNEL(seh);
65 WINE_DECLARE_DEBUG_CHANNEL(relay);
67 static pthread_key_t teb_key;
69 /***********************************************************************
70 * signal context platform-specific definitions
72 #ifdef linux
74 #if defined(__ANDROID__) && !defined(HAVE_SYS_UCONTEXT_H)
75 typedef struct ucontext
77 unsigned long uc_flags;
78 struct ucontext *uc_link;
79 stack_t uc_stack;
80 struct sigcontext uc_mcontext;
81 sigset_t uc_sigmask;
82 unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
83 } ucontext_t;
84 #endif
86 /* All Registers access - only for local access */
87 # define REG_sig(reg_name, context) ((context)->uc_mcontext.reg_name)
88 # define REGn_sig(reg_num, context) ((context)->uc_mcontext.arm_r##reg_num)
90 /* Special Registers access */
91 # define SP_sig(context) REG_sig(arm_sp, context) /* Stack pointer */
92 # define LR_sig(context) REG_sig(arm_lr, context) /* Link register */
93 # define PC_sig(context) REG_sig(arm_pc, context) /* Program counter */
94 # define CPSR_sig(context) REG_sig(arm_cpsr, context) /* Current State Register */
95 # define IP_sig(context) REG_sig(arm_ip, context) /* Intra-Procedure-call scratch register */
96 # define FP_sig(context) REG_sig(arm_fp, context) /* Frame pointer */
98 /* Exceptions */
99 # define ERROR_sig(context) REG_sig(error_code, context)
100 # define TRAP_sig(context) REG_sig(trap_no, context)
102 #elif defined(__FreeBSD__)
104 /* All Registers access - only for local access */
105 # define REGn_sig(reg_num, context) ((context)->uc_mcontext.__gregs[reg_num])
107 /* Special Registers access */
108 # define SP_sig(context) REGn_sig(_REG_SP, context) /* Stack pointer */
109 # define LR_sig(context) REGn_sig(_REG_LR, context) /* Link register */
110 # define PC_sig(context) REGn_sig(_REG_PC, context) /* Program counter */
111 # define CPSR_sig(context) REGn_sig(_REG_CPSR, context) /* Current State Register */
112 # define IP_sig(context) REGn_sig(_REG_R12, context) /* Intra-Procedure-call scratch register */
113 # define FP_sig(context) REGn_sig(_REG_FP, context) /* Frame pointer */
115 #endif /* linux */
117 enum arm_trap_code
119 TRAP_ARM_UNKNOWN = -1, /* Unknown fault (TRAP_sig not defined) */
120 TRAP_ARM_PRIVINFLT = 6, /* Invalid opcode exception */
121 TRAP_ARM_PAGEFLT = 14, /* Page fault */
122 TRAP_ARM_ALIGNFLT = 17, /* Alignment check exception */
125 typedef void (WINAPI *raise_func)( EXCEPTION_RECORD *rec, CONTEXT *context );
126 typedef int (*wine_signal_handler)(unsigned int sig);
128 static wine_signal_handler handlers[256];
131 struct UNWIND_INFO
133 WORD function_length;
134 WORD unknown1 : 7;
135 WORD count : 5;
136 WORD unknown2 : 4;
140 /***********************************************************************
141 * get_trap_code
143 * Get the trap code for a signal.
145 static inline enum arm_trap_code get_trap_code( const ucontext_t *sigcontext )
147 #ifdef TRAP_sig
148 return TRAP_sig(sigcontext);
149 #else
150 return TRAP_ARM_UNKNOWN; /* unknown trap code */
151 #endif
154 /***********************************************************************
155 * get_error_code
157 * Get the error code for a signal.
159 static inline WORD get_error_code( const ucontext_t *sigcontext )
161 #ifdef ERROR_sig
162 return ERROR_sig(sigcontext);
163 #else
164 return 0;
165 #endif
168 /***********************************************************************
169 * dispatch_signal
171 static inline int dispatch_signal(unsigned int sig)
173 if (handlers[sig] == NULL) return 0;
174 return handlers[sig](sig);
177 /*******************************************************************
178 * is_valid_frame
180 static inline BOOL is_valid_frame( void *frame )
182 if ((ULONG_PTR)frame & 3) return FALSE;
183 return (frame >= NtCurrentTeb()->Tib.StackLimit &&
184 (void **)frame < (void **)NtCurrentTeb()->Tib.StackBase - 1);
187 /***********************************************************************
188 * save_context
190 * Set the register values from a sigcontext.
192 static void save_context( CONTEXT *context, const ucontext_t *sigcontext )
194 #define C(x) context->R##x = REGn_sig(x,sigcontext)
195 /* Save normal registers */
196 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
197 #undef C
199 context->ContextFlags = CONTEXT_FULL;
200 context->Sp = SP_sig(sigcontext); /* Stack pointer */
201 context->Lr = LR_sig(sigcontext); /* Link register */
202 context->Pc = PC_sig(sigcontext); /* Program Counter */
203 context->Cpsr = CPSR_sig(sigcontext); /* Current State Register */
204 context->R11 = FP_sig(sigcontext); /* Frame pointer */
205 context->R12 = IP_sig(sigcontext); /* Intra-Procedure-call scratch register */
209 /***********************************************************************
210 * restore_context
212 * Build a sigcontext from the register values.
214 static void restore_context( const CONTEXT *context, ucontext_t *sigcontext )
216 #define C(x) REGn_sig(x,sigcontext) = context->R##x
217 /* Restore normal registers */
218 C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
219 #undef C
221 SP_sig(sigcontext) = context->Sp; /* Stack pointer */
222 LR_sig(sigcontext) = context->Lr ; /* Link register */
223 PC_sig(sigcontext) = context->Pc; /* Program Counter */
224 CPSR_sig(sigcontext) = context->Cpsr; /* Current State Register */
225 FP_sig(sigcontext) = context->R11; /* Frame pointer */
226 IP_sig(sigcontext) = context->R12; /* Intra-Procedure-call scratch register */
230 /***********************************************************************
231 * save_fpu
233 * Set the FPU context from a sigcontext.
235 static inline void save_fpu( CONTEXT *context, const ucontext_t *sigcontext )
237 FIXME("not implemented\n");
241 /***********************************************************************
242 * restore_fpu
244 * Restore the FPU context to a sigcontext.
246 static inline void restore_fpu( CONTEXT *context, const ucontext_t *sigcontext )
248 FIXME("not implemented\n");
251 /**************************************************************************
252 * __chkstk (NTDLL.@)
254 * Incoming r4 contains words to allocate, converting to bytes then return
256 __ASM_GLOBAL_FUNC( __chkstk, "lsl r4, r4, #2\n\t"
257 "bx lr" )
259 /***********************************************************************
260 * RtlCaptureContext (NTDLL.@)
262 /* FIXME: Use the Stack instead of the actual register values */
263 __ASM_STDCALL_FUNC( RtlCaptureContext, 4,
264 ".arm\n\t"
265 "stmib r0, {r0-r12}\n\t" /* context->R0..R12 */
266 "mov r1, #0x0200000\n\t" /* CONTEXT_ARM */
267 "add r1, r1, #0x3\n\t" /* CONTEXT_FULL */
268 "str r1, [r0]\n\t" /* context->ContextFlags */
269 "str SP, [r0, #0x38]\n\t" /* context->Sp */
270 "str LR, [r0, #0x3c]\n\t" /* context->Lr */
271 "str PC, [r0, #0x40]\n\t" /* context->Pc */
272 "mrs r1, CPSR\n\t"
273 "str r1, [r0, #0x44]\n\t" /* context->Cpsr */
274 "bx lr"
278 /***********************************************************************
279 * set_cpu_context
281 * Set the new CPU context.
283 void DECLSPEC_HIDDEN set_cpu_context( const CONTEXT *context );
284 __ASM_GLOBAL_FUNC( set_cpu_context,
285 ".arm\n\t"
286 "ldr r1, [r0, #0x44]\n\t" /* context->Cpsr */
287 "msr CPSR_f, r1\n\t"
288 "ldr r1, [r0, #0x40]\n\t" /* context->Pc */
289 "ldr lr, [r0, #0x3c]\n\t" /* context->Lr */
290 "ldr sp, [r0, #0x38]\n\t" /* context->Sp */
291 "push {r1}\n\t"
292 "ldmib r0, {r0-r12}\n\t" /* context->R0..R12 */
293 "pop {pc}" )
296 /***********************************************************************
297 * get_server_context_flags
299 * Convert CPU-specific flags to generic server flags
301 static unsigned int get_server_context_flags( DWORD flags )
303 unsigned int ret = 0;
305 flags &= ~CONTEXT_ARM; /* get rid of CPU id */
306 if (flags & CONTEXT_CONTROL) ret |= SERVER_CTX_CONTROL;
307 if (flags & CONTEXT_INTEGER) ret |= SERVER_CTX_INTEGER;
308 if (flags & CONTEXT_FLOATING_POINT) ret |= SERVER_CTX_FLOATING_POINT;
309 if (flags & CONTEXT_DEBUG_REGISTERS) ret |= SERVER_CTX_DEBUG_REGISTERS;
310 return ret;
314 /***********************************************************************
315 * copy_context
317 * Copy a register context according to the flags.
319 static void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags )
321 flags &= ~CONTEXT_ARM; /* get rid of CPU id */
322 if (flags & CONTEXT_CONTROL)
324 to->Sp = from->Sp;
325 to->Lr = from->Lr;
326 to->Pc = from->Pc;
327 to->Cpsr = from->Cpsr;
329 if (flags & CONTEXT_INTEGER)
331 to->R0 = from->R0;
332 to->R1 = from->R1;
333 to->R2 = from->R2;
334 to->R3 = from->R3;
335 to->R4 = from->R4;
336 to->R5 = from->R5;
337 to->R6 = from->R6;
338 to->R7 = from->R7;
339 to->R8 = from->R8;
340 to->R9 = from->R9;
341 to->R10 = from->R10;
342 to->R11 = from->R11;
343 to->R12 = from->R12;
345 if (flags & CONTEXT_FLOATING_POINT)
347 to->Fpscr = from->Fpscr;
348 memcpy( to->u.D, from->u.D, sizeof(to->u.D) );
353 /***********************************************************************
354 * context_to_server
356 * Convert a register context to the server format.
358 NTSTATUS context_to_server( context_t *to, const CONTEXT *from )
360 DWORD i, flags = from->ContextFlags & ~CONTEXT_ARM; /* get rid of CPU id */
362 memset( to, 0, sizeof(*to) );
363 to->cpu = CPU_ARM;
365 if (flags & CONTEXT_CONTROL)
367 to->flags |= SERVER_CTX_CONTROL;
368 to->ctl.arm_regs.sp = from->Sp;
369 to->ctl.arm_regs.lr = from->Lr;
370 to->ctl.arm_regs.pc = from->Pc;
371 to->ctl.arm_regs.cpsr = from->Cpsr;
373 if (flags & CONTEXT_INTEGER)
375 to->flags |= SERVER_CTX_INTEGER;
376 to->integer.arm_regs.r[0] = from->R0;
377 to->integer.arm_regs.r[1] = from->R1;
378 to->integer.arm_regs.r[2] = from->R2;
379 to->integer.arm_regs.r[3] = from->R3;
380 to->integer.arm_regs.r[4] = from->R4;
381 to->integer.arm_regs.r[5] = from->R5;
382 to->integer.arm_regs.r[6] = from->R6;
383 to->integer.arm_regs.r[7] = from->R7;
384 to->integer.arm_regs.r[8] = from->R8;
385 to->integer.arm_regs.r[9] = from->R9;
386 to->integer.arm_regs.r[10] = from->R10;
387 to->integer.arm_regs.r[11] = from->R11;
388 to->integer.arm_regs.r[12] = from->R12;
390 if (flags & CONTEXT_FLOATING_POINT)
392 to->flags |= SERVER_CTX_FLOATING_POINT;
393 for (i = 0; i < 32; i++) to->fp.arm_regs.d[i] = from->u.D[i];
394 to->fp.arm_regs.fpscr = from->Fpscr;
396 if (flags & CONTEXT_DEBUG_REGISTERS)
398 to->flags |= SERVER_CTX_DEBUG_REGISTERS;
399 for (i = 0; i < ARM_MAX_BREAKPOINTS; i++) to->debug.arm_regs.bvr[i] = from->Bvr[i];
400 for (i = 0; i < ARM_MAX_BREAKPOINTS; i++) to->debug.arm_regs.bcr[i] = from->Bcr[i];
401 for (i = 0; i < ARM_MAX_WATCHPOINTS; i++) to->debug.arm_regs.wvr[i] = from->Wvr[i];
402 for (i = 0; i < ARM_MAX_WATCHPOINTS; i++) to->debug.arm_regs.wcr[i] = from->Wcr[i];
404 return STATUS_SUCCESS;
408 /***********************************************************************
409 * context_from_server
411 * Convert a register context from the server format.
413 NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
415 DWORD i;
417 if (from->cpu != CPU_ARM) return STATUS_INVALID_PARAMETER;
419 to->ContextFlags = CONTEXT_ARM;
420 if (from->flags & SERVER_CTX_CONTROL)
422 to->ContextFlags |= CONTEXT_CONTROL;
423 to->Sp = from->ctl.arm_regs.sp;
424 to->Lr = from->ctl.arm_regs.lr;
425 to->Pc = from->ctl.arm_regs.pc;
426 to->Cpsr = from->ctl.arm_regs.cpsr;
428 if (from->flags & SERVER_CTX_INTEGER)
430 to->ContextFlags |= CONTEXT_INTEGER;
431 to->R0 = from->integer.arm_regs.r[0];
432 to->R1 = from->integer.arm_regs.r[1];
433 to->R2 = from->integer.arm_regs.r[2];
434 to->R3 = from->integer.arm_regs.r[3];
435 to->R4 = from->integer.arm_regs.r[4];
436 to->R5 = from->integer.arm_regs.r[5];
437 to->R6 = from->integer.arm_regs.r[6];
438 to->R7 = from->integer.arm_regs.r[7];
439 to->R8 = from->integer.arm_regs.r[8];
440 to->R9 = from->integer.arm_regs.r[9];
441 to->R10 = from->integer.arm_regs.r[10];
442 to->R11 = from->integer.arm_regs.r[11];
443 to->R12 = from->integer.arm_regs.r[12];
445 if (from->flags & SERVER_CTX_FLOATING_POINT)
447 to->ContextFlags |= CONTEXT_FLOATING_POINT;
448 for (i = 0; i < 32; i++) to->u.D[i] = from->fp.arm_regs.d[i];
449 to->Fpscr = from->fp.arm_regs.fpscr;
451 if (from->flags & SERVER_CTX_DEBUG_REGISTERS)
453 to->ContextFlags |= CONTEXT_DEBUG_REGISTERS;
454 for (i = 0; i < ARM_MAX_BREAKPOINTS; i++) to->Bvr[i] = from->debug.arm_regs.bvr[i];
455 for (i = 0; i < ARM_MAX_BREAKPOINTS; i++) to->Bcr[i] = from->debug.arm_regs.bcr[i];
456 for (i = 0; i < ARM_MAX_WATCHPOINTS; i++) to->Wvr[i] = from->debug.arm_regs.wvr[i];
457 for (i = 0; i < ARM_MAX_WATCHPOINTS; i++) to->Wcr[i] = from->debug.arm_regs.wcr[i];
459 return STATUS_SUCCESS;
462 /***********************************************************************
463 * NtSetContextThread (NTDLL.@)
464 * ZwSetContextThread (NTDLL.@)
466 NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
468 NTSTATUS ret;
469 BOOL self;
470 context_t server_context;
472 context_to_server( &server_context, context );
473 ret = set_thread_context( handle, &server_context, &self );
474 if (self && ret == STATUS_SUCCESS) set_cpu_context( context );
475 return ret;
479 /***********************************************************************
480 * NtGetContextThread (NTDLL.@)
481 * ZwGetContextThread (NTDLL.@)
483 NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
485 NTSTATUS ret;
486 DWORD needed_flags = context->ContextFlags;
487 BOOL self = (handle == GetCurrentThread());
489 if (!self)
491 context_t server_context;
492 unsigned int server_flags = get_server_context_flags( context->ContextFlags );
494 if ((ret = get_thread_context( handle, &server_context, server_flags, &self ))) return ret;
495 if ((ret = context_from_server( context, &server_context ))) return ret;
496 needed_flags &= ~context->ContextFlags;
499 if (self && needed_flags)
501 CONTEXT ctx;
502 RtlCaptureContext( &ctx );
503 copy_context( context, &ctx, ctx.ContextFlags & needed_flags );
504 context->ContextFlags |= ctx.ContextFlags & needed_flags;
506 return STATUS_SUCCESS;
510 extern void raise_func_trampoline_thumb( EXCEPTION_RECORD *rec, CONTEXT *context, raise_func func );
511 __ASM_GLOBAL_FUNC( raise_func_trampoline_thumb,
512 ".thumb\n\t"
513 "blx r2\n\t"
514 "bkpt")
516 extern void raise_func_trampoline_arm( EXCEPTION_RECORD *rec, CONTEXT *context, raise_func func );
517 __ASM_GLOBAL_FUNC( raise_func_trampoline_arm,
518 ".arm\n\t"
519 "blx r2\n\t"
520 "bkpt")
522 /***********************************************************************
523 * setup_exception_record
525 * Setup the exception record and context on the thread stack.
527 static EXCEPTION_RECORD *setup_exception( ucontext_t *sigcontext, raise_func func )
529 struct stack_layout
531 CONTEXT context;
532 EXCEPTION_RECORD rec;
533 } *stack;
534 DWORD exception_code = 0;
536 stack = (struct stack_layout *)(SP_sig(sigcontext) & ~3);
537 stack--; /* push the stack_layout structure */
539 stack->rec.ExceptionRecord = NULL;
540 stack->rec.ExceptionCode = exception_code;
541 stack->rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
542 stack->rec.ExceptionAddress = (LPVOID)PC_sig(sigcontext);
543 stack->rec.NumberParameters = 0;
545 save_context( &stack->context, sigcontext );
547 /* now modify the sigcontext to return to the raise function */
548 SP_sig(sigcontext) = (DWORD)stack;
549 if (CPSR_sig(sigcontext) & 0x20)
550 PC_sig(sigcontext) = (DWORD)raise_func_trampoline_thumb;
551 else
552 PC_sig(sigcontext) = (DWORD)raise_func_trampoline_arm;
553 REGn_sig(0, sigcontext) = (DWORD)&stack->rec; /* first arg for raise_func */
554 REGn_sig(1, sigcontext) = (DWORD)&stack->context; /* second arg for raise_func */
555 REGn_sig(2, sigcontext) = (DWORD)func; /* the raise_func as third arg for the trampoline */
558 return &stack->rec;
561 /**********************************************************************
562 * raise_segv_exception
564 static void WINAPI raise_segv_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
566 NTSTATUS status;
568 switch(rec->ExceptionCode)
570 case EXCEPTION_ACCESS_VIOLATION:
571 if (rec->NumberParameters == 2)
573 if (!(rec->ExceptionCode = virtual_handle_fault( (void *)rec->ExceptionInformation[1],
574 rec->ExceptionInformation[0], FALSE )))
575 goto done;
577 break;
579 status = NtRaiseException( rec, context, TRUE );
580 if (status) raise_status( status, rec );
581 done:
582 set_cpu_context( context );
585 /**********************************************************************
586 * call_stack_handlers
588 * Call the stack handlers chain.
590 static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
592 EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame;
593 DWORD res;
595 frame = NtCurrentTeb()->Tib.ExceptionList;
596 nested_frame = NULL;
597 while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL)
599 /* Check frame address */
600 if (!is_valid_frame( frame ))
602 rec->ExceptionFlags |= EH_STACK_INVALID;
603 break;
606 /* Call handler */
607 TRACE( "calling handler at %p code=%x flags=%x\n",
608 frame->Handler, rec->ExceptionCode, rec->ExceptionFlags );
609 res = frame->Handler( rec, frame, context, &dispatch );
610 TRACE( "handler at %p returned %x\n", frame->Handler, res );
612 if (frame == nested_frame)
614 /* no longer nested */
615 nested_frame = NULL;
616 rec->ExceptionFlags &= ~EH_NESTED_CALL;
619 switch(res)
621 case ExceptionContinueExecution:
622 if (!(rec->ExceptionFlags & EH_NONCONTINUABLE)) return STATUS_SUCCESS;
623 return STATUS_NONCONTINUABLE_EXCEPTION;
624 case ExceptionContinueSearch:
625 break;
626 case ExceptionNestedException:
627 if (nested_frame < dispatch) nested_frame = dispatch;
628 rec->ExceptionFlags |= EH_NESTED_CALL;
629 break;
630 default:
631 return STATUS_INVALID_DISPOSITION;
633 frame = frame->Prev;
635 return STATUS_UNHANDLED_EXCEPTION;
639 /*******************************************************************
640 * raise_exception
642 * Implementation of NtRaiseException.
644 static NTSTATUS raise_exception( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
646 NTSTATUS status;
648 if (first_chance)
650 DWORD c;
652 TRACE( "code=%x flags=%x addr=%p pc=%08x tid=%04x\n",
653 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
654 context->Pc, GetCurrentThreadId() );
655 for (c = 0; c < rec->NumberParameters; c++)
656 TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] );
657 if (rec->ExceptionCode == EXCEPTION_WINE_STUB)
659 if (rec->ExceptionInformation[1] >> 16)
660 MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
661 rec->ExceptionAddress,
662 (char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] );
663 else
664 MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
665 rec->ExceptionAddress,
666 (char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] );
668 else
670 TRACE( " r0=%08x r1=%08x r2=%08x r3=%08x r4=%08x r5=%08x\n",
671 context->R0, context->R1, context->R2, context->R3, context->R4, context->R5 );
672 TRACE( " r6=%08x r7=%08x r8=%08x r9=%08x r10=%08x r11=%08x\n",
673 context->R6, context->R7, context->R8, context->R9, context->R10, context->R11 );
674 TRACE( " r12=%08x sp=%08x lr=%08x pc=%08x cpsr=%08x\n",
675 context->R12, context->Sp, context->Lr, context->Pc, context->Cpsr );
678 status = send_debug_event( rec, TRUE, context );
679 if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
680 return STATUS_SUCCESS;
682 if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION)
683 return STATUS_SUCCESS;
685 if ((status = call_stack_handlers( rec, context )) != STATUS_UNHANDLED_EXCEPTION)
686 return status;
689 /* last chance exception */
691 status = send_debug_event( rec, FALSE, context );
692 if (status != DBG_CONTINUE)
694 if (rec->ExceptionFlags & EH_STACK_INVALID)
695 ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
696 else if (rec->ExceptionCode == STATUS_NONCONTINUABLE_EXCEPTION)
697 ERR("Process attempted to continue execution after noncontinuable exception.\n");
698 else
699 ERR("Unhandled exception code %x flags %x addr %p\n",
700 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
701 NtTerminateProcess( NtCurrentProcess(), rec->ExceptionCode );
703 return STATUS_SUCCESS;
707 /**********************************************************************
708 * segv_handler
710 * Handler for SIGSEGV and related errors.
712 static void segv_handler( int signal, siginfo_t *info, void *ucontext )
714 EXCEPTION_RECORD *rec;
715 ucontext_t *context = ucontext;
717 /* check for page fault inside the thread stack */
718 if (get_trap_code(context) == TRAP_ARM_PAGEFLT &&
719 (char *)info->si_addr >= (char *)NtCurrentTeb()->DeallocationStack &&
720 (char *)info->si_addr < (char *)NtCurrentTeb()->Tib.StackBase &&
721 virtual_handle_stack_fault( info->si_addr ))
723 /* check if this was the last guard page */
724 if ((char *)info->si_addr < (char *)NtCurrentTeb()->DeallocationStack + 2*4096)
726 rec = setup_exception( context, raise_segv_exception );
727 rec->ExceptionCode = EXCEPTION_STACK_OVERFLOW;
729 return;
732 rec = setup_exception( context, raise_segv_exception );
733 if (rec->ExceptionCode == EXCEPTION_STACK_OVERFLOW) return;
735 switch(get_trap_code(context))
737 case TRAP_ARM_PRIVINFLT: /* Invalid opcode exception */
738 rec->ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
739 break;
740 case TRAP_ARM_PAGEFLT: /* Page fault */
741 rec->ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
742 rec->NumberParameters = 2;
743 rec->ExceptionInformation[0] = (get_error_code(context) & 0x800) != 0;
744 rec->ExceptionInformation[1] = (ULONG_PTR)info->si_addr;
745 break;
746 case TRAP_ARM_ALIGNFLT: /* Alignment check exception */
747 rec->ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
748 break;
749 case TRAP_ARM_UNKNOWN: /* Unknown fault code */
750 rec->ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
751 rec->NumberParameters = 2;
752 rec->ExceptionInformation[0] = 0;
753 rec->ExceptionInformation[1] = 0xffffffff;
754 break;
755 default:
756 ERR("Got unexpected trap %d\n", get_trap_code(context));
757 rec->ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
758 break;
762 /**********************************************************************
763 * trap_handler
765 * Handler for SIGTRAP.
767 static void trap_handler( int signal, siginfo_t *info, void *ucontext )
769 EXCEPTION_RECORD rec;
770 CONTEXT context;
771 NTSTATUS status;
773 switch ( info->si_code )
775 case TRAP_TRACE:
776 rec.ExceptionCode = EXCEPTION_SINGLE_STEP;
777 break;
778 case TRAP_BRKPT:
779 default:
780 rec.ExceptionCode = EXCEPTION_BREAKPOINT;
781 break;
784 save_context( &context, ucontext );
785 rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
786 rec.ExceptionRecord = NULL;
787 rec.ExceptionAddress = (LPVOID)context.Pc;
788 rec.NumberParameters = 0;
789 status = raise_exception( &rec, &context, TRUE );
790 if (status) raise_status( status, &rec );
791 restore_context( &context, ucontext );
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.Pc;
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.Pc;
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.Pc;
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 >= ARRAY_SIZE(handlers)) 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;
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 = 0;
986 NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
990 /**********************************************************************
991 * signal_init_thread
993 void signal_init_thread( TEB *teb )
995 static BOOL init_done;
997 if (!init_done)
999 pthread_key_create( &teb_key, NULL );
1000 init_done = TRUE;
1003 #if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_8A__)
1004 /* Win32/ARM applications expect the TEB pointer to be in the TPIDRURW register. */
1005 __asm__ __volatile__( "mcr p15, 0, %0, c13, c0, 2" : : "r" (teb) );
1006 #endif
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 * RtlAddFunctionTable (NTDLL.@)
1055 BOOLEAN CDECL RtlAddFunctionTable( RUNTIME_FUNCTION *table, DWORD count, DWORD addr )
1057 FIXME( "%p %u %x: stub\n", table, count, addr );
1058 return TRUE;
1061 /**********************************************************************
1062 * RtlInstallFunctionTableCallback (NTDLL.@)
1064 BOOLEAN CDECL RtlInstallFunctionTableCallback( DWORD table, DWORD base, DWORD length,
1065 PGET_RUNTIME_FUNCTION_CALLBACK callback, PVOID context, PCWSTR dll )
1067 FIXME( "%x %x %d %p %p %s: stub\n", table, base, length, callback, context, wine_dbgstr_w(dll) );
1068 return TRUE;
1071 /*************************************************************************
1072 * RtlAddGrowableFunctionTable (NTDLL.@)
1074 DWORD WINAPI RtlAddGrowableFunctionTable( void **table, RUNTIME_FUNCTION *functions, DWORD count, DWORD max_count,
1075 ULONG_PTR base, ULONG_PTR end )
1077 FIXME( "(%p, %p, %d, %d, %ld, %ld) stub!\n", table, functions, count, max_count, base, end );
1078 if (table) *table = NULL;
1079 return STATUS_SUCCESS;
1082 /*************************************************************************
1083 * RtlGrowFunctionTable (NTDLL.@)
1085 void WINAPI RtlGrowFunctionTable( void *table, DWORD count )
1087 FIXME( "(%p, %d) stub!\n", table, count );
1090 /*************************************************************************
1091 * RtlDeleteGrowableFunctionTable (NTDLL.@)
1093 void WINAPI RtlDeleteGrowableFunctionTable( void *table )
1095 FIXME( "(%p) stub!\n", table );
1098 /**********************************************************************
1099 * RtlDeleteFunctionTable (NTDLL.@)
1101 BOOLEAN CDECL RtlDeleteFunctionTable( RUNTIME_FUNCTION *table )
1103 FIXME( "%p: stub\n", table );
1104 return TRUE;
1107 /**********************************************************************
1108 * find_function_info
1110 static RUNTIME_FUNCTION *find_function_info( ULONG_PTR pc, HMODULE module,
1111 RUNTIME_FUNCTION *func, ULONG size )
1113 int min = 0;
1114 int max = size/sizeof(*func) - 1;
1116 while (min <= max)
1118 int pos = (min + max) / 2;
1119 DWORD begin = (func[pos].BeginAddress & ~1), end;
1120 if (func[pos].u.s.Flag)
1121 end = begin + func[pos].u.s.FunctionLength * 2;
1122 else
1124 struct UNWIND_INFO *info;
1125 info = (struct UNWIND_INFO *)((char *)module + func[pos].u.UnwindData);
1126 end = begin + info->function_length * 2;
1129 if ((char *)pc < (char *)module + begin) max = pos - 1;
1130 else if ((char *)pc >= (char *)module + end) min = pos + 1;
1131 else return func + pos;
1133 return NULL;
1136 /**********************************************************************
1137 * RtlLookupFunctionEntry (NTDLL.@)
1139 PRUNTIME_FUNCTION WINAPI RtlLookupFunctionEntry( ULONG_PTR pc, DWORD *base,
1140 UNWIND_HISTORY_TABLE *table )
1142 LDR_MODULE *module;
1143 RUNTIME_FUNCTION *func;
1144 ULONG size;
1146 /* FIXME: should use the history table to make things faster */
1148 if (LdrFindEntryForAddress( (void *)pc, &module ))
1150 WARN( "module not found for %lx\n", pc );
1151 return NULL;
1153 if (!(func = RtlImageDirectoryEntryToData( module->BaseAddress, TRUE,
1154 IMAGE_DIRECTORY_ENTRY_EXCEPTION, &size )))
1156 WARN( "no exception table found in module %p pc %lx\n", module->BaseAddress, pc );
1157 return NULL;
1159 func = find_function_info( pc, module->BaseAddress, func, size );
1160 if (func) *base = (DWORD)module->BaseAddress;
1161 return func;
1164 /***********************************************************************
1165 * RtlUnwind (NTDLL.@)
1167 void WINAPI RtlUnwind( void *endframe, void *target_ip, EXCEPTION_RECORD *rec, void *retval )
1169 CONTEXT context;
1170 EXCEPTION_RECORD record;
1171 EXCEPTION_REGISTRATION_RECORD *frame, *dispatch;
1172 DWORD res;
1174 RtlCaptureContext( &context );
1175 context.R0 = (DWORD)retval;
1177 /* build an exception record, if we do not have one */
1178 if (!rec)
1180 record.ExceptionCode = STATUS_UNWIND;
1181 record.ExceptionFlags = 0;
1182 record.ExceptionRecord = NULL;
1183 record.ExceptionAddress = (void *)context.Pc;
1184 record.NumberParameters = 0;
1185 rec = &record;
1188 rec->ExceptionFlags |= EH_UNWINDING | (endframe ? 0 : EH_EXIT_UNWIND);
1190 TRACE( "code=%x flags=%x\n", rec->ExceptionCode, rec->ExceptionFlags );
1192 /* get chain of exception frames */
1193 frame = NtCurrentTeb()->Tib.ExceptionList;
1194 while ((frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) && (frame != endframe))
1196 /* Check frame address */
1197 if (endframe && ((void*)frame > endframe))
1198 raise_status( STATUS_INVALID_UNWIND_TARGET, rec );
1200 if (!is_valid_frame( frame )) raise_status( STATUS_BAD_STACK, rec );
1202 /* Call handler */
1203 TRACE( "calling handler at %p code=%x flags=%x\n",
1204 frame->Handler, rec->ExceptionCode, rec->ExceptionFlags );
1205 res = frame->Handler(rec, frame, &context, &dispatch);
1206 TRACE( "handler at %p returned %x\n", frame->Handler, res );
1208 switch(res)
1210 case ExceptionContinueSearch:
1211 break;
1212 case ExceptionCollidedUnwind:
1213 frame = dispatch;
1214 break;
1215 default:
1216 raise_status( STATUS_INVALID_DISPOSITION, rec );
1217 break;
1219 frame = __wine_pop_frame( frame );
1223 /*******************************************************************
1224 * NtRaiseException (NTDLL.@)
1226 NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
1228 NTSTATUS status = raise_exception( rec, context, first_chance );
1229 if (status == STATUS_SUCCESS) NtSetContextThread( GetCurrentThread(), context );
1230 return status;
1233 /***********************************************************************
1234 * RtlRaiseException (NTDLL.@)
1236 void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec )
1238 CONTEXT context;
1239 NTSTATUS status;
1241 RtlCaptureContext( &context );
1242 rec->ExceptionAddress = (LPVOID)context.Pc;
1243 status = raise_exception( rec, &context, TRUE );
1244 if (status) raise_status( status, rec );
1247 /*************************************************************************
1248 * RtlCaptureStackBackTrace (NTDLL.@)
1250 USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
1252 FIXME( "(%d, %d, %p, %p) stub!\n", skip, count, buffer, hash );
1253 return 0;
1256 /***********************************************************************
1257 * call_thread_entry_point
1259 static void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg )
1261 __TRY
1263 TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg );
1264 RtlExitUserThread( entry( arg ));
1266 __EXCEPT(call_unhandled_exception_filter)
1268 NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
1270 __ENDTRY
1271 abort(); /* should not be reached */
1274 extern void DECLSPEC_NORETURN start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend,
1275 void *relay, TEB *teb );
1276 __ASM_GLOBAL_FUNC( start_thread,
1277 ".arm\n\t"
1278 "push {r4-r12,lr}\n\t"
1279 /* store exit frame */
1280 "ldr r4, [sp, #40]\n\t" /* teb */
1281 "str sp, [r4, #0x1d4]\n\t" /* teb->SystemReserved2 */
1282 /* switch to thread stack */
1283 "ldr r4, [r4, #4]\n\t" /* teb->Tib.StackBase */
1284 "sub sp, r4, #0x1000\n\t"
1285 /* attach dlls */
1286 "bl " __ASM_NAME("attach_thread") "\n\t"
1287 "mov sp, r0\n\t"
1288 /* clear the stack */
1289 "and r0, #~0xff0\n\t" /* round down to page size */
1290 "bl " __ASM_NAME("virtual_clear_thread_stack") "\n\t"
1291 /* switch to the initial context */
1292 "mov r0, sp\n\t"
1293 "b " __ASM_NAME("set_cpu_context") )
1295 extern void DECLSPEC_NORETURN call_thread_exit_func( int status, void (*func)(int), TEB *teb );
1296 __ASM_GLOBAL_FUNC( call_thread_exit_func,
1297 ".arm\n\t"
1298 "ldr r3, [r2, #0x1d4]\n\t" /* teb->SystemReserved2 */
1299 "mov ip, #0\n\t"
1300 "str ip, [r2, #0x1d4]\n\t"
1301 "cmp r3, ip\n\t"
1302 "movne sp, r3\n\t"
1303 "blx r1" )
1305 /***********************************************************************
1306 * init_thread_context
1308 static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry, void *arg, void *relay )
1310 context->R0 = (DWORD)entry;
1311 context->R1 = (DWORD)arg;
1312 context->Sp = (DWORD)NtCurrentTeb()->Tib.StackBase;
1313 context->Pc = (DWORD)relay;
1317 /***********************************************************************
1318 * attach_thread
1320 PCONTEXT DECLSPEC_HIDDEN attach_thread( LPTHREAD_START_ROUTINE entry, void *arg,
1321 BOOL suspend, void *relay )
1323 CONTEXT *ctx;
1325 if (suspend)
1327 CONTEXT context = { CONTEXT_ALL };
1329 init_thread_context( &context, entry, arg, relay );
1330 wait_suspend( &context );
1331 ctx = (CONTEXT *)((ULONG_PTR)context.Sp & ~15) - 1;
1332 *ctx = context;
1334 else
1336 ctx = (CONTEXT *)NtCurrentTeb()->Tib.StackBase - 1;
1337 init_thread_context( ctx, entry, arg, relay );
1339 ctx->ContextFlags = CONTEXT_FULL;
1340 LdrInitializeThunk( ctx, (void **)&ctx->R0, 0, 0 );
1341 return ctx;
1345 /***********************************************************************
1346 * signal_start_thread
1348 * Thread startup sequence:
1349 * signal_start_thread()
1350 * -> thread_startup()
1351 * -> call_thread_entry_point()
1353 void signal_start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend )
1355 start_thread( entry, arg, suspend, call_thread_entry_point, NtCurrentTeb() );
1358 /**********************************************************************
1359 * signal_start_process
1361 * Process startup sequence:
1362 * signal_start_process()
1363 * -> thread_startup()
1364 * -> kernel32_start_process()
1366 void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend )
1368 start_thread( entry, NtCurrentTeb()->Peb, suspend, kernel32_start_process, NtCurrentTeb() );
1371 /***********************************************************************
1372 * signal_exit_thread
1374 void signal_exit_thread( int status )
1376 call_thread_exit_func( status, exit_thread, NtCurrentTeb() );
1379 /***********************************************************************
1380 * signal_exit_process
1382 void signal_exit_process( int status )
1384 call_thread_exit_func( status, exit, NtCurrentTeb() );
1387 /**********************************************************************
1388 * DbgBreakPoint (NTDLL.@)
1390 void WINAPI DbgBreakPoint(void)
1392 kill(getpid(), SIGTRAP);
1395 /**********************************************************************
1396 * DbgUserBreakPoint (NTDLL.@)
1398 void WINAPI DbgUserBreakPoint(void)
1400 kill(getpid(), SIGTRAP);
1403 /**********************************************************************
1404 * NtCurrentTeb (NTDLL.@)
1406 TEB * WINAPI NtCurrentTeb(void)
1408 return pthread_getspecific( teb_key );
1411 #endif /* __arm__ */