feat: use PIC code model for shared libraries, fix shared library bugs
This commit is contained in:
+14
-6
@@ -71,6 +71,13 @@ namespace Hal {
|
||||
return frame->CS;
|
||||
}
|
||||
|
||||
static System::PanicFrame* GetExceptionRegs(uint8_t vector, System::PanicFrame* frame) {
|
||||
if (ExceptionHasErrorCode(vector)) {
|
||||
return (System::PanicFrame*)((uint8_t*)frame + sizeof(uint64_t));
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
template<size_t i>
|
||||
__attribute__((interrupt)) void ExceptionHandler(System::PanicFrame* frame)
|
||||
{
|
||||
@@ -85,6 +92,7 @@ namespace Hal {
|
||||
// instead of panicking the entire system.
|
||||
if (fromUser && Sched::GetCurrentPid() >= 0) {
|
||||
auto* proc = Sched::GetCurrentProcessPtr();
|
||||
auto* regs = GetExceptionRegs(i, frame);
|
||||
Kt::KernelLogStream(Kt::ERROR, "Exception")
|
||||
<< ExceptionStrings[i] << " in process \""
|
||||
<< proc->name << "\" (pid " << proc->pid
|
||||
@@ -99,11 +107,11 @@ namespace Hal {
|
||||
rep.exceptionVector = i;
|
||||
for (int j = 0; j < 32 && ExceptionStrings[i][j]; j++) rep.exceptionName[j] = ExceptionStrings[i][j];
|
||||
rep.exceptionName[31] = '\0';
|
||||
rep.instructionPointer = frame->IP;
|
||||
rep.codeSegment = frame->CS;
|
||||
rep.flags = frame->Flags;
|
||||
rep.stackPointer = frame->SP;
|
||||
rep.stackSegment = frame->SS;
|
||||
rep.instructionPointer = regs->IP;
|
||||
rep.codeSegment = regs->CS;
|
||||
rep.flags = regs->Flags;
|
||||
rep.stackPointer = regs->SP;
|
||||
rep.stackSegment = regs->SS;
|
||||
|
||||
if (i == 0x0E) {
|
||||
// Page fault: read CR2 for faulting address
|
||||
@@ -215,4 +223,4 @@ namespace Hal {
|
||||
void IDTReload() {
|
||||
LoadIDT(IDTR);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -268,10 +268,11 @@ namespace Sched {
|
||||
uint64_t copyEnd = (pageEnd < targetSegFileEnd) ? pageEnd : targetSegFileEnd;
|
||||
|
||||
if (copyStart < copyEnd) {
|
||||
// Source: file data at (copyStart - targetSegStart) offset from p_offset
|
||||
// Source stays segment-relative, but the destination must be page-relative.
|
||||
// Using a segment-relative destination offset leaves page 2+ zero-filled and
|
||||
// writes past the newly allocated page in the kernel mapping.
|
||||
uint64_t srcOffset = phdr->p_offset + (copyStart - targetSegStart);
|
||||
// Dest: page at (copyStart - targetSegStart) offset, then adjusted for this page
|
||||
uint64_t pageDataOffset = copyStart - targetSegStart;
|
||||
uint64_t pageDataOffset = copyStart - pageStart;
|
||||
uint64_t copySize = copyEnd - copyStart;
|
||||
|
||||
uint8_t* dst = (uint8_t*)Memory::HHDM(physAddr) + pageDataOffset;
|
||||
|
||||
Reference in New Issue
Block a user