Created
October 11, 2016 01:09
-
-
Save toptensoftware/9d70546d900ba52a9267d06750ba7ebb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public override void Load(Machine machine) | |
| { | |
| // Load all segments | |
| for (int i=0; i<_neFile.Segments.Length; i++) | |
| { | |
| // Get the segment | |
| var seg = _neFile.Segments[i]; | |
| // Work out how much memory needed. For the automatic data segments | |
| // add the size of the heap and for programs add on the stack size | |
| uint allocSize = seg.allocationBytes; | |
| if ((ushort)(i+1) == neHeader.AutoDataSegIndex) | |
| { | |
| allocSize += neHeader.InitHeapSize; | |
| if (!IsDll) | |
| allocSize += neHeader.InitStackSize; | |
| } | |
| // Allocate memory from the global heap | |
| seg.globalHandle = machine.GlobalHeap.Alloc(0, allocSize); | |
| if (seg.globalHandle == 0) | |
| throw new VirtualException("Out of Memory"); | |
| // Configure the selector for "can execute" and "can write" | |
| seg.globalHandle = machine.GlobalHeap.SetSelectorAttributes(seg.globalHandle, | |
| !seg.flags.HasFlag(SegmentFlags.Data), // can execute? | |
| seg.flags.HasFlag(SegmentFlags.ReadOnly) // read only? | |
| ); | |
| // Get the buffer, read the segment from the NE file | |
| var bytes = machine.GlobalHeap.GetBuffer(seg.globalHandle); | |
| _neFile.ReadSegment(seg, bytes); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment