Skip to content

Commit

Permalink
thunks: avoid loading ELF header to DOS [#172][skip CI]
Browse files Browse the repository at this point in the history
As we now support arbitrary load offsets, load to DOS starting
from .ptext section, rather than from what PT_LOAD says to load.
  • Loading branch information
stsp committed Oct 17, 2023
1 parent 6e81825 commit 89f398f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fdpp/thunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ const char *FdppKernelMapName(void)
struct krnl_hndl {
void *elf;
const void *start;
unsigned load_off;
};

void *FdppKernelLoad(const char *dname, int *len, struct fdpp_bss_list **bss,
Expand All @@ -663,7 +664,7 @@ void *FdppKernelLoad(const char *dname, int *len, struct fdpp_bss_list **bss,
return NULL;
}
free(kname);
start = elf_getloadaddr(handle);
start = elf_getsym(handle, "_start");
s = elf_getsymoff(handle, "_start");
if (s == -1)
goto err_close;
Expand Down Expand Up @@ -704,6 +705,7 @@ void *FdppKernelLoad(const char *dname, int *len, struct fdpp_bss_list **bss,
h = (struct krnl_hndl *)malloc(sizeof(*h));
h->elf = handle;
h->start = start;
h->load_off = s;
return h;

err_close:
Expand All @@ -716,10 +718,9 @@ const void *FdppKernelReloc(void *handle, uint16_t seg, uint16_t *r_seg)
int i;
far_s f;
struct krnl_hndl *h = (struct krnl_hndl *)handle;
unsigned load_off = elf_getloadoff(h->elf);

assert(!(load_off & 0xf));
seg -= load_off >> 4;
assert(!(h->load_off & 0xf));
seg -= h->load_off >> 4;
elf_reloc(h->elf, seg);

farhlp_init(&sym_tab);
Expand Down

0 comments on commit 89f398f

Please sign in to comment.