Esempio n. 1
0
int
main(int argc, char *argv[])
{
    void *dcontext = dr_standalone_init();

    test_all_opcodes(dcontext);

#ifdef X64
    /* FIXME: NYI */
#else
    test_disp_control(dcontext);

    test_indirect_cti(dcontext);

    test_cti_prefixes(dcontext);

    test_modrm16(dcontext);

    test_size_changes(dcontext);
#endif

    test_nop_xchg(dcontext);

    print("all done\n");
    return 0;
}
Esempio n. 2
0
int
main(int argc, char *argv[])
{
#ifdef STANDALONE_DECODER
    void *dcontext = GLOBAL_DCONTEXT;
#else
    void *dcontext = dr_standalone_init();

    /* simple test of deadlock_avoidance, etc. being disabled in standalone */
    void *x = dr_mutex_create();
    dr_mutex_lock(x);
    dr_mutex_unlock(x);
    dr_mutex_destroy(x);
#endif

    test_all_opcodes_0(dcontext);
#ifndef STANDALONE_DECODER /* speed up compilation */
    test_all_opcodes_1(dcontext);
    test_all_opcodes_2(dcontext);
    test_all_opcodes_2_mm(dcontext);
    test_all_opcodes_3(dcontext);
    test_all_opcodes_3_avx(dcontext);
    test_all_opcodes_4(dcontext);
#endif

    test_disp_control(dcontext);

    test_indirect_cti(dcontext);

    test_cti_prefixes(dcontext);

#ifndef X64
    test_modrm16(dcontext);
#endif

    test_size_changes(dcontext);

    test_nop_xchg(dcontext);

#ifdef X64
    test_x86_mode(dcontext);

    test_x64_abs_addr(dcontext);

    test_x64_inc(dcontext);
#endif

    test_regs(dcontext);

    test_instr_opnds(dcontext);

    test_strict_invalid(dcontext);

    print("all done\n");
    return 0;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
    double res = 0.;
    int i;
#ifndef X64
    int j;
#endif
    char *buf;
#ifdef LINUX
    stack_t sigstack;
#endif

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif
  
#ifdef LINUX
    /* our modrm16 tests clobber esp so we need an alternate stack */
    sigstack.ss_sp = (char *) malloc(ALT_STACK_SIZE);
    sigstack.ss_size = ALT_STACK_SIZE;
    sigstack.ss_flags = SS_ONSTACK;
    i = sigaltstack(&sigstack, NULL);
    assert(i == 0);
    intercept_signal(SIGILL, signal_handler);
    intercept_signal(SIGSEGV, signal_handler);
#else
    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) our_top_handler);
#endif

    buf = allocate_mem(7*256+1, ALLOW_READ|ALLOW_WRITE|ALLOW_EXEC);
    assert(buf != NULL);

#ifndef X64
    print("Jumping to a sequence of every addr16 modrm byte\n");
    for (j=0; j<256; j++) {
        int mod = ((j >> 6) & 0x3); /* top 2 bits */
        int reg = ((j >> 3) & 0x7); /* middle 3 bits */
        int rm  = (j & 0x7);        /* bottom 3 bits */
# if defined(LINUX) || defined(X64)
        buf[j*7 + 0] = 0x65; /* gs: */
# else
        buf[j*7 + 0] = 0x64; /* fs: */
# endif
        buf[j*7 + 1] = 0x67; /* addr16 */
        buf[j*7 + 2] = 0x8b; /* load */
# ifdef WINDOWS
        /* Windows can't handle stack pointer being off */
        if (reg == 4) { /* xsp */
            buf[j*7 + 3] = j | 0x8;
        } else
            buf[j*7 + 3] = j; /* nearly every single modrm byte */
# else
        buf[j*7 + 3] = j; /* every single modrm byte */
# endif
        if (mod == 1) {
            buf[j*7 + 4] = 0x03; /* disp */
            buf[j*7 + 5] = 0xc3;
        } else if (mod == 2 || (mod == 0 && rm == 6)) {
            buf[j*7 + 4] = 0x03; /* disp */
            buf[j*7 + 5] = 0x00; /* disp */
        } else {
            buf[j*7 + 4] = 0xc3; /* ret */
            buf[j*7 + 5] = 0xc3;
        }
        buf[j*7 + 6] = 0xc3;
    }
    buf[256*7] = 0xcc;
    print_access_vio = false;
    for (j=0; j<256; j++) {
        i = setjmp(mark);
        if (i == 0)
            test_modrm16(&buf[j*7]);
        else
            continue;
    }
    print("Done with modrm test: tested %d\n", j);
    count = 0;
    print_access_vio = true;
#endif /* !X64 */

    /* multi-byte nop tests (case 9862) */
    i = setjmp(mark);
    if (i == 0) {
        print("Testing nops\n");
        test_nops();
        print("Done with nops\n");
    }

    /* SSE3 and 3DNow instrs will not run on all processors so we can't have this
     * regression test fully test everything: for now its main use is running
     * manually on the proper machines, or manually verifying decoding of these,
     * but we'll leave as a suite/ regression test.
     */

    /* SSE3 tests: mostly w/ modrm of (%edx) */
    i = setjmp(mark);
    if (i == 0) {
        print("Testing SSE3\n");
        test_sse3(buf);
        print("Should not get here\n");
    }

    /* 3D-Now tests: mostly w/ modrm of (%ebx) */
    i = setjmp(mark);
    if (i == 0) {
        print("Testing 3D-Now\n");
        test_3dnow(buf);
        print("Should not get here\n");
    }

    /* case 6962: far call/jmp tests 
     * Note that DR currently gets the target address wrong for all of these
     * since we skip the segment and only care about the address:
     * not going to fix that anytime soon.
     */
    print("Testing far call/jmp\n");
    test_far_cti();

    /* PR 242815: data16 mbr */
    print("Testing data16 mbr\n");
    test_data16_mbr();

#ifdef LINUX
    free(sigstack.ss_sp);
#endif

    print("All done\n");

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}