mirror of
https://github.com/Cxbx-Reloaded/subhook.git
synced 2024-12-04 09:23:47 +00:00
Fix C++ test crash because of misaligned stack
This commit is contained in:
parent
f348fb52a8
commit
3a61f8f270
@ -24,8 +24,7 @@ else()
|
||||
endif()
|
||||
|
||||
set(options "-f" "${asm_format}")
|
||||
if(APPLE
|
||||
OR (WIN32 AND (CMAKE_SIZEOF_VOID_P EQUAL 4 OR SUBHOOK_FORCE_32BIT)))
|
||||
if(APPLE OR (WIN32 AND (CMAKE_SIZEOF_VOID_P EQUAL 4 OR SUBHOOK_FORCE_32BIT)))
|
||||
list(APPEND options "--prefix=_")
|
||||
endif()
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
|
5
tests/foo.cpp
Normal file
5
tests/foo.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" void foo() {
|
||||
puts("foo() called");
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
yasm -f elf64 foo_64_unix.asm
|
||||
gcc -c foo_main.c -o foo_main.o
|
||||
gcc foo_64_unix.o foo_main.o -o foo
|
||||
|
||||
./foo
|
@ -1,7 +1,7 @@
|
||||
extern puts
|
||||
global foo
|
||||
|
||||
section .data
|
||||
section .rodata
|
||||
|
||||
message:
|
||||
db 'foo() called', 0
|
||||
@ -21,11 +21,11 @@ section .text
|
||||
%define nop9 db 0x66, 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 ; 66 NOP DWORD ptr [EAX + EAX*1 + 00000000H]
|
||||
|
||||
foo:
|
||||
nop
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
sub esp, 4 ; align the stack to a 16-byte boundary
|
||||
push message
|
||||
call puts
|
||||
add esp, 4
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
xor eax, eax
|
||||
ret
|
||||
|
6
tests/foo_main.cpp
Normal file
6
tests/foo_main.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
extern "C" void foo(void);
|
||||
|
||||
int main() {
|
||||
foo();
|
||||
return 0;
|
||||
}
|
@ -11,7 +11,8 @@ typedef void (*foo_func_t)(void);
|
||||
#elif defined SUBHOOK_UNIX
|
||||
#define FOO_CALL __attribute__((cdecl))
|
||||
#endif
|
||||
#else
|
||||
#endif
|
||||
#ifndef FOO_CALL
|
||||
#define FOO_CALL
|
||||
#endif
|
||||
|
||||
|
@ -9,7 +9,8 @@ typedef void (*foo_func_t)();
|
||||
#elif defined SUBHOOK_UNIX
|
||||
#define FOO_CALL __attribute__((cdecl))
|
||||
#endif
|
||||
#else
|
||||
#endif
|
||||
#ifndef FOO_CALL
|
||||
#define FOO_CALL
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user