コード例 #1
0
ファイル: run.c プロジェクト: noka57/packetdrill
struct state *state_new(struct config *config,
                        struct script *script,
                        struct netdev *netdev)
{
	struct state *state = calloc(1, sizeof(struct state));

	if (pthread_mutex_init(&state->mutex, NULL) != 0)
		die_perror("pthread_mutex_init");

	run_lock(state);

	state->config = config;
	state->script = script;
	state->netdev = netdev;
	state->packets = packets_new();
	state->syscalls = syscalls_new(state);
	state->code = code_new(config);
	state->sockets = NULL;
	return state;
}
コード例 #2
0
ファイル: vm.c プロジェクト: mtasic85/nativetrap
void f() {
    // instructions and registers
    inst_array_t * insts = inst_array_new();
    reg_array_t * regs = reg_array_new();

    #define insts_append(op, a, b, c) \
        inst_array_append(insts, (inst_t){&&op, a, b, c})
    
    /*
    a = 10
    b = 2
    c = 200000000
    d = 7
    e = 1
    f = 0
    i = a

    while i < c:
        if i % d == 0:
            while i < c:
                i = i + e

                if i % d == f:
                    break
        else:
            i = i + b
    */

    // insttructions
    insts_append(int_const, 0, 10, D);       // a = 10
    insts_append(int_const, 1, 2, D);        // b = 2
    insts_append(int_const, 2, 200000000, D);// c = 200000000
    insts_append(int_const, 3, 7, D);        // d = 7
    insts_append(int_const, 4, 1, D);        // e = 1
    insts_append(int_const, 5, 0, D);        // f = 0
    insts_append(mov,   6,   0,   D);        // i = a
    insts_append(jlt,   6,   2,  16);        // while (i < c) {
    insts_append(mod,   7,   6,   3);        //   r7 = i % d
    insts_append(jeq,   7,   5,  10);        //   if (r7 == f) {
    insts_append(jlt,   6,   2,   7);        //     while (i < c) {
    insts_append(add,   6,   6,   4);        //       i += e
    insts_append(mod,   8,   6,   3);        //       r8 = i % d
    insts_append(jeq,   8,   5,   2);        //       if (r8 == f) {
    insts_append(jmp,   3,   D,   D);        //         break
    insts_append(nop,   D,   D,   D);        //       }
    insts_append(jmp,  -6,   D,   D);        //
    insts_append(nop,   D,   D,   D);        //     }
    insts_append(jmp,   3,   D,   D);        //
    insts_append(nop,   D,   D,   D);        //   } else {
    insts_append(add,   6,   6,   1);        //     i += b
    insts_append(nop,   D,   D,   D);        //   }
    insts_append(jmp, -15,   D,   D);        //
    insts_append(end,   D,   D,   D);        // }

    #ifdef NEW_APPROACH

    code * p = code_new();

    // a = 10
    // b = 2
    // c = 200000000
    // d = 7
    // e = 1
    // f = 0
    set_var(p, "a", (reg_t){.t = I, .v = (value_t){.i = 10}});