Skip to content

Commit

Permalink
[runtime] Fixed marshalling bug in `mono_marshal_get_native_func_wrap…
Browse files Browse the repository at this point in the history
…per`.

It was caused by a mismatch of the `sig` and `csig` variables when looking the wrapper in the marshalling cache.

This was manifesting as the following crash in all Monodroid programs:

```
#0  mono_type_hash () at /Users/joao/Dev/droid/mono/mono/metadata/metadata.c:1390
#1  0x7512edf4 in mono_signature_hash () at /Users/joao/Dev/droid/mono/mono/metadata/metadata.c:4957
#2  0x75115d18 in signature_pointer_pair_hash () from /Users/joao/Dev/droid/monodroid/tests/runtime/gdb-symbols/libmonosgen-2.0.so
#3  0x751dca10 in rehash () from /Users/joao/Dev/droid/monodroid/tests/runtime/gdb-symbols/libmonosgen-2.0.so
#4  0x751dcbe0 in monoeg_g_hash_table_insert_replace () from /Users/joao/Dev/droid/monodroid/tests/runtime/gdb-symbols/libmonosgen-2.0.so
#5  0x75119570 in mono_mb_create_and_cache_full () from /Users/joao/Dev/droid/monodroid/tests/runtime/gdb-symbols/libmonosgen-2.0.so
#6  0x75127390 in mono_marshal_get_native_func_wrapper () from /Users/joao/Dev/droid/monodroid/tests/runtime/gdb-symbols/libmonosgen-2.0.so
#7  0x75127780 in mono_ftnptr_to_delegate () from /Users/joao/Dev/droid/monodroid/tests/runtime/gdb-symbols/libmonosgen-2.0.so
```

Originally introduced in #1540.
  • Loading branch information
tritao committed Feb 6, 2015
1 parent 6733010 commit a8390dc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -7375,7 +7375,10 @@ mono_marshal_get_native_func_wrapper (MonoImage *image, MonoMethodSignature *sig
gboolean found;
char *name;

key.sig = sig;
csig = signature_dup (image, sig);
csig->pinvoke = 0;

key.sig = csig;
key.pointer = func;

cache = get_cache (&image->native_func_wrapper_cache, signature_pointer_pair_hash, signature_pointer_pair_equal);
Expand All @@ -7390,9 +7393,6 @@ mono_marshal_get_native_func_wrapper (MonoImage *image, MonoMethodSignature *sig
mono_marshal_emit_native_wrapper (image, mb, sig, piinfo, mspecs, func, FALSE, TRUE, FALSE);
#endif

csig = signature_dup (image, sig);
csig->pinvoke = 0;

new_key = g_new (SignaturePointerPair,1);
*new_key = key;
res = mono_mb_create_and_cache_full (cache, new_key, mb, csig, csig->param_count + 16, NULL, &found);
Expand Down

0 comments on commit a8390dc

Please sign in to comment.