summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC/assert.cpp
blob: 07a5d009c66907c2f688c58f9a2a8c09287f9015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/Format.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/internals.h>
#include <syscall.h>
#include <unistd.h>

extern "C" {

extern bool __stdio_is_initialized;
#ifdef DEBUG
void __assertion_failed(const char* msg)
{
    dbgln("USERSPACE({}) ASSERTION FAILED: {}", getpid(), msg);
    if (__stdio_is_initialized)
        warnln("ASSERTION FAILED: {}", msg);

    Syscall::SC_set_coredump_metadata_params params {
        { "assertion", strlen("assertion") },
        { msg, strlen(msg) },
    };
    syscall(SC_set_coredump_metadata, &params);
    abort();
}
#endif
}

void _abort()
{
    asm volatile("ud2");
    __builtin_unreachable();
}