Exemplo n.º 1
0
        /// <summary>
        /// Signal that a virtual memory event happened at the given location.
        /// </summary>
        /// <param name="address">Virtual address accessed</param>
        /// <param name="size">Size of the region affected in bytes</param>
        /// <param name="write">Whether the region was written to or read</param>
        /// <returns>True if the event triggered any tracking regions, false otherwise</returns>
        public bool VirtualMemoryEvent(ulong address, ulong size, bool write)
        {
            // Look up the virtual region using the region list.
            // Signal up the chain to relevant handles.

            lock (TrackingLock)
            {
                var results = _virtualResults;
                int count   = _virtualRegions.FindOverlapsNonOverlapping(address, size, ref results);

                if (count == 0)
                {
                    if (!_memoryManager.IsMapped(address))
                    {
                        throw new InvalidMemoryRegionException();
                    }

                    _memoryManager.TrackingReprotect(address & ~(ulong)(_pageSize - 1), (ulong)_pageSize, MemoryPermission.ReadAndWrite);
                    return(false); // We can't handle this - it's probably a real invalid access.
                }

                for (int i = 0; i < count; i++)
                {
                    VirtualRegion region = results[i];
                    region.Signal(address, size, write);
                }
            }

            return(true);
        }