| 81 | } |
| 82 | |
| 83 | uc_err init(uc_engine *uc, int p_do_print_exit_info, uint64_t p_fuzz_consumption_timeout, uint64_t p_instr_limit, uint32_t global_timer_scale) { |
| 84 | // TODO: assumes shared endianness |
| 85 | // uc->mem_write(uc->ctx, CPUID_ADDR, &CPUID_CORTEX_M4, sizeof(CPUID_CORTEX_M4)); |
| 86 | |
| 87 | // Allocate memory for data managed by Fuzzware. |
| 88 | struct FwContext *ctx = malloc(sizeof(struct FwContext)); |
| 89 | memset(ctx, 0, sizeof(struct FwContext)); |
| 90 | uc->fw = ctx; |
| 91 | |
| 92 | // Configure default timer state. |
| 93 | ctx->config.timer_scale = global_timer_scale; |
| 94 | ctx->timers.end_ind = 0; |
| 95 | ctx->timers.num_inuse = 0; |
| 96 | ctx->timers.cur_interval = MAX_RELOAD_VAL; |
| 97 | ctx->timers.cur_countdown = MAX_RELOAD_VAL; |
| 98 | ctx->timers.global_ticker = 0; |
| 99 | |
| 100 | ctx->config.do_print_exit_info = p_do_print_exit_info; |
| 101 | |
| 102 | // Add fuzz consumption timeout as timer |
| 103 | ctx->config.fuzz_consumption_timeout = p_fuzz_consumption_timeout; |
| 104 | ctx->fuzz_consumption_timer_id = add_timer(&uc->fw->timers, p_fuzz_consumption_timeout, fuzz_consumption_timeout_cb, NULL, TIMER_IRQ_NOT_USED); |
| 105 | if(p_fuzz_consumption_timeout) { |
| 106 | start_timer(uc, ctx->fuzz_consumption_timer_id); |
| 107 | } |
| 108 | |
| 109 | #ifdef DEBUG_INJECT_TIMER |
| 110 | // debug timer to debug precise timing consistencies |
| 111 | start_timer(uc, add_timer(&uc->fw->timers, DEBUG_TIMER_TIMEOUT, test_timeout_cb, NULL, TIMER_IRQ_NOT_USED)); |
| 112 | #endif |
| 113 | |
| 114 | ctx->config.instr_limit = p_instr_limit; |
| 115 | ctx->instr_limit_timer_id = add_timer(&uc->fw->timers, p_instr_limit, instr_limit_timeout_cb, NULL, TIMER_IRQ_NOT_USED); |
| 116 | if(p_instr_limit) { |
| 117 | start_timer(uc, ctx->instr_limit_timer_id); |
| 118 | } |
| 119 | |
| 120 | return UC_ERR_OK; |
| 121 | } |
no test coverage detected