Exemple #1
0
 public TranslatedFunction(GuestFunction func, ulong guestSize, bool highCq)
 {
     _func     = func;
     GuestSize = guestSize;
     HighCq    = highCq;
     FuncPtr   = Marshal.GetFunctionPointerForDelegate(func);
 }
        public TranslatedFunction(GuestFunction func, bool highCq)
        {
            _func = func;

            HighCq  = highCq;
            FuncPtr = Marshal.GetFunctionPointerForDelegate <GuestFunction>(func);
        }
Exemple #3
0
        private static TranslatedFunction FastTranslate(byte[] code, ulong guestSize, UnwindInfo unwindInfo, bool highCq)
        {
            CompiledFunction cFunc = new CompiledFunction(code, unwindInfo);

            IntPtr codePtr = JitCache.Map(cFunc);

            GuestFunction gFunc = Marshal.GetDelegateForFunctionPointer <GuestFunction>(codePtr);

            TranslatedFunction tFunc = new TranslatedFunction(gFunc, guestSize, highCq);

            return(tFunc);
        }
Exemple #4
0
        private static TranslatedFunction FastTranslate(ReadOnlySpan <byte> code, Counter callCounter, ulong guestSize, UnwindInfo unwindInfo, bool highCq)
        {
            CompiledFunction cFunc = new CompiledFunction(code.ToArray(), unwindInfo);

            IntPtr codePtr = JitCache.Map(cFunc);

            GuestFunction gFunc = Marshal.GetDelegateForFunctionPointer <GuestFunction>(codePtr);

            TranslatedFunction tFunc = new TranslatedFunction(gFunc, callCounter, guestSize, highCq);

            return(tFunc);
        }
Exemple #5
0
        private TranslatedFunction Translate(ulong address, ExecutionMode mode, bool highCq)
        {
            ArmEmitterContext context = new ArmEmitterContext(_memory, _jumpTable, (long)address, highCq, Aarch32Mode.User);

            OperandHelper.PrepareOperandPool(highCq);
            OperationHelper.PrepareOperationPool(highCq);

            Logger.StartPass(PassName.Decoding);

            Block[] blocks = AlwaysTranslateFunctions
                ? Decoder.DecodeFunction(_memory, address, mode, highCq)
                : Decoder.DecodeBasicBlock(_memory, address, mode);

            Logger.EndPass(PassName.Decoding);

            Logger.StartPass(PassName.Translation);

            EmitSynchronization(context);

            if (blocks[0].Address != address)
            {
                context.Branch(context.GetLabel(address));
            }

            ControlFlowGraph cfg = EmitAndGetCFG(context, blocks);

            Logger.EndPass(PassName.Translation);

            Logger.StartPass(PassName.RegisterUsage);

            RegisterUsage.RunPass(cfg, mode, isCompleteFunction: false);

            Logger.EndPass(PassName.RegisterUsage);

            OperandType[] argTypes = new OperandType[] { OperandType.I64 };

            CompilerOptions options = highCq
                ? CompilerOptions.HighCq
                : CompilerOptions.None;

            GuestFunction func = Compiler.Compile <GuestFunction>(cfg, argTypes, OperandType.I64, options);

            OperandHelper.ResetOperandPool(highCq);
            OperationHelper.ResetOperationPool(highCq);

            return(new TranslatedFunction(func, rejit: !highCq));
        }
 public static void InitializeStubs()
 {
     if (_initialized)
     {
         return;
     }
     lock (_lock)
     {
         if (_initialized)
         {
             return;
         }
         _directCallStub       = GenerateDirectCallStub(false);
         _directTailCallStub   = GenerateDirectCallStub(true);
         _indirectCallStub     = GenerateIndirectCallStub(false);
         _indirectTailCallStub = GenerateIndirectCallStub(true);
         _initialized          = true;
     }
 }
Exemple #7
0
 public TranslatedFunction(GuestFunction func, bool rejit)
 {
     _func  = func;
     _rejit = rejit;
 }