Example #1
0
 public static ELFSharedObject LoadLibrary_FromELFSO(File ELFSharedObjectFile, ELFProcess theProcess)
 {
     //bool reenable = Scheduler.Enabled;
     //if (reenable)
     //{
     //    Scheduler.Disable();
     //}
     ELFSharedObject result = new ELFFile(ELFSharedObjectFile).LoadSharedObject(theProcess);
     //if (reenable)
     //{
     //    Scheduler.Enable();
     //}
     return result;
 }
Example #2
0
 public ELFProcess(ELFFile anELFFile)
 {
     theFile = anELFFile;
 }
Example #3
0
 public static ELFProcess LoadProcess_FromELFExe(File ELFExeFile, bool UserMode)
 {
     //bool reenable = Scheduler.Enabled;
     //if (reenable)
     //{
     //    Scheduler.Disable();
     //}
     ELFProcess result = new ELFFile(ELFExeFile).LoadExecutable(UserMode);
     //if (reenable)
     //{
     //    Scheduler.Enable();
     //}
     return result;
 }
Example #4
0
        public void LoadSegments(ELFFile fileToLoadFrom, ref bool OK, ref bool DynamicLinkingRequired, uint memBaseAddress)
        {
            uint fileBaseAddress = fileToLoadFrom.BaseAddress;
            List Segments = fileToLoadFrom.Segments;
            
            for (int i = 0; i < Segments.Count; i++)
            {
                ELFSegment segment = (ELFSegment)Segments[i];

                if (segment.Header.Type == ELFSegmentType.Interp ||
                    segment.Header.Type == ELFSegmentType.Dynamic)
                {
                    DynamicLinkingRequired = true;
                }
                else if (segment.Header.Type == ELFSegmentType.Load)
                {
                    int bytesRead = segment.Read(fileToLoadFrom.TheStream);
                    if (bytesRead != segment.Header.FileSize)
                    {
                        OK = false;
                        ExceptionMethods.Throw(new FOS_System.Exception("Error loading ELF segments! Failed to load correct segment bytes from file."));
                    }

                    byte* destMemPtr = (segment.Header.VAddr - fileBaseAddress) + memBaseAddress;
                    byte* pageAlignedDestMemPtr = (byte*)((uint)destMemPtr & 0xFFFFF000);

                    Console.Default.Write(" Loading segment from ");
                    Console.Default.Write_AsDecimal((uint)segment.Header.VAddr);
                    Console.Default.Write(" to ");
                    Console.Default.WriteLine_AsDecimal((uint)destMemPtr);

                    BasicConsole.Write(" Loading segment from ");
                    BasicConsole.Write((uint)segment.Header.VAddr);
                    BasicConsole.Write(" to ");
                    BasicConsole.WriteLine((uint)destMemPtr);
                    SystemCalls.SleepThread(1000);

                    uint copyOffset = (uint)(destMemPtr - pageAlignedDestMemPtr);
                    uint copyFromOffset = 0;

                    bool executable = (segment.Header.Flags & ELFFlags.Executable) != 0;

                    for (uint pageOffset = 0; pageOffset < segment.Header.MemSize; pageOffset += 4096)
                    {
                        uint physPageAddr = Hardware.VirtMemManager.FindFreePhysPage();
                        uint virtPageAddr = (uint)pageAlignedDestMemPtr + pageOffset;

                        Hardware.VirtMemManager.Map(
                            physPageAddr,
                            virtPageAddr,
                            4096,
                            theProcess.UserMode ? Hardware.VirtMem.VirtMemImpl.PageFlags.None : Hardware.VirtMem.VirtMemImpl.PageFlags.KernelOnly);
                        ProcessManager.CurrentProcess.TheMemoryLayout.AddDataPage(physPageAddr, virtPageAddr);

                        if (executable)
                        {
                            theProcess.TheMemoryLayout.AddCodePage(physPageAddr, virtPageAddr);
                        }
                        else
                        {
                            theProcess.TheMemoryLayout.AddDataPage(physPageAddr, virtPageAddr);
                        }

                        uint copySize = FOS_System.Math.Min((uint)bytesRead, 4096 - copyOffset);
                        if (copySize > 0)
                        {
                            Utilities.MemoryUtils.MemCpy_32(
                                (byte*)(virtPageAddr + copyOffset),
                                ((byte*)Utilities.ObjectUtilities.GetHandle(segment.Data)) + FOS_System.Array.FieldsBytesSize + pageOffset - copyFromOffset,
                                copySize);

                            bytesRead -= (int)copySize;
                        }

                        for (uint j = copySize + copyOffset; j < 4096; j++)
                        {
                            *(byte*)(virtPageAddr + j) = 0;
                        }

                        if (copyOffset > 0)
                        {
                            copyFromOffset += copyOffset;
                            copyOffset = 0;
                        }
                    }
                }
            }
        }
Example #5
0
 public ELFProcess(ELFFile anELFFile)
 {
     theFile = anELFFile;
 }
Example #6
0
        public void LoadSegments(ELFFile fileToLoadFrom, ref bool OK, ref bool DynamicLinkingRequired, uint memBaseAddress)
        {
            uint fileBaseAddress = fileToLoadFrom.BaseAddress;
            List Segments        = fileToLoadFrom.Segments;

            for (int i = 0; i < Segments.Count; i++)
            {
                ELFSegment segment = (ELFSegment)Segments[i];

                if (segment.Header.Type == ELFSegmentType.Interp ||
                    segment.Header.Type == ELFSegmentType.Dynamic)
                {
                    DynamicLinkingRequired = true;
                }
                else if (segment.Header.Type == ELFSegmentType.Load)
                {
                    int bytesRead = segment.Read(fileToLoadFrom.TheStream);
                    if (bytesRead != segment.Header.FileSize)
                    {
                        OK = false;
                        ExceptionMethods.Throw(new FOS_System.Exception("Error loading ELF segments! Failed to load correct segment bytes from file."));
                    }

                    byte *destMemPtr            = (segment.Header.VAddr - fileBaseAddress) + memBaseAddress;
                    byte *pageAlignedDestMemPtr = (byte *)((uint)destMemPtr & 0xFFFFF000);

                    Console.Default.Write(" Loading segment from ");
                    Console.Default.Write_AsDecimal((uint)segment.Header.VAddr);
                    Console.Default.Write(" to ");
                    Console.Default.WriteLine_AsDecimal((uint)destMemPtr);

                    BasicConsole.Write(" Loading segment from ");
                    BasicConsole.Write((uint)segment.Header.VAddr);
                    BasicConsole.Write(" to ");
                    BasicConsole.WriteLine((uint)destMemPtr);
                    Hardware.Processes.Thread.Sleep(1000);

                    uint copyOffset     = (uint)(destMemPtr - pageAlignedDestMemPtr);
                    uint copyFromOffset = 0;

                    bool executable = (segment.Header.Flags & ELFFlags.Executable) != 0;

                    for (uint pageOffset = 0; pageOffset < segment.Header.MemSize; pageOffset += 4096)
                    {
                        uint physPageAddr = Hardware.VirtMemManager.FindFreePhysPage();
                        uint virtPageAddr = (uint)pageAlignedDestMemPtr + pageOffset;

                        Hardware.VirtMemManager.Map(
                            physPageAddr,
                            virtPageAddr,
                            4096,
                            theProcess.UserMode ? Hardware.VirtMem.VirtMemImpl.PageFlags.None : Hardware.VirtMem.VirtMemImpl.PageFlags.KernelOnly);
                        ProcessManager.CurrentProcess.TheMemoryLayout.AddDataPage(physPageAddr, virtPageAddr);

                        if (executable)
                        {
                            theProcess.TheMemoryLayout.AddCodePage(physPageAddr, virtPageAddr);
                        }
                        else
                        {
                            theProcess.TheMemoryLayout.AddDataPage(physPageAddr, virtPageAddr);
                        }

                        uint copySize = FOS_System.Math.Min((uint)bytesRead, 4096 - copyOffset);
                        if (copySize > 0)
                        {
                            Utilities.MemoryUtils.MemCpy_32(
                                (byte *)(virtPageAddr + copyOffset),
                                ((byte *)Utilities.ObjectUtilities.GetHandle(segment.Data)) + FOS_System.Array.FieldsBytesSize + pageOffset - copyFromOffset,
                                copySize);

                            bytesRead -= (int)copySize;
                        }

                        for (uint j = copySize + copyOffset; j < 4096; j++)
                        {
                            *(byte *)(virtPageAddr + j) = 0;
                        }

                        if (copyOffset > 0)
                        {
                            copyFromOffset += copyOffset;
                            copyOffset      = 0;
                        }
                    }
                }
            }
        }
Example #7
0
 public ELFSharedObject(ELFFile anELFFile, ELFProcess aProcess)
 {
     theFile = anELFFile;
     theProcess = aProcess;
 }
Example #8
0
 public ELFSharedObject(ELFFile anELFFile, ELFProcess aProcess)
 {
     theFile    = anELFFile;
     theProcess = aProcess;
 }