Debugging Segfault in JIT_ChkCastClassSpecial_Portable

  • Thread starter Thread starter Nicholas Wilson ---
  • Start date Start date
N

Nicholas Wilson ---

Guest
I have a class `Class1` that I want to wrap in static interface with `Class1Static` for use with the CoreCLR (can only call static methods, not instance methods).

public class Class1
{
int a;
public Class1(int aa) { a = aa; }
public string ToString() { return a.ToString(); }
}

public class Class1static
{
public static IntPtr make(int a)
{
Object ret = new Class1(a);
GCHandle gch = GCHandle.Alloc(ret);
return GCHandle.ToIntPtr(gch);
}

public static string toString(IntPtr pthis)
{
var gch = GCHandle.FromIntPtr(pthis);
var targ = gch.Target;
Class2 actual = (Class2)targ;
return actual.ToString();
}
public static void unpin(IntPtr pthis)
{
GCHandle gch = GCHandle.FromIntPtr(pthis);
gch.Free();
return;
}
}

The idea is to have the native code call Class1static::make to get an opaque handle that won't get collected by the GC that can be resolved on the C# side to an object of the correct type to call instance methods like ToString on, and then once the native code is finished with it, it calls Class1static::unpin so the GC can clean it up.


So all the native application does after loading the CoreCLR is: resolve the delegate for Class1static::make, call it, resolve the delegate for Class1static::toString() and call it with the result of the first delegate. Both delegates are returned as non-null pointers as is the pointer returned by the first delegate.

However, I get a segfault in JIT_ChkCastClassSpecial_Portable:

(Backtrace is not very helpful as it hits something in the JIT.

* thread #1: tid = 0xe2dae0, 0x0000000102274f20 libcoreclr.dylib`JIT_ChkCastClassSpecial_Portable + 16, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
* frame #0: 0x0000000102274f20 libcoreclr.dylib`JIT_ChkCastClassSpecial_Portable + 16
frame #1: 0x00000001090d1614
frame #2: 0x00000001090d1550
frame #3: 0x00000001023a342b libcoreclr.dylib`UMThunkStub + 273

Disassembly shows that it is a null pObject in https://github.com/dotnet/coreclr/b...2afebc3dbe896e896/src/vm/jithelpers.cpp#L2323

Any Ideas what I can try to do?


Thanks

Nic


P.S. whats with the reply link doing nothing? I can't seem to respond to other posts.

Continue reading...
 
Back
Top