vfs: check userland buffers before reading them.
[haiku.git] / src / tests / system / glue / StackAlign.cpp
blob361b5490f36018d34323bb828012083cdf68172d
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <signal.h>
4 #include <OS.h>
7 uint32 gStackPointer;
9 #define CHECK_STACK_ALIGN(from) \
10 asm volatile ("mov %%esp, %0" : "=r" (gStackPointer) :); \
11 if (gStackPointer & 0xF) \
12 printf("In %s, stack is NOT aligned: %lx\n", from, gStackPointer); \
13 else \
14 printf("In %s, stack is aligned!\n", from);
16 int function(void)
18 CHECK_STACK_ALIGN("function");
20 return 0;
23 status_t thread(void* arg)
25 CHECK_STACK_ALIGN("thread");
27 return B_OK;
30 void handler(int param)
32 CHECK_STACK_ALIGN("signal");
35 int main(void)
37 CHECK_STACK_ALIGN("main");
39 // Test from called function
40 function();
42 // Test from thread
44 status_t rv;
45 wait_for_thread(spawn_thread(thread, "test", B_NORMAL_PRIORITY, NULL), &rv);
48 // Test from signal handler
50 stack_t signalStack;
51 struct sigaction action;
53 signalStack.ss_sp = malloc(SIGSTKSZ);
54 signalStack.ss_flags = 0;
55 signalStack.ss_size = SIGSTKSZ;
56 sigaltstack(&signalStack, NULL);
58 action.sa_handler = handler;
59 action.sa_mask = 0;
60 action.sa_flags = SA_ONSTACK;
61 sigaction(SIGUSR1, &action, NULL);
63 kill(getpid(), SIGUSR1);
66 return 0;
69 struct Foo {
70 Foo()
72 CHECK_STACK_ALIGN("init");
75 ~Foo()
77 CHECK_STACK_ALIGN("fini");
81 Foo init;