hrev51665 adds 1 changeset to branch 'master'
old head: 6a028821b69c665eedd4bdee93ac321221c2b9ad
new head: d87218f79e132dc809e44f01be114bf279082949
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=d87218f79e13+%5E6a028821b69c
----------------------------------------------------------------------------
d87218f79e13: Add test for stack alignment.
[ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev51665
Commit: d87218f79e132dc809e44f01be114bf279082949
URL: http://cgit.haiku-os.org/haiku/commit/?id=d87218f79e13
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Sun Dec 10 08:28:49 2017 UTC
----------------------------------------------------------------------------
3 files changed, 87 insertions(+)
src/tests/system/Jamfile | 1 +
src/tests/system/glue/Jamfile | 5 ++
src/tests/system/glue/StackAlign.cpp | 81 ++++++++++++++++++++++++++++++++
----------------------------------------------------------------------------
diff --git a/src/tests/system/Jamfile b/src/tests/system/Jamfile
index f5e6afa..3277dca 100644
--- a/src/tests/system/Jamfile
+++ b/src/tests/system/Jamfile
@@ -2,5 +2,6 @@ SubDir HAIKU_TOP src tests system ;
SubInclude HAIKU_TOP src tests system benchmarks ;
SubInclude HAIKU_TOP src tests system boot ;
+SubInclude HAIKU_TOP src tests system glue ;
SubInclude HAIKU_TOP src tests system kernel ;
SubInclude HAIKU_TOP src tests system libroot ;
diff --git a/src/tests/system/glue/Jamfile b/src/tests/system/glue/Jamfile
new file mode 100644
index 0000000..65e3b3c
--- /dev/null
+++ b/src/tests/system/glue/Jamfile
@@ -0,0 +1,5 @@
+SubDir HAIKU_TOP src tests system glue ;
+
+SimpleTest StackAlign :
+ StackAlign.cpp
+;
diff --git a/src/tests/system/glue/StackAlign.cpp
b/src/tests/system/glue/StackAlign.cpp
new file mode 100644
index 0000000..361b549
--- /dev/null
+++ b/src/tests/system/glue/StackAlign.cpp
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <OS.h>
+
+
+uint32 gStackPointer;
+
+#define CHECK_STACK_ALIGN(from) \
+ asm volatile ("mov %%esp, %0" : "=r" (gStackPointer) :); \
+ if (gStackPointer & 0xF) \
+ printf("In %s, stack is NOT aligned: %lx\n", from,
gStackPointer); \
+ else \
+ printf("In %s, stack is aligned!\n", from);
+
+int function(void)
+{
+ CHECK_STACK_ALIGN("function");
+
+ return 0;
+}
+
+status_t thread(void* arg)
+{
+ CHECK_STACK_ALIGN("thread");
+
+ return B_OK;
+}
+
+void handler(int param)
+{
+ CHECK_STACK_ALIGN("signal");
+}
+
+int main(void)
+{
+ CHECK_STACK_ALIGN("main");
+
+ // Test from called function
+ function();
+
+ // Test from thread
+ {
+ status_t rv;
+ wait_for_thread(spawn_thread(thread, "test", B_NORMAL_PRIORITY,
NULL), &rv);
+ }
+
+ // Test from signal handler
+ {
+ stack_t signalStack;
+ struct sigaction action;
+
+ signalStack.ss_sp = malloc(SIGSTKSZ);
+ signalStack.ss_flags = 0;
+ signalStack.ss_size = SIGSTKSZ;
+ sigaltstack(&signalStack, NULL);
+
+ action.sa_handler = handler;
+ action.sa_mask = 0;
+ action.sa_flags = SA_ONSTACK;
+ sigaction(SIGUSR1, &action, NULL);
+
+ kill(getpid(), SIGUSR1);
+ }
+
+ return 0;
+}
+
+struct Foo {
+ Foo()
+ {
+ CHECK_STACK_ALIGN("init");
+ }
+
+ ~Foo()
+ {
+ CHECK_STACK_ALIGN("fini");
+ }
+};
+
+Foo init;