Skip to content

Abort

Description

Custom abort function that can be redirected for testing purposes. Traps directly via the architecture’s native trap instruction. If a callback is registered via OnAbort, it runs first; control then falls through to the trap (a callback that wants to short-circuit Abort must longjmp or exit itself).

Success

Function does not return. Any registered callback runs first, then the hardware trap fires.

Failure

Function cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    // Forward declaration to avoid circular includes
    void Abort(void);
    
    ///
            StrDeinit(&UNPL(m));                                                                                           \
            HeapAllocatorDeinit(&UNPL(log_alloc));                                                                         \
            Abort();                                                                                                       \
        } while (0)
            StrDeinit(&UNPL(m));                                                                                           \
            HeapAllocatorDeinit(&UNPL(log_alloc));                                                                         \
            Abort();                                                                                                       \
        } while (0)
    ///
    #define ASSERT_OR_FATAL(cond, msg)                                                                                     \
        ((cond) ? 0 : (LogWrite(LOG_MESSAGE_TYPE_FATAL, __func__, __LINE__, (msg)), Abort(), 0))
    
    ///
            "stack-protector: canary corrupted -- buffer overflow detected"
        );
        Abort();
        // Abort() is not declared noreturn in Misra/Std/Log.h (it's a
        // function pointer indirection through OnAbort in some
    }
    
    void Abort(void) {
        if (g_abort_callback) {
            g_abort_callback();
            if (expect_failure) {
                WriteFmt("    [Expected failure: Test aborted as expected]\n");
                test_result = true; // Abort was the contract.
            } else {
                WriteFmt("    [Unexpected failure: Test aborted unexpectedly]\n");
Last updated on