50 lines
1.3 KiB
C
50 lines
1.3 KiB
C
#include "vxBoot/loader.h"
|
|
#include "vxBoot/fs/smemfs.h"
|
|
#include "vxBoot/terminal.h"
|
|
|
|
#include <string.h>
|
|
|
|
/* loader_got_patch() : Try to patch the GOT section */
|
|
int loader_got_patch(
|
|
struct smemfs_inode const * restrict const inode,
|
|
struct kernel_info * const kernel,
|
|
Elf32_Ehdr *hdr
|
|
) {
|
|
Elf32_Shdr shdr;
|
|
uintptr_t *got;
|
|
char name[5];
|
|
off_t stroff;
|
|
off_t shoff;
|
|
|
|
/* find the section header table */
|
|
shoff = hdr->e_shoff;
|
|
|
|
/* find the section string table ".strtable" */
|
|
smemfs_pread(
|
|
inode,
|
|
&shdr, sizeof(Elf32_Shdr),
|
|
shoff + (sizeof(Elf32_Shdr) * hdr->e_shstrndx)
|
|
);
|
|
stroff = shdr.sh_offset;
|
|
|
|
/* walk throught each section and find the .got section */
|
|
for (int i = 0; i < hdr->e_shnum; ++i) {
|
|
smemfs_pread(inode, &shdr, sizeof(Elf32_Shdr), shoff);
|
|
smemfs_pread(inode, name, 5, shdr.sh_name + stroff);
|
|
if (strcmp(name, ".got") != 0) {
|
|
shoff += sizeof(Elf32_Shdr);
|
|
continue;
|
|
}
|
|
got = kernel->memory.program.start;
|
|
got = (void*)((uintptr_t)got + (uintptr_t)shdr.sh_addr);
|
|
terminal_write(" GOT section found at %p...\n", got);
|
|
for (uint32_t j = 0 ; j < shdr.sh_size >> 2 ; ++j) {
|
|
terminal_write(" path symbols %p...\n", got[j]);
|
|
got[j] += (uintptr_t)kernel->hardware.ram.physical.kernel_addr;
|
|
got[j] |= (uintptr_t)0x80000000;
|
|
}
|
|
return (0);
|
|
}
|
|
return (-1);
|
|
}
|