Reactos
at master 114 lines 2.9 kB view raw
1/*** 2*abort.c - abort a program by raising SIGABRT 3* 4* Copyright (c) Microsoft Corporation. All rights reserved. 5* 6*Purpose: 7* defines abort() - print a message and raise SIGABRT. 8* 9*******************************************************************************/ 10 11#include <corecrt_internal.h> 12#include <signal.h> 13#include <stdlib.h> 14 15#ifdef _DEBUG 16 #define _INIT_ABORT_BEHAVIOR _WRITE_ABORT_MSG 17#else 18 #define _INIT_ABORT_BEHAVIOR _CALL_REPORTFAULT 19#endif 20 21extern "C" { unsigned int __abort_behavior = _INIT_ABORT_BEHAVIOR; } 22 23/*** 24*void abort() - abort the current program by raising SIGABRT 25* 26*Purpose: 27* print out an abort message and raise the SIGABRT signal. If the user 28* hasn't defined an abort handler routine, terminate the program 29* with exit status of 3 without cleaning up. 30* 31* Multi-thread version does not raise SIGABRT -- this isn't supported 32* under multi-thread. 33* 34*Entry: 35* None. 36* 37*Exit: 38* Does not return. 39* 40*Uses: 41* 42*Exceptions: 43* 44*******************************************************************************/ 45 46extern "C" void __cdecl abort() 47{ 48 #ifdef _DEBUG 49 if (__abort_behavior & _WRITE_ABORT_MSG) 50 { 51 __acrt_report_runtime_error(L"abort() has been called"); 52 } 53 #endif 54 55 56 /* Check if the user installed a handler for SIGABRT. 57 * We need to read the user handler atomically in the case 58 * another thread is aborting while we change the signal 59 * handler. 60 */ 61 __crt_signal_handler_t const sigabrt_action = __acrt_get_sigabrt_handler(); 62 if (sigabrt_action != SIG_DFL) 63 { 64 raise(SIGABRT); 65 } 66 67 /* If there is no user handler for SIGABRT or if the user 68 * handler returns, then exit from the program anyway 69 */ 70 71 if (__abort_behavior & _CALL_REPORTFAULT) 72 { 73 #if defined _M_ARM || defined _M_ARM64 || defined _M_ARM64EC || defined _UCRT_ENCLAVE_BUILD 74 __fastfail(FAST_FAIL_FATAL_APP_EXIT); 75 #else 76 if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE)) 77 __fastfail(FAST_FAIL_FATAL_APP_EXIT); 78 79 __acrt_call_reportfault(_CRT_DEBUGGER_ABORT, STATUS_FATAL_APP_EXIT, EXCEPTION_NONCONTINUABLE); 80 #endif 81 } 82 83 84 /* If we don't want to call ReportFault, then we call _exit(3), which is the 85 * same as invoking the default handler for SIGABRT 86 */ 87 88 89 _exit(3); 90} 91 92/*** 93*unsigned int _set_abort_behavior(unsigned int, unsigned int) - set the behavior on abort 94* 95*Purpose: 96* 97*Entry: 98* unsigned int flags - the flags we want to set 99* unsigned int mask - mask the flag values 100* 101*Exit: 102* Return the old behavior flags 103* 104*Exceptions: 105* None 106* 107*******************************************************************************/ 108 109extern "C" unsigned int __cdecl _set_abort_behavior(unsigned int flags, unsigned int mask) 110{ 111 unsigned int oldflags = __abort_behavior; 112 __abort_behavior = oldflags & (~mask) | flags & mask; 113 return oldflags; 114}