Add NvAPI_GPU_GetPerfDecreaseInfo() -- but i doesn't work, so deactive it
[hashcat.git] / src / ext_nvapi.c
1 /**
2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * Gabriele Gristina <matrix@hashcat.net>
4 *
5 * License.....: MIT
6 */
7
8 #include <ext_nvapi.h>
9
10 int nvapi_init (NVAPI_PTR *nvapi)
11 {
12 if (!nvapi) return (-1);
13
14 memset (nvapi, 0, sizeof (NVAPI_PTR));
15
16 #if __x86_64__
17 nvapi->lib = hc_dlopen ("nvapi64.dll");
18 #elif __x86__
19 nvapi->lib = hc_dlopen ("nvapi.dll");
20 #endif
21
22 if (!nvapi->lib)
23 {
24 //if (data.quiet == 0)
25 // log_info ("WARNING: load NVAPI library failed, proceed without NVAPI HWMon enabled.");
26
27 return (-1);
28 }
29
30 HC_LOAD_FUNC(nvapi, nvapi_QueryInterface, NVAPI_QUERYINTERFACE, NVAPI, 0)
31 HC_LOAD_ADDR(nvapi, NvAPI_Initialize, NVAPI_INITIALIZE, nvapi_QueryInterface, 0x0150E828, NVAPI, 0)
32 HC_LOAD_ADDR(nvapi, NvAPI_Unload, NVAPI_UNLOAD, nvapi_QueryInterface, 0xD22BDD7E, NVAPI, 0)
33 HC_LOAD_ADDR(nvapi, NvAPI_GetErrorMessage, NVAPI_GETERRORMESSAGE, nvapi_QueryInterface, 0x6C2D048C, NVAPI, 0)
34 HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921F, NVAPI, 0)
35 HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetDynamicPstatesInfoEx, NVAPI_GPU_GETDYNAMICPSTATESINFOEX, nvapi_QueryInterface, 0x60DED2ED, NVAPI, 0)
36 HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetThermalSettings, NVAPI_GPU_GETTHERMALSETTINGS, nvapi_QueryInterface, 0xE3640A56, NVAPI, 0)
37 HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetTachReading, NVAPI_GPU_GETTACHREADING, nvapi_QueryInterface, 0x5F608315, NVAPI, 0)
38 HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetCoolerSettings, NVAPI_GPU_GETCOOLERSETTINGS, nvapi_QueryInterface, 0xDA141340, NVAPI, 0)
39 HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetAllClockFrequencies, NVAPI_GPU_GETALLCLOCKFREQUENCIES, nvapi_QueryInterface, 0xDCB616C3, NVAPI, 0)
40 HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetCurrentPCIEDownstreamWidth, NVAPI_GPU_GETCURRENTPCIEDOWNSTREAMWIDTH, nvapi_QueryInterface, 0xD048C3B1, NVAPI, 0)
41 HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfDecreaseInfo, NVAPI_GPU_GETPERFDECREASEINFO, nvapi_QueryInterface, 0x7F7F4600, NVAPI, 0)
42
43 return 0;
44 }
45
46 void nvapi_close (NVAPI_PTR *nvapi)
47 {
48 if (nvapi)
49 {
50 if (nvapi->lib)
51 hc_dlclose (nvapi->lib);
52
53 myfree (nvapi);
54 }
55 }
56
57 int hm_NvAPI_Initialize (NVAPI_PTR *nvapi)
58 {
59 if (!nvapi) return (-1);
60
61 NvAPI_Status NvAPI_rc = nvapi->NvAPI_Initialize ();
62
63 if (NvAPI_rc == NVAPI_LIBRARY_NOT_FOUND) NvAPI_rc = NVAPI_OK; // not a bug
64
65 if (NvAPI_rc != NVAPI_OK)
66 {
67 NvAPI_ShortString string = { 0 };
68
69 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
70
71 log_info ("WARN: %s %d %s\n", "NvAPI_Initialize()", NvAPI_rc, string);
72 }
73
74 return NvAPI_rc;
75 }
76
77 int hm_NvAPI_Unload (NVAPI_PTR *nvapi)
78 {
79 if (!nvapi) return (-1);
80
81 NvAPI_Status NvAPI_rc = nvapi->NvAPI_Unload ();
82
83 if (NvAPI_rc != NVAPI_OK)
84 {
85 NvAPI_ShortString string = { 0 };
86
87 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
88
89 log_info ("WARN: %s %d %s\n", "NvAPI_Unload()", NvAPI_rc, string);
90 }
91
92 return NvAPI_rc;
93 }
94
95 int hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, NvAPI_Status NvAPI_rc, NvAPI_ShortString string)
96 {
97 if (!nvapi) return (-1);
98
99 return nvapi->NvAPI_GetErrorMessage (NvAPI_rc, string);
100 }
101
102 int hm_NvAPI_EnumPhysicalGPUs (NVAPI_PTR *nvapi, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount)
103 {
104 if (!nvapi) return (-1);
105
106 NvAPI_Status NvAPI_rc = nvapi->NvAPI_EnumPhysicalGPUs (nvGPUHandle, pGpuCount);
107
108 if (NvAPI_rc != NVAPI_OK)
109 {
110 NvAPI_ShortString string = { 0 };
111
112 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
113
114 log_info ("WARN: %s %d %s\n", "NvAPI_EnumPhysicalGPUs()", NvAPI_rc, string);
115 }
116
117 return NvAPI_rc;
118 }
119
120 int hm_NvAPI_GPU_GetThermalSettings (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 sensorIndex, NV_GPU_THERMAL_SETTINGS *pThermalSettings)
121 {
122 if (!nvapi) return (-1);
123
124 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetThermalSettings (hPhysicalGpu, sensorIndex, pThermalSettings);
125
126 if (NvAPI_rc != NVAPI_OK)
127 {
128 NvAPI_ShortString string = { 0 };
129
130 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
131
132 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetThermalSettings()", NvAPI_rc, string);
133 }
134
135 return NvAPI_rc;
136 }
137
138 int hm_NvAPI_GPU_GetTachReading (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGPU, NvU32 *pValue)
139 {
140 if (!nvapi) return (-1);
141
142 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetTachReading (hPhysicalGPU, pValue);
143
144 if (NvAPI_rc != NVAPI_OK)
145 {
146 NvAPI_ShortString string = { 0 };
147
148 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
149
150 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetTachReading()", NvAPI_rc, string);
151 }
152
153 return NvAPI_rc;
154 }
155
156 int hm_NvAPI_GPU_GetCoolerSettings (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex, NV_GPU_COOLER_SETTINGS *pCoolerSettings)
157 {
158 if (!nvapi) return (-1);
159
160 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetCoolerSettings (hPhysicalGpu, coolerIndex, pCoolerSettings);
161
162 if (NvAPI_rc != NVAPI_OK)
163 {
164 NvAPI_ShortString string = { 0 };
165
166 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
167
168 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetCoolerSettings()", NvAPI_rc, string);
169 }
170
171 return NvAPI_rc;
172 }
173
174 int hm_NvAPI_GPU_GetDynamicPstatesInfoEx (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_DYNAMIC_PSTATES_INFO_EX *pDynamicPstatesInfoEx)
175 {
176 if (!nvapi) return (-1);
177
178 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetDynamicPstatesInfoEx (hPhysicalGpu, pDynamicPstatesInfoEx);
179
180 if (NvAPI_rc != NVAPI_OK)
181 {
182 NvAPI_ShortString string = { 0 };
183
184 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
185
186 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetDynamicPstatesInfoEx()", NvAPI_rc, string);
187 }
188
189 return NvAPI_rc;
190 }
191
192 int hm_NvAPI_GPU_GetAllClockFrequencies (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_CLOCK_FREQUENCIES *pClkFreqs)
193 {
194 if (!nvapi) return (-1);
195
196 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetAllClockFrequencies (hPhysicalGpu, pClkFreqs);
197
198 if (NvAPI_rc != NVAPI_OK)
199 {
200 NvAPI_ShortString string = { 0 };
201
202 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
203
204 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetAllClockFrequencies()", NvAPI_rc, string);
205 }
206
207 return NvAPI_rc;
208 }
209
210 int hm_NvAPI_GPU_GetCurrentPCIEDownstreamWidth (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 *pWidth)
211 {
212 if (!nvapi) return (-1);
213
214 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetCurrentPCIEDownstreamWidth (hPhysicalGpu, pWidth);
215
216 if (NvAPI_rc != NVAPI_OK)
217 {
218 NvAPI_ShortString string = { 0 };
219
220 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
221
222 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetCurrentPCIEDownstreamWidth()", NvAPI_rc, string);
223 }
224
225 return NvAPI_rc;
226 }
227
228 int hm_NvAPI_GPU_GetPerfDecreaseInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 *pPerfDecrInfo)
229 {
230 if (!nvapi) return (-1);
231
232 NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfDecreaseInfo (hPhysicalGpu, pPerfDecrInfo);
233
234 if (NvAPI_rc != NVAPI_OK)
235 {
236 NvAPI_ShortString string = { 0 };
237
238 hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
239
240 log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetPerfDecreaseInfo()", NvAPI_rc, string);
241 }
242
243 return NvAPI_rc;
244 }
245
246 #ifdef __MINGW64__
247
248 void __security_check_cookie (uintptr_t _StackCookie)
249 {
250 (void) _StackCookie;
251 }
252
253 void __GSHandlerCheck ()
254 {
255 }
256
257 #endif