/** * Log calls to free. */ PUBLIC void log_free (const char *file, int line, const char *func, void *ptr) { size_t size = get_allocation_size (ptr); ptr = (void *) (((size_t *) ptr) - 1); free (ptr); fprintf (logfd, "free,\"%s\",%d,\"%s\",%p,%d\n", file, line, func, ptr, size); }
static void test_self_direct(dcontext_t *dcontext) { app_pc base_pc; size_t size; uint found; uint newfound; #ifdef WINDOWS /* this will get both code and data FIXME: data2data reference * will be the majority */ size = get_allocation_size((app_pc)test_self_direct, &base_pc); #else /* platform agnostic but only looks for current CODE section, and * on windows is not quite what we want - since base_pc will just * be just page aligned */ get_memory_info((app_pc)test_self_direct, &base_pc, &size, NULL); #endif mutex_lock(&rct_module_lock); found = find_address_references(dcontext, base_pc, base_pc+size, base_pc, base_pc+size); mutex_unlock(&rct_module_lock); /* guesstimate */ EXPECT_RELATION(found, >, 140); #ifdef WINDOWS /* FIXME: note data2data have a huge part here */ EXPECT_RELATION(found, <, 20000); #else EXPECT_RELATION(found, <, 1000); #endif EXPECT(is_address_taken(dcontext, (app_pc)f3), true); EXPECT(is_address_taken(dcontext, (app_pc)f2), true); EXPECT(is_address_taken(dcontext, (app_pc)f7), true); /* array reference only */ /* it is pretty hard to produce the address of a static * (e.g. test_self) without making it address taken ;) so we just * add a number to known to be good one's */ EXPECT(is_address_taken(dcontext, (app_pc)f3 + 1), false); EXPECT(is_address_taken(dcontext, (app_pc)f3 + 2), false); EXPECT(is_address_taken(dcontext, (app_pc)f2 + 1), false); EXPECT(is_address_taken(dcontext, (app_pc)f7 + 1), false); mutex_lock(&rct_module_lock); EXPECT(invalidate_ind_branch_target_range(dcontext, 0, (app_pc)-1), found); EXPECT_RELATION(invalidate_ind_branch_target_range(dcontext, 0, (app_pc)-1) , == , 0); /* nothing missed */ mutex_unlock(&rct_module_lock); /* now try manually rct_analyze_module_at_violation */ mutex_lock(&rct_module_lock); EXPECT(rct_analyze_module_at_violation(dcontext, (app_pc)test_self_direct), true); /* should be all found */ /* FIXME: with the data2data in fact a few noisy entries show up * since second lookup in data may differ from original */ newfound = find_address_references(dcontext, base_pc, base_pc+size, base_pc, base_pc+size); EXPECT_RELATION(newfound, <, 4); EXPECT_RELATION(invalidate_ind_branch_target_range(dcontext, 0, (app_pc)-1) , > , found + newfound - 5); /* FIXME: data references uncomparable */ EXPECT_RELATION(invalidate_ind_branch_target_range(dcontext, 0, (app_pc)-1) , == , 0); /* nothing missed */ mutex_unlock(&rct_module_lock); }