Exemple #1
0
static void
our_memcpy_vs_libc(void)
{
    /* Compare our memcpy with libc memcpy.
     * XXX: Should compare on more sizes, especially small ones.
     */
    size_t alloc_size = 20 * 1024;
    int loop_count = 100 * 1000;
    void *src = global_heap_alloc(alloc_size HEAPACCT(ACCT_OTHER));
    void *dst = global_heap_alloc(alloc_size HEAPACCT(ACCT_OTHER));
    int i;
    memcpy_t glibc_memcpy = (memcpy_t) dlsym(RTLD_NEXT, "memcpy");
    uint64 our_memcpy_start, our_memcpy_end, our_memcpy_time;
    uint64 libc_memcpy_start, libc_memcpy_end, libc_memcpy_time;
    memset(src, -1, alloc_size);
    memset(dst, 0, alloc_size);

    our_memcpy_start = query_time_millis();
    for (i = 0; i < loop_count; i++) {
        memcpy(src, dst, alloc_size);
    }
    our_memcpy_end = query_time_millis();

    libc_memcpy_start = query_time_millis();
    for (i = 0; i < loop_count; i++) {
        glibc_memcpy(src, dst, alloc_size);
    }
    libc_memcpy_end = query_time_millis();

    global_heap_free(src, alloc_size HEAPACCT(ACCT_OTHER));
    global_heap_free(dst, alloc_size HEAPACCT(ACCT_OTHER));
    our_memcpy_time = our_memcpy_end - our_memcpy_start;
    libc_memcpy_time = libc_memcpy_end - libc_memcpy_start;
    print_file(STDERR, "our_memcpy_time: "UINT64_FORMAT_STRING"\n",
               our_memcpy_time);
    print_file(STDERR, "libc_memcpy_time: "UINT64_FORMAT_STRING"\n",
               libc_memcpy_time);
    /* We could assert that we're not too much slower, but that's a recipe for
     * flaky failures when the suite is run on shared VMs or in parallel.
     */
}
Exemple #2
0
BOOL WINAPI
redirect_RtlDestroyHeap(HANDLE base)
{
    if (redirect_heap_call(base)) {
        /* XXX i#: need to iterate over all blocks in the heap and free them:
         * would have to keep a list of blocks.
         * For now assume all private heaps practice individual dealloc
         * instead of whole-pool-free.
         */
        LOG(GLOBAL, LOG_LOADER, 2, "%s "PFX"\n", __FUNCTION__, base);
        global_heap_free((byte *)base, 1 HEAPACCT(ACCT_LIBDUP));
        return TRUE;
    } else
        return RtlDestroyHeap(base);
}
static void
print_all_ldt(void)
{
    int i, bytes;
    /* can't fit 64K on our stack */
    raw_ldt_entry_t *ldt = global_heap_alloc(sizeof(raw_ldt_entry_t) * LDT_ENTRIES
                                           HEAPACCT(ACCT_OTHER));
    /* make sure our struct size jives w/ ldt.h */
    ASSERT(sizeof(raw_ldt_entry_t) == LDT_ENTRY_SIZE);
    memset(ldt, 0, sizeof(*ldt));
    bytes = modify_ldt_syscall(0, (void *)ldt, sizeof(raw_ldt_entry_t) * LDT_ENTRIES);
    LOG(GLOBAL, LOG_ALL, 3, "read %d bytes, should == %d * %d\n",
        bytes, sizeof(raw_ldt_entry_t), LDT_ENTRIES);
    ASSERT(bytes == 0 /* no ldt entries */ ||
           bytes == sizeof(raw_ldt_entry_t) * LDT_ENTRIES);
    for (i = 0; i < bytes/sizeof(raw_ldt_entry_t); i++) {
        if (((ldt[i].base3124<<24) | (ldt[i].base2316<<16) | ldt[i].base1500) != 0) {
            LOG(GLOBAL, LOG_ALL, 1, "ldt at index %d:\n", i);
            print_raw_ldt(&ldt[i]);
        }
    }
    global_heap_free(ldt, sizeof(raw_ldt_entry_t) * LDT_ENTRIES HEAPACCT(ACCT_OTHER));
}
Exemple #4
0
void
wrapped_dr_free(byte *ptr)
{
    ptr -= sizeof(size_t);
    global_heap_free(ptr, *((size_t *)ptr) HEAPACCT(ACCT_LIBDUP));
}