/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue"> /// The existing value of object being read. If there is no existing value then <c>null</c> /// will be used. /// </param> /// <param name="hasExistingValue">The existing value has a value.</param> /// <param name="serializer">The calling serializer.</param> /// <returns>The object value.</returns> /// <inheritdoc /> public override MemoryChunk ReadJson(JsonReader reader, Type objectType, MemoryChunk existingValue, bool hasExistingValue, JsonSerializer serializer) { var jobj = JObject.Load(reader); byte[] bytes = null; Position position = null; MemoryRange memoryRange = null; foreach (var prop in jobj) { switch (prop.Key) { case "Bytes": bytes = prop.Value.Value <byte[]>(); break; case "Position": position = prop.Value.ToObject <Position>(serializer); break; case "MemoryRange": memoryRange = prop.Value.Value <MemoryRange>(); break; } } return(new MemoryChunk { Bytes = bytes, Position = position, MemoryRange = memoryRange }); }
public ImageDataProvider(DataModel data, string cacheFolder) : base(data, cacheFolder) { _imageFilename = ""; ImageLength = 0; if (_data.MemoryImageFilename == "") { throw new ArgumentException("Memory Image Name Isn't Set"); } IsLive = false; // check to see if we are looking at a new image file if (_data.MemoryImageFilename != _imageFilename) { _imageFilename = _data.MemoryImageFilename; FileInfo fiCheck = new FileInfo(_imageFilename); if (!fiCheck.Exists) { _imageFilename = ""; ImageLength = 0; throw new ArgumentException("Memory Image Doesn't Exist: " + _imageFilename); } ImageLength = (ulong)fiCheck.Length; MemoryRange range = new MemoryRange(); range.StartAddress = 0; range.Length = ImageLength; range.PageCount = (uint)(ImageLength / 0x1000); _memoryRangeList.Add(range); } }
private void buttonOk_Click(object sender, EventArgs e) { MemoryRange tempRange = new MemoryRange(); try { ulong start = Convert.ToUInt64(textBoxFrom.Text, 16); ulong end = Convert.ToUInt64(textBoxTo.Text, 16); if (start >= end) { MessageBox.Show("End address must be after the start address.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } tempRange = new MemoryRange(start, end); } catch { MessageBox.Show("Memory range is not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Range = tempRange; // Close dialog DialogResult = DialogResult.OK; Close(); }
public Subscriber(String tag, MemoryRange range, MemoryChangeHandler callback) { id = Guid.NewGuid(); this.tag = tag; this.range = range; this.callback = callback; }
/// <summary> /// Extracts the memory ranges. /// </summary> /// <param name="args">The arguments.</param> /// <param name="i">The i.</param> /// <param name="arg">The argument.</param> /// <param name="options">The options.</param> /// <exception cref="FormatException"></exception> /// <exception cref="ArgumentException"></exception> /// <exception cref="System.FormatException"></exception> /// <exception cref="System.ArgumentException"></exception> internal void ExtractMemoryRanges(string[] args, int i, string arg, IndexOptions options) { var ranges = new List <MemoryRange>(); for (var j = i + 1; j < args.Length; j++) { var ptr = args[j]; if (Switches.Contains(ptr)) { break; } try { var range = MemoryRange.Parse(ptr); ranges.Add(range); } catch (Exception e) { throw new FormatException($"Unable to parse memory range {ptr}", e); } } if (!ranges.Any()) { throw new ArgumentException($"No memory ranges provided to {arg}"); } options.MemoryRanges = ranges; }
public Mbc1(string romPath, bool hasRam, int romBankCount, RamSize ramSize, byte[] cartridgeData) : base(romPath) { mode = 0; this.romBankCount = romBankCount; MemoryRange[] switchableBanks = new MemoryRange[romBankCount]; for (int i = 0; i < romBankCount; i++) { int startAddress = RomSizePerBank * i; var bankdata = GetCartridgeChunk(startAddress, RomSizePerBank, cartridgeData); switchableBanks[i] = new MemoryRange(bankdata, true); } romBanks = new Bank(switchableBanks); romBanks.Switch(1); if (hasRam) { ramBanks = new MbcRam(ramSize.Banks, ramSize.SizePerBank, GetSaveFilePath()); } else { ramBanks = new MbcRam(0, 0); } Bank0 = romBanks.GetBank(0); }
public ClrmdSegment(ClrmdHeap heap, IHeapHelpers helpers, ISegmentData data) { if (helpers is null) { throw new ArgumentNullException(nameof(helpers)); } if (data is null) { throw new ArgumentNullException(nameof(data)); } _helpers = helpers; _clrmdHeap = heap; LogicalHeap = data.LogicalHeap; IsLargeObjectSegment = data.IsLargeObjectSegment; IsPinnedObjectSegment = data.IsPinnedObjectSegment; IsEphemeralSegment = data.IsEphemeralSegment; ObjectRange = new MemoryRange(data.Start, data.End); ReservedMemory = new MemoryRange(data.CommittedEnd, data.ReservedEnd); CommittedMemory = new MemoryRange(data.BaseAddress, data.CommittedEnd); Generation0 = MemoryRange.CreateFromLength(data.Gen0Start, data.Gen0Length); Generation1 = MemoryRange.CreateFromLength(data.Gen1Start, data.Gen1Length); Generation2 = MemoryRange.CreateFromLength(data.Gen2Start, data.Gen2Length); _markers = new ulong[MarkerCount]; }
/// <summary> /// Gets a writable region from GPU mapped memory. /// </summary> /// <param name="range">Range</param> /// <param name="tracked">True if write tracking is triggered on the span</param> /// <returns>A writable region with the data at the specified memory location</returns> public WritableRegion GetWritableRegion(MultiRange range, bool tracked = false) { if (range.Count == 1) { MemoryRange subrange = range.GetSubRange(0); return(GetWritableRegion(subrange.Address, (int)subrange.Size, tracked)); } else { Memory <byte> memory = new byte[range.GetSize()]; int offset = 0; for (int i = 0; i < range.Count; i++) { var currentRange = range.GetSubRange(i); int size = (int)currentRange.Size; if (currentRange.Address != MemoryManager.PteUnmapped) { GetSpan(currentRange.Address, size).CopyTo(memory.Span.Slice(offset, size)); } offset += size; } return(new WritableRegion(new MultiRangeWritableBlock(range, this), 0, memory, tracked)); } }
/// <summary> /// Checks if a given GPU virtual memory range is mapped to the same physical regions /// as the specified physical memory multi-range. /// </summary> /// <param name="range">Physical memory multi-range</param> /// <param name="va">GPU virtual memory address</param> /// <returns>True if the virtual memory region is mapped into the specified physical one, false otherwise</returns> public bool CompareRange(MultiRange range, ulong va) { va &= ~PageMask; for (int i = 0; i < range.Count; i++) { MemoryRange currentRange = range.GetSubRange(i); ulong address = currentRange.Address & ~PageMask; ulong endAddress = (currentRange.EndAddress + PageMask) & ~PageMask; while (address < endAddress) { if (Translate(va) != address) { return(false); } va += PageSize; address += PageSize; } } return(true); }
public void Not_Parse_Invalid_Input() { // arrange var l1 = "hello"; var l2 = "-123:-24"; Action throw1 = () => MemoryRange.Parse(l1); Action throw2 = () => MemoryRange.Parse(l2); // act // assert throw1.Should().Throw <FormatException>(); throw2.Should().Throw <FormatException>(); }
public Mbc2Ram(string saveFileName) : base(null, null) { banks = new IMemoryRange[1]; var ram = new IMemory[RAMSize]; for (int i = 0; i < RAMSize; i++) { ram[i] = new MaskedRegister(0xF0); } banks[0] = new MemoryRange(ram); PrepareSaveFile(saveFileName); }
// public for debugging purposes, later used only internally by RenewVisibleValues public MemoryRange GetCurrentVisibleRange() { var range = new MemoryRange(); var rowsShown = dataGridView1.DisplayedRowCount(true); var firstVisibleRow = GetFirstRowIndexShown(); // calculate addresses using the columnsPerRow range.StartAddress = (int)((firstVisibleRow * ColumnsPerRow) + StartAddress); range.Length = rowsShown * ColumnsPerRow; return(range); }
public MBC3(string romPath, bool hasRam, int romBankCount, RamSize ramSize, byte[] cartridgeData) : base(romPath) { this.romBankCount = romBankCount; MemoryRange[] switchableBanks = new MemoryRange[romBankCount]; for (int i = 0; i < romBankCount; i++) { int startAddress = RomSizePerBank * i; var bankData = GetCartridgeChunk(startAddress, RomSizePerBank, cartridgeData); switchableBanks[i] = new MemoryRange(bankData, true); } romBanks = new Bank(switchableBanks); romBanks.Switch(1); byte count; ushort size; if (!hasRam) { count = 0; size = 0; } else { count = ramSize.Banks; size = ramSize.SizePerBank; } IMemoryRange[] ramAndClock = new IMemoryRange[0xD]; var clock = new RTC(); for (int i = 0; i < ramAndClock.Length; i++) { if (i > 0x07) { ramAndClock[i] = clock; } else { if (i <= count) { ramAndClock[i] = new MemoryRange(size); } else { ramAndClock[i] = new DummyRange(); } } } ramBanks = new MbcRam(ramAndClock, GetSaveFilePath()); }
public Bank(byte count, ushort size, bool isReadOnly = false) { if (count == 0) { banks = new IMemoryRange[] { new DummyRange() }; } else { banks = new IMemoryRange[count]; for (int i = 0; i < count; i++) { banks[i] = new MemoryRange(size, isReadOnly); } } }
public void Parse_Both_Forms_Of_Input() { // arrange var l1 = "abcl100"; var l2 = "ABCL100"; var s1 = "abc:def"; var s2 = "ABC:DEF"; // act // assert MemoryRange.Parse(l1).Should().Be(new MemoryRange(0xabc, 0xbbc)); MemoryRange.Parse(l1).Should().Be(new MemoryRange(0xabc, 0xbbc)); MemoryRange.Parse(s1).Should().Be(new MemoryRange(0xabc, 0xdef)); MemoryRange.Parse(s1).Should().Be(new MemoryRange(0xabc, 0xdef)); // todo: make some 32 }
/// <summary> /// Generate a TextureGroupHandle covering a specified range of views. /// </summary> /// <param name="viewStart">The start view of the handle</param> /// <param name="views">The number of views to cover</param> /// <returns>A TextureGroupHandle covering the given views</returns> private TextureGroupHandle GenerateHandles(int viewStart, int views) { int offset = _allOffsets[viewStart]; int endOffset = (viewStart + views == _allOffsets.Length) ? (int)Storage.Size : _allOffsets[viewStart + views]; int size = endOffset - offset; var result = new List <CpuRegionHandle>(); for (int i = 0; i < TextureRange.Count; i++) { MemoryRange item = TextureRange.GetSubRange(i); int subRangeSize = (int)item.Size; int sliceStart = Math.Clamp(offset, 0, subRangeSize); int sliceEnd = Math.Clamp(endOffset, 0, subRangeSize); if (sliceStart != sliceEnd) { result.Add(GenerateHandle(item.Address + (ulong)sliceStart, (ulong)(sliceEnd - sliceStart))); } offset -= subRangeSize; endOffset -= subRangeSize; if (endOffset <= 0) { break; } } (int firstLayer, int firstLevel) = GetLayerLevelForView(viewStart); if (_hasLayerViews && _hasMipViews) { size = _sliceSizes[firstLevel]; } var groupHandle = new TextureGroupHandle(this, _allOffsets[viewStart], (ulong)size, _views, firstLayer, firstLevel, result.ToArray()); foreach (CpuRegionHandle handle in result) { handle.RegisterDirtyEvent(() => DirtyAction(groupHandle)); } return(groupHandle); }
public override Dictionary <string, object> GetInformation() { Dictionary <string, object> _information = new Dictionary <string, object>(); //uint error = GetLastError(); byte[] buffer = new byte[4096]; IntPtr procAddress = GetProcAddress(_helperLib, "GetInfo"); GetInfo info = (GetInfo)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(GetInfo)); int result2 = info(buffer); if (result2 == 0) { ulong itemValue = BitConverter.ToUInt64(buffer, 0); _information.Add("dtb", itemValue); itemValue = BitConverter.ToUInt64(buffer, 8); _information.Add("buildNumber", itemValue); itemValue = BitConverter.ToUInt64(buffer, 16); _information.Add("kernelBase", itemValue); itemValue = BitConverter.ToUInt64(buffer, 24); _information.Add("kdbg", itemValue); itemValue = BitConverter.ToUInt64(buffer, 288); _information.Add("pfnDatabase", itemValue); itemValue = BitConverter.ToUInt64(buffer, 296); _information.Add("psLoadedModuleList", itemValue); itemValue = BitConverter.ToUInt64(buffer, 304); _information.Add("ntBuildNumberAddress", itemValue); itemValue = BitConverter.ToUInt64(buffer, 2352); //_information.Add("runCount", itemValue); int count = (int)itemValue; for (int i = 0; i < count; i++) { MemoryRange range = new MemoryRange(); range.StartAddress = BitConverter.ToUInt64(buffer, 2360 + (i * 16)); range.Length = BitConverter.ToUInt64(buffer, 2368 + (i * 16)); range.PageCount = (uint)(range.Length / 4096); _memoryRangeList.Add(range); if (range.StartAddress + range.Length > _maximumPhysicalAddress) { _maximumPhysicalAddress = range.StartAddress + range.Length - 1; } } _information.Add("maximumPhysicalAddress", _maximumPhysicalAddress); ImageLength = _maximumPhysicalAddress; } return(_information); }
public void Subscribe(string tag, MemoryRange range, MemoryChangeHandler callback) { Subscriber h; foreach (Subscriber handler in subscribers) { if (range.start == handler.range.start && range.end == handler.range.end) { h = handler; h.callback += callback; Debug.Log(string.Format("{0} subscribed to memory range {1:X8}-{2:X8} as secondary", tag, range.start, range.end)); return; } } h = new Subscriber(tag, range, callback); subscribers.Add(h); Debug.Log(string.Format("{0} subscribed to memory range {1:X8}-{2:X8}", tag, range.start, range.end)); }
public Mbc2(string romPath, int romBankCount, byte[] cartridgeData) : base(romPath) { this.romBankCount = romBankCount; if (romBankCount > 16) { throw new ArgumentOutOfRangeException(nameof(romBankCount)); } MemoryRange[] switchableBanks = new MemoryRange[romBankCount]; for (int i = 0; i < romBankCount; i++) { int startAddress = RomSizePerBank * i; var bankData = GetCartridgeChunk(startAddress, RomSizePerBank, cartridgeData); switchableBanks[i] = new MemoryRange(bankData, true); } romBanks = new Bank(switchableBanks); romBanks.Switch(1); ramBanks = new Mbc2Ram(GetSaveFilePath()); }
public void Exhibit_Value_Equality_And_Comparison() { // arrange var m1 = new MemoryRange(0, 0); var m2 = new MemoryRange(0, 0); var m3 = new MemoryRange(1, 2); var m4 = new MemoryRange(1, 3); var m5 = new MemoryRange(2, 2); // act // assert (m1 == null).Should().BeFalse(); (m1 == m1).Should().BeTrue(); m1.Equals(null).Should().BeFalse(); m1.Equals((object)m1).Should().BeTrue(); m1.Equals((object)null).Should().BeFalse(); m1.Equals(null).Should().BeFalse(); m1.Equals(null); m1.Equals(new object()).Should().BeFalse(); m1.CompareTo(m1).Should().Be(0); m1.Equals((object)m1).Should().BeTrue(); m1.Equals(m1).Should().BeTrue(); m1.Equals(m2).Should().BeTrue(); m1.Equals((object)m2).Should().BeTrue(); m1.CompareTo(m2).Should().Be(0); m1.CompareTo((object)m2).Should().Be(0); (m1 == m2).Should().BeTrue(); (m1 != m4).Should().BeTrue(); m1.GetHashCode().Should().Be(m2.GetHashCode()); (m2 < m3).Should().BeTrue(); (m2 <= m4).Should().BeTrue(); (m4 > m3).Should().BeTrue(); (m5 >= m4).Should().BeTrue(); m1.CompareTo((object)m1).Should().Be(0); m1.CompareTo((object)null).Should().Be(1); m1.CompareTo(null).Should().Be(1); Action a = () => m1.CompareTo(new object()); a.Should().Throw <ArgumentException>(); }
internal virtual int ExtractMemoryRanges(string[] args, int startIndex, string arg, IndexOptions options) { var ranges = new List<MemoryRange>(); int j; for (j = startIndex + 1; j < args.Length; j++) { var ptr = args[j]; if (Switches.Contains(ptr)) break; try { var range = MemoryRange.Parse(ptr); ranges.Add(range); } catch (Exception e) { throw new FormatException($"Unable to parse memory range {ptr}", e); } } options.MemoryRanges = ranges; return j - 1; }
//# // @return Whether the region and the given range intersect at any point. public virtual bool intersectsRange(object start, UInt32?end = null, UInt32?length = null, MemoryRange range = null) { var _tup_1 = check_range(start, end, length, range); start = _tup_1.Item1; end = _tup_1.Item2; return((UInt32)start <= this.start && end >= this.start || (UInt32)start <= this.end && end >= this.end || (UInt32)start >= this.start && end <= this.end); }
public virtual List <MemoryRegion> getIntersectingRegions(object start, UInt32?end = null, UInt32?length = null, MemoryRange range = null) { var _tup_1 = check_range(start, end, length, range); start = _tup_1.Item1; end = _tup_1.Item2; return(this._regions.Where(r => r.intersectsRange(start, end)).ToList()); }
//# // @return Whether the given range is fully contained by the region. public virtual bool containsRange(UInt32 start, UInt32?end = null, UInt32?length = null, MemoryRange range = null) { var _tup_1 = check_range(start, end, length, range); start = _tup_1.Item1; end = _tup_1.Item2; return(this.containsAddress(start) && this.containsAddress((UInt32)end)); }
private void assureFreeMemoryByMinimumMemoryCopy(long bytes) { int n = this.structureByAddress.Count; MemoryRange[] memory = new MemoryRange[n]; int storeIndex = 0; long lastPointer = 0L, totalFreeSoFar = 0L, totalCostSoFar = 0L; foreach (MemoryBlockByAddress block in this.structureByAddress) { long occupiedBytes = block.Address - lastPointer; totalFreeSoFar += block.Size; totalCostSoFar += occupiedBytes; memory[storeIndex++] = new MemoryRange(totalFreeSoFar, totalCostSoFar); lastPointer = block.End; } if (totalFreeSoFar != this.free) { throw new InvalidOperationException("Free memory mismatch."); } int startIndex = -1, endIndex = -1; long maxFreeBlockCost = long.MaxValue; int j = memory.BinarySearchLeftmostGreaterOrEqual(bytes, mr => mr.TotalFreeBytes); for (int i = 0; i < n && j < n; i++) { long cost = memory[j].TotalCost - memory[i].TotalCost; long freeBytes = memory[j].TotalFreeBytes - (i == 0 ? 0L : memory[i - 1].TotalFreeBytes); if (freeBytes >= bytes && cost < maxFreeBlockCost) { startIndex = i; endIndex = j; maxFreeBlockCost = cost; } while (j < n && memory[j].TotalFreeBytes - memory[i].TotalFreeBytes < bytes) { j++; } } long actualCost = 0L; MemoryBlockByAddress resultBlock = this.structureByAddress[startIndex]; for (int i = startIndex + 1; i <= endIndex; i++) { MemoryBlockByAddress foundNode, block = this.structureByAddress[i]; long count = block.Address - resultBlock.End; this.memoryMove(resultBlock.End, resultBlock.Address, count); int sti = this.allocationsByAddress.GetLeftmostGreaterOrEqualIndex(new MemoryBlockByAddress(resultBlock.End, 0L), out foundNode); int eni = this.allocationsByAddress.GetLeftmostGreaterOrEqualIndex(new MemoryBlockByAddress(block.Address, 0L), out foundNode); actualCost += count; long delta = resultBlock.Size; for (int k = eni; --k >= sti;) { this.allocationsByAddress[k].Address -= delta; } resultBlock = new MemoryBlockByAddress(block.Address - resultBlock.Size, resultBlock.Size + block.Size); } if (actualCost != maxFreeBlockCost) { Debugger.Break(); } for (int i = endIndex + 1; --i >= startIndex;) { MemoryBlockBySize memoryBlockSize = this.structureByAddress[i].ToSize; this.structureBySize.Remove(memoryBlockSize); this.structureByAddress.RemoveAt(i); } this.structureByAddress.Add(resultBlock); this.structureBySize.Add(resultBlock.ToSize); }
/// <summary> /// Returns whether this memory range and <paramref name="other"/> contains any addresses which /// overlap. /// </summary> /// <param name="other">The other memory range to compare this to.</param> /// <returns>True if memory ranges overlap at all.</returns> public bool Overlaps(MemoryRange other) => other.Length > 0 && (Contains(other.Start) || Contains(other.End - 1));
/// <summary> /// Returns whether this memory range contains all of <paramref name="other"/>. /// </summary> /// <param name="other">The other memory range to compare this to.</param> /// <returns>True if this memory range completely encloses <paramref name="other"/>.</returns> public bool Contains(MemoryRange other) => other.Length > 0 && (Contains(other.Start) && Contains(other.End - 1));
/// <summary> /// Reads the virtual memory. /// </summary> /// <param name="memoryRange">The memory range.</param> /// <returns>System.Byte[].</returns> /// <inheritdoc /> public byte[] ReadVirtualMemory(MemoryRange memoryRange) { return MemoryEngine.ReadMemory(memoryRange.LowAddress, memoryRange.HighAddress, Dataspaces); }
public MemoryRangeDialog() { InitializeComponent(); Range = new MemoryRange(); }
public static Tuple <UInt32, UInt32> check_range(object start, UInt32?end = null, UInt32?length = null, MemoryRange range = null) { Debug.Assert(start != null && (start is MemoryRange || range != null || end != null ^ length != null)); if (start is MemoryRange) { range = (MemoryRange)start; } if (range != null) { start = range.start; end = range.end; } else if (end == null) { end = (UInt32)start + length - 1; } return(Tuple.Create((UInt32)start, (UInt32)end)); }