Skip to content

Commit

Permalink
loader: elf_xx --> fdelf_xx
Browse files Browse the repository at this point in the history
Avoids clash with some libelf.
  • Loading branch information
stsp committed Jun 13, 2024
1 parent 3b3be67 commit a321f48
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions fdpp/loader/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void elf_dl(struct elfstate *state, uint16_t seg)
}
}

void *elf_open(const char *name)
void *fdelf_open(const char *name)
{
Elf *elf;
Elf_Scn *scn = NULL;
Expand Down Expand Up @@ -207,14 +207,14 @@ void *elf_open(const char *name)
return NULL;
}

void elf_reloc(void *arg, uint16_t seg)
void fdelf_reloc(void *arg, uint16_t seg)
{
struct elfstate *state = (struct elfstate *)arg;

elf_dl(state, seg);
}

void elf_close(void *arg)
void fdelf_close(void *arg)
{
struct elfstate *state = (struct elfstate *)arg;

Expand All @@ -230,7 +230,7 @@ static int do_getsymoff(struct elfstate *state, const char *name)
return (err ? -1 : sym.st_value);
}

void *elf_getsym(void *arg, const char *name)
void *fdelf_getsym(void *arg, const char *name)
{
struct elfstate *state = (struct elfstate *)arg;
int off = do_getsymoff(state, name);
Expand All @@ -239,19 +239,19 @@ void *elf_getsym(void *arg, const char *name)
return state->addr + state->load_offs + off;
}

int elf_getsymoff(void *arg, const char *name)
int fdelf_getsymoff(void *arg, const char *name)
{
struct elfstate *state = (struct elfstate *)arg;
return do_getsymoff(state, name);
}

void *elf_getloadaddr(void *arg)
void *fdelf_getloadaddr(void *arg)
{
struct elfstate *state = (struct elfstate *)arg;
return state->addr + state->load_offs;
}

int elf_getloadoff(void *arg)
int fdelf_getloadoff(void *arg)
{
struct elfstate *state = (struct elfstate *)arg;
return state->load_offs;
Expand Down
14 changes: 7 additions & 7 deletions fdpp/loader/elf_priv.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <stdint.h>

void *elf_open(const char *name);
void elf_reloc(void *arg, uint16_t seg);
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);
void *fdelf_open(const char *name);
void fdelf_reloc(void *arg, uint16_t seg);
void fdelf_close(void *arg);
void *fdelf_getsym(void *arg, const char *name);
int fdelf_getsymoff(void *arg, const char *name);
void *fdelf_getloadaddr(void *arg);
int fdelf_getloadoff(void *arg);
24 changes: 12 additions & 12 deletions fdpp/loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,31 @@ void *FdppKernelLoad(const char *dname, int *len, struct fdpp_bss_list **bss,

rc = asprintf(&kname, "%s/%s", dname, _S(KRNL_ELFNAME));
assert(rc != -1);
handle = elf_open(kname);
handle = fdelf_open(kname);
if (!handle) {
fprintf(stderr, "failed to open %s\n", kname);
free(kname);
return NULL;
}
free(kname);
start = elf_getsym(handle, "_start");
s = elf_getsymoff(handle, "_start");
start = fdelf_getsym(handle, "_start");
s = fdelf_getsymoff(handle, "_start");
if (s == -1)
goto err_close;
*_start = s;
end = elf_getsym(handle, "__InitTextEnd");
end = fdelf_getsym(handle, "__InitTextEnd");
if (!end)
goto err_close;
bstart = elf_getsym(handle, "__bss_start");
bstart = fdelf_getsym(handle, "__bss_start");
if (!bstart)
goto err_close;
bend = elf_getsym(handle, "__bss_end");
bend = fdelf_getsym(handle, "__bss_end");
if (!bend)
goto err_close;
ibstart = elf_getsym(handle, "__ibss_start");
ibstart = fdelf_getsym(handle, "__ibss_start");
if (!ibstart)
goto err_close;
ibend = elf_getsym(handle, "__ibss_end");
ibend = fdelf_getsym(handle, "__ibss_end");
if (!ibend)
goto err_close;
*len = (uintptr_t)end - (uintptr_t)start;
Expand Down Expand Up @@ -107,7 +107,7 @@ void *FdppKernelLoad(const char *dname, int *len, struct fdpp_bss_list **bss,
return h;

err_close:
elf_close(handle);
fdelf_close(handle);
return NULL;
}

Expand All @@ -118,9 +118,9 @@ const void *FdppKernelReloc(void *handle, uint16_t seg, uint16_t *r_seg,

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

hook(seg, elf_getsymoff, h->elf);
hook(seg, fdelf_getsymoff, h->elf);

*r_seg = seg;
return h->start;
Expand All @@ -130,6 +130,6 @@ void FdppKernelFree(void *handle)
{
struct krnl_hndl *h = (struct krnl_hndl *)handle;

elf_close(h->elf);
fdelf_close(h->elf);
free(h);
}

0 comments on commit a321f48

Please sign in to comment.