xref: /aosp_15_r20/external/compiler-rt/test/tsan/setuid.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot // setuid(0) hangs on powerpc64 big endian.  When this is fixed remove
4*7c3d14c8STreehugger Robot // the unsupported flag.
5*7c3d14c8STreehugger Robot // https://llvm.org/bugs/show_bug.cgi?id=25799
6*7c3d14c8STreehugger Robot //
7*7c3d14c8STreehugger Robot // UNSUPPORTED: powerpc64-unknown-linux-gnu
8*7c3d14c8STreehugger Robot #include "test.h"
9*7c3d14c8STreehugger Robot #include <sys/types.h>
10*7c3d14c8STreehugger Robot #include <unistd.h>
11*7c3d14c8STreehugger Robot 
12*7c3d14c8STreehugger Robot // Setuid call used to hang because the background tsan thread did not handle
13*7c3d14c8STreehugger Robot // SIGSETXID signal. Note that we don't care whether setuid call succeeds
14*7c3d14c8STreehugger Robot // or not.
15*7c3d14c8STreehugger Robot 
thread(void * arg)16*7c3d14c8STreehugger Robot static void *thread(void *arg) {
17*7c3d14c8STreehugger Robot   (void)arg;
18*7c3d14c8STreehugger Robot   sleep(1);
19*7c3d14c8STreehugger Robot   return 0;
20*7c3d14c8STreehugger Robot }
21*7c3d14c8STreehugger Robot 
main()22*7c3d14c8STreehugger Robot int main() {
23*7c3d14c8STreehugger Robot   // Create another thread just for completeness of the picture.
24*7c3d14c8STreehugger Robot   pthread_t th;
25*7c3d14c8STreehugger Robot   pthread_create(&th, 0, thread, 0);
26*7c3d14c8STreehugger Robot   setuid(0);
27*7c3d14c8STreehugger Robot   pthread_join(th, 0);
28*7c3d14c8STreehugger Robot   fprintf(stderr, "DONE\n");
29*7c3d14c8STreehugger Robot   return 0;
30*7c3d14c8STreehugger Robot }
31*7c3d14c8STreehugger Robot 
32*7c3d14c8STreehugger Robot // CHECK: DONE
33