Skip to content

Instantly share code, notes, and snippets.

@rolfbjarne
Created February 4, 2016 13:34
Show Gist options
  • Save rolfbjarne/7b854b15a4660f57f7e3 to your computer and use it in GitHub Desktop.
Save rolfbjarne/7b854b15a4660f57f7e3 to your computer and use it in GitHub Desktop.
commit 12f4523a638ec7063edcb1b47307d80707c1c111
Author: Rolf Bjarne Kvinge <[email protected]>
Date: Thu Feb 4 14:24:21 2016 +0100
[runtime] Fix a stack smashing bug due to managed 'bool' being 32-bits and native 'bool' being 8-bits.
diff --git a/runtime/delegates.t4 b/runtime/delegates.t4
index 68d015d..658b85e 100644
--- a/runtime/delegates.t4
+++ b/runtime/delegates.t4
@@ -111,7 +111,7 @@
new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_nsobject_with_type",
"id", "IntPtr", "obj",
"void *", "IntPtr", "type",
- "bool *", "out bool", "created"
+ "int32_t *", "out bool", "created"
) { WrappedManagedFunction = "GetNSObjectWithType" },
new XDelegate ("void", "void", "xamarin_dispose",
diff --git a/runtime/runtime.m b/runtime/runtime.m
index 602b282..6722dcb 100644
--- a/runtime/runtime.m
+++ b/runtime/runtime.m
@@ -216,12 +216,12 @@ xamarin_get_parameter_type (MonoMethod *managed_method, int index)
MonoObject *
xamarin_get_nsobject_with_type_for_ptr (id self, bool owns, MonoType* type)
{
- bool created;
+ int32_t created;
return xamarin_get_nsobject_with_type_for_ptr_created (self, owns, type, &created);
}
MonoObject *
-xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *type, bool *created)
+xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *type, int32_t *created)
{
MonoObject *mobj = NULL;
uint32_t gchandle = 0;
diff --git a/runtime/trampolines-invoke.m b/runtime/trampolines-invoke.m
index 4e0123a..2657132 100644
--- a/runtime/trampolines-invoke.m
+++ b/runtime/trampolines-invoke.m
@@ -275,7 +275,7 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
[id_arg autorelease];
}
MonoObject *obj;
- bool created = false;
+ int32_t created = false;
obj = xamarin_get_nsobject_with_type_for_ptr_created (id_arg, false, p, &created);
if (created && obj) {
diff --git a/runtime/xamarin/runtime.h b/runtime/xamarin/runtime.h
index 03159db..f92da9e 100644
--- a/runtime/xamarin/runtime.h
+++ b/runtime/xamarin/runtime.h
@@ -97,7 +97,7 @@ bool xamarin_is_class_inativeobject (MonoClass *cls);
bool xamarin_is_class_array (MonoClass *cls);
MonoType * xamarin_get_parameter_type (MonoMethod *managed_method, int index);
MonoObject * xamarin_get_nsobject_with_type_for_ptr (id self, bool owns, MonoType* type);
-MonoObject * xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *type, bool *created);
+MonoObject * xamarin_get_nsobject_with_type_for_ptr_created (id self, bool owns, MonoType *type, int32_t *created);
int * xamarin_get_delegate_for_block_parameter (MonoMethod *method, int par, void *nativeBlock);
id xamarin_get_block_for_delegate (MonoMethod *method, MonoObject *delegate);
id xamarin_get_nsobject_handle (MonoObject *obj);
@@ -179,7 +179,7 @@ MonoReflectionMethod* xamarin_get_generic_method_direct (MonoObject *self, co
MonoObject* xamarin_try_get_or_construct_nsobject (id obj);
MonoObject* xamarin_get_inative_object_dynamic (id obj, bool owns, void *type);
MonoObject* xamarin_get_inative_object_static (id obj, bool owns, const char *type_name, const char *iface_name);
-MonoObject* xamarin_get_nsobject_with_type (id obj, void *type, bool *created);
+MonoObject* xamarin_get_nsobject_with_type (id obj, void *type, int32_t *created);
void xamarin_dispose (MonoObject *mobj);
bool xamarin_is_parameter_transient (MonoReflectionMethod *method, int parameter /* 0-based */);
bool xamarin_is_parameter_out (MonoReflectionMethod *method, int parameter /* 0-based */);
diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs
index 6a4495c..3a793c3 100644
--- a/tools/common/StaticRegistrar.cs
+++ b/tools/common/StaticRegistrar.cs
@@ -2935,7 +2935,7 @@ namespace XamCore.Registrar {
setup_call_stack.AppendLine ("[nsobj{0} autorelease];", i);
}
setup_call_stack.AppendLine ("MonoObject *mobj{0} = NULL;", i);
- setup_call_stack.AppendLine ("bool created{0} = false;", i);
+ setup_call_stack.AppendLine ("int32_t created{0} = false;", i);
setup_call_stack.AppendLine ("if (nsobj{0}) {{", i);
setup_call_stack.AppendLine ("MonoType *paramtype{0} = xamarin_get_parameter_type (managed_method, {0});", i);
setup_call_stack.AppendLine ("mobj{0} = xamarin_get_nsobject_with_type_for_ptr_created (nsobj{0}, false, paramtype{0}, &created{0});", i);
diff --git a/tools/mtouch/OldStaticRegistrar.cs b/tools/mtouch/OldStaticRegistrar.cs
index 6addb6e..c6e5260 100644
--- a/tools/mtouch/OldStaticRegistrar.cs
+++ b/tools/mtouch/OldStaticRegistrar.cs
@@ -1396,7 +1396,7 @@ namespace XamCore.Registrar {
setup_call_stack.AppendFormat ("\t\t[nsobj{0} autorelease];\n", i);
}
setup_call_stack.AppendFormat ("\t\tMonoObject *mobj{0} = NULL;\n", i);
- setup_call_stack.AppendFormat ("\t\tbool created{0} = false;\n", i);
+ setup_call_stack.AppendFormat ("\t\tint32_t created{0} = false;\n", i);
setup_call_stack.AppendFormat ("\t\tif (nsobj{0}) {{\n", i);
// if (MTouch.EnableDebug) {
// setup_call_stack.AppendFormat ("\t\t\tmobj{0} = get_managed_object_for_ptr_fast (nsobj{0}, false);\n", i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment