static List <COMIPIDEntry> ParseIPIDEntries <T>(NtProcess process, IntPtr ipid_table, ISymbolResolver resolver) where T : struct, IPIDEntryNativeInterface { List <COMIPIDEntry> entries = new List <COMIPIDEntry>(); PageAllocator palloc = new PageAllocator(process, ipid_table); if (palloc.Pages.Length == 0 || palloc.EntrySize < Marshal.SizeOf(typeof(T))) { return(entries); } foreach (IntPtr page in palloc.Pages) { int total_size = palloc.EntriesPerPage * palloc.EntrySize; var data = process.ReadMemory(page.ToInt64(), palloc.EntriesPerPage * palloc.EntrySize); if (data.Length < total_size) { continue; } using (var buf = new SafeHGlobalBuffer(data)) { for (int entry_index = 0; entry_index < palloc.EntriesPerPage; ++entry_index) { IPIDEntryNativeInterface ipid_entry = buf.Read <T>((ulong)(entry_index * palloc.EntrySize)); if ((ipid_entry.Flags != 0xF1EEF1EE) && (ipid_entry.Flags != 0)) { entries.Add(new COMIPIDEntry(ipid_entry, process, resolver)); } } } } return(entries); }
static List <COMIPIDEntry> ParseIPIDEntries <T>(SafeProcessHandle process, IntPtr ipid_table, SymbolResolver resolver) where T : struct, IPIDEntryNativeInterface { List <COMIPIDEntry> entries = new List <COMIPIDEntry>(); PageAllocator palloc = new PageAllocator(process, ipid_table); if (palloc.Pages.Length == 0 || palloc.EntrySize < Marshal.SizeOf(typeof(T))) { return(entries); } foreach (IntPtr page in palloc.Pages) { using (var buf = process.ReadBuffer(page, palloc.EntriesPerPage * palloc.EntrySize)) { if (buf == null) { continue; } for (int entry_index = 0; entry_index < palloc.EntriesPerPage; ++entry_index) { IPIDEntryNativeInterface ipid_entry = buf.Read <T>((ulong)(entry_index * palloc.EntrySize)); if ((ipid_entry.Flags != 0xF1EEF1EE) && (ipid_entry.Flags != 0)) { entries.Add(new COMIPIDEntry(ipid_entry, process, resolver)); } } } } return(entries); }
/** * <summary> * Changes the mapping of an individual page. * </summary> */ public static PageAllocator.Errors MapPage(void *page, void *phys_page, uint granularity, PageAttributes attr) { uint nativeAttr = 0, pde = 0, pte = 0; uint *table = null; // validity checks Diagnostics.Assert(ADC.Pager.GetPointerGranularity(page) == granularity, "X86.Pager::MapPage(): bad alignment on virtual page pointer"); Diagnostics.Assert(ADC.Pager.GetPointerGranularity(phys_page) == granularity, "X86.Pager::MapPage(): bad alignment on physical page pointer"); Diagnostics.Assert(page != PageTables, "X86.Pager::MapPage(): tried to change mapping of the page table!"); Diagnostics.Assert(page != PageDirectory, "X86.Pager::MapPage(): tried to change mapping of the page directory!"); Diagnostics.Assert(!PageAllocator.IsPageReserved(page), "X86.Pager::MapPage(): tried to change mapping on a reserved page."); // perform mapping nativeAttr = (uint)GetNativePMA(attr); PagePtrToTables(page, &pde, &pte); // Make sure the directory is present and read write PageDirectory[pde] |= (uint)PageAttr.Present; PageDirectory[pde] |= (uint)PageAttr.ReadWrite; if (granularity == 0) { uint tablePointer = PageDirectory[pde] & (uint)PageAttr.FrameMask; table = (uint *)tablePointer; } if (nativeAttr == 0xFFFFFFFF) { nativeAttr = table[pte] & (uint)PageAttr.AttributeMask; } // set our table entry to it's new target table[pte] = (uint)phys_page | nativeAttr; return(PageAllocator.Errors.Success); }
public static unsafe void Setup(byte *free) { // DMA 1) memory must be under 16M and 2) access must start on 64k boundary // force align onto 64k boundary // the trick here is add 64k to last allocation and then mask bit against (64k - 1) value dmaReserve = (byte *)(((uint)free + (64 * 1024)) & ((64 * 1024) - 1)); if ((((uint)dmaReserve + (64 * 1024 * 3)) >> 24) != 0) { Diagnostics.Panic("Can not allocated DMA memory under 16M"); } // Reserve 64K for each channel // DMA channel 0 is reserved - and not used on the x86 platform PageAllocator.ReservePageRange(dmaReserve, 64 * 1024 / ADC.Pager.AtomicPageSize, "dma #1"); PageAllocator.ReservePageRange(dmaReserve + (64 * 1024), 64 * 1024 / ADC.Pager.AtomicPageSize, "dma #2"); PageAllocator.ReservePageRange(dmaReserve + (2 * 64 * 1024), 64 * 1024 / ADC.Pager.AtomicPageSize, "dma #3"); }
private void GenerateTrampolineInner(out int trampolineLength, out int jmpLength) { if (TrampolinePtr != IntPtr.Zero) { trampolineLength = TrampolineSize; jmpLength = TrampolineJmpSize; return; } var instructionBuffer = new byte[32]; Marshal.Copy(OriginalFunctionPtr, instructionBuffer, 0, 32); var trampolineAlloc = PageAllocator.Instance.Allocate(OriginalFunctionPtr); logger.Log(LogLevel.Debug, $"Original: {OriginalFunctionPtr.ToInt64():X}, Trampoline: {trampolineAlloc:X}, diff: {Math.Abs(OriginalFunctionPtr.ToInt64() - trampolineAlloc):X}; is within +-1GB range: {PageAllocator.IsInRelJmpRange(OriginalFunctionPtr, trampolineAlloc)}"); DetourHelper.Native.MakeWritable(trampolineAlloc, PageAllocator.PAGE_SIZE); var arch = IntPtr.Size == 8 ? Architecture.X64 : Architecture.X86; DetourGenerator.CreateTrampolineFromFunction(instructionBuffer, OriginalFunctionPtr, trampolineAlloc, DetourGenerator.GetDetourLength(arch), arch, out trampolineLength, out jmpLength); DetourHelper.Native.MakeExecutable(trampolineAlloc, PageAllocator.PAGE_SIZE); TrampolinePtr = trampolineAlloc; TrampolineSize = trampolineLength; TrampolineJmpSize = jmpLength; }
public unsafe static void BootEntry(uint magic, uint pointer, uint kernelStart, uint kernelEnd) { // Initialize architecture-specific portion of the kernel Architecture.Setup(); // Set up text mode display TextMode.Setup(); TextMode.SetAttributes(TextColor.Yellow, TextColor.Black); TextMode.ClearScreen(); TextMode.SetCursor(0, 0); // Write the banner DisplayBanner(); StageMessage("Multiboot setup..."); if (!Multiboot.Setup(magic, pointer, kernelStart, kernelEnd)) { StageError("Error: multiboot loader required!"); return; } kernelStartLoc = (void *)kernelStart; kernelEndLoc = (void *)kernelEnd; StageMessage("Commandline setup..."); CommandLine.Setup(); StageMessage("PageAllocator setup..."); PageAllocator.Setup( Multiboot.KernelAddress, Multiboot.KernelSize, Multiboot.UpperMemorySize + 1000); StageMessage("MemoryManager setup..."); ADC.MemoryManager.Setup(); StageMessage("Debug setup..."); Debug.Setup(); // Must be done after MemoryManager setup. StageMessage("Runtime setup..."); ExceptionHandling.Setup(); StageMessage("Event Dispatch setup..."); SimpleEventDispatch.Setup(); StageMessage("Device setup..."); DeviceSystem.Boot.Start(); Debug.Setup2(); StageMessage("Diagnostic Tool setup..."); DiagnosticTool.Server.Setup(); StageMessage("Scheduler setup..."); ThreadManager.Setup(); StageMessage("File System setup..."); FileSystem.Boot.Start(); //StageMessage ("Clock setup..."); Clock.Setup(); StageMessage("Keymap setup..."); KeyMap.Setup(); StageMessage("Keyboard setup..."); Keyboard.Setup(); StageMessage("Console setup..."); SharpOS.Kernel.Console.Setup(); TextMode.SaveAttributes(); TextMode.SetAttributes(TextColor.LightGreen, TextColor.Black); TextMode.WriteLine(""); TextMode.WriteLine("Pinky: What are we gonna do tonight, Brain?"); TextMode.WriteLine("The Brain: The same thing we do every night, Pinky - Try to take over the world!"); TextMode.RestoreAttributes(); //SharpOS.Kernel.Memory.PageAllocator.DumpInfo (); #if KERNEL_TESTS // Testcases MemoryManager.__RunTests(); ByteString.__RunTests(); StringBuilder.__RunTests(); CString8.__RunTests(); PString8.__RunTests(); InternalSystem.String.__RunTests(); Runtime.__RunTests(); Debug.COM1.WriteLine("Failed AOT Tests:"); //SharpOS.Kernel.Tests.Wrapper.Run (); Debug.COM1.WriteLine(); Debug.COM1.WriteLine("Kernel Tests:"); #endif /* * void* thread = ThreadManager.CreateThread(Stubs.GetFunctionPointer ("TEST")); * void* thread2 = ThreadManager.CreateThread(Stubs.GetFunctionPointer ("TEST2")); * * ThreadManager.ScheduleThread(thread); * ThreadManager.ScheduleThread(thread2); * ThreadManager.Enabled = true; */ //Multiboot.WriteMultibootInfo(); StageMessage("Shell setup..."); SharpOS.Kernel.Shell.Prompter.Setup(); SharpOS.Kernel.Shell.Prompter.Start(); SetKernelStage(KernelStage.Diagnostics); // Infinite loop used to halt the processors //FIXME We must know on each processor the current thread runs on. // Halt all other procs, then halt the current one. IProcessor[] procs = Architecture.GetProcessors(); int procCount = Architecture.GetProcessorCount(); while (stayInLoop) { for (int i = 0; i < procCount; i++) { procs[i].Halt(); } } }
public Tree(TableIndex index, TreeRootHeader root, PageAllocator pageAllocator) { _root = root; _index = index; _pageAllocator = pageAllocator; }