public bool AllocateBuffer(ulong Size) { unsafe { // Allocate the memory indicated as parameter, as nonGC #if SINGULARITY_KERNEL UIntPtr pages = Microsoft.Singularity.Memory.MemoryManager.PagesFromBytes(Size); bufferMemory = (byte *)Microsoft.Singularity.Memory.MemoryManager.KernelAllocate( pages, null, 0, System.GCs.PageType.NonGC).ToPointer(); // Allocation at page granularity. Preserve the actual size of the buffer BufferSize = (ulong)pages * Microsoft.Singularity.Memory.MemoryManager.PageSize; #else // !SINGULARITY_KERNEL bufferMemory = (byte *)PageTableService.Allocate(Size); BufferSize = Size; #endif //SINGULARITY_KERNEL if (bufferMemory == null) { BufferSize = 0; return(false); } } return(true); }
// Initialization, prior to attempting to set this profiler into the GC. It's // inappropriate to do this stuff inside a constructor. internal void Initialize(ulong Size, ulong Flags) { options = Flags; typeTable = new Hashtable(); stackTable = new Hashtable(); funcTable = new Hashtable(); stackEips = new UIntPtr[stackSize]; stackNos = new uint[stackSize]; generations = new int[maxGeneration]; functionsIDs = new uint[stackSize]; Buffer = new ProfilerBuffer(); tempGCBuffer = new UIntPtr[tempBufferSize]; tempGCBufferEntries = 0; #if LEGACY_GCTRACING bufferSize = Size; unsafe { // Allocate the memory indicated as parameter, as nonGC #if SINGULARITY_KERNEL UIntPtr pages = Microsoft.Singularity.Memory.MemoryManager.PagesFromBytes(bufferSize); bufferMemory = (byte *)Microsoft.Singularity.Memory.MemoryManager.KernelAllocate( pages, null, 0, System.GCs.PageType.NonGC).ToPointer(); #else // !SINGULARITY_KERNEL bufferMemory = (byte *)PageTableService.Allocate(bufferSize); #endif //SINGULARITY_KERNEL if (bufferMemory != null) { // When we set this, we are no longer single-threaded: ProfilerBuffer.SetupBuffer(bufferMemory, bufferSize); this.enabled = true; } } #else // LEGACY_GCTRACING typeSource = GCTypeSource.Create("GC.TypeDefinitions", (uint)Size, options); EventSource = GCEventSource.Create("GC.Events", (uint)Size, options); if ((typeSource == null) || (EventSource == null)) { typeSource = null; EventSource = null; this.enabled = false; } else { TypeStorageHandle = typeSource.Storage.GetHandle(); StorageHandle = EventSource.Storage.GetHandle(); this.enabled = true; } #endif // LEGACY_GCTRACING }
public static int Main() { #if TEST_CONSOLE int i = 10; long l = 100; byte b = 1; bool o = true; #endif DebugStub.Print("Hello from NullTest::Main\n"); #if TEST_CONSOLE DebugStub.Print(b); DebugStub.Print("\n"); DebugStub.Print(i); DebugStub.Print("\n"); DebugStub.Print(l); DebugStub.Print("\n"); DebugStub.Print(o); DebugStub.Print("\n"); #endif #if TEST_MEMORY_ABI uint tag = PageTableService.GetProcessTag(); DebugStub.Print("Process Tag: "); DebugStub.Print((ulong)tag); DebugStub.Print("\n"); uint pages = PageTableService.GetPageCount(); DebugStub.Print("Pages: "); DebugStub.Print(pages); DebugStub.Print("\n"); uint addr = PageTableService.Allocate(0x1000); DebugStub.Print("Allocation: "); DebugStub.Print((ulong)addr); DebugStub.Print("\n"); Probe(addr); addr = 1; for (i = 0; i < 20 && addr != 0 && addr < 0xc0000000; i++) { addr = Probe(addr); } #endif // TEST_MEMORY_ABI #if TEST_STACK_ABI Test1(1); #endif // TEST_STACK_ABI return(0); }
public static int Main() { int i = 10; long l = 100; byte b = 1; bool o = true; DebugService.Print('H'); DebugService.Print(b); DebugService.Print(','); DebugService.Print(i); DebugService.Print(','); DebugService.Print(l); DebugService.Print(','); DebugService.Print(o); DebugService.Print('\n'); #if TEST_MEMORY_ABI uint tag = PageTableService.GetProcessTag(); DebugService.Print('p'); DebugService.Print((ulong)tag); DebugService.Print('\n'); uint pages = PageTableService.GetPageCount(); DebugService.Print('n'); DebugService.Print(pages); DebugService.Print('\n'); uint addr = PageTableService.Allocate(0x1000); DebugService.Print('a'); DebugService.Print((ulong)addr); DebugService.Print('\n'); Probe(addr); addr = 1; for (i = 0; i < 20 && addr != 0 && addr < 0xc0000000; i++) { addr = Probe(addr); } #endif // TEST_MEMORY_ABI #if TEST_STACK_ABI Test1(1); #endif // TEST_STACK_ABI return(999); }
//////////////////////////////////// Allocation and Free Routines. // // Allocation is optimized for the case where an allocation starts // with a relatively small amount of memory and grows over time. // This is exactly the behavior exhibited by stacks and GC heaps. // // The allocation strategy also works well for large initial // allocations. The strategy would be very inefficient if a very // large number of small, completely independent allocations are // made. // // AllocateMemory(size) performs an initial allocation. // AllocateMemory(startAddr, size) performs growing allocations. // internal static unsafe UIntPtr AllocateMemory(UIntPtr size) { VTable.Assert(PageTable.PageAligned(size)); #if SINGULARITY_KERNEL UIntPtr addr = Sing_MemoryManager.KernelAllocate( Sing_MemoryManager.PagesFromBytes(size), Process.kernelProcess, 0, PageType.Unknown); #elif SINGULARITY_PROCESS UIntPtr addr = PageTableService.Allocate(size); #endif #if SINGULARITY_KERNEL Kernel.Waypoint((int)size); Kernel.Waypoint(811); #endif // SINGULARITY_KERNEL if (addr != UIntPtr.Zero) { Util.MemClear(addr, size); } return(addr); }