Beispiel #1
0
        internal static unsafe object[] DoUnwind(Unwinder u, UIntPtr exit_address, bool get_symbols = true)
        {
            System.Collections.ArrayList ret = new System.Collections.ArrayList();
            UIntPtr pc;

            while (u.CanContinue() && ((pc = u.GetInstructionPointer()) != exit_address))
            {
                void * offset;
                string sym;
                if (get_symbols)
                {
                    sym = JitOperations.GetNameOfAddress((void *)pc, out offset);
                }
                else
                {
                    offset = (void *)pc;
                    sym    = "offset_0";
                }
                ret.Add(new UnwinderEntry {
                    ProgramCounter = pc, Symbol = sym, Offset = (UIntPtr)offset
                });
                u.UnwindOne();
            }

            return(ret.ToArray());
        }
Beispiel #2
0
        static byte *GetResource(TysosAssembly ass, string resourceName, out ulong length, StackCrawlMarkHandle stackMark,
                                 bool skipSecurityCheck)
        {
            System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetResource(" + ass.assemblyName + ", " + resourceName + ", out ulong length, " +
                                            "StackCrawlMarkHandle stackMark, bool skipSecurityCheck) called");

            var res_addr = JitOperations.GetAddressOfObject(ass.assemblyName + "_resources");

            if (res_addr == null)
            {
                System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetResource: cannot find " + ass.assemblyName + "_resources");
                length = 0;
                return(null);
            }

            uint *ret = (uint *)res_addr;

            // length is the first int32
            length = *ret++;

            System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetResource: returning: " + ((ulong)ret).ToString("X") +
                                            ", length: " + length.ToString("X"));

            return((byte *)ret);
        }
Beispiel #3
0
            public override DataInterface LoadAssembly(string name)
            {
                void *ptr;

                System.Diagnostics.Debugger.Log(0, "metadata", "Metadata.BinaryAssemblyLoader.LoadAssembly: request to load " + name);
                if (name == "mscorlib" || name == "mscorlib.dll")
                {
                    ptr = OtherOperations.GetStaticObjectAddress("mscorlib");
                }
                else if (name == "libsupcs" || name == "libsupcs.dll")
                {
                    ptr = OtherOperations.GetStaticObjectAddress("libsupcs");
                }
                else if (name == "metadata" || name == "metadata.dll")
                {
                    ptr = OtherOperations.GetStaticObjectAddress("metadata");
                }
                else
                {
                    ptr = JitOperations.GetAddressOfObject(name);
                }

                return(new BinaryInterface(ptr));
            }
Beispiel #4
0
        public override object Invoke(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture)
        {
            uint flags = 0;

            if (MethodAddress == null)
            {
                var mangled_name = mspec.MangleMethod();
                System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosMethod.Invoke: requesting run-time address for " + mangled_name);
                MethodAddress = JitOperations.GetAddressOfObject(mspec.MangleMethod());
                if (MethodAddress == null)
                {
                    System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosMethod.Invoke: jit compiling method");
                    MethodAddress = JitOperations.JitCompile(this.mspec);
                }
            }
            if (MethodAddress == null)
            {
                throw new System.Reflection.TargetException("Method does not have a defined implementation (" + OwningType.FullName + "." + Name + "())");
            }
            if (!IsStatic && (obj == null))
            {
                throw new System.Reflection.TargetException("Instance method and obj is null (" + OwningType.FullName + "." + Name + "())");
            }

            // TODO: check number and type of parameters is what the method expects

            // Get total number of parameters
            int p_length = 0;

            if (parameters != null)
            {
                p_length = parameters.Length;
            }
            if (!IsStatic)
            {
                p_length++;
            }

            // See InternalStrCpy for the rationale here
            int     max_stack_alloc = p_length > 512 ? 512 : p_length;
            IntPtr *pstack          = stackalloc IntPtr[max_stack_alloc];
            IntPtr *tstack          = stackalloc IntPtr[max_stack_alloc];

            void **ps, ts;

            if (max_stack_alloc <= 512)
            {
                ps = (void **)pstack;
                ts = (void **)tstack;
            }
            else
            {
                ps = (void **)MemoryOperations.GcMalloc(p_length * sizeof(void *));
                ts = (void **)MemoryOperations.GcMalloc(p_length * sizeof(void *));
            }

            // Build a new params array to include obj if necessary, and a tysos type array
            int curptr = 0;

            if (!IsStatic)
            {
                ps[0] = CastOperations.ReinterpretAsPointer(obj);
                ts[0] = OtherOperations.GetStaticObjectAddress("_Zu1O");
                curptr++;
            }
            if (parameters != null)
            {
                for (int i = 0; i < parameters.Length; i++, curptr++)
                {
                    var cp = CastOperations.ReinterpretAsPointer(parameters[i]);
                    ps[curptr] = cp;
                    ts[curptr] = *(void **)cp;
                }
            }

            if (!IsStatic)
            {
                flags |= invoke_flag_instance;
            }
            if (OwningType.IsValueType)
            {
                flags |= invoke_flag_vt;
            }
            if (ReturnType != null && ReturnType.IsValueType)
            {
                flags |= invoke_flag_vt_ret;
            }

            return(CastOperations.ReinterpretAsObject(InternalInvoke(MethodAddress, p_length, ps, ts,
                                                                     (ReturnType != null) ? TysosType.ReinterpretAsType(ReturnType)._impl : null, flags)));
        }
Beispiel #5
0
        static void GetExecutingAssembly(StackCrawlMarkHandle scmh, TysosModule.ObjectHandleOnStack ret)
        {
            int scm = *(int *)scmh.ptr;

            System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: scm: " + scm.ToString());

            Unwinder u = OtherOperations.GetUnwinder();

            u.UnwindOne();
            u.UnwindOne();      // we are double-nested within coreclr so unwind this and calling method (GetExecutingAssembly(ref StackMarkHandle)) first

            switch (scm)
            {
            case 0:
                break;

            case 1:
                u.UnwindOne();
                break;

            case 2:
                u.UnwindOne();
                u.UnwindOne();
                break;

            default:
                System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: unsupported scm: " + scm.ToString());
                throw new NotSupportedException();
            }

            System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: requested pc " + ((ulong)u.GetInstructionPointer()).ToString("X"));

            void *offset;
            var   name = JitOperations.GetNameOfAddress((void *)u.GetInstructionPointer(), out offset);

            if (name == null)
            {
                System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: symbol not found");
                *ret.ptr = null;
                return;
            }

            System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: found method " + name);

            var ts = Metadata.MSCorlib.DemangleObject(name);

            if (ts == null)
            {
                System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: demangler returned null");
                *ret.ptr = null;
                return;
            }
            var m = ts.Metadata;

            if (m == null)
            {
                System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: returned ts had no assembly");
                *ret.ptr = null;
                return;
            }
            var aptr = (m.file as Metadata.BinaryInterface).b;
            var retm = TysosModule.GetModule(aptr, m.AssemblyName);

            System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: returning " + retm.ass.assemblyName);
            *ret.ptr = CastOperations.ReinterpretAsPointer(retm.ass);
        }