Skip to content
Permalink
Browse files

Fix two jit bugs

  • Loading branch information...
theAsmodai committed Aug 24, 2018
1 parent 0fff979 commit 0cf2f709dbeae18ca84d2fafd4481ffbba06ad0c
Showing with 15 additions and 36 deletions.
  1. +15 −36 metamod/src/callback_jit.cpp
@@ -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);

@@ -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);

@@ -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);

@@ -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]);
@@ -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);

0 comments on commit 0cf2f70

Please sign in to comment.
You can’t perform that action at this time.