1
0
mirror of https://github.com/sgmarz/osblog.git synced 2024-11-23 18:06:20 +04:00

Fixed ELF loader and added offset.

This commit is contained in:
Stephen Marz 2020-04-26 09:19:07 -04:00
parent 8f61253aea
commit bc6ef9d689
2 changed files with 8 additions and 3 deletions

View File

@ -25,7 +25,7 @@ pub fn test_elf() {
// interrupt context right now, so we cannot pause. Usually, this would
// be done by an exec system call.
let files_inode = 25u32;
let files_size = 14304;
let files_size = 14440;
let bytes_to_read = 1024 * 50;
let mut buffer = BlockBuffer::new(bytes_to_read);
// Read the file from the disk. I got the inode by mounting
@ -137,10 +137,14 @@ pub fn test_elf() {
// is provided in the ELF program header.
let pages = (ph.memsz + PAGE_SIZE) / PAGE_SIZE;
for i in 0..pages {
// Align the offset to the nearest page for mapping.
// We might not need to do this, but not doing this could leak
// a different section into the virtual address space of another.
let off = (ph.off + PAGE_SIZE - 1) & !(PAGE_SIZE - 1);
let vaddr = ph.vaddr + i * PAGE_SIZE;
// The ELF specifies a paddr, but not when we
// use the vaddr!
let paddr = program_mem as usize + i * PAGE_SIZE;
let paddr = program_mem as usize + off + i * PAGE_SIZE;
map(table, vaddr, paddr, bits, 0);
}
}

View File

@ -1,9 +1,10 @@
#include <printf.h>
#include <syscall.h>
int myarray[1000];
int main()
{
int myarray[1000];
printf("I'm a C++ program, and I'm running in user space. How about a big, Hello World\n");
printf("My array is at 0x%p\n", myarray);
printf("I'm going to start crunching some numbers, so gimme a minute.\n");