8 #include <sys/syscall.h>
9 #include "../memcheck/memcheck.h"
10 int using_threads
= 0; /* test collision with a global in gdbserver */
11 /* we will undefine one char on two */
12 static char undefined
[10] = "undefined";
14 #define LOOPS 10000000
15 static int loopmain
, loopt1
, loopt2
;
17 static double pi
= 3.14159265358979323846264338327950288;
22 return syscall(__NR_gettid
);
27 static void whoami(char *msg
)
29 printf("pid %d Thread %d %s\n", getpid(), gettid(), msg
); fflush(stdout
);
33 static int sleeps
= 15;
34 static void make_error (char *s
)
36 char *make_error_name
__attribute__((unused
)) = "make_error name";
37 char c
__attribute__((unused
));
38 double pi2
__attribute__((unused
)) = 2.0 * pi
;
41 printf ("%s int_und is zero %d\n", s
, int_und
);
43 printf ("%s int_und is not zero\n", s
);
49 char *level_name
__attribute__((unused
)) = "level name";
50 make_error ("called from level");
53 static void loops (int *loopnr
)
56 for (i
= 0; i
< LOOPS
; i
++)
57 for (j
= 0; j
< LOOPS
; j
++)
61 static void *brussels_fn(void *v
)
63 char *brussels_name
__attribute__((unused
)) = "Brussels";
64 make_error ("called from Brussels");
66 while (! (loopt1
&& loopt2
&& loopmain
))
71 static void *london_fn(void *v
)
73 char *london_name
__attribute__((unused
)) = "London";
74 make_error ("called from London");
76 while (! (loopt1
&& loopt2
&& loopmain
))
82 static void *petaouchnok_fn(void *v
)
84 char *petaouchnok_name
__attribute__((unused
)) = "Petaouchnok";
87 for (i
= 1; i
<= sleeps
; i
++) {
90 fprintf (stderr
, "Petaouchnok sleep nr %d out of %d sleeping 5 seconds\n",
93 select (0, NULL
, NULL
, NULL
, &t
);
97 static void leaf(void) {}
98 static void breakme(int line
)
101 leaf(); // ensures not leaf, as ppc unwind implies VEX iropt precise exns
103 int main (int argc
, char *argv
[])
105 char *main_name
__attribute__((unused
)) = "main name";
106 pthread_t ebbr
, egll
, zzzz
;
109 char *some_mem
__attribute__((unused
)) = malloc(100);
110 VALGRIND_MAKE_MEM_UNDEFINED(&undef
, 1);
111 int len
= strlen(undefined
);
112 breakme(__LINE__
); //break1
113 for (i
= len
-1; i
>= 0; i
=i
-2)
114 undefined
[i
] = undef
;
115 *(char*)&int_und
= undef
;
117 breakme(__LINE__
); //break2
120 sleeps
= atoi(argv
[1]);
123 make_error ("called from main");
125 pthread_create(&ebbr
, NULL
, brussels_fn
, NULL
);
126 pthread_create(&egll
, NULL
, london_fn
, NULL
);
127 pthread_create(&zzzz
, NULL
, petaouchnok_fn
, NULL
);
130 while (! (loopt1
&& loopt2
&& loopmain
))
132 for (i
= 0; i
< LOOPS
; i
++) {
135 if (loopmain
== 10000)
136 make_error ("in main loop");
139 pthread_join(ebbr
, NULL
);
141 make_error ("called from main (the end, before joining t3)");
143 pthread_join(zzzz
, NULL
);
146 for (i
= 0; i
< 100; i
++)
147 if ((*(&undef
+ i
*4000) == 0) || (*(&undef
- i
*4000) == 0)) {
148 printf ("there are some null bytes here and there %d\n", i
);