FreeBSD regtest: add missing helgrind expecteds
[valgrind.git] / helgrind / tests / tc07_hbl1.c
bloba4250c62c43df2000607abac5d2108bf4c2527d4
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 /* Simple test program, no race. Parent and child both modify x and
7 use the hardware bus lock. */
9 #undef PLAT_x86_darwin
10 #undef PLAT_amd64_darwin
11 #undef PLAT_x86_freebsd
12 #undef PLAT_amd64_freebsd
13 #undef PLAT_arm64_freebsd
14 #undef PLAT_x86_linux
15 #undef PLAT_amd64_linux
16 #undef PLAT_ppc32_linux
17 #undef PLAT_ppc64_linux
18 #undef PLAT_arm_linux
19 #undef PLAT_arm64_linux
20 #undef PLAT_s390x_linux
21 #undef PLAT_mips32_linux
22 #undef PLAT_x86_solaris
23 #undef PLAT_amd64_solaris
25 #if defined(__APPLE__) && defined(__i386__)
26 # define PLAT_x86_darwin 1
27 #elif defined(__APPLE__) && defined(__x86_64__)
28 # define PLAT_amd64_darwin 1
29 #elif defined(__FreeBSD__) && defined(__i386__)
30 # define PLAT_x86_freebsd 1
31 #elif defined(__FreeBSD__) && defined(__amd64__)
32 # define PLAT_amd64_freebsd 1
33 #elif defined(__FreeBSD__) && defined(__aarch64__)
34 # define PLAT_arm64_freebsd 1
35 #elif defined(__linux__) && defined(__i386__)
36 # define PLAT_x86_linux 1
37 #elif defined(__linux__) && defined(__x86_64__)
38 # define PLAT_amd64_linux 1
39 #elif defined(__linux__) && defined(__powerpc__) && !defined(__powerpc64__)
40 # define PLAT_ppc32_linux 1
41 #elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__)
42 # define PLAT_ppc64_linux 1
43 #elif defined(__linux__) && defined(__arm__) && !defined(__aarch64__)
44 # define PLAT_arm_linux 1
45 #elif defined(__linux__) && defined(__aarch64__) && !defined(__arm__)
46 # define PLAT_arm64_linux 1
47 #elif defined(__linux__) && defined(__s390x__)
48 # define PLAT_s390x_linux 1
49 #elif defined(__linux__) && defined(__mips__)
50 # define PLAT_mips32_linux 1
51 #elif defined(__linux__) && defined(__nanomips__)
52 # define PLAT_nanomips_linux 1
53 #elif defined(__sun__) && defined(__i386__)
54 # define PLAT_x86_solaris 1
55 #elif defined(__sun__) && defined(__x86_64__)
56 # define PLAT_amd64_solaris 1
57 #endif
59 #if defined(PLAT_amd64_linux) || defined(PLAT_x86_linux) \
60 || defined(PLAT_amd64_darwin) || defined(PLAT_x86_darwin) \
61 || defined(PLAT_amd64_solaris) || defined(PLAT_x86_solaris) \
62 || defined(PLAT_amd64_freebsd) || defined(PLAT_x86_freebsd)
63 # define INC(_lval,_lqual) \
64 __asm__ __volatile__ ( \
65 "lock ; incl (%0)" : /*out*/ : /*in*/"r"(&(_lval)) : "memory", "cc" )
66 #elif defined(PLAT_ppc32_linux) || defined(PLAT_ppc64_linux)
67 # define INC(_lval,_lqual) \
68 __asm__ __volatile__( \
69 "1:\n" \
70 " lwarx 15,0,%0\n" \
71 " addi 15,15,1\n" \
72 " stwcx. 15,0,%0\n" \
73 " bne- 1b\n" \
74 : /*out*/ : /*in*/ "b"(&(_lval)) \
75 : /*trash*/ "r15", "cr0", "memory" \
77 #elif defined(PLAT_arm_linux)
78 # define INC(_lval,_lqual) \
79 __asm__ __volatile__( \
80 "1:\n" \
81 " ldrex r8, [%0, #0]\n" \
82 " add r8, r8, #1\n" \
83 " strex r9, r8, [%0, #0]\n" \
84 " cmp r9, #0\n" \
85 " bne 1b\n" \
86 : /*out*/ : /*in*/ "r"(&(_lval)) \
87 : /*trash*/ "r8", "r9", "cc", "memory" \
89 #elif defined(PLAT_arm64_linux) || defined(PLAT_arm64_freebsd)
90 # define INC(_lval,_lqual) \
91 __asm__ __volatile__( \
92 "1:\n" \
93 " ldxr w8, [%0, #0]\n" \
94 " add w8, w8, #1\n" \
95 " stxr w9, w8, [%0, #0]\n" \
96 " cmp w9, #0\n" \
97 " bne 1b\n" \
98 : /*out*/ : /*in*/ "r"(&(_lval)) \
99 : /*trash*/ "x8", "x9", "cc", "memory" \
101 #elif defined(PLAT_s390x_linux)
102 # define INC(_lval,_lqual) \
103 __asm__ __volatile__( \
104 "1: l 0,%0\n" \
105 " lr 1,0\n" \
106 " ahi 1,1\n" \
107 " cs 0,1,%0\n" \
108 " jl 1b\n" \
109 : "+m" (_lval) :: "cc", "1","2" \
111 #elif defined(PLAT_mips32_linux)
112 # define INC(_lval,_lqual) \
113 __asm__ __volatile__ ( \
114 "1:\n" \
115 " move $8, %0\n" \
116 " ll $9, 0($8)\n" \
117 " addiu $9, $9, 1\n" \
118 " sc $9, 0($8)\n" \
119 " li $10, 1\n" \
120 " bne $9, $10, 1b\n" \
121 " nop\n" \
122 : /*out*/ : /*in*/ "r"(&(_lval)) \
123 : /*trash*/ "$8", "$9", "$10", "cc", "memory" \
125 #elif defined(PLAT_nanomips_linux)
126 # define INC(_lval,_lqual) \
127 __asm__ __volatile__ ( \
128 "1:\n" \
129 " move $t0, %0\n" \
130 " ll $t1, 0($t0)\n" \
131 " addiu $t1, $t1, 1\n" \
132 " sc $t1, 0($t0)\n" \
133 " beqc $t1, $zero, 1b\n" \
134 : /*out*/ : /*in*/ "r"(&(_lval)) \
135 : /*trash*/ "$t0", "$t1", "memory" \
137 #else
138 # error "Fix Me for this platform"
139 #endif
142 int x = 0;
144 void* child_fn ( void* arg )
146 INC(x, "childfn");
147 return NULL;
150 int main ( void )
152 pthread_t child;
154 if (pthread_create(&child, NULL, child_fn, NULL)) {
155 perror("pthread_create");
156 exit(1);
159 INC(x, "main");
161 if (pthread_join(child, NULL)) {
162 perror("pthread join");
163 exit(1);
166 printf("x = %d\n", x);
167 return 0;