public void SetValue(DarksVMContext ctx, DarksVMSlot slot, PointerType type)
        {
            TypedReference typedRef;

            if (this._ptr != null)
            {
                *&typedRef = *(TypedReference *)this._ptr.Value;
            }
            else
            {
                *(PseudoTypedRef *)&typedRef = this._typedRef;
            }

            Type   refType = __reftype(typedRef);
            object value   = slot.ToObject(refType);

            TypedReferenceHelpers.SetTypedRef(value, &typedRef);
        }
Exemple #2
0
        public void SetValue(VMContext ctx, VMSlot slot, PointerType type)
        {
            TypedReference typedRef;

            if (_ptr != null)
            {
                *&typedRef = *(TypedReference *)_ptr.Value;
            }
            else
            {
                *(PseudoTypedRef *)&typedRef = _typedRef;
            }

            var refType = __reftype(typedRef);
            var value   = slot.ToObject(refType);

            TypedReferenceHelpers.SetTypedRef(value, &typedRef);
        }
Exemple #3
0
        private void Run(ulong codeAddr, uint key, VMFuncSig sig, void *[] arguments, void *retTypedRef)
        {
            if (currentCtx != null)
            {
                ctxStack.Push(currentCtx);
            }
            currentCtx = new VMContext(this);

            try
            {
                Debug.Assert(sig.ParamTypes.Length == arguments.Length);
                currentCtx.Stack.SetTopPosition((uint)arguments.Length + 1);
                for (uint i = 0; i < arguments.Length; i++)
                {
                    var paramType = sig.ParamTypes[i];
                    if (paramType.IsByRef)
                    {
                        currentCtx.Stack[i + 1] = new VMSlot {
                            O = new TypedRef(arguments[i])
                        };
                    }
                    else
                    {
                        var typedRef = *(TypedReference *)arguments[i];
                        currentCtx.Stack[i + 1] = VMSlot.FromObject(TypedReference.ToObject(typedRef), __reftype(typedRef));
                    }
                }
                currentCtx.Stack[(uint)arguments.Length + 1] = new VMSlot {
                    U8 = 1
                };

                currentCtx.Registers[Constants.REG_K1] = new VMSlot {
                    U4 = key
                };
                currentCtx.Registers[Constants.REG_BP] = new VMSlot {
                    U4 = 0
                };
                currentCtx.Registers[Constants.REG_SP] = new VMSlot {
                    U4 = (uint)arguments.Length + 1
                };
                currentCtx.Registers[Constants.REG_IP] = new VMSlot {
                    U8 = codeAddr
                };
                VMDispatcher.Run(currentCtx);
                Debug.Assert(currentCtx.EHStack.Count == 0);

                if (sig.RetType != typeof(void))
                {
                    if (sig.RetType.IsByRef)
                    {
                        var retRef = currentCtx.Registers[Constants.REG_R0].O;
                        if (!(retRef is IReference))
                        {
                            throw new ExecutionEngineException();
                        }
                        ((IReference)retRef).ToTypedReference(currentCtx, retTypedRef, sig.RetType.GetElementType());
                    }
                    else
                    {
                        var    retSlot = currentCtx.Registers[Constants.REG_R0];
                        object retVal;
                        if (Type.GetTypeCode(sig.RetType) == TypeCode.String && retSlot.O == null)
                        {
                            retVal = Data.LookupString(retSlot.U4);
                        }
                        else
                        {
                            retVal = retSlot.ToObject(sig.RetType);
                        }
                        TypedReferenceHelpers.SetTypedRef(retVal, retTypedRef);
                    }
                }
            }
            finally
            {
                currentCtx.Stack.FreeAllLocalloc();

                if (ctxStack.Count > 0)
                {
                    currentCtx = ctxStack.Pop();
                }
            }
        }