From 81bc9081ad845c1dd2aa71f961a582c105b9b20c Mon Sep 17 00:00:00 2001 From: jsteube Date: Wed, 28 Sep 2016 15:26:56 +0200 Subject: [PATCH] Prepare hwmon_ctx_t, not used yet --- include/hwmon.h | 3 +++ include/types.h | 19 +++++++++++++++++++ src/hashcat.c | 15 +++++++++++++++ src/hwmon.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) diff --git a/include/hwmon.h b/include/hwmon.h index e0e3a773b..dca6644fd 100644 --- a/include/hwmon.h +++ b/include/hwmon.h @@ -40,4 +40,7 @@ int hm_set_fanspeed_with_device_id_xnvctrl (const uint device_id, const int fa void hm_device_val_to_str (char *target_buf, int max_buf_size, char *suffix, int value); +int hwmon_ctx_init (hwmon_ctx_t *hwmon_ctx, const user_options_t *user_options); +void hwmon_ctx_destroy (hwmon_ctx_t *hwmon_ctx); + #endif // _HWMON_H diff --git a/include/types.h b/include/types.h index d27eed164..268358d72 100644 --- a/include/types.h +++ b/include/types.h @@ -1194,6 +1194,24 @@ typedef struct } mask_ctx_t; +typedef struct +{ + bool enabled; + + void *hm_adl; + void *hm_nvml; + void *hm_nvapi; + void *hm_xnvctrl; + + hm_attrs_t *hm_adapters_adl; + hm_attrs_t *hm_adapters_nvapi; + hm_attrs_t *hm_adapters_nvml; + hm_attrs_t *hm_adapters_xnvctrl; + + hm_attrs_t *hm_device; + +} hwmon_ctx_t; + typedef struct { /** @@ -1205,6 +1223,7 @@ typedef struct debugfile_ctx_t *debugfile_ctx; hashconfig_t *hashconfig; hashes_t *hashes; + hwmon_ctx_t *hwmon_ctx; induct_ctx_t *induct_ctx; logfile_ctx_t *logfile_ctx; loopback_ctx_t *loopback_ctx; diff --git a/src/hashcat.c b/src/hashcat.c index 0fb5ff487..06c2fd876 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -2219,6 +2219,19 @@ int main (int argc, char **argv) * HM devices: init */ + hwmon_ctx_t *hwmon_ctx = (hwmon_ctx_t *) mymalloc (sizeof (hwmon_ctx_t)); + + data.hwmon_ctx = hwmon_ctx; + + const int rc_hwmon_init = hwmon_ctx_init (hwmon_ctx, user_options); + + if (rc_hwmon_init == -1) + { + log_error ("ERROR: hwmon_ctx_init() failed"); + + return -1; + } + hm_attrs_t hm_adapters_adl[DEVICES_MAX]; hm_attrs_t hm_adapters_nvapi[DEVICES_MAX]; hm_attrs_t hm_adapters_nvml[DEVICES_MAX]; @@ -2952,6 +2965,8 @@ int main (int argc, char **argv) opencl_ctx_devices_destroy (opencl_ctx); + hwmon_ctx_destroy (hwmon_ctx); + restore_ctx_destroy (restore_ctx); time_t proc_stop; diff --git a/src/hwmon.c b/src/hwmon.c index 548214f24..62fe23746 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -869,3 +869,47 @@ int hm_set_fanspeed_with_device_id_xnvctrl (const uint device_id, const int fans return -1; } + +int hwmon_ctx_init (hwmon_ctx_t *hwmon_ctx, const user_options_t *user_options) +{ + hwmon_ctx->enabled = false; + + if (user_options->gpu_temp_disable == true) return 0; + + hwmon_ctx->hm_adapters_adl = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); + hwmon_ctx->hm_adapters_nvapi = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); + hwmon_ctx->hm_adapters_nvml = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); + hwmon_ctx->hm_adapters_xnvctrl = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); + + hwmon_ctx->hm_device = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); + + hwmon_ctx->enabled = true; + + return 0; +} + +void hwmon_ctx_destroy (hwmon_ctx_t *hwmon_ctx) +{ + if (hwmon_ctx->enabled == false) return; + + myfree (hwmon_ctx->hm_device); + + myfree (hwmon_ctx->hm_adapters_adl); + myfree (hwmon_ctx->hm_adapters_nvapi); + myfree (hwmon_ctx->hm_adapters_nvml); + myfree (hwmon_ctx->hm_adapters_xnvctrl); + + hwmon_ctx->hm_device = NULL; + + hwmon_ctx->hm_adapters_adl = NULL; + hwmon_ctx->hm_adapters_nvapi = NULL; + hwmon_ctx->hm_adapters_nvml = NULL; + hwmon_ctx->hm_adapters_xnvctrl = NULL; + + hwmon_ctx->hm_adl = NULL; + hwmon_ctx->hm_nvml = NULL; + hwmon_ctx->hm_nvapi = NULL; + hwmon_ctx->hm_xnvctrl = NULL; + + myfree (hwmon_ctx); +}