Skip to content

Commit

Permalink
elf: allow non-zero load offset [#172]
Browse files Browse the repository at this point in the history
Incompatible API change again. :(
  • Loading branch information
stsp committed Oct 17, 2023
1 parent 425084b commit 21ecc17
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions fdpp/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,9 @@ void *elf_getloadaddr(void *arg)
struct elfstate *state = (struct elfstate *)arg;
return state->addr + state->load_offs;
}

int elf_getloadoff(void *arg)
{
struct elfstate *state = (struct elfstate *)arg;
return state->load_offs;
}
1 change: 1 addition & 0 deletions fdpp/elf_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ void elf_close(void *arg);
void *elf_getsym(void *arg, const char *name);
int elf_getsymoff(void *arg, const char *name);
void *elf_getloadaddr(void *arg);
int elf_getloadoff(void *arg);
7 changes: 6 additions & 1 deletion fdpp/thunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,15 @@ void *FdppKernelLoad(const char *dname, int *len, struct fdpp_bss_list **bss,
return NULL;
}

const void *FdppKernelReloc(void *handle, uint16_t seg)
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;
elf_reloc(h->elf, seg);

farhlp_init(&sym_tab);
Expand Down Expand Up @@ -743,6 +747,7 @@ const void *FdppKernelReloc(void *handle, uint16_t seg)
f.off = elf_getsymoff(h->elf, "init_near_wrp");
near_wrp[1] = f;

*r_seg = seg;
return h->start;
}

Expand Down
4 changes: 2 additions & 2 deletions include/fdpp/thunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <stdarg.h>
#include <stddef.h>

#define FDPP_API_VER 33
#define FDPP_API_VER 34

#ifndef FDPP
struct fdpp_far_s {
Expand Down Expand Up @@ -87,7 +87,7 @@ struct fdpp_bss_list {

void *FdppKernelLoad(const char *dname, int *len, struct fdpp_bss_list **bss,
uint32_t *_start);
const void *FdppKernelReloc(void *handle, uint16_t seg);
const void *FdppKernelReloc(void *handle, uint16_t seg, uint16_t *r_seg);
void FdppKernelFree(void *handle);

#ifdef __cplusplus
Expand Down

0 comments on commit 21ecc17

Please sign in to comment.