示例#1
0
        public int ReserveTableEntry(long ownerAddress, long address, bool isJump)
        {
            int entry = Interlocked.Increment(ref _tableEnd);

            if (entry >= JumpTableSize)
            {
                throw new OutOfMemoryException("JIT Direct Jump Table exhausted.");
            }

            _jumpRegion.ExpandIfNeeded((ulong)((entry + 1) * JumpTableStride));

            // Is the address we have already registered? If so, put the function address in the jump table.
            // If not, it will point to the direct call stub.
            long value = (long)DirectCallStubs.DirectCallStub(isJump);

            if (_targets.TryGetValue((ulong)address, out TranslatedFunction func))
            {
                value = func.GetPointer().ToInt64();
            }

            // Make sure changes to the function at the target address update this jump table entry.
            LinkedList <int> targetDependants = _dependants.GetOrAdd((ulong)address, (addr) => new LinkedList <int>());

            lock (targetDependants)
            {
                targetDependants.AddLast(entry);
            }

            IntPtr addr = _jumpRegion.Pointer + entry * JumpTableStride;

            Marshal.WriteInt64(addr, 0, address);
            Marshal.WriteInt64(addr, 8, value);

            return(entry);
        }
示例#2
0
        public int ReserveTableEntry(long ownerAddress, long address, bool isJump)
        {
            int entry = Interlocked.Increment(ref _tableEnd);

            ExpandIfNeededJumpTable(entry);

            // Is the address we have already registered? If so, put the function address in the jump table.
            // If not, it will point to the direct call stub.
            long value = DirectCallStubs.DirectCallStub(isJump).ToInt64();

            if (Targets.TryGetValue((ulong)address, out TranslatedFunction func))
            {
                value = func.FuncPtr.ToInt64();
            }

            // Make sure changes to the function at the target address update this jump table entry.
            LinkedList <int> targetDependants = Dependants.GetOrAdd((ulong)address, (addr) => new LinkedList <int>());

            lock (targetDependants)
            {
                targetDependants.AddLast(entry);
            }

            IntPtr addr = GetEntryAddressJumpTable(entry);

            Marshal.WriteInt64(addr, 0, address);
            Marshal.WriteInt64(addr, 8, value);

            return(entry);
        }