Skip to content

Commit

Permalink
thunks: support elf payload split [closes #9]
Browse files Browse the repository at this point in the history
  • Loading branch information
stsp committed Oct 2, 2024
1 parent 266d821 commit 0b29943
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/libc/dj64/plt.S
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ plt_init:
movl $1, %eax
int $0x31
/* call manager */
movl %fs:STUBINFO_FLAGS, %eax
movl maddr, %ebx
movl %fs:STUBINFO_SELF_SIZE, %ecx
movl %fs:STUBINFO_MEM_BASE, %edx
Expand Down
50 changes: 32 additions & 18 deletions src/libc/dj64/thunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ static int dj64_ctrl(int handle, int libid, int fn, unsigned esi, uint8_t *sp)
switch (fn) {
case DL_SET_SYMTAB: {
struct udisp *u = &udisps[handle];
uint32_t flags = regs->eax;
int have_core = (flags & 0x4000);
uint32_t addr = regs->ebx;
uint32_t size = regs->ecx;
uint32_t mem_base = regs->edx;
Expand All @@ -271,34 +273,46 @@ static int dj64_ctrl(int handle, int libid, int fn, unsigned esi, uint8_t *sp)
char *elf = (char *)djaddr2ptr(addr);
djlogprintf("data %p(%s)\n", elf, elf);
eh = u->eops->open(elf, size);
} else {
eh = u->eops->open_dyn();
if (!eh)
return -1;
if (have_core) {
ret = process_athunks(&u->core_at, mem_base, u->eops, eh);
if (ret)
goto err;
ret = process_pthunks(&u->core_pt, u->eops, eh);
if (ret)
goto err;
}
if (u->at) {
ret = process_athunks(u->at, mem_base, u->eops, eh);
if (ret)
goto err;
}
if (u->pt) {
ret = process_pthunks(u->pt, u->eops, eh);
if (ret)
goto err;
}
u->eops->close(eh);
}
if (!eh)
return -1;
ret = process_athunks(&u->core_at, mem_base, u->eops, eh);
if (ret)
goto err;
if (u->at) {
ret = process_athunks(u->at, mem_base, u->eops, eh);
if (!have_core) {
eh = u->eops->open_dyn();
if (!eh)
return -1;
ret = process_athunks(&u->core_at, mem_base, u->eops, eh);
if (ret)
goto err;
}
ret = process_pthunks(&u->core_pt, u->eops, eh);
if (ret)
goto err;
if (u->pt) {
ret = process_pthunks(u->pt, u->eops, eh);
ret = process_pthunks(&u->core_pt, u->eops, eh);
if (ret)
goto err;
u->eops->close(eh);
}
u->eops->close(eh);

do_early_init(handle);
return ret;
return 0;
err:
u->eops->close(eh);
return ret;
break;
}
}
return -1;
Expand Down

0 comments on commit 0b29943

Please sign in to comment.