summaryrefslogtreecommitdiff
path: root/source/base/base_memory.h
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-10-05 22:02:56 +0200
committernasr <nsrddyn@gmail.com>2026-10-05 22:02:56 +0200
commitf6d3090f7fa76eb8e0dbe060b8490cb49c001c39 (patch)
tree433c773997e51f22738acb8b04c4fd2fc6b1bdc9 /source/base/base_memory.h
init: base
Diffstat (limited to 'source/base/base_memory.h')
-rw-r--r--source/base/base_memory.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/source/base/base_memory.h b/source/base/base_memory.h
new file mode 100644
index 0000000..eb9ac85
--- /dev/null
+++ b/source/base/base_memory.h
@@ -0,0 +1,42 @@
1#ifndef BASE_MEMORY_H
2#define BASE_MEMORY_H
3
4//- asan
5
6// Marks memory region [addr, addr+size) as unaddressable.
7// This memory must be previously allocated by the user program. Accessing
8// addresses in this region from instrumented code is forbidden until
9// this region is unpoisoned. This function is not guaranteed to poison
10// the whole region - it may poison only subregion of [addr, addr+size) due
11// to ASan alignment restrictions.
12// Method is NOT thread-safe in the sense that no two threads can
13// (un)poison memory in the same memory region simultaneously.
14void __asan_poison_memory_region(void const volatile *addr, size_t size);
15// Marks memory region [addr, addr+size) as addressable.
16// This memory must be previously allocated by the user program. Accessing
17// addresses in this region is allowed until this region is poisoned again.
18// This function may unpoison a superregion of [addr, addr+size) due to
19// ASan alignment restrictions.
20// Method is NOT thread-safe in the sense that no two threads can
21// (un)poison memory in the same memory region simultaneously.
22void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
23
24// User code should use macros instead of functions.
25#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
26#define ASAN_POISON_MEMORY_REGION(addr, size) __asan_poison_memory_region((addr), (size))
27#define ASAN_UNPOISON_MEMORY_REGION(addr, size) __asan_unpoison_memory_region((addr), (size))
28#else
29#define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
30#define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
31#endif
32
33//- helper functions
34
35#define KiB(n) (((u64)(n)) << 10)
36#define MiB(n) (((u64)(n)) << 20)
37#define GiB(n) (((u64)(n)) << 30)
38
39internal b32 is_pow(umm x);
40internal u64 align(u64 pointer, umm alignment);
41
42#endif // BASE_MEMORY_H