protected unsafe override void AddVmCalls(IDictionary<string, LinkerSymbol> virtualMachineCalls) { Trace.WriteLine(@"TestAssemblyLinker adding VM calls:"); IntPtr allocate = Marshal.GetFunctionPointerForDelegate(allocateArrayHandler); const string allocateArrayMethod = @"Mosa.Internal.Runtime.AllocateArray(Ptr methodTable,U4 elementSize,U4 elements)"; long virtualAddress = allocate.ToInt64(); Trace.WriteLine(String.Format("\t{0} at 0x{1:x08}", allocateArrayMethod, virtualAddress)); LinkerSymbol symbol = new LinkerSymbol(allocateArrayMethod, SectionKind.Text, virtualAddress); symbol.VirtualAddress = new IntPtr(symbol.SectionAddress); virtualMachineCalls.Remove(allocateArrayMethod); virtualMachineCalls.Add(allocateArrayMethod, symbol); IntPtr allocateObject = Marshal.GetFunctionPointerForDelegate(allocateObjectHandler); const string allocateObjectMethod = @"Mosa.Internal.Runtime.AllocateObject(Ptr methodTable,U4 classSize)"; virtualAddress = allocateObject.ToInt64(); Trace.WriteLine(String.Format("\t{0} at 0x{1:x08}", allocateObjectMethod, virtualAddress)); symbol = new LinkerSymbol(allocateObjectMethod, SectionKind.Text, virtualAddress); symbol.VirtualAddress = new IntPtr(symbol.SectionAddress); virtualMachineCalls.Remove(allocateObjectMethod); virtualMachineCalls.Add(allocateObjectMethod, symbol); }
/// <summary> /// Allocates a symbol of the given name in the specified section. /// </summary> /// <param name="name">The name of the symbol.</param> /// <param name="section">The executable section to allocate From.</param> /// <param name="size">The number of bytes to allocate. If zero, indicates an unknown amount of memory is required.</param> /// <param name="alignment">The alignment. A value of zero indicates the use of a default alignment for the section.</param> /// <returns> /// A stream, which can be used to populate the section. /// </returns> public virtual Stream Allocate(string name, SectionKind section, int size, int alignment) { try { Stream baseStream = Allocate(section, size, alignment); // Create a linker symbol for the name LinkerSymbol symbol = new LinkerSymbol(name, section, baseStream.Position); // Save the symbol for later use symbols.Add(symbol.Name, symbol); // Wrap the stream to catch premature disposal Stream result = new LinkerStream(symbol, baseStream, size); return result; } catch (ArgumentException argx) { throw new LinkerException(String.Format(@"Symbol {0} defined multiple times.", name), argx); } }