1 // Check that if LSan finds that SP doesn't point into thread stack (e.g.
2 // if swapcontext is used), LSan will not hit the guard page.
3 // RUN: %clang_lsan %s -o %t && %run %t
4 // Missing 'getcontext' and 'makecontext' on Android.
5 // UNSUPPORTED: android
14 pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
15 pthread_mutex_t mutex
= PTHREAD_MUTEX_INITIALIZER
;
16 int ctxfunc_started
= 0;
18 static void die(const char* msg
, int err
) {
21 fprintf(stderr
, "%s: %s\n", msg
, strerror(err
));
25 static void ctxfunc() {
26 pthread_mutex_lock(&mutex
);
28 // printf("ctxfunc\n");
29 pthread_cond_signal(&cond
);
30 pthread_mutex_unlock(&mutex
);
31 // Leave this context alive when the program exits.
35 static void* thread(void* arg
) {
40 if (getcontext(&ctx
) < 0)
42 stack
= malloc(1 << 12);
45 ctx
.uc_stack
.ss_sp
= stack
;
46 ctx
.uc_stack
.ss_size
= 1 << 12;
47 makecontext(&ctx
, ctxfunc
, 0);
57 pthread_mutex_lock(&mutex
);
58 i
= pthread_create(&tid
, NULL
, thread
, NULL
);
60 die("pthread_create", i
);
61 while (!ctxfunc_started
) pthread_cond_wait(&cond
, &mutex
);
62 pthread_mutex_unlock(&mutex
);