@@ -192,11 +192,15 @@ void wrap_pre_unlock(void *wrapcxt, OUT void **user_data) {
192
192
if (program_locks [i ].unlock_count >= program_locks [i ].lock_count ) {
193
193
program_locks [i ].state = ReadHeld ;
194
194
}
195
- pthread_mutex_unlock (& mutex_program_locks );
196
195
thread_accessed -> last_locked_mutex_addr = -1 ;
196
+ pthread_mutex_unlock (& mutex_program_locks );
197
197
}
198
198
// todo => handle post lock/unlock and check wether it was successfull!.
199
199
void wrap_pre_lock (void * wrapcxt , OUT void * * user_data ) {
200
+ // wait(10000000000000);
201
+
202
+ int i ;
203
+ for (i = 0 ; i <= 100000000 ; i ++ ) {}
200
204
// printf("pre LOCK\n");
201
205
void * addr = drwrap_get_arg (wrapcxt , 0 );
202
206
// printf("locking: %ld \n", addr);
@@ -208,10 +212,11 @@ void wrap_pre_lock(void *wrapcxt, OUT void **user_data) {
208
212
return ;
209
213
}
210
214
ThreadState * thread_accessed = & program_threads [t_index ];
215
+ // printf("--: %d %d \n ", (usize)addr, thread_id);
211
216
pthread_mutex_lock (& mutex_program_threads );
212
217
thread_accessed -> last_locked_mutex_addr = (usize )addr ;
213
218
pthread_mutex_unlock (& mutex_program_threads );
214
- int i ;
219
+ // int i;
215
220
for (i = 0 ; i <= n_program_locks ; i ++ ) {
216
221
if (program_locks [i ].addr == (usize )addr ) break ;
217
222
if (i >= n_program_locks ) {
@@ -263,6 +268,10 @@ void wrap_pre_malloc(void *wrapcxt, OUT void **user_data) {
263
268
}
264
269
265
270
void check_for_race (ThreadState * thread_state ) {
271
+ // int i;
272
+ // for (i = 0; i <= thread_state->mem_write_set_len; i++) {
273
+ // printf("state %d \n", thread_state->mem_write_set[i].lock_access.state);
274
+ // }
266
275
int thread_i , write_set_i , write_set_i_plus1 , read_set_i ;
267
276
for (write_set_i = 0 ; write_set_i < thread_state -> mem_write_set_len ; write_set_i ++ ) {
268
277
for (thread_i = 0 ; thread_i < n_program_threads ; thread_i ++ ) {
@@ -282,14 +291,12 @@ void check_for_race(ThreadState *thread_state) {
282
291
}
283
292
// write write-read pairs
284
293
for (write_set_i_plus1 = 0 ; write_set_i_plus1 < iterated_thread -> mem_write_set_len ; write_set_i_plus1 ++ ) {
285
- if (thread_state -> mem_write_set [write_set_i ].address_accessed == iterated_thread -> mem_write_set [write_set_i_plus1 ].address_accessed ) {
286
- if (thread_state -> mem_write_set [write_set_i ].callee_thread_id != iterated_thread -> mem_write_set [write_set_i_plus1 ].callee_thread_id ) {
294
+ if (thread_state -> mem_write_set [write_set_i ].address_accessed == iterated_thread -> mem_write_set [write_set_i_plus1 + 1 ].address_accessed ) {
295
+ if (thread_state -> mem_write_set [write_set_i ].callee_thread_id != iterated_thread -> mem_write_set [write_set_i_plus1 + 1 ].callee_thread_id ) {
287
296
// printf("addr match(not smae thread id) %ld, %ld \n", thread_state->mem_write_set[write_set_i].address_accessed, iterated_thread->mem_write_set[write_set_i_plus1].address_accessed);
288
- if (thread_state -> mem_write_set [write_set_i ].lock_access .state != WriteHeld && iterated_thread -> mem_write_set [write_set_i_plus1 ].lock_access .state != WriteHeld ) {
297
+ if (thread_state -> mem_write_set [write_set_i ].lock_access .state != WriteHeld && iterated_thread -> mem_write_set [write_set_i_plus1 + 1 ].lock_access .state != WriteHeld ) {
289
298
detected_races_counter += 1 ;
290
299
printf ("race on: %ld \n" , thread_state -> mem_write_set [write_set_i ].address_accessed );
291
- // printf("lol\n");
292
- // printf("state match %d, %d \n", thread_state->mem_write_set[write_set_i].lock_access.state, iterated_thread->mem_write_set[write_set_i_plus1].lock_access.state);
293
300
break ;
294
301
}
295
302
}
@@ -374,6 +381,7 @@ void memtrace(void *drcontext, u64 thread_id) {
374
381
// todo => should not be invoked
375
382
printf ("no lock for addr %ld \n" , mem_ref -> addr );
376
383
}
384
+ printf ("held: %d \n" , program_locks [lock_state_i ].state );
377
385
thread_accessed -> mem_write_set_len += 1 ;
378
386
} else if (mem_ref -> type == 0 || mem_ref -> type == 227 || mem_ref -> type == 225 || mem_ref -> type == 197 || mem_ref -> type == 228 || mem_ref -> type == 229 || mem_ref -> type == 299 || mem_ref -> type == 173 ) {
379
387
// mem read
@@ -391,8 +399,10 @@ void memtrace(void *drcontext, u64 thread_id) {
391
399
} else {
392
400
printf ("no lock for addr %ld \n" , mem_ref -> addr );
393
401
}
402
+ printf ("held: %d \n" , program_locks [lock_state_i ].state );
394
403
thread_accessed -> mem_read_set_len += 1 ;
395
404
}
405
+
396
406
pthread_mutex_unlock (& mutex_program_threads );
397
407
check_for_race (thread_accessed );
398
408
continue_outer_loop :;
0 commit comments