OSDev.org
https://forum.osdev.org/

Invalid memory access, from faulty ELF loader
https://forum.osdev.org/viewtopic.php?f=1&t=43514
Page 1 of 1

Author:  austanss [ Sun May 09, 2021 2:47 pm ]
Post subject:  Invalid memory access, from faulty ELF loader

Note: I have been locked out of my account for months: I tried to reset my password and I forgot to click the link to activate the new password! Oh my am I a special case.

I have been attempting to write an ELF loader. I have written a simple little shell, dubbed "mnsh", and at first it was integrated into the kernel binary. Then, I shoved it into userspace and isolated it from the rest of the kernel. Now, I am attempting to load a separate executable via stivale modules and ELF loading. (The next step up is writing a proper FAT32 driver and a VFS, I'm a little stumped on that at the moment however and an ELF loader seemed to be the best option to work on at the moment.)

[ELF Loader Source Code: https://github.com/rizet/micron/tree/wa ... scheduling]
[MNSH Source Code: https://github.com/rizet/micron/tree/wa ... alpha/mnsh]

However, I printed the entry point address I am returning, and it seems to point to the correct code. However, when I actually do return the address, and call into it in the userspace entry, I page fault.
In particular, a faulty read that violated page protections during an instruction fetch for userspace code.

All the ELF headers/values seem to be correct, I've printed them out and objdump'd them a few times, just to cross-check. I originally believed that the loading executable was relocatable, but it is not: my memory has failed me.

So I am unsure if I lost the value in the long road from loading to executing, if the program segments are incorrectly loaded, or if I mapped the pages incorrectly.

Thank you in advance for your support.

Author:  austanss [ Sun May 09, 2021 3:07 pm ]
Post subject:  Re: Invalid memory access, from faulty ELF loader

Well all bugs come from simple mistakes.

I did indeed lose the value, from an incorrect asm statement.

mov rax, rdi
instead of
mov rdi, rax

I feel incredibly accomplished.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/