aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorZeex <zeex@rocketmail.com>2018-09-07 18:53:56 +0600
committerZeex <zeex@rocketmail.com>2018-09-07 22:05:54 +0600
commit3a61f8f2700862fba0eceeb51381f006816bad5e (patch)
treef992083bf01b1511445b1c9a17544a9b41d40ce7 /tests
parentf348fb52a83438a20223c25b2f149039f9a2d32b (diff)
downloadsubhook-3a61f8f2700862fba0eceeb51381f006816bad5e.zip
subhook-3a61f8f2700862fba0eceeb51381f006816bad5e.tar.gz
subhook-3a61f8f2700862fba0eceeb51381f006816bad5e.tar.bz2
Fix C++ test crash because of misaligned stack
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/foo.cpp5
-rw-r--r--tests/foo.sh7
-rw-r--r--tests/foo_32.asm8
-rw-r--r--tests/foo_main.cpp6
-rw-r--r--tests/test.c3
-rw-r--r--tests/test.cpp3
7 files changed, 20 insertions, 15 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 92c8461..2a2ab84 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -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")
diff --git a/tests/foo.cpp b/tests/foo.cpp
new file mode 100644
index 0000000..c3e7def
--- /dev/null
+++ b/tests/foo.cpp
@@ -0,0 +1,5 @@
+#include <stdio.h>
+
+extern "C" void foo() {
+ puts("foo() called");
+}
diff --git a/tests/foo.sh b/tests/foo.sh
deleted file mode 100644
index 0f0e940..0000000
--- a/tests/foo.sh
+++ /dev/null
@@ -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
diff --git a/tests/foo_32.asm b/tests/foo_32.asm
index 16a2533..f1de5b3 100644
--- a/tests/foo_32.asm
+++ b/tests/foo_32.asm
@@ -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
diff --git a/tests/foo_main.cpp b/tests/foo_main.cpp
new file mode 100644
index 0000000..b49a3cc
--- /dev/null
+++ b/tests/foo_main.cpp
@@ -0,0 +1,6 @@
+extern "C" void foo(void);
+
+int main() {
+ foo();
+ return 0;
+}
diff --git a/tests/test.c b/tests/test.c
index 513c060..bbf75b5 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -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
diff --git a/tests/test.cpp b/tests/test.cpp
index 0eee1fa..5536a36 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -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