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); \
14 printf("In %s, stack is aligned!\n", from);
18 CHECK_STACK_ALIGN("function");
23 status_t
thread(void* arg
)
25 CHECK_STACK_ALIGN("thread");
30 void handler(int param
)
32 CHECK_STACK_ALIGN("signal");
37 CHECK_STACK_ALIGN("main");
39 // Test from called function
45 wait_for_thread(spawn_thread(thread
, "test", B_NORMAL_PRIORITY
, NULL
), &rv
);
48 // Test from signal handler
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
;
60 action
.sa_flags
= SA_ONSTACK
;
61 sigaction(SIGUSR1
, &action
, NULL
);
63 kill(getpid(), SIGUSR1
);
72 CHECK_STACK_ALIGN("init");
77 CHECK_STACK_ALIGN("fini");