1 /* Check that ASan plays well with easy cases of makecontext/swapcontext. */
3 /* { dg-do run { target swapcontext } } */
9 ucontext_t orig_context
;
10 ucontext_t child_context
;
12 void Child(int mode
) {
13 char x
[32] = {0}; /* Stack gets poisoned. */
14 printf("Child: %p\n", x
);
15 /* (a) Do nothing, just return to parent function.
16 (b) Jump into the original function. Stack remains poisoned unless we do
19 if (swapcontext(&child_context
, &orig_context
) < 0) {
20 perror("swapcontext");
26 int Run(int arg
, int mode
) {
28 const int kStackSize
= 1 << 20;
29 char child_stack
[kStackSize
+ 1];
30 printf("Child stack: %p\n", child_stack
);
31 /* Setup child context. */
32 getcontext(&child_context
);
33 child_context
.uc_stack
.ss_sp
= child_stack
;
34 child_context
.uc_stack
.ss_size
= kStackSize
/ 2;
36 child_context
.uc_link
= &orig_context
;
38 makecontext(&child_context
, (void (*)())Child
, 1, mode
);
39 if (swapcontext(&orig_context
, &child_context
) < 0) {
40 perror("swapcontext");
43 /* Touch childs's stack to make sure it's unpoisoned. */
44 for (i
= 0; i
< kStackSize
; i
++) {
47 return child_stack
[arg
];
50 volatile int zero
= 0;
52 int main(int argc
, char **argv
) {
55 printf("Test1 passed\n");
57 printf("Test2 passed\n");
61 /* { dg-output "WARNING: ASan doesn't fully support makecontext/swapcontext.*" } */
62 /* { dg-output "Test1 passed.*" } */
63 /* { dg-output "Test2 passed.*" } */