public Region AllocRegion(ulong length, ulong align, string name, ulong stack_protect, Region.RegionType r_type, bool gc_data) { /* Allocate a new region from the 'free' region */ lock (this) { ulong start = util.align(free.start, align); if ((start + length + stack_protect) > (free.start + free.length)) { System.Diagnostics.Debugger.Log(0, "VirtualRegions", "Out of memory allocating space for " + name + ", start: " + start.ToString("X") + ", length: " + length.ToString() + ", stack_protect: " + stack_protect.ToString("X") + ", free.start: " + free.start.ToString("X") + ", free.length: " + free.length.ToString("X")); throw new OutOfMemoryException(); } ulong old_free_start = free.start; free.start = start + length + stack_protect; free.length -= (free.start - old_free_start); Region ret = new Region(); ret.type = r_type; ret.name = name; ret.start = start; ret.length = length + stack_protect; ret.stack_protect = stack_protect; Add(ret); if (gc_data) { if (gc.gengc.heap == null) { Formatter.WriteLine("VirtualRegions: attempt to allocate gc_data region without valid gc", Program.arch.DebugOutput); } else { unsafe { gc.gengc.heap.AddRoots((byte *)(start + stack_protect), (byte *)(start + length + stack_protect)); } } } Formatter.Write("VirtualRegions: Allocated new region: ", Program.arch.DebugOutput); Formatter.Write(name, Program.arch.DebugOutput); Formatter.Write(", start: ", Program.arch.DebugOutput); Formatter.Write(start, "X", Program.arch.DebugOutput); Formatter.Write(", length: ", Program.arch.DebugOutput); Formatter.Write(length, "X", Program.arch.DebugOutput); if (gc_data) { Formatter.Write(", gc_data", Program.arch.DebugOutput); } Formatter.WriteLine(Program.arch.DebugOutput); return(ret); } }
public Region AllocRegion(ulong length, ulong align, string name, ulong stack_protect, Region.RegionType r_type) { return(AllocRegion(length, align, name, stack_protect, r_type, false)); }