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;
19 static pid_t
gettid_sys()
22 return syscall(__NR_gettid
);
27 static void whoami(char *msg
)
29 printf("pid %ld Thread %ld %s\n", (long) getpid(), (long) gettid_sys(), msg
);
34 static int sleeps
= 15;
35 static void make_error (char *s
)
37 char *make_error_name
__attribute__((unused
)) = "make_error name";
38 char c
__attribute__((unused
));
39 double pi2
__attribute__((unused
)) = 2.0 * pi
;
42 printf ("%s int_und is zero %d\n", s
, int_und
);
44 printf ("%s int_und is not zero\n", s
);
50 char *level_name
__attribute__((unused
)) = "level name";
51 make_error ("called from level");
54 static void loops (int *loopnr
)
57 for (i
= 0; i
< LOOPS
; i
++)
58 for (j
= 0; j
< LOOPS
; j
++)
62 static void *brussels_fn(void *v
)
64 char *brussels_name
__attribute__((unused
)) = "Brussels";
65 make_error ("called from Brussels");
67 while (! (loopt1
&& loopt2
&& loopmain
))
72 static void *london_fn(void *v
)
74 char *london_name
__attribute__((unused
)) = "London";
75 make_error ("called from London");
77 while (! (loopt1
&& loopt2
&& loopmain
))
83 static void *petaouchnok_fn(void *v
)
85 char *petaouchnok_name
__attribute__((unused
)) = "Petaouchnok";
88 for (i
= 1; i
<= sleeps
; i
++) {
91 fprintf (stderr
, "Petaouchnok sleep nr %d out of %d sleeping 5 seconds\n",
94 select (0, NULL
, NULL
, NULL
, &t
);
98 static void leaf(void) {}
99 static void breakme(int line
)
102 leaf(); // ensures not leaf, as ppc unwind implies VEX iropt precise exns
104 int main (int argc
, char *argv
[])
106 char *main_name
__attribute__((unused
)) = "main name";
107 pthread_t ebbr
, egll
, zzzz
;
110 char *some_mem
__attribute__((unused
)) = malloc(100);
111 VALGRIND_MAKE_MEM_UNDEFINED(&undef
, 1);
112 int len
= strlen(undefined
);
113 breakme(__LINE__
); //break1
114 for (i
= len
-1; i
>= 0; i
=i
-2)
115 undefined
[i
] = undef
;
116 *(char*)&int_und
= undef
;
118 breakme(__LINE__
); //break2
121 sleeps
= atoi(argv
[1]);
124 make_error ("called from main");
126 pthread_create(&ebbr
, NULL
, brussels_fn
, NULL
);
127 pthread_create(&egll
, NULL
, london_fn
, NULL
);
128 pthread_create(&zzzz
, NULL
, petaouchnok_fn
, NULL
);
131 while (! (loopt1
&& loopt2
&& loopmain
))
133 for (i
= 0; i
< LOOPS
; i
++) {
136 if (loopmain
== 10000)
137 make_error ("in main loop");
140 pthread_join(ebbr
, NULL
);
142 make_error ("called from main (the end, before joining t3)");
144 pthread_join(zzzz
, NULL
);
147 for (i
= 0; i
< 100; i
++)
148 if ((*(&undef
+ i
*4000) == 0) || (*(&undef
- i
*4000) == 0)) {
149 printf ("there are some null bytes here and there %d\n", i
);