From 133c9295f56d0bbf71931efb7129f3e4642286cd Mon Sep 17 00:00:00 2001 From: jsteube Date: Thu, 29 Sep 2016 23:49:33 +0200 Subject: [PATCH] Cleaned up data_t, only contexts left --- include/induct.h | 2 +- include/opencl.h | 2 +- include/terminal.h | 4 +- include/types.h | 82 +++++++++++++++++++---------------- src/dispatch.c | 34 +++++++-------- src/hashcat.c | 101 +++++++++++++++++--------------------------- src/induct.c | 4 +- src/monitor.c | 10 ++--- src/opencl.c | 14 ++---- src/outfile_check.c | 2 +- src/restore.c | 2 +- src/status.c | 44 +++++++++++-------- src/terminal.c | 12 +++--- src/thread.c | 14 +++--- 14 files changed, 158 insertions(+), 169 deletions(-) diff --git a/include/induct.h b/include/induct.h index ebb4b0274..4864494ed 100644 --- a/include/induct.h +++ b/include/induct.h @@ -12,7 +12,7 @@ static const char INDUCT_DIR[] = "induct"; -int induct_ctx_init (induct_ctx_t *induct_ctx, const user_options_t *user_options, const folder_config_t *folder_config, const time_t proc_start); +int induct_ctx_init (induct_ctx_t *induct_ctx, const user_options_t *user_options, const folder_config_t *folder_config, const status_ctx_t *status_ctx); void induct_ctx_scan (induct_ctx_t *induct_ctx); void induct_ctx_cleanup (induct_ctx_t *induct_ctx); void induct_ctx_destroy (induct_ctx_t *induct_ctx); diff --git a/include/opencl.h b/include/opencl.h index b095f2205..69a668428 100644 --- a/include/opencl.h +++ b/include/opencl.h @@ -41,7 +41,7 @@ void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx); int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const user_options_t *user_options); void opencl_ctx_devices_destroy (opencl_ctx_t *opencl_ctx); -void opencl_ctx_devices_update_power (opencl_ctx_t *opencl_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra); +void opencl_ctx_devices_update_power (opencl_ctx_t *opencl_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, status_ctx_t *status_ctx); void opencl_ctx_devices_kernel_loops (opencl_ctx_t *opencl_ctx, const user_options_extra_t *user_options_extra, const hashconfig_t *hashconfig, const hashes_t *hashes, straight_ctx_t *straight_ctx, combinator_ctx_t *combinator_ctx, mask_ctx_t *mask_ctx); int opencl_session_begin (opencl_ctx_t *opencl_ctx, hashconfig_t *hashconfig, const hashes_t *hashes, const straight_ctx_t *straight_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, const folder_config_t *folder_config, const bitmap_ctx_t *bitmap_ctx, const tuning_db_t *tuning_db); diff --git a/include/terminal.h b/include/terminal.h index b55f56ea4..540a83fb2 100644 --- a/include/terminal.h +++ b/include/terminal.h @@ -23,8 +23,8 @@ #include #endif // _WIN -void welcome_screen (const user_options_t *user_options, const time_t proc_start); -void goodbye_screen (const user_options_t *user_options, const time_t proc_start, const time_t proc_stop); +void welcome_screen (const user_options_t *user_options, const status_ctx_t *status_ctx); +void goodbye_screen (const user_options_t *user_options, const status_ctx_t *status_ctx); int setup_console (); diff --git a/include/types.h b/include/types.h index 648078fa3..2f6571e14 100644 --- a/include/types.h +++ b/include/types.h @@ -721,9 +721,6 @@ typedef struct int force_jit_compilation; - hc_thread_mutex_t mux_dispatcher; - hc_thread_mutex_t mux_counter; - } opencl_ctx_t; #if defined (__APPLE__) @@ -1219,26 +1216,68 @@ typedef struct typedef struct { + /** + * main status + */ + u32 devices_status; + /** + * thread control + */ + bool run_main_level1; bool run_main_level2; bool run_main_level3; bool run_thread_level1; bool run_thread_level2; + bool shutdown_inner; + bool shutdown_outer; + + hc_thread_mutex_t mux_dispatcher; + hc_thread_mutex_t mux_counter; + hc_thread_mutex_t mux_hwmon; + hc_thread_mutex_t mux_display; + + /** + * workload + */ + + u64 words_cnt; + u64 words_cur; + u64 words_base; + + /** + * progress + */ + u64 *words_progress_done; // progress number of words done per salt u64 *words_progress_rejected; // progress number of words rejected per salt u64 *words_progress_restored; // progress number of words restored per salt + /** + * timer + */ + + time_t runtime_start; + time_t runtime_stop; + + time_t prepare_start; + time_t prepare_time; + + time_t proc_start; + time_t proc_stop; + + hc_timer_t timer_running; // timer on current dict + hc_timer_t timer_paused; // timer on current dict + + double ms_paused; // timer on current dict + } status_ctx_t; typedef struct { - /** - * migrated - */ - bitmap_ctx_t *bitmap_ctx; combinator_ctx_t *combinator_ctx; cpt_ctx_t *cpt_ctx; @@ -1261,35 +1300,6 @@ typedef struct user_options_extra_t *user_options_extra; user_options_t *user_options; - /** - * threads - */ - - bool shutdown_inner; - bool shutdown_outer; - - /** - * status, timer - */ - - time_t runtime_start; - time_t runtime_stop; - - time_t prepare_start; - time_t prepare_time; - - time_t proc_start; - time_t proc_stop; - - u64 words_cnt; - u64 words_cur; - u64 words_base; - - hc_timer_t timer_running; // timer on current dict - hc_timer_t timer_paused; // timer on current dict - - double ms_paused; // timer on current dict - } hc_global_data_t; #endif // _TYPES_H diff --git a/src/dispatch.c b/src/dispatch.c index b4feff98c..fc946c418 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -75,12 +75,12 @@ static u32 get_power (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param) return device_param->kernel_power; } -static uint get_work (opencl_ctx_t *opencl_ctx, const user_options_t *user_options, hc_device_param_t *device_param, const u64 max) +static uint get_work (opencl_ctx_t *opencl_ctx, status_ctx_t *status_ctx, const user_options_t *user_options, hc_device_param_t *device_param, const u64 max) { - hc_thread_mutex_lock (opencl_ctx->mux_dispatcher); + hc_thread_mutex_lock (status_ctx->mux_dispatcher); - const u64 words_cur = data.words_cur; - const u64 words_base = (user_options->limit == 0) ? data.words_base : MIN (user_options->limit, data.words_base); + const u64 words_cur = status_ctx->words_cur; + const u64 words_base = (user_options->limit == 0) ? status_ctx->words_base : MIN (user_options->limit, status_ctx->words_base); device_param->words_off = words_cur; @@ -102,9 +102,9 @@ static uint get_work (opencl_ctx_t *opencl_ctx, const user_options_t *user_optio work = MIN (work, max); - data.words_cur += work; + status_ctx->words_cur += work; - hc_thread_mutex_unlock (opencl_ctx->mux_dispatcher); + hc_thread_mutex_unlock (status_ctx->mux_dispatcher); return work; } @@ -133,11 +133,11 @@ void *thread_calc_stdin (void *p) while (status_ctx->run_thread_level1 == true) { - hc_thread_mutex_lock (opencl_ctx->mux_dispatcher); + hc_thread_mutex_lock (status_ctx->mux_dispatcher); if (feof (stdin) != 0) { - hc_thread_mutex_unlock (opencl_ctx->mux_dispatcher); + hc_thread_mutex_unlock (status_ctx->mux_dispatcher); break; } @@ -184,14 +184,14 @@ void *thread_calc_stdin (void *p) { if ((line_len < hashconfig->pw_min) || (line_len > hashconfig->pw_max)) { - hc_thread_mutex_lock (opencl_ctx->mux_counter); + hc_thread_mutex_lock (status_ctx->mux_counter); for (uint salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) { status_ctx->words_progress_rejected[salt_pos] += straight_ctx->kernel_rules_cnt; } - hc_thread_mutex_unlock (opencl_ctx->mux_counter); + hc_thread_mutex_unlock (status_ctx->mux_counter); continue; } @@ -204,7 +204,7 @@ void *thread_calc_stdin (void *p) while (status_ctx->run_thread_level1 == false) break; } - hc_thread_mutex_unlock (opencl_ctx->mux_dispatcher); + hc_thread_mutex_unlock (status_ctx->mux_dispatcher); while (status_ctx->run_thread_level1 == false) break; @@ -267,7 +267,7 @@ void *thread_calc (void *p) { while (status_ctx->run_thread_level1 == true) { - const uint work = get_work (opencl_ctx, user_options, device_param, -1u); + const uint work = get_work (opencl_ctx, status_ctx, user_options, device_param, -1u); if (work == 0) break; @@ -379,7 +379,7 @@ void *thread_calc (void *p) while (max) { - const uint work = get_work (opencl_ctx, user_options, device_param, max); + const uint work = get_work (opencl_ctx, status_ctx, user_options, device_param, max); if (work == 0) break; @@ -424,14 +424,14 @@ void *thread_calc (void *p) { max++; - hc_thread_mutex_lock (opencl_ctx->mux_counter); + hc_thread_mutex_lock (status_ctx->mux_counter); for (uint salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) { status_ctx->words_progress_rejected[salt_pos] += straight_ctx->kernel_rules_cnt; } - hc_thread_mutex_unlock (opencl_ctx->mux_counter); + hc_thread_mutex_unlock (status_ctx->mux_counter); continue; } @@ -445,14 +445,14 @@ void *thread_calc (void *p) { max++; - hc_thread_mutex_lock (opencl_ctx->mux_counter); + hc_thread_mutex_lock (status_ctx->mux_counter); for (uint salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) { status_ctx->words_progress_rejected[salt_pos] += combinator_ctx->combs_cnt; } - hc_thread_mutex_unlock (opencl_ctx->mux_counter); + hc_thread_mutex_unlock (status_ctx->mux_counter); continue; } diff --git a/src/hashcat.c b/src/hashcat.c index 38578caa2..bb527f03f 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -57,9 +57,6 @@ extern hc_global_data_t data; extern int SUPPRESS_OUTPUT; -extern hc_thread_mutex_t mux_hwmon; -extern hc_thread_mutex_t mux_display; - extern const int DEFAULT_BENCHMARK_ALGORITHMS_CNT; extern const int DEFAULT_BENCHMARK_ALGORITHMS_BUF[]; @@ -82,25 +79,25 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, status_progress_reset (status_ctx, hashes); - data.words_cur = 0; + status_ctx->words_cur = 0; restore_data_t *rd = restore_ctx->rd; if (rd->words_cur) { - data.words_cur = rd->words_cur; + status_ctx->words_cur = rd->words_cur; user_options->skip = 0; } if (user_options->skip) { - data.words_cur = user_options->skip; + status_ctx->words_cur = user_options->skip; user_options->skip = 0; } - data.ms_paused = 0; + status_ctx->ms_paused = 0; opencl_session_reset (opencl_ctx); @@ -137,11 +134,11 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, return -1; } - data.words_cnt = count_words (wl_data, user_options, user_options_extra, straight_ctx, combinator_ctx, fd2, straight_ctx->dict, dictstat_ctx); + status_ctx->words_cnt = count_words (wl_data, user_options, user_options_extra, straight_ctx, combinator_ctx, fd2, straight_ctx->dict, dictstat_ctx); fclose (fd2); - if (data.words_cnt == 0) + if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); @@ -165,7 +162,7 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, return -1; } - data.words_cnt = count_words (wl_data, user_options, user_options_extra, straight_ctx, combinator_ctx, fd2, combinator_ctx->dict1, dictstat_ctx); + status_ctx->words_cnt = count_words (wl_data, user_options, user_options_extra, straight_ctx, combinator_ctx, fd2, combinator_ctx->dict1, dictstat_ctx); fclose (fd2); } @@ -180,12 +177,12 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, return -1; } - data.words_cnt = count_words (wl_data, user_options, user_options_extra, straight_ctx, combinator_ctx, fd2, combinator_ctx->dict2, dictstat_ctx); + status_ctx->words_cnt = count_words (wl_data, user_options, user_options_extra, straight_ctx, combinator_ctx, fd2, combinator_ctx->dict2, dictstat_ctx); fclose (fd2); } - if (data.words_cnt == 0) + if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); @@ -215,11 +212,11 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, return -1; } - data.words_cnt = count_words (wl_data, user_options, user_options_extra, straight_ctx, combinator_ctx, fd2, straight_ctx->dict, dictstat_ctx); + status_ctx->words_cnt = count_words (wl_data, user_options, user_options_extra, straight_ctx, combinator_ctx, fd2, straight_ctx->dict, dictstat_ctx); fclose (fd2); - if (data.words_cnt == 0) + if (status_ctx->words_cnt == 0) { logfile_sub_msg ("STOP"); @@ -231,7 +228,7 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, logfile_sub_string (mask_ctx->mask); } - u64 words_base = data.words_cnt; + u64 words_base = status_ctx->words_cnt; if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) { @@ -255,7 +252,7 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, } } - data.words_base = words_base; + status_ctx->words_base = words_base; if (user_options->keyspace == true) { @@ -264,34 +261,34 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, return 0; } - if (data.words_cur > data.words_base) + if (status_ctx->words_cur > status_ctx->words_base) { log_error ("ERROR: Restore value greater keyspace"); return -1; } - if (data.words_cur) + if (status_ctx->words_cur) { if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) { for (uint i = 0; i < hashes->salts_cnt; i++) { - status_ctx->words_progress_restored[i] = data.words_cur * straight_ctx->kernel_rules_cnt; + status_ctx->words_progress_restored[i] = status_ctx->words_cur * straight_ctx->kernel_rules_cnt; } } else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { for (uint i = 0; i < hashes->salts_cnt; i++) { - status_ctx->words_progress_restored[i] = data.words_cur * combinator_ctx->combs_cnt; + status_ctx->words_progress_restored[i] = status_ctx->words_cur * combinator_ctx->combs_cnt; } } else if (user_options_extra->attack_kern == ATTACK_KERN_BF) { for (uint i = 0; i < hashes->salts_cnt; i++) { - status_ctx->words_progress_restored[i] = data.words_cur * mask_ctx->bfs_cnt; + status_ctx->words_progress_restored[i] = status_ctx->words_cur * mask_ctx->bfs_cnt; } } } @@ -331,7 +328,7 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, * autotune modified kernel_accel, which modifies opencl_ctx->kernel_power_all */ - opencl_ctx_devices_update_power (opencl_ctx, user_options, user_options_extra); + opencl_ctx_devices_update_power (opencl_ctx, user_options, user_options_extra, status_ctx); /** * Begin loopback recording @@ -363,15 +360,15 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, * Prepare cracking stats */ - hc_timer_set (&data.timer_running); + hc_timer_set (&status_ctx->timer_running); time_t runtime_start; time (&runtime_start); - data.runtime_start = runtime_start; + status_ctx->runtime_start = runtime_start; - data.prepare_time = runtime_start - data.prepare_start; + status_ctx->prepare_time = runtime_start - status_ctx->prepare_start; /** * create cracker threads @@ -415,12 +412,12 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, time (&runtime_stop); - data.runtime_stop = runtime_stop; + status_ctx->runtime_stop = runtime_stop; logfile_sub_uint (runtime_start); logfile_sub_uint (runtime_stop); - time (&data.prepare_start); + time (&status_ctx->prepare_start); logfile_sub_msg ("STOP"); @@ -684,7 +681,7 @@ static int inner1_loop (status_ctx_t *status_ctx, user_options_t *user_options, sp_tbl_to_css (mask_ctx->root_table_buf, mask_ctx->markov_table_buf, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, user_options->markov_threshold, uniq_tbls); - data.words_cnt = sp_get_sum (0, mask_ctx->css_cnt, mask_ctx->root_css_buf); + status_ctx->words_cnt = sp_get_sum (0, mask_ctx->css_cnt, mask_ctx->root_css_buf); // copy + args @@ -1190,7 +1187,7 @@ static int outer_loop (status_ctx_t *status_ctx, user_options_t *user_options, u * setup prepare timer */ - time (&data.prepare_start); + time (&status_ctx->prepare_start); /** * setup variables and buffers depending on hash_mode @@ -1503,7 +1500,7 @@ static int outer_loop (status_ctx_t *status_ctx, user_options_t *user_options, u hc_thread_t *inner_threads = (hc_thread_t *) mycalloc (10, sizeof (hc_thread_t)); - data.shutdown_inner = false; + status_ctx->shutdown_inner = false; /** * Outfile remove @@ -1577,7 +1574,7 @@ static int outer_loop (status_ctx_t *status_ctx, user_options_t *user_options, u // wait for inner threads - data.shutdown_inner = true; + status_ctx->shutdown_inner = true; for (uint thread_idx = 0; thread_idx < inner_threads_cnt; thread_idx++) { @@ -1656,21 +1653,6 @@ int main (int argc, char **argv) setup_umask (); - /** - * Real init - */ - - memset (&data, 0, sizeof (hc_global_data_t)); - - time_t proc_start; - - time (&proc_start); - - data.proc_start = proc_start; - - hc_thread_mutex_init (mux_display); - hc_thread_mutex_init (mux_hwmon); - /** * status init */ @@ -1773,7 +1755,7 @@ int main (int argc, char **argv) * - this is giving us a visual header before preparations start, so we do not need to clear them afterwards */ - welcome_screen (user_options, proc_start); + welcome_screen (user_options, status_ctx); /** * logfile init @@ -1809,7 +1791,7 @@ int main (int argc, char **argv) data.induct_ctx = induct_ctx; - const int rc_induct_ctx_init = induct_ctx_init (induct_ctx, user_options, folder_config, proc_start); + const int rc_induct_ctx_init = induct_ctx_init (induct_ctx, user_options, folder_config, status_ctx); if (rc_induct_ctx_init == -1) return -1; @@ -1947,7 +1929,7 @@ int main (int argc, char **argv) hc_thread_t *outer_threads = (hc_thread_t *) mycalloc (10, sizeof (hc_thread_t)); - data.shutdown_outer = false; + status_ctx->shutdown_outer = false; if (user_options->keyspace == false && user_options->benchmark == false && user_options->stdout_flag == false) { @@ -1996,7 +1978,7 @@ int main (int argc, char **argv) // wait for outer threads - data.shutdown_outer = true; + status_ctx->shutdown_outer = true; for (uint thread_idx = 0; thread_idx < outer_threads_cnt; thread_idx++) { @@ -2010,11 +1992,6 @@ int main (int argc, char **argv) user_options->quiet = false; } - // destroy others mutex - - hc_thread_mutex_delete (mux_display); - hc_thread_mutex_delete (mux_hwmon); - // free memory debugfile_destroy (debugfile_ctx); @@ -2041,20 +2018,20 @@ int main (int argc, char **argv) opencl_ctx_devices_destroy (opencl_ctx); + opencl_ctx_destroy (opencl_ctx); + restore_ctx_destroy (restore_ctx); - time_t proc_stop; + time (&status_ctx->proc_stop); - time (&proc_stop); - - logfile_top_uint (proc_start); - logfile_top_uint (proc_stop); + logfile_top_uint (status_ctx->proc_start); + logfile_top_uint (status_ctx->proc_stop); logfile_top_msg ("STOP"); logfile_destroy (logfile_ctx); - goodbye_screen (user_options, proc_start, proc_stop); + goodbye_screen (user_options, status_ctx); user_options_destroy (user_options); @@ -2065,8 +2042,6 @@ int main (int argc, char **argv) if (status_ctx->devices_status == STATUS_EXHAUSTED) rc_final = 1; if (status_ctx->devices_status == STATUS_CRACKED) rc_final = 0; - opencl_ctx_destroy (opencl_ctx); - status_ctx_destroy (status_ctx); return rc_final; diff --git a/src/induct.c b/src/induct.c index 33902ae4b..14bad34e5 100644 --- a/src/induct.c +++ b/src/induct.c @@ -21,7 +21,7 @@ static int sort_by_mtime (const void *p1, const void *p2) return s2.st_mtime - s1.st_mtime; } -int induct_ctx_init (induct_ctx_t *induct_ctx, const user_options_t *user_options, const folder_config_t *folder_config, const time_t proc_start) +int induct_ctx_init (induct_ctx_t *induct_ctx, const user_options_t *user_options, const folder_config_t *folder_config, const status_ctx_t *status_ctx) { induct_ctx->enabled = false; @@ -47,7 +47,7 @@ int induct_ctx_init (induct_ctx_t *induct_ctx, const user_options_t *user_option { char *root_directory_mv = (char *) mymalloc (HCBUFSIZ_TINY); - snprintf (root_directory_mv, HCBUFSIZ_TINY - 1, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) proc_start); + snprintf (root_directory_mv, HCBUFSIZ_TINY - 1, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) status_ctx->proc_start); if (rename (root_directory, root_directory_mv) != 0) { diff --git a/src/monitor.c b/src/monitor.c index 3bfc34ead..36626efd4 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -112,7 +112,7 @@ void *thread_monitor (void *p) u32 remove_left = user_options->remove_timer; u32 status_left = user_options->status_timer; - while (data.shutdown_inner == false) + while (status_ctx->shutdown_inner == false) { hc_sleep (sleep_time); @@ -291,15 +291,15 @@ void *thread_monitor (void *p) } } - if ((runtime_check == true) && (data.runtime_start > 0)) + if ((runtime_check == true) && (status_ctx->runtime_start > 0)) { - double ms_paused = data.ms_paused; + double ms_paused = status_ctx->ms_paused; if (status_ctx->devices_status == STATUS_PAUSED) { double ms_paused_tmp = 0; - hc_timer_get (data.timer_paused, ms_paused_tmp); + hc_timer_get (status_ctx->timer_paused, ms_paused_tmp); ms_paused += ms_paused_tmp; } @@ -308,7 +308,7 @@ void *thread_monitor (void *p) time (&runtime_cur); - int runtime_left = data.proc_start + user_options->runtime + data.prepare_time + (ms_paused / 1000) - runtime_cur; + int runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (ms_paused / 1000) - runtime_cur; if (runtime_left <= 0) { diff --git a/src/opencl.c b/src/opencl.c index 9c3a7ecac..42262c8e2 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -1299,11 +1299,11 @@ int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hash u64 perf_sum_all = (u64) pws_cnt * (u64) innerloop_left; - hc_thread_mutex_lock (opencl_ctx->mux_counter); + hc_thread_mutex_lock (status_ctx->mux_counter); status_ctx->words_progress_done[salt_pos] += perf_sum_all; - hc_thread_mutex_unlock (opencl_ctx->mux_counter); + hc_thread_mutex_unlock (status_ctx->mux_counter); /** * speed @@ -1359,9 +1359,6 @@ int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const user_options_t *user_option if (user_options->left == true) return 0; if (user_options->keyspace == true) return 0; - hc_thread_mutex_init (opencl_ctx->mux_dispatcher); - hc_thread_mutex_init (opencl_ctx->mux_counter); - opencl_ctx->ocl = (OCL_PTR *) mymalloc (sizeof (OCL_PTR)); hc_device_param_t *devices_param = (hc_device_param_t *) mycalloc (DEVICES_MAX, sizeof (hc_device_param_t)); @@ -1534,9 +1531,6 @@ void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx) myfree (opencl_ctx->platform_devices); - hc_thread_mutex_delete (opencl_ctx->mux_counter); - hc_thread_mutex_delete (opencl_ctx->mux_dispatcher); - myfree (opencl_ctx); } @@ -2454,7 +2448,7 @@ void opencl_ctx_devices_destroy (opencl_ctx_t *opencl_ctx) opencl_ctx->need_xnvctrl = 0; } -void opencl_ctx_devices_update_power (opencl_ctx_t *opencl_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra) +void opencl_ctx_devices_update_power (opencl_ctx_t *opencl_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra, status_ctx_t *status_ctx) { u32 kernel_power_all = 0; @@ -2473,7 +2467,7 @@ void opencl_ctx_devices_update_power (opencl_ctx_t *opencl_ctx, const user_optio if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - if (data.words_base < kernel_power_all) + if (status_ctx->words_base < kernel_power_all) { if (user_options->quiet == false) { diff --git a/src/outfile_check.c b/src/outfile_check.c index d868c4210..4ca6ad6b3 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -74,7 +74,7 @@ void *thread_outfile_remove (void *p) uint check_left = outfile_check_timer; // or 1 if we want to check it at startup - while (data.shutdown_inner == false) + while (status_ctx->shutdown_inner == false) { hc_sleep (1); diff --git a/src/restore.c b/src/restore.c index 93ceac971..e20abc2f4 100644 --- a/src/restore.c +++ b/src/restore.c @@ -40,7 +40,7 @@ u64 get_lowest_words_done (const restore_ctx_t *restore_ctx, const opencl_ctx_t // It's possible that a device's workload isn't finished right after a restore-case. // In that case, this function would return 0 and overwrite the real restore point - // There's also data.words_cur which is set to rd->words_cur but it changes while + // There's also status_ctx->words_cur which is set to rd->words_cur but it changes while // the attack is running therefore we should stick to rd->words_cur. // Note that -s influences rd->words_cur we should keep a close look on that. diff --git a/src/status.c b/src/status.c index 4d981e8c2..264a6aaa8 100644 --- a/src/status.c +++ b/src/status.c @@ -233,7 +233,7 @@ void status_display_machine_readable (status_ctx_t *status_ctx, opencl_ctx_t *op * counter */ - u64 progress_total = data.words_cnt * hashes->salts_cnt; + u64 progress_total = status_ctx->words_cnt * hashes->salts_cnt; u64 all_done = 0; u64 all_rejected = 0; @@ -253,7 +253,7 @@ void status_display_machine_readable (status_ctx_t *status_ctx, opencl_ctx_t *op if (user_options->skip) { - progress_skip = MIN (user_options->skip, data.words_base) * hashes->salts_cnt; + progress_skip = MIN (user_options->skip, status_ctx->words_base) * hashes->salts_cnt; if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt; @@ -262,7 +262,7 @@ void status_display_machine_readable (status_ctx_t *status_ctx, opencl_ctx_t *op if (user_options->limit) { - progress_end = MIN (user_options->limit, data.words_base) * hashes->salts_cnt; + progress_end = MIN (user_options->limit, status_ctx->words_base) * hashes->salts_cnt; if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= straight_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= combinator_ctx->combs_cnt; @@ -323,7 +323,7 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h } // in this case some required buffers are free'd, ascii_digest() would run into segfault - if (data.shutdown_inner == 1) return; + if (status_ctx->shutdown_inner == 1) return; if (user_options->machine_readable == true) { @@ -625,15 +625,15 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h double ms_running = 0; - hc_timer_get (data.timer_running, ms_running); + hc_timer_get (status_ctx->timer_running, ms_running); - double ms_paused = data.ms_paused; + double ms_paused = status_ctx->ms_paused; if (status_ctx->devices_status == STATUS_PAUSED) { double ms_paused_tmp = 0; - hc_timer_get (data.timer_paused, ms_paused_tmp); + hc_timer_get (status_ctx->timer_paused, ms_paused_tmp); ms_paused += ms_paused_tmp; } @@ -674,7 +674,7 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h format_timer_display (&tm_run, display_run, sizeof (tm_run)); - char *start = ctime (&data.proc_start); + char *start = ctime (&status_ctx->proc_start); size_t start_len = strlen (start); @@ -693,7 +693,7 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h * counters */ - u64 progress_total = data.words_cnt * hashes->salts_cnt; + u64 progress_total = status_ctx->words_cnt * hashes->salts_cnt; u64 all_done = 0; u64 all_rejected = 0; @@ -715,7 +715,7 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h + status_ctx->words_progress_rejected[salt_pos] + status_ctx->words_progress_restored[salt_pos]; - const u64 left = data.words_cnt - all; + const u64 left = status_ctx->words_cnt - all; progress_noneed += left; } @@ -728,7 +728,7 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h if (user_options->skip) { - progress_skip = MIN (user_options->skip, data.words_base) * hashes->salts_cnt; + progress_skip = MIN (user_options->skip, status_ctx->words_base) * hashes->salts_cnt; if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt; @@ -737,7 +737,7 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h if (user_options->limit) { - progress_end = MIN (user_options->limit, data.words_base) * hashes->salts_cnt; + progress_end = MIN (user_options->limit, status_ctx->words_base) * hashes->salts_cnt; if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= straight_ctx->kernel_rules_cnt; else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= combinator_ctx->combs_cnt; @@ -819,13 +819,13 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h #if defined (_WIN) - __time64_t runtime_left = data.proc_start + user_options->runtime + data.prepare_time + (ms_paused / 1000) - runtime_cur; + __time64_t runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (ms_paused / 1000) - runtime_cur; tmp = _gmtime64 (&runtime_left); #else - time_t runtime_left = data.proc_start + user_options->runtime + data.prepare_time + (ms_paused / 1000) - runtime_cur; + time_t runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (ms_paused / 1000) - runtime_cur; tmp = gmtime (&runtime_left); @@ -958,7 +958,7 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h u64 restore_point = get_lowest_words_done (restore_ctx, opencl_ctx); - u64 restore_total = data.words_base; + u64 restore_total = status_ctx->words_base; double percent_restore = 0; @@ -1160,7 +1160,7 @@ void status_benchmark (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const return; } - if (data.shutdown_inner == 1) return; + if (status_ctx->shutdown_inner == 1) return; if (user_options->machine_readable == true) { @@ -1283,12 +1283,22 @@ int status_ctx_init (status_ctx_t *status_ctx) status_ctx->run_thread_level1 = true; status_ctx->run_thread_level2 = true; + hc_thread_mutex_init (status_ctx->mux_dispatcher); + hc_thread_mutex_init (status_ctx->mux_counter); + hc_thread_mutex_init (status_ctx->mux_display); + hc_thread_mutex_init (status_ctx->mux_hwmon); + + time (&status_ctx->proc_start); + return 0; } void status_ctx_destroy (status_ctx_t *status_ctx) { - + hc_thread_mutex_delete (status_ctx->mux_dispatcher); + hc_thread_mutex_delete (status_ctx->mux_counter); + hc_thread_mutex_delete (status_ctx->mux_display); + hc_thread_mutex_delete (status_ctx->mux_hwmon); myfree (status_ctx); } diff --git a/src/terminal.c b/src/terminal.c index 48e62b65f..94a5c3f1e 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -38,7 +38,7 @@ extern const char *version_tag; const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint [q]uit => "; -void welcome_screen (const user_options_t *user_options, const time_t proc_start) +void welcome_screen (const user_options_t *user_options, const status_ctx_t *status_ctx) { if (user_options->quiet == true) return; if (user_options->keyspace == true) return; @@ -55,7 +55,7 @@ void welcome_screen (const user_options_t *user_options, const time_t proc_start } else { - log_info ("# %s (%s) %s", PROGNAME, version_tag, ctime (&proc_start)); + log_info ("# %s (%s) %s", PROGNAME, version_tag, ctime (&status_ctx->proc_start)); } } else if (user_options->restore == true) @@ -70,7 +70,7 @@ void welcome_screen (const user_options_t *user_options, const time_t proc_start } } -void goodbye_screen (const user_options_t *user_options, const time_t proc_start, const time_t proc_stop) +void goodbye_screen (const user_options_t *user_options, const status_ctx_t *status_ctx) { if (user_options->quiet == true) return; if (user_options->keyspace == true) return; @@ -78,8 +78,8 @@ void goodbye_screen (const user_options_t *user_options, const time_t proc_start if (user_options->show == true) return; if (user_options->left == true) return; - log_info_nn ("Started: %s", ctime (&proc_start)); - log_info_nn ("Stopped: %s", ctime (&proc_stop)); + log_info_nn ("Started: %s", ctime (&status_ctx->proc_start)); + log_info_nn ("Stopped: %s", ctime (&status_ctx->proc_stop)); } int setup_console () @@ -155,7 +155,7 @@ void *thread_keypress (void *p) tty_break (); - while (data.shutdown_outer == false) + while (status_ctx->shutdown_outer == false) { int ch = tty_getchar (); diff --git a/src/thread.c b/src/thread.c index d0b405b7a..4f9d43a43 100644 --- a/src/thread.c +++ b/src/thread.c @@ -51,7 +51,7 @@ BOOL WINAPI sigHandler_default (DWORD sig) * function otherwise it is too late (e.g. after returning from this function) */ - myabort (data.opencl_ctx); + myabort (data.status_ctx); SetConsoleCtrlHandler (NULL, TRUE); @@ -63,7 +63,7 @@ BOOL WINAPI sigHandler_default (DWORD sig) case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: - myabort (data.opencl_ctx); + myabort (data.status_ctx); SetConsoleCtrlHandler (NULL, TRUE); @@ -79,7 +79,7 @@ BOOL WINAPI sigHandler_benchmark (DWORD sig) { case CTRL_CLOSE_EVENT: - myquit (data.opencl_ctx); + myquit (data.status_ctx); SetConsoleCtrlHandler (NULL, TRUE); @@ -91,7 +91,7 @@ BOOL WINAPI sigHandler_benchmark (DWORD sig) case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: - myquit (data.opencl_ctx); + myquit (data.status_ctx); SetConsoleCtrlHandler (NULL, TRUE); @@ -198,7 +198,7 @@ void SuspendThreads (status_ctx_t *status_ctx) { if (status_ctx->devices_status != STATUS_RUNNING) return; - hc_timer_set (&data.timer_paused); + hc_timer_set (&status_ctx->timer_paused); status_ctx->devices_status = STATUS_PAUSED; @@ -211,9 +211,9 @@ void ResumeThreads (status_ctx_t *status_ctx) double ms_paused; - hc_timer_get (data.timer_paused, ms_paused); + hc_timer_get (status_ctx->timer_paused, ms_paused); - data.ms_paused += ms_paused; + status_ctx->ms_paused += ms_paused; status_ctx->devices_status = STATUS_RUNNING;