1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #include "win32_ucontext.h"
13 #include "win32_ucontext.c"
19 #if defined(TEST_sigstack) || defined(TEST_sigaltstack)
20 #include <sys/types.h>
24 #if defined(TEST_makecontext)
34 static volatile char *handler_addr = (char *)0xDEAD;
35 #if defined(TEST_sigstack) || defined(TEST_sigaltstack)
36 static volatile int handler_done = 0;
42 for (i = 0; i < 1024; i++)
44 handler_addr = (char *)&dummy;
49 #if defined(TEST_makecontext)
50 static ucontext_t uc_handler;
51 static ucontext_t uc_main;
57 for (i = 0; i < 1024; i++)
59 handler_addr = (char *)&dummy;
60 swapcontext(&uc_handler, &uc_main);
64 int main(int argc, char *argv[])
73 skbuf = (char *)malloc(sksize*2+2*sizeof(union alltypes));
76 for (i = 0; i < sksize*2+2*sizeof(union alltypes); i++)
78 skaddr = skbuf+sizeof(union alltypes);
79 #if defined(TEST_sigstack) || defined(TEST_sigaltstack)
82 #if defined(TEST_sigstack)
84 #elif defined(TEST_sigaltstack) && defined(HAVE_STACK_T)
87 struct sigaltstack ss;
89 #if defined(TEST_sigstack)
90 ss.ss_sp = (void *)(skaddr + sksize);
92 if (sigstack(&ss, NULL) < 0)
94 #elif defined(TEST_sigaltstack)
95 ss.ss_sp = (void *)(skaddr + sksize);
98 if (sigaltstack(&ss, NULL) < 0)
101 memset((void *)&sa, 0, sizeof(struct sigaction));
102 sa.sa_handler = handler;
103 sa.sa_flags = SA_ONSTACK;
104 sigemptyset(&sa.sa_mask);
105 sigaction(SIGUSR1, &sa, NULL);
106 kill(getpid(), SIGUSR1);
107 while (!handler_done)
111 #if defined(TEST_makecontext)
113 if (getcontext(&uc_handler) != 0)
115 uc_handler.uc_link = NULL;
116 uc_handler.uc_stack.ss_sp = (void *)(skaddr + sksize);
117 uc_handler.uc_stack.ss_size = sksize;
118 uc_handler.uc_stack.ss_flags = 0;
119 makecontext(&uc_handler, handler, 0);
120 swapcontext(&uc_main, &uc_handler);
123 if (handler_addr == (char *)0xDEAD)
125 if (handler_addr < skaddr+sksize) {
126 /* stack was placed into lower area */
127 if (*(skaddr+sksize) != 'A')
128 sprintf(result, "(skaddr)+(sksize)-%d,(sksize)-%d",
129 sizeof(union alltypes), sizeof(union alltypes));
131 strcpy(result, "(skaddr)+(sksize),(sksize)");
134 /* stack was placed into higher area */
135 if (*(skaddr+sksize*2) != 'A')
136 sprintf(result, "(skaddr),(sksize)-%d", sizeof(union alltypes));
138 strcpy(result, "(skaddr),(sksize)");
140 if ((f = fopen("conftestval", "w")) == NULL)
142 fprintf(f, "%s\n", result);