Skip to content

Commit

Permalink
thunks: restore context after noret jmp
Browse files Browse the repository at this point in the history
This fixes crash with trumpet's ftp2.
  • Loading branch information
stsp committed Aug 11, 2024
1 parent 4674801 commit b94ab9e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/libc/dj64/thunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ uint32_t djptr2addr(const uint8_t *ptr)
}

static int _dj64_call(struct udisp *u, int libid, int fn, dpmi_regs *regs,
uint8_t *sp, unsigned esi, dj64dispatch_t *disp)
uint8_t *sp, unsigned esi, dj64dispatch_t *disp, int handle)
{
int len;
UDWORD res;
Expand All @@ -144,6 +144,9 @@ static int _dj64_call(struct udisp *u, int libid, int fn, dpmi_regs *regs,
u->s_regs = *regs;
if ((rc = setjmp(noret))) {
int i;

for (i = 0; i < num_chooks; i++)
chooks[i].restore(handle);
/* gc lost objects, esp in ABORT case */
for (i = 0; i < MAX_OBJS; i++) {
if (u->objs[u->recur_cnt - 1][i])
Expand Down Expand Up @@ -187,7 +190,7 @@ static int dj64_call(int handle, int libid, int fn, unsigned esi, uint8_t *sp)
chooks[i].restore(handle);
saved_noret = u->noret_jmp;
last_objcnt = u->objcnt;
ret = _dj64_call(u, libid, fn, regs, sp, esi, u->disp);
ret = _dj64_call(u, libid, fn, regs, sp, esi, u->disp, handle);
assert(u->objcnt == last_objcnt); // make sure no leaks, esp on NORETURN
u->noret_jmp = saved_noret;
if (ret == DJ64_RET_OK) {
Expand Down

0 comments on commit b94ab9e

Please sign in to comment.