mirror of
https://github.com/rehlds/metamod-r.git
synced 2025-03-03 17:15:26 +03:00
Force stack align for callbacks
This commit is contained in:
parent
bcb6bd1af5
commit
08b965e485
@ -51,6 +51,7 @@ void CForwardCallbackJIT::naked_main()
|
|||||||
push(ebp);
|
push(ebp);
|
||||||
mov(ebp, esp);
|
mov(ebp, esp);
|
||||||
push(ebx);
|
push(ebx);
|
||||||
|
and_(esp, 0xFFFFFFF0);
|
||||||
|
|
||||||
enum // stack map
|
enum // stack map
|
||||||
{
|
{
|
||||||
@ -58,22 +59,27 @@ void CForwardCallbackJIT::naked_main()
|
|||||||
over_ret = 4
|
over_ret = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto align = [](size_t v, size_t a)
|
||||||
|
{
|
||||||
|
return (v + a - 1) & ~a;
|
||||||
|
};
|
||||||
|
|
||||||
auto globals = ebx;
|
auto globals = ebx;
|
||||||
auto mg_backup = m_jitdata->has_ret ? 8 /* orig + over */ : 0;
|
auto mg_backup = m_jitdata->has_ret ? 8 /* orig + over */ : 0;
|
||||||
auto framesize = mg_backup + sizeof(meta_globals_t);
|
auto framesize = align(mg_backup + sizeof(meta_globals_t) + m_jitdata->args_count * sizeof(int), 16) - m_jitdata->args_count * sizeof(int);
|
||||||
|
|
||||||
if (m_jitdata->has_varargs) {
|
if (m_jitdata->has_varargs) {
|
||||||
size_t buf_offset = framesize;
|
size_t buf_offset = framesize;
|
||||||
|
|
||||||
sub(esp, framesize += MAX_STRBUF_LEN);
|
sub(esp, framesize += align(MAX_STRBUF_LEN, 16));
|
||||||
|
|
||||||
// format varargs
|
// format varargs
|
||||||
lea(edx, dword_ptr[ebp + 8 + m_jitdata->args_count * 4]); // varargs ptr
|
lea(edx, dword_ptr[ebp + 8 + m_jitdata->args_count * sizeof(int)]); // varargs ptr
|
||||||
lea(eax, dword_ptr[esp + buf_offset]); // buf ptr
|
lea(eax, dword_ptr[esp + buf_offset]); // buf ptr
|
||||||
mov(ecx, size_t(vsnprintf));
|
mov(ecx, size_t(vsnprintf));
|
||||||
|
|
||||||
push(edx);
|
push(edx);
|
||||||
push(dword_ptr[ebp + 8 + (m_jitdata->args_count - 1) * 4]); // last arg of pfn (format string)
|
push(dword_ptr[ebp + 8 + (m_jitdata->args_count - 1) * sizeof(int)]); // last arg of pfn (format string)
|
||||||
push(MAX_STRBUF_LEN);
|
push(MAX_STRBUF_LEN);
|
||||||
push(eax);
|
push(eax);
|
||||||
call(ecx);
|
call(ecx);
|
||||||
@ -254,12 +260,9 @@ void CForwardCallbackJIT::naked_main()
|
|||||||
cmovz(eax, dword_ptr[esp + over_ret]);
|
cmovz(eax, dword_ptr[esp + over_ret]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (framesize) {
|
|
||||||
add(esp, framesize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// epilogue
|
// epilogue
|
||||||
pop(ebx);
|
pop(ebx);
|
||||||
|
mov(esp, ebp);
|
||||||
pop(ebp);
|
pop(ebp);
|
||||||
ret();
|
ret();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user