Skip to content

Commit

Permalink
Fix use-after-free at shutdown, sync API files
Browse files Browse the repository at this point in the history
  • Loading branch information
mihe committed Oct 16, 2022
1 parent f33dfdb commit 4fb0646
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 6 deletions.
15 changes: 15 additions & 0 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,8 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
if is_singleton:
result.append(f"\tstatic {class_name} *get_singleton();")
result.append("")
result.append(f"\t~{class_name}();")
result.append("")

if "methods" in class_api:
for method in class_api["methods"]:
Expand Down Expand Up @@ -1291,6 +1293,8 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
result.append("")

if is_singleton:
result.append(f"static bool {class_name}_singleton_destroyed = false;")
result.append("")
result.append(f"{class_name} *{class_name}::get_singleton() {{")
result.append(
f'\tstatic GDNativeObjectPtr singleton_obj = internal::gdn_interface->global_get_singleton("{class_name}");'
Expand All @@ -1301,9 +1305,20 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
result.append(
f"\tstatic {class_name} *singleton = reinterpret_cast<{class_name} *>(internal::gdn_interface->object_get_instance_binding(singleton_obj, internal::token, &{class_name}::___binding_callbacks));"
)
result.append(f"\tstatic struct {class_name}_BindingsCleanup {{")
result.append(f"\t\t~{class_name}_BindingsCleanup() {{")
result.append(f"\t\t\tif (!{class_name}_singleton_destroyed) {{")
result.append("\t\t\t\tinternal::gdn_interface->object_clear_instance_binding(singleton_obj, internal::token);")
result.append("\t\t\t}")
result.append("\t\t}")
result.append("\t} bindings_cleanup;")
result.append("\treturn singleton;")
result.append("}")
result.append("")
result.append(f"{class_name}::~{class_name}() {{")
result.append(f"\t{class_name}_singleton_destroyed = true;")
result.append("}")
result.append("")

if "methods" in class_api:
for method in class_api["methods"]:
Expand Down
273 changes: 267 additions & 6 deletions godot-headers/extension_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version_major": 4,
"version_minor": 0,
"version_patch": 0,
"version_status": "beta3",
"version_build": "official",
"version_full_name": "Godot Engine v4.0.beta3.official"
"version_status": "beta",
"version_build": "custom_build",
"version_full_name": "Godot Engine v4.0.beta.custom_build"
},
"builtin_class_sizes": [
{
Expand Down Expand Up @@ -91600,6 +91600,13 @@
}
]
},
{
"name": "FramebufferCacheRD",
"is_refcounted": false,
"is_instantiable": false,
"inherits": "Object",
"api_type": "core"
},
{
"name": "GDScript",
"is_refcounted": true,
Expand Down Expand Up @@ -106326,9 +106333,12 @@
"name": "create",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_static": true,
"is_virtual": false,
"hash": 2904688759,
"hash": 986942177,
"return_value": {
"type": "Image"
},
"arguments": [
{
"name": "width",
Expand All @@ -106354,6 +106364,41 @@
"name": "create_from_data",
"is_const": false,
"is_vararg": false,
"is_static": true,
"is_virtual": false,
"hash": 299398494,
"return_value": {
"type": "Image"
},
"arguments": [
{
"name": "width",
"type": "int",
"meta": "int32"
},
{
"name": "height",
"type": "int",
"meta": "int32"
},
{
"name": "use_mipmaps",
"type": "bool"
},
{
"name": "format",
"type": "enum::Image.Format"
},
{
"name": "data",
"type": "PackedByteArray"
}
]
},
{
"name": "set_data",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 2740482212,
Expand Down Expand Up @@ -133600,7 +133645,7 @@
"type": "Node"
},
{
"name": "to_position",
"name": "to_index",
"type": "int",
"meta": "int32"
}
Expand Down Expand Up @@ -245902,6 +245947,13 @@
}
]
},
{
"name": "UniformSetCacheRD",
"is_refcounted": false,
"is_instantiable": false,
"inherits": "Object",
"api_type": "core"
},
{
"name": "VBoxContainer",
"is_refcounted": false,
Expand Down Expand Up @@ -262585,6 +262637,31 @@
"type": "float",
"meta": "float"
}
},
{
"name": "set_current",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 2586408642,
"arguments": [
{
"name": "enabled",
"type": "bool"
}
]
},
{
"name": "is_current",
"is_const": true,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 36873697,
"return_value": {
"type": "bool"
}
}
],
"properties": [
Expand All @@ -262594,6 +262671,13 @@
"setter": "set_world_scale",
"getter": "get_world_scale",
"index": -1
},
{
"type": "bool",
"name": "current",
"setter": "set_current",
"getter": "is_current",
"index": -1
}
]
},
Expand Down Expand Up @@ -263577,6 +263661,183 @@
"index": -1
}
]
},
{
"name": "ZIPPacker",
"is_refcounted": true,
"is_instantiable": true,
"inherits": "RefCounted",
"api_type": "core",
"enums": [
{
"name": "ZipAppend",
"is_bitfield": false,
"values": [
{
"name": "APPEND_CREATE",
"value": 0
},
{
"name": "APPEND_CREATEAFTER",
"value": 1
},
{
"name": "APPEND_ADDINZIP",
"value": 2
}
]
}
],
"methods": [
{
"name": "open",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 3715508516,
"return_value": {
"type": "enum::Error"
},
"arguments": [
{
"name": "path",
"type": "String"
},
{
"name": "append",
"type": "enum::ZIPPacker.ZipAppend",
"default_value": "0"
}
]
},
{
"name": "start_file",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 166001499,
"return_value": {
"type": "enum::Error"
},
"arguments": [
{
"name": "path",
"type": "String"
}
]
},
{
"name": "write_file",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 680677267,
"return_value": {
"type": "enum::Error"
},
"arguments": [
{
"name": "data",
"type": "PackedByteArray"
}
]
},
{
"name": "close_file",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 166280745,
"return_value": {
"type": "enum::Error"
}
},
{
"name": "close",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 166280745,
"return_value": {
"type": "enum::Error"
}
}
]
},
{
"name": "ZIPReader",
"is_refcounted": true,
"is_instantiable": true,
"inherits": "RefCounted",
"api_type": "core",
"methods": [
{
"name": "open",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 166001499,
"return_value": {
"type": "enum::Error"
},
"arguments": [
{
"name": "path",
"type": "String"
}
]
},
{
"name": "close",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 166280745,
"return_value": {
"type": "enum::Error"
}
},
{
"name": "get_files",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 2981934095,
"return_value": {
"type": "PackedStringArray"
}
},
{
"name": "read_file",
"is_const": false,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 156385007,
"return_value": {
"type": "PackedByteArray"
},
"arguments": [
{
"name": "path",
"type": "String"
},
{
"name": "case_sensitive",
"type": "bool",
"default_value": "true"
}
]
}
]
}
],
"singletons": [
Expand Down
1 change: 1 addition & 0 deletions godot-headers/godot/gdnative_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ typedef struct {

void *(*object_get_instance_binding)(GDNativeObjectPtr p_o, void *p_token, const GDNativeInstanceBindingCallbacks *p_callbacks);
void (*object_set_instance_binding)(GDNativeObjectPtr p_o, void *p_token, void *p_binding, const GDNativeInstanceBindingCallbacks *p_callbacks);
void (*object_clear_instance_binding)(GDNativeObjectPtr p_o, void *p_token);

void (*object_set_instance)(GDNativeObjectPtr p_o, const char *p_classname, GDExtensionClassInstancePtr p_instance); /* p_classname should be a registered extension class and should extend the p_o object's class. */

Expand Down

0 comments on commit 4fb0646

Please sign in to comment.