"""
+ self.bindings_version_file = ""
+
self.bindings_footer = """
export async function initializeWasm(allowDoubleInitialization: boolean = false): Promise<void> {
if(isWasmInitialized && !allowDoubleInitialization) {
void free(void *ptr);
#define MALLOC(a, _) malloc(a)
-#define FREE(p) if ((long)(p) > 1024) { free(p); }
+#define FREE(p) if ((unsigned long)(p) > 4096) { free(p); }
#define DO_ASSERT(a) (void)(a)
#define CHECK(a)
+#define CHECK_ACCESS(p)
+#define CHECK_INNER_FIELD_ACCESS_OR_NULL(v)
"""
else:
self.c_file_pfx = self.c_file_pfx + """
__real_free(it);
}
static void FREE(void* ptr) {
- if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
+ if ((unsigned long)ptr <= 4096) return; // Rust loves to create pointers to the NULL page for dummys
alloc_freed(ptr);
__real_free(ptr);
}
+static void CHECK_ACCESS(void* ptr) {
+ allocation* it = allocation_ll;
+ while (it->ptr != ptr) {
+ it = it->next;
+ if (it == NULL) {
+ return; // addrsan should catch malloc-unknown and print more info than we have
+ }
+ }
+}
+#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); \\
+ } \\
+ }
+
void* __wrap_malloc(size_t len) {
void* res = __real_malloc(len);
new_allocation(res, "malloc call");
}
"""
+ self.c_version_file = ""
+
self.hu_struct_file_prefix = f"""
import CommonBase from './CommonBase';
import * as bindings from '../bindings' // TODO: figure out location
out_typescript_enum_fields = ""
- for var in variants:
+ for var, var_docs in variants:
out_c = out_c + "\t\tcase %d: return %s;\n" % (ord_v, var)
ord_v = ord_v + 1
+ if var_docs is not None:
+ out_typescript_enum_fields += f"/**\n * {var_docs}\n */\n"
out_typescript_enum_fields += f"{var},\n\t\t\t\t"
out_c = out_c + "\t}\n"
out_c = out_c + "\tabort();\n"
out_c = out_c + "static inline int32_t LDK" + struct_name + "_to_js(LDK" + struct_name + " val) {\n"
out_c = out_c + "\tswitch (val) {\n"
ord_v = 0
- for var in variants:
+ for var, _ in variants:
out_c = out_c + "\t\tcase " + var + ": return %d;\n" % ord_v
ord_v = ord_v + 1
out_c = out_c + "\t\tdefault: abort();\n"
out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " ret = js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
elif fn_line.ret_ty_info.java_ty == "void":
out_c = out_c + "\tjs_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
+ elif fn_line.ret_ty_info.java_ty == "String":
+ out_c = out_c + "\tuint32_t ret = js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
elif not fn_line.ret_ty_info.passed_as_ptr:
out_c = out_c + "\treturn js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
else:
"""
return out_opaque_struct_human
- def map_function(self, argument_types, c_call_string, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, takes_self_as_ref, args_known, type_mapping_generator, doc_comment):
+ def map_tuple(self, struct_name):
+ return self.map_opaque_struct(struct_name, "A Tuple")
+
+ def map_function(self, argument_types, c_call_string, method_name, meth_n, return_type_info, struct_meth, default_constructor_args, takes_self, takes_self_as_ref, args_known, type_mapping_generator, doc_comment):
out_java = ""
out_c = ""
out_java_struct = None
if not args_known:
out_java_struct += ("\t// Skipped " + method_name + "\n")
else:
- meth_n = method_name[len(struct_meth) + 1:]
if not takes_self:
out_java_struct += (
"\tpublic static " + return_type_info.java_hu_ty + " constructor_" + meth_n + "(")