public void TestWAHBitArray4() { var b = new WAHBitArray(); int count = 25; for (int i = 0; i < 5; i++) { b.Set(i, true); } for (int i = 5; i < count + 5; i++) { b.Set(i, false); } for (int i = 30; i < 64; i++) { b.Set(i, i != 35); } for (int i = 64; i < 100; i++) { b.Set(i, true); } var expected = b.GetBitIndexes().ToArray(); var b2 = new WAHBitArray(WAHBitArray.TYPE.Compressed_WAH, b.GetCompressed()); var actual = b2.GetBitIndexes().ToArray(); expected.Should(Be.EqualTo(actual)); }
public static void WAH_test() { int count = 500; for (int i = 0; i < 1000; i++) { Console.Write("."); if (i % 80 == 0) { Console.WriteLine(); } WAHBitArray ba = new WAHBitArray(); for (int j = 0; j < count; j++) { ba.Set(i * count + j, true); } WAHBitArray.TYPE type; var bits = ba.GetCompressed(out type); var ba2 = new WAHBitArray(type, bits); var res = ba2.Xor(ba); long c = res.CountOnes(); Assert.AreEqual(0, c); } //Random r = new Random(); //WAHBitArray b = new WAHBitArray(); //for (int i = 0; i < 100000; i++) //{ // b.Set( //} }
public long GetPageForPhysAddr(HARDWARE_ADDRESS_ENTRY PAddr, ref long[] block, ref bool GotData, bool NoCache = true) { long rv = 0; // convert PAddr to PFN var aPFN = PAddr.NextTable_PFN; GotData = false; //NoCache = true; if (!NoCache && PageCache.ContainsKey(aPFN)) { do { PageCache.TryGetValue(aPFN, out block); }while (block == null); // shift down since were loading a long[] GotData = true; return(block[(PAddr >> 3) & 0x1ff]); } // should return with - error_value if (aPFN > int.MaxValue || aPFN < 0) { return(0); } #if USE_BITMAP if (pfnTableIdx != null) { pfnTableIdx.Set((int)PFN, true); } #endif // paranoid android setting var FileOffset = OffsetToMemIndex(aPFN); if (FileOffset < 0) { rv = MagicNumbers.BAD_RUN_CONFIG_READ; } else { // add back in the file offset for possible exact byte lookup rv = GetPageFromFileOffset(FileOffset + PAddr.AddressOffset, ref block, ref GotData); } if (!GotData) { rv = MagicNumbers.BAD_VALUE_READ; } if (!NoCache && GotData) { PageCache.TryAdd(aPFN, block); } return(rv); }
// Extract a single page of data from a physical address in source dump // account for memory gaps/run layout // TODO: Add windowing currently uses naive single-page-at-a-time view public long GetPageForPhysAddr(HARDWARE_ADDRESS_ENTRY PAddr, ref long[] block) { // convert PAddr to PFN var PFN = PAddr.NextTable_PFN; if (PageCache.ContainsKey(PFN)) { if (PageCache.TryGetValue(PAddr, out block)) { return(block[PAddr & 0x1ff]); } } // record our access attempt to the pfnIndex if (PFN > int.MaxValue || PFN > MD.MaxAddressablePageNumber) { return(0); } pfnTableIdx.Set((int)PFN, true); // paranoid android setting var Fail = true; long IndexedPFN = 0; for (int i = 0; i < MD.NumberOfRuns; i++) { if (PFN >= MD.Run[i].BasePage && PFN < (MD.Run[i].BasePage + MD.Run[i].PageCount)) { var currBaseOffset = PFN - MD.Run[i].BasePage; IndexedPFN += currBaseOffset; Fail = false; break; } IndexedPFN += MD.Run[i].PageCount; } if (Fail) { throw new MemoryRunMismatchException(PAddr.PTE); } // Determine file offset based on indexed/gap adjusted PFN and page size var FileOffset = StartOfMemory + (IndexedPFN * PAGE_SIZE); // add back in the file offset for possible exact byte lookup var rv = GetPageFromFileOffset(FileOffset + PAddr.AddressOffset, ref block); if (block != null) { PageCache.TryAdd(PFN, block); } return(rv); }
public void TestWAHBitArray1() { var b = new WAHBitArray(); int count = 31; for (int i = 0; i < count; i++) { b.Set(i, true); } var expected = b.GetBitIndexes().ToArray(); var b2 = new WAHBitArray(WAHBitArray.TYPE.Compressed_WAH, b.GetCompressed()); var actual = b2.GetBitIndexes().ToArray(); expected.Should(Be.EqualTo(actual)); }
public long GetPageForPhysAddr(HARDWARE_ADDRESS_ENTRY PAddr, ref long[] block, ref bool GotData) { long rv = 0; // convert PAddr to PFN var aPFN = PAddr.NextTable_PFN; GotData = false; // should return with - error_value // This happens quite a bit and is a good boost // I guess were constrained by int.MaxValue pages here. // so that is about 8TB // TODO: explore 5 level page tables and larger than 8TB inputs :) if (aPFN > int.MaxValue || aPFN < 0) { return(0); } #if USE_BITMAP if (pfnTableIdx != null) { pfnTableIdx.Set((int)PFN, true); } #endif // paranoid android setting var FileOffset = OffsetToMemIndex(aPFN); if (FileOffset >= 0) { rv = GetPageFromFileOffset(FileOffset + PAddr.AddressOffset, ref block, ref GotData); } if (!GotData) { rv = MagicNumbers.BAD_VALUE_READ; } return(rv); }
private Result <T> ReturnRows2 <T>(WAHBitArray ba, List <T> trows, int start, int count, List <int> orderby) { DateTime dt = FastDateTime.Now; List <T> rows = new List <T>(); Result <T> ret = new Result <T>(); int skip = start; int c = 0; ret.TotalCount = (int)ba.CountOnes(); if (count == -1) { count = ret.TotalCount; } if (count > 0) { foreach (int i in orderby) { if (ba.Get(i)) { if (skip > 0) { skip--; } else { bool b = OutputRow <T>(rows, i); if (b && count > 0) { c++; } } ba.Set(i, false); if (c == count) { break; } } } foreach (int i in ba.GetBitIndexes()) { if (c < count) { if (skip > 0) { skip--; } else { bool b = OutputRow <T>(rows, i); if (b && count > 0) { c++; } } if (c == count) { break; } } } } if (trows != null)// TODO : move to start and decrement in count { foreach (var o in trows) { rows.Add(o); } } _log.Debug("query rows fetched (ms) : " + FastDateTime.Now.Subtract(dt).TotalMilliseconds); _log.Debug("query rows count : " + rows.Count.ToString("#,0")); ret.OK = true; ret.Count = rows.Count; ret.Rows = rows; return(ret); }