4 #include "tests/sys_mman.h"
8 #define STACK_SIZE (10 * 4096)
10 // This test is checking the libc context calls (setcontext, etc.) and
11 // checks that Valgrind notices their stack changes properly.
13 typedef ucontext_t mycontext
;
15 mycontext ctx1
, ctx2
, oldc
;
18 void hello(mycontext
*newc
)
20 printf("hello, world: %d\n", count
);
26 int init_context(mycontext
*uc
)
31 if (getcontext(uc
) == -1) {
32 //perror("getcontext");
33 printf("getcontext() doesn't seem to work\n");
37 stack
= (void *)mmap(0, STACK_SIZE
, PROT_READ
|PROT_WRITE
|PROT_EXEC
,
38 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
40 if (stack
== (void*)-1) {
45 ret
= VALGRIND_STACK_REGISTER(stack
, stack
+ STACK_SIZE
);
48 uc
->uc_stack
.ss_sp
= stack
;
49 uc
->uc_stack
.ss_size
= STACK_SIZE
;
50 uc
->uc_stack
.ss_flags
= 0;
55 int main(int argc
, char **argv
)
57 int c1
= init_context(&ctx1
);
58 int c2
= init_context(&ctx2
);
60 makecontext(&ctx1
, (void (*)()) hello
, 1, &ctx2
);
61 makecontext(&ctx2
, (void (*)()) hello
, 1, &ctx1
);
63 swapcontext(&oldc
, &ctx1
);
65 VALGRIND_STACK_DEREGISTER(c1
);
66 //free(ctx1.uc_stack.ss_sp);
67 VALGRIND_STACK_DEREGISTER(c2
);
68 //free(ctx2.uc_stack.ss_sp);