Skip to content

Commit

Permalink
Fix two jit bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
theAsmodai committed Aug 24, 2018
1 parent 0fff979 commit 0cf2f70
Showing 1 changed file with 15 additions and 36 deletions.
51 changes: 15 additions & 36 deletions metamod/src/callback_jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void CForwardCallbackJIT::naked_main()
}

// setup meta globals
mov(dword_ptr[globals + mg_mres], MRES_UNSET);
mov(dword_ptr[globals + mg_status], MRES_UNSET);
mov(dword_ptr[globals + mg_esp_save], esp);

Expand Down Expand Up @@ -140,21 +141,10 @@ void CForwardCallbackJIT::naked_main()
jecxz(go_next_plugin);
jnz(go_next_plugin);

if (plug == m_jitdata->plugins->front()) { // init meta globals
xor_(eax, eax);
mov(dword_ptr[globals + mg_mres], MRES_IGNORED);
mov(dword_ptr[globals + mg_prev_mres], eax); // MRES_UNSET
mov(dword_ptr[globals + mg_status], eax); // NULL

// FIXME: in some cases causes a crash
//mov(dword_ptr[globals + mg_mres], MRES_IGNORED);
//mov(dword_ptr[globals + mg_prev_mres], MRES_UNSET);
}
else {
mov(eax, dword_ptr[globals + mg_mres]);
mov(dword_ptr[globals + mg_mres], MRES_IGNORED);
mov(dword_ptr[globals + mg_prev_mres], eax);
}
// update meta globals
mov(eax, dword_ptr[globals + mg_mres]);
mov(dword_ptr[globals + mg_mres], MRES_IGNORED);
mov(dword_ptr[globals + mg_prev_mres], eax);

call_func(ecx);

Expand Down Expand Up @@ -241,21 +231,10 @@ void CForwardCallbackJIT::naked_main()
jecxz(go_next_plugin);
jnz(go_next_plugin);

if (plug == m_jitdata->plugins->front()) { // init meta globals
xor_(eax, eax);
mov(dword_ptr[globals + mg_mres], MRES_IGNORED);
mov(dword_ptr[globals + mg_prev_mres], eax); // MRES_UNSET
mov(dword_ptr[globals + mg_status], eax); // NULL

// FIXME: in some cases causes a crash
//mov(dword_ptr[globals + mg_mres], MRES_IGNORED);
//mov(dword_ptr[globals + mg_prev_mres], MRES_UNSET);
}
else {
mov(eax, dword_ptr[globals + mg_mres]);
mov(dword_ptr[globals + mg_mres], MRES_IGNORED);
mov(dword_ptr[globals + mg_prev_mres], eax);
}
// update meta globals
mov(eax, dword_ptr[globals + mg_mres]);
mov(dword_ptr[globals + mg_mres], MRES_IGNORED);
mov(dword_ptr[globals + mg_prev_mres], eax);

call_func(ecx);

Expand Down Expand Up @@ -289,12 +268,6 @@ void CForwardCallbackJIT::naked_main()
call_func(ecx);
}

// restore meta globals
movaps(xmm0, xmmword_ptr[esp + mg_backup + sizeof(int) * 2]);
movq(xmm1, qword_ptr[esp + mg_backup]);
movaps(xmmword_ptr[globals], xmm0);
movq(qword_ptr[globals + xmmreg_size], xmm1);

// setup return value and override it if needed
if (m_jitdata->rettype == rt_integer) {
mov(eax, dword_ptr[esp + orig_ret]);
Expand All @@ -308,6 +281,12 @@ void CForwardCallbackJIT::naked_main()
fld(dword_ptr[eax]);
}

// restore meta globals
movaps(xmm0, xmmword_ptr[esp + mg_backup + sizeof(int) * 2]);
movq(xmm1, qword_ptr[esp + mg_backup]);
movaps(xmmword_ptr[globals], xmm0);
movq(qword_ptr[globals + xmmreg_size], xmm1);

// epilogue
mov(esp, ebp);
pop(ebp);
Expand Down

0 comments on commit 0cf2f70

Please sign in to comment.