Debugging Segfault in JIT_ChkCastClassSpecial_Portable RRS feed

  • Question

  • 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);

    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 = '', 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

    Any Ideas what I can try to do?



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

    Monday, June 24, 2019 2:04 PM

All replies

  • Hi Nicholas,

    Thank you for posting here.

    >>However, I get a segfault in JIT_ChkCastClassSpecial_Portable:

    What is your current project? How do you get the error?

    I hope that you could describe it more clearly.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, June 25, 2019 8:31 AM