+static void CHECK_ACCESS(const void* ptr) {
+ DO_ASSERT(!pthread_mutex_lock(&allocation_mtx));
+ allocation* it = allocation_ll;
+ while (it->ptr != ptr) {
+ it = it->next;
+ if (it == NULL) {
+ DEBUG_PRINT("ERROR: Tried to access unknown pointer %p at:\\n", ptr);
+ void* bt[BT_MAX];
+ int bt_len = backtrace(bt, BT_MAX);
+ backtrace_symbols_fd(bt, bt_len, STDERR_FILENO);
+ DEBUG_PRINT("\\n\\n");
+ DO_ASSERT(!pthread_mutex_unlock(&allocation_mtx));
+ return; // addrsan should catch and print more info than we have
+ }
+ }
+ DO_ASSERT(!pthread_mutex_unlock(&allocation_mtx));
+}
+#define CHECK_INNER_FIELD_ACCESS_OR_NULL(v) \\
+ if (v.is_owned && v.inner != NULL) { \\
+ const void *p = __unmangle_inner_ptr(v.inner); \\
+ if (p != NULL) { \\
+ CHECK_ACCESS(p); \\
+ } \\
+ }
+