1/* @title: Address sanitization */
2#include <log.h>
3#include <stddef.h>
4
5#define ASAN_SHADOW_SCALE 3ULL /* 1 shadow byte per 8 real bytes */
6#define ASAN_SHADOW_OFFSET \
7 0xfffffc0000000000ULL /* fixed virtual base for shadow memory */
8#define ASAN_REDZONE 16 /* optional redzone per allocation */
9#define ASAN_POISON_VALUE 0xFF
10#define ASAN_ABORT_IF_NOT_READY() \
11 do { \
12 if (!asan_ready) \
13 return; \
14 } while (0)
15
16LOG_SITE_EXTERN(asan);
17LOG_HANDLE_EXTERN(asan);
18
19#define asan_log(lvl, fmt, ...) \
20 log(LOG_SITE(asan), LOG_HANDLE(asan), lvl, fmt, ##__VA_ARGS__)
21
22#define asan_err(fmt, ...) asan_log(LOG_ERROR, fmt, ##__VA_ARGS__)
23#define asan_warn(fmt, ...) asan_log(LOG_WARN, fmt, ##__VA_ARGS__)
24#define asan_info(fmt, ...) asan_log(LOG_INFO, fmt, ##__VA_ARGS__)
25#define asan_debug(fmt, ...) asan_log(LOG_DEBUG, fmt, ##__VA_ARGS__)
26#define asan_trace(fmt, ...) asan_log(LOG_TRACE, fmt, ##__VA_ARGS__)
27
28void asan_init(void);
29void asan_poison(void *addr, size_t size);
30void asan_unpoison(void *addr, size_t size);
31