class CommonBase {
long ptr;
LinkedList<Object> ptrs_to = new LinkedList();
- protected CommonBase(long ptr) { assert ptr > 1024; this.ptr = ptr; }
+ protected CommonBase(long ptr) { assert ptr < 0 || ptr > 1024; this.ptr = ptr; }
}
"""
if not DEBUG or sys.platform == "darwin":
self.c_file_pfx = self.c_file_pfx + """#define MALLOC(a, _) malloc(a)
#define FREE(p) if ((uint64_t)(p) > 1024) { free(p); }
+#define CHECK_ACCESS(p)
"""
if not DEBUG:
self.c_file_pfx += """#define DO_ASSERT(a) (void)(a)
while (it->ptr != ptr) {
p = it; it = it->next;
if (it == NULL) {
- DEBUG_PRINT("Tried to free unknown pointer %p at:\\n", ptr);
+ DEBUG_PRINT("ERROR: Tried to free 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);
__real_free(ptr);
}
+static void CHECK_ACCESS(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));
+}
+
void* __real_realloc(void* ptr, size_t newlen);
void* __wrap_realloc(void* ptr, size_t len) {
if (ptr != NULL) alloc_freed(ptr);
out_java_struct += (info.arg_name)
out_java_struct += (");\n")
if return_type_info.java_ty == "long" and return_type_info.java_hu_ty != "long":
- out_java_struct += "\t\tif (ret < 1024) { return null; }\n"
+ out_java_struct += "\t\tif (ret >= 0 && ret < 1024) { return null; }\n"
if return_type_info.to_hu_conv is not None:
if not takes_self: