Beispiel #1
0
/* auto_setup: called by dynamo_auto_start for non-early follow children.
 * This routine itself would be dynamo_auto_start except that we want
 * our own go-native path separate from load_dynamo (we could still have
 * this by dynamo_auto_start and jump to an asm routine for go-native,
 * but keeping the entry in asm is more flexible).
 * Assumptions: The saved priv_mcontext_t for the start of the app is on
 * the stack, followed by a pointer to a region of memory to free
 * (which can be NULL) and its size.  If we decide not to take over
 * this process, this routine returns; otherwise it does not return.
 */
void
auto_setup(ptr_uint_t appstack)
{
    dcontext_t *dcontext;
    priv_mcontext_t *mcontext;
    byte *pappstack;
    byte        *addr;

    pappstack = (byte *)appstack;

    /* Our parameter points at a priv_mcontext_t struct, beyond which are
     * two other fields:
       pappstack --> +0  priv_mcontext_t struct
                     +x  addr of memory to free (can be NULL)
                     +y  sizeof memory to free
    */

    automatic_startup = true;
    /* we should control all threads */
    control_all_threads = true;
    dynamorio_app_init();
    if (INTERNAL_OPTION(nullcalls)) {
        dynamorio_app_exit();
        return;
    }

    /* For apps injected using follow_children, this is where control should be 
     * allowed to go native for hotp_only & thin_client.
     */
    if (RUNNING_WITHOUT_CODE_CACHE())
        return;

    /* useful to debug fork-following */
    DOLOG(4, LOG_TOP, { SYSLOG_INTERNAL_INFO("dynamo auto start"); });
Beispiel #2
0
int
main()
{
#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    INIT();

    print("initapc main()\n");
    import_me(37);

    /* ensure still checking ret-after-call after stack bottom issues w/ APC 
     * use a nop between push and ret to avoid VB push/ret pattern match
     */
    __asm {
        push offset next_instr
        nop
        ret
    next_instr:
        nop
    }

    print("*** invalid ret allowed!\n");

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}
Beispiel #3
0
int
main(int argc, char *argv[])
{
    int i;
#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif
    INIT();

    /* set up SEH */
    __asm {
        push eax
        mov eax, offset vcex
        mov dword ptr fs:[0], eax
        pop eax
    }

    print("ret-SEH test starting\n");
    for (i=0; i<NUM_SCOPE_ENTRIES; i++) {
        /* levels start at -1 */
        ret_SEH(i-1);
    }
    print("ret-SEH test stopping\n");

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}
Beispiel #4
0
int main()
{
#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    sleeptime.tv_sec = 0;
    sleeptime.tv_nsec = 10*1000*1000; /* 10ms */

    child_exit = false;
    child_done = false;
    child = create_thread(run, NULL, &stack);
    assert(child > -1);

    /* waste some time */
    nanosleep(&sleeptime, NULL);
    
    child_exit = true;
    /* we want deterministic printf ordering */
    while (!child_done)
        nanosleep(&sleeptime, NULL);
    delete_thread(child, stack);

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
}
Beispiel #5
0
int
main()
{
    /* get aligned test buffers */
    char buffer_stack[BUFFER_SIZE];

    char *buf = page_align(buffer);
    char *buf_stack = page_align(buffer_stack);
    INIT();
    
#if USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    print("starting up\n");
    do_test(buf, 2*PAGE_SIZE);
    print("starting stack tests\n");
    do_test(buf_stack, 2*PAGE_SIZE);

    print("starting overlap tests\n");
    test_alloc_overlap();

    print("about to exit\n");

#if USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
}
Beispiel #6
0
int main(int argc, char *argv[])
{
    double res = 0.;

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif
  
#ifdef LINUX
    intercept_signal(SIGSEGV, signal_handler);
#else
    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) our_top_handler);
#endif

    print("Segfault about to happen\n");

    *((volatile int *)0) = 4;

    print("SHOULD NEVER GET HERE\n");

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}
Beispiel #7
0
int
main()
{
#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    INIT();

    print("calling via IAT-style call\n");
    import_me1(57);
    print("calling in a thread\n");
    join_thread(create_thread((fptr)import_me1));

    print("calling in a thread that dies\n");
    join_thread(create_thread((fptr)import_me_die));
    print("case 5455 regression passed\n");

    print("all done\n");

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}
Beispiel #8
0
int
main()
{
    INIT();

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    /* make foo code writable */
    protect_mem(code_self_mod, 1024, ALLOW_READ|ALLOW_WRITE|ALLOW_EXEC);
    // Note that main and the exception handler __except_handler3 are on this page too

    foo(0xabcd);
    foo(0x1234);
    foo(0xef01);

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif

    return 0;
}
int main(int argc, char *argv[])
{
    pid_t child;

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif
    if (argc < 2) {
        print("ERROR: not enough args\n");
        return -1;
    }

    if (find_dynamo_library())
	print("parent is running under DynamoRIO\n");
    else
	print("parent is running natively\n");
    child = fork();
    if (child < 0) {
	perror("ERROR on fork");
    } else if (child > 0) {
	pid_t result;
	result = waitpid(child, NULL, 0);
	assert(result == child);
	print("child has exited\n");
    } else {
	int result;
	char *arg[3];
#if NULL_ENV
	char **env = NULL;
#else
	char *env0 = "LD_LIBRARY_PATH=/bin:.";
	char *env[2];
	env[0] = env0;
	env[1] = NULL;
#endif
	arg[0] = argv[1];
	arg[1] = "/fake/path/it_worked";
	arg[2] = NULL;
	if (find_dynamo_library())
	    print("child is running under DynamoRIO\n");
	else
	    print("child is running natively\n");
	result = execve("/bin/bogus_will_fail", arg, env);
	result = execve(argv[1], arg, env);
	if (result < 0)
	    perror("ERROR in execve");
    }	

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
}
Beispiel #10
0
int
main(int argc, char **argv)
{
    pthread_t thread0, thread1;
    void * retval;

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

#if 0
    /* Get the number of intervals */
    if (argc != 2) {
	fprintf(stderr, "Usage: %s <intervals>\n", argv[0]);
	exit(0);
    }
    intervals = atoi(argv[1]);
#else /* for batch mode */
    intervals = 10;
#endif

    /* Initialize the lock on pi */
    pthread_mutex_init(&pi_lock, NULL);

    /* Make the two threads */
    if (pthread_create(&thread0, NULL, process, "0") ||
	pthread_create(&thread1, NULL, process, "1")) {
	fprintf(stderr, "%s: cannot make thread\n", argv[0]);
	exit(1);
    }
    
    /* Join (collapse) the two threads */
    if (pthread_join(thread0, &retval) ||
	pthread_join(thread1, &retval)) {
	fprintf(stderr, "%s: thread join failed\n", argv[0]);
	exit(1);
    }

    /* Print the result */
    printf("Estimation of pi is %16.15f\n", pi);

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
}
Beispiel #11
0
int main()
{
    ptr_int_t myaddr;
#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif
    /* make sure dynamorio can handle this non-call */
    myaddr = get_retaddr();
#if VERBOSE
    print("my address is something like "PFX"\n", myaddr);
#endif
    call_with_retaddr((void*)foo);
#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}
Beispiel #12
0
int main()
{
    int i;
#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    sleeptime.tv_sec = 0;
    sleeptime.tv_nsec = 10*1000*1000; /* 10ms */

    /* parent remains in own group. creates child who creates a thread group
     * and then exits them all
     */
    for (i = 0; i < NUM_THREADS; i++) {
        child_started[i] = false;
        child_exit[i] = false;
    }
    child[0] = create_thread(run, (void *)(long)0, &stack[0], false);
    assert(child[0] > -1);

    /* wait for child to start rest of threads */
    for (i = 0; i < NUM_THREADS; i++) {
        while (!child_started[i]) {
            /* waste some time: FIXME: should use futex */
            nanosleep(&sleeptime, NULL);
        }
    }
    
    child_exit[0] = true;
    while (!child_done[0])
        nanosleep(&sleeptime, NULL);
    delete_thread(child[0], stack[0]);
    for (i = 1; i < NUM_THREADS; i++)
        stack_free(stack[i], THREAD_STACK_SIZE);

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
}
Beispiel #13
0
int
main()
{
    void *p;
    BOOL res;
    int size = 0x04000;

#if USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    p = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    assert(p);
    res = VirtualFree(p, 0, MEM_RELEASE);
    assert(res);
    printf("Successful\n");

#if USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
}
Beispiel #14
0
int main()
{
    int i;
#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    sleeptime.tv_sec = 0;
    sleeptime.tv_nsec = 10*1000*1000; /* 10ms */

    for (i = 0; i < NUM_THREADS; i++) {
        child_started[i] = false;
        child_exit[i] = false;
        child[i] = create_thread(run, (void *)(long)i, &stack[i]);
        assert(child[i] > -1);
    }

    for (i = 0; i < NUM_THREADS; i++) {
        while (!child_started[i]) {
            /* waste some time: FIXME: should use futex */
            nanosleep(&sleeptime, NULL);
        }
    }

    /* we have the 1st child exit the whole group to test DR's synchall-at-exit */
    child_exit[0] = true;
    /* parent doesn't exit on its own */
    while (true)
        nanosleep(&sleeptime, NULL);

    fprintf(stderr, "Should never get here\n");
#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
}
Beispiel #15
0
int
main()
{
    unsigned int tid;
    HANDLE hThread;
    int res;

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    printf("Before _beginthreadex\n");
    fflush(stdout);
    hThread = (HANDLE) _beginthreadex(NULL, 0, run_func, NULL, 0, &tid);

    while (synch_2) {
        SwitchToThread();
    }

    res = QueueUserAPC(apc_func, hThread, 37);
    printf("QueueUserAPC returned %d\n", res);
    fflush(stdout);
    
    synch_1 = FALSE;

    WaitForSingleObject((HANDLE)hThread, INFINITE);

    printf("After _beginthreadex\n");

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}
Beispiel #16
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;
}
Beispiel #17
0
int
main()
{
    uint i;
    uint writes = 0;
    byte *DR_base;
    INIT();
    
#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

#ifdef UNIX
    intercept_signal(SIGSEGV, (handler_3_t) signal_handler, false);
#else
    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) our_top_handler);
#endif

    where = setjmp(mark);
    if (where == 0) {
        DR_base = get_DR_base();
#if VERBOSE
        print("DR base is "PFX"\n", DR_base);
#endif
        for (i=0; i<DATASEC_NUM; i++) {
            byte *start, *end, *pc;
            bool found = get_named_section_bounds(DR_base,
                                                  /*FIXME use drmarker to find*/
                                                  datasec_names[i], &start, &end);
            assert(found);
#if VERBOSE
            print("data section %s: "PFX"-"PFX"\n", datasec_names[i], start, end);
#endif
            print("about to write to every page in %s\n", datasec_names[i]);
            for (pc = start; pc < end; pc += PAGE_SIZE) {
                /* try to write to every single page */
                where = setjmp(mark);
                if (where == 0) {
                    uint old = *((uint *)pc);
                    *((uint *)pc) = 0x0badbad0;
                    /* restore in same bb so we don't crash DR */
                    *((uint *)pc) = old;
                    /* if the section is protected we shouldn't get here */
                    writes++;
#if VERBOSE
                    print("successfully wrote to "PFX" in %s!\n",
                          pc, datasec_names[i]);
#endif
                }
            }
#if VERBOSE
            print("successfully wrote to %d pages!\n", writes);
#endif
            if (writes > 0)
                print("successfully wrote to %s\n", datasec_names[i]);
        }
    } else {
        print("no DR or no data sections found: are you running natively?\n");
    }

    print("all done\n");

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
}
static int 
main(int argc, char **argv) 
{
    STARTUPINFO si = { sizeof(STARTUPINFO) };
    PROCESS_INFORMATION pi;
    char cmdline[128];
    DWORD result = 0;

    INIT();
    USE_USER32();               /* can't be in runall otherwise! */
    
#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    if (argc == 1) {
        /* normal execution */

        _snprintf(cmdline, sizeof(cmdline), "%s %d", argv[0], depth);

        print("starting chain %d...\n", depth);

    }

    if (argc == 2) {
        depth = atoi(argv[1]);
        print("subprocess %d running.\n", depth);

        _snprintf(cmdline, sizeof(cmdline), "%s %d", argv[0], depth-1);
    }

    if (depth != 0) {
        if (!CreateProcess(argv[0],
                           cmdline,
                           NULL,
                           NULL,
                           FALSE,
                           0,
                           NULL,
                           NULL,
                           &si,
                           &pi)) 
            print("CreateProcess failure\n"); 
        else {
            DWORD exit_code = 0;
            print("waiting for child\n"); 
            WaitForSingleObject(pi.hProcess, INFINITE);
            if (!GetExitCodeProcess(pi.hProcess, &exit_code)) {
                print("GetExitCodeProcess failure %d\n", GetLastError()); 
            } else {
                print("process returned %d\n", exit_code);
            }
        }
    }
    
#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif

    return depth * 10;
    /* make sure not 259 STILL_ACTIVE which may be returned by GetExitCodeProcess() */
}
Beispiel #19
0
int main(int argc, char *argv[])
{
    double res = 0.;
    int i;

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif
  
#ifdef LINUX
    intercept_signal(SIGILL, signal_handler);
    intercept_signal(SIGSEGV, signal_handler);
#else
# ifdef X64_DEBUGGER
    /* FIXME: the vectored handler works fine in the debugger, but natively
     * the app crashes here: yet the SetUnhandled hits infinite fault loops
     * in the debugger, and works fine natively!
     */
    AddVectoredExceptionHandler(1/*first*/,
                                (PVECTORED_EXCEPTION_HANDLER) our_top_handler);
# else
    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) our_top_handler);
# endif
#endif

    /* privileged instructions */
    print("Privileged instructions about to happen\n");
    count = 0;
    i = setjmp(mark);
    switch (i) {
    case 0: test_priv_0();
    case 1: test_priv_1();
    case 2: test_priv_2();
    case 3: test_priv_3();
    }

    /* prefix tests */
    print("OK instr about to happen\n");
    /* multiple prefixes */
    /* FIXME: actually these prefixes on a jmp are "reserved" but this seems to work */
    test_prefix_0();
    print("Bad instr about to happen\n");
    /* lock prefix, which is illegal instruction if placed on jmp */
    count = 0;
    invalid_lock = true;
    if (setjmp(mark) == 0) {
        test_prefix_1();
    }
    invalid_lock = false;

    print("Invalid instructions about to happen\n");
    count = 0;
    i = setjmp(mark);
    switch (i) {
        /* note that we decode until a CTI, so for every case the suffix is decoded
         * and changes in later cases may fail even the earlier ones.
         */
    case 0: test_inval_0();
    case 1: test_inval_1();
    case 2: test_inval_2();
    case 3: test_inval_3();
    case 4: test_inval_4();
    case 5: test_inval_5();
    case 6: test_inval_6();
    case 7: test_inval_7();
    default: ;
    }

    print("All done\n");

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}
Beispiel #20
0
int main(int argc, char *argv[])
{
    double res = 0.;
    int i, j;
#if defined(USE_DYNAMO) || USE_TIMER || USE_SIGSTACK
    int rc;
#endif
#if USE_SIGSTACK
    stack_t sigstack;
#endif
#if USE_TIMER
    struct itimerval t;
#endif
  
#ifdef USE_DYNAMO
    rc = dynamorio_app_init();
    ASSERT_NOERR(rc);
    dynamorio_app_start();
#endif

#if USE_TIMER
    intercept_signal(SIGVTALRM, (handler_t) signal_handler);
    t.it_interval.tv_sec = 0;
    t.it_interval.tv_usec = 10000;
    t.it_value.tv_sec = 0;
    t.it_value.tv_usec = 10000;
    rc = setitimer(ITIMER_VIRTUAL, &t, NULL);
    ASSERT_NOERR(rc);
#endif

#if USE_SIGSTACK
    sigstack.ss_sp = (char *) malloc(ALT_STACK_SIZE);
    sigstack.ss_size = ALT_STACK_SIZE;
    sigstack.ss_flags = SS_ONSTACK;
    rc = sigaltstack(&sigstack, NULL);
    ASSERT_NOERR(rc);
# if VERBOSE
    fprintf(stderr, "Set up sigstack: 0x%08x - 0x%08x\n",
	    sigstack.ss_sp, sigstack.ss_sp + sigstack.ss_size);
# endif
#endif

    intercept_signal(SIGSEGV, (handler_t) signal_handler);
    intercept_signal(SIGUSR1, (handler_t) signal_handler);
    intercept_signal(SIGUSR2, (handler_t) SIG_IGN);

    res = cos(0.56);

    fprintf(stderr, "Sending SIGUSR2\n");
    kill(getpid(), SIGUSR2);

    fprintf(stderr, "Sending SIGUSR1\n");
    kill(getpid(), SIGUSR1);

#if USE_SIGSTACK
    /* now remove alt stack */
    free(sigstack.ss_sp);
    sigstack.ss_sp = 0;
    sigstack.ss_size = 0;
    sigstack.ss_flags = SS_DISABLE;
    rc = sigaltstack(&sigstack, NULL);
    ASSERT_NOERR(rc);
#endif

    fprintf(stderr, "Generating SIGSEGV\n");
#if USE_LONGJMP
    res = setjmp(env);
    if (res == 0) {
	*((int *)0) = 4;
    }
#else
    kill(getpid(), SIGSEGV);
#endif

    for (i=0; i<ITERS; i++) {
	if (i % 2 == 0) {
	    res += cos(1./(double)(i+1));
	} else {
	    res += sin(1./(double)(i+1));
	}
	j = (i << 4) / (i | 0x38);
	a[i] += j;
    }
    fprintf(stderr, "%f\n", res);

#if USE_TIMER
    memset(&t, 0, sizeof(t));
    rc = setitimer(ITIMER_VIRTUAL, &t, NULL);
    ASSERT_NOERR(rc);

    if (timer_hits == 0)
	fprintf(stderr, "Got 0 timer hits!\n");
    else
	fprintf(stderr, "Got some timer hits!\n");
#endif

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}
Beispiel #21
0
int
main()
{
    int round;
    int t;

    GET_NTDLL(NtTerminateProcess, (IN HANDLE ProcessHandle OPTIONAL,
                                   IN NTSTATUS ExitStatus));

    INIT();

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    for (round = 0; round < ROUNDS; round++) {
#ifdef VERBOSE
        print("round %d\n", round);
#endif
        if (round > 0) {
            /* clean up first */
            NtTerminateProcess(0 /* everyone but me */, 666);
#ifdef VERBOSE
            print("all alone again %d\n", round);
#endif VERBOSE
        }

        global_started = 0;
        global_finished = 0;

        for (t = 0; t < TOTAL_THREADS; t++) {
            thread[t] = (HANDLE)create_thread(executor);
            if (thread[t] == NULL)
                print("GLE: %d\n", GetLastError());
            assert(thread[t] != NULL);
        }

#ifdef VERBOSE
        print("started %d threads\n", TOTAL_THREADS);
#else
        print("started some threads\n");
#endif

        /* wait for some to start */
        while (global_started < WAIT_TO_START)
            YIELD();

        /* wait for some work to get done */
        while (global_finished < WAIT_TO_FINISH)
            YIELD();
#ifdef VERBOSE
        print("some %d work, done %d\n", global_started, global_finished);
#endif
    }

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif

    print("done\n");
    return 0;
}
Beispiel #22
0
int main(int argc, char** argv)
{
    HANDLE lib;
    HANDLE event;
    ULONG_PTR hThread;
    int reloaded = 0;

    USE_USER32();

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

#ifdef LINUX
    /* though win32/ */
    intercept_signal(SIGSEGV, signal_handler);
#else
    /* note that can't normally if we have a debugger attached this
     * will not get this executed */
    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) our_top_handler);
#endif

    event = CreateEvent(NULL, TRUE, FALSE, NULL);
    hThread = _beginthreadex(NULL, 0, run_func, event, 0, NULL);

    /* need to run as long as necessary to hit the required faults */
    while (transitions < NUM_TRANSITIONS) {
        lib = LoadLibrary("win32.reload-race.dll.dll");
        if (lib == NULL) {
            print("error loading library\n");
            break;
        } else {
            reloaded++;
#if VERBOSE
    print("reloaded %d times %d\n", reloaded);
#endif
            import1 = (funptr)
                GetProcAddress(lib, (LPCSTR)"import_me1");
            import2 = (funptr)
                GetProcAddress(lib, (LPCSTR)"import_me2");
            /* may want to explicitly sleep here but that may be slower */
            if (reloaded % 2 == 0)
                YIELD();
            FreeLibrary(lib);
            if (reloaded % 3 == 0)
                YIELD();
        }
    }

    SetEvent(event);
    WaitForSingleObject((HANDLE)hThread, INFINITE);
    print("main loop done\n");
    check_mem_usage();
#if VERBOSE
    print("reloaded %d times %d\n", reloaded);
#endif


#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif
    return 0;
}
Beispiel #23
0
int
main()
{
    int round;
    int b, t;
    int res;

    INIT();

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif


    /* this doesn't do much in fact */
    res = SetProcessWorkingSetSize(GetCurrentProcess(),
                                   MINSIZE_KB*1024,
                                   MAXSIZE_KB*1024);
    // on Win2003 there is a SetProcessWorkingSetSizeEx that sets QUOTA_LIMITS_HARDWS_ENABLE


    if (res == 0)
        print("SetProcessWorkingSetSize failed GLE: %d\n", GetLastError());

    for (round = 0; round < ROUNDS; round++) {
#ifdef VERBOSE
        print("round %d\n", round);
#endif
        global_started = 0;
        global_finished = 0;

        /* do in a batch */
        for (b = 0; b < TOTAL_THREADS / BATCH_SIZE; b++) {
            for (t = 0; t < BATCH_SIZE; t++) {
                thread[t] = create_thread(executor);
                if (thread[t] == NULL)
                    print("GLE: %d\n", GetLastError());
                assert(thread[t] != NULL);
            }
            /* now synchronize with all of them - or maybe some? */

#ifdef VERBOSE
            print("started %d threads\n", TOTAL_THREADS);
#else
#ifndef SILENT
            print("started some threads\n");
#endif
#endif
            for (t = 0; t < BATCH_SIZE; t++) {
                assert(thread[t] != NULL);
                join_thread(thread[t]);
                CloseHandle((HANDLE)thread[t]);
                thread[t] = NULL; /* in case want to synch with some in a batch, but with all at the end */

                if (SWAP_OUT_AFTER_THREAD) {
                    res = SetProcessWorkingSetSize(GetCurrentProcess(),
                                                   -1, -1);
                }
            }
#ifdef VERBOSE
            print("some %d work, done %d\n", global_started, global_finished);
#endif
            if (SWAP_OUT_AFTER_BATCH) {
                res = SetProcessWorkingSetSize(GetCurrentProcess(),
                                               -1, -1);
            }
        }
    }

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif

    print("done\n");
    return 0;
}
Beispiel #24
0
int
main(void)
{
    HANDLE ht;
    DWORD tid;
    CONTEXT tc;

#ifdef USE_DYNAMO
    dynamorio_app_init();
    dynamorio_app_start();
#endif

    control = 0;
    start_addr = 0;

    ht = CreateThread(NULL, 0, &ThreadProc1, NULL, 0, &tid);

    while (start_addr == 0)
        ; /* wait for thread to set start_addr */

    SuspendThread(ht);

    memset(&tc, 0, sizeof(tc));
    tc.ContextFlags = CONTEXT_CONTROL;
    GetThreadContext(ht, &tc);
    assert(tc.ContextFlags == CONTEXT_CONTROL);
    /* 16 bytes is through je wait4control */
    if (tc.CXT_XIP >= start_addr && tc.CXT_XIP <= start_addr + 0x10)
        print("eip is valid\n");
    else
        print("invalid eip: %p\n", (void *)tc.CXT_XIP);

    /* test non-CONTROL flags */
    memset(&tc, 0, sizeof(tc));
    tc.ContextFlags = CONTEXT_INTEGER;
    GetThreadContext(ht, &tc);
    assert(tc.ContextFlags == CONTEXT_INTEGER);
    if (tc.CXT_XAX == 0xdeadbeef)
        print("eax is valid\n");
    else
        print("invalid eax: %p\n", (void *)tc.CXT_XAX);

    control = 1; /* stop thread */
    ResumeThread(ht);
    WaitForSingleObject(ht, INFINITE);

    /* try getting own context (technically you're not supposed to do this, msdn says
     * result is undefined, but we should handle it reasonably */
    tc.ContextFlags = CONTEXT_FULL;
    GetThreadContext(GetCurrentThread(), &tc);
    /* FIXME - ok we got some result, what can we do to check it? we shouldn't screw up
     * the reg state, so ignore that, pc should be the post syscall pc (based on
     * observations of native behavior) so either in ntdll.dll or vsyscall page */
    print("get context self eip > 0x74000000? %s\n",
          tc.CXT_XIP > 0x74000000 ? "yes" : "no");

#ifdef USE_DYNAMO
    dynamorio_app_stop();
    dynamorio_app_exit();
#endif

    print("done\n");

    return 0;
}