matos/core/assert.h
Mathieu Maret 6854ad489f Use gcc stack protector
Trick was to use the stack-protector-guard option otherwise gcc expect
the canary value to be stored on the Thread Local Storage of the current
thread.
That does not work the same way for us, so trying to access TLS at
%gs (the canonical place for the TLS), where gcc expect the canary to be
storeg, lead to system reboot as it is not setup.
2025-02-20 17:13:01 +01:00

36 lines
2.5 KiB
C

#pragma once
#include "klibc.h"
#include "stack.h"
#define assert(p) \
do { \
if (!(p)) { \
printf("BUG at %s:%d assert(%s)\n", __FILE__, __LINE__, #p); \
printStackTrace(3); \
while (1) { \
} \
} \
} while (0)
#define assertmsg(p, ...) \
do { \
if (!(p)) { \
printf("BUG at %s:%d assert(%s)\n", __FILE__, __LINE__, #p); \
printf(__VA_ARGS__); \
printStackTrace(3); \
while (1) { \
} \
} \
} while (0)
#define panic(fmt, args...) \
do { \
asm volatile("cli"); \
printf("PANIC at %s:%d\n " fmt "", __FILE__, __LINE__); \
printf("PANIC: " fmt "\n", ##args); \
printStackTrace(3); \
while (1) \
asm volatile("hlt"); \
__builtin_unreachable(); \
} while (0)