1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-22 22:58:30 +00:00

Fix clock_gettime() on OSX (v2)

This commit is contained in:
Gabriele Gristina 2018-01-11 02:41:16 +01:00
parent 43ce4f6135
commit 03fab4a345
3 changed files with 7 additions and 22 deletions

View File

@ -6,13 +6,6 @@
#ifndef _TIMER_H #ifndef _TIMER_H
#define _TIMER_H #define _TIMER_H
#if defined(__APPLE__) && defined(MISSING_CLOCK_GETTIME)
#include <sys/time.h>
#include <mach/clock.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#endif
void hc_timer_set (hc_timer_t *a); void hc_timer_set (hc_timer_t *a);
double hc_timer_get (hc_timer_t a); double hc_timer_get (hc_timer_t a);

View File

@ -47,6 +47,8 @@ typedef uint64_t u64;
#if defined (_WIN) #if defined (_WIN)
typedef LARGE_INTEGER hc_timer_t; typedef LARGE_INTEGER hc_timer_t;
#elif defined(__APPLE__) && defined(MISSING_CLOCK_GETTIME)
typedef struct timeval hc_timer_t;
#else #else
typedef struct timespec hc_timer_t; typedef struct timespec hc_timer_t;
#endif #endif

View File

@ -34,21 +34,7 @@ inline double hc_timer_get (hc_timer_t a)
inline void hc_timer_set (hc_timer_t* a) inline void hc_timer_set (hc_timer_t* a)
{ {
#if defined(__APPLE__) && defined(MISSING_CLOCK_GETTIME) #if defined(__APPLE__) && defined(MISSING_CLOCK_GETTIME)
// taken from proxmark3/client/util_posix gettimeofday (a, NULL);
static uint64_t clock_start_time = 0;
static mach_timebase_info_data_t timebase_info = {0, 0};
uint64_t now = mach_absolute_time();
if (clock_start_time == 0)
{
mach_timebase_info(&timebase_info);
clock_start_time = now;
}
now = (uint64_t)((double)(now - clock_start_time) * (double)timebase_info.numer / (double)timebase_info.denom);
a->tv_sec = now / 1000000000;
a->tv_nsec = now % 1000000000;
#else #else
clock_gettime (CLOCK_MONOTONIC, a); clock_gettime (CLOCK_MONOTONIC, a);
#endif #endif
@ -60,6 +46,9 @@ inline double hc_timer_get (hc_timer_t a)
hc_timer_set (&hr_tmp); hc_timer_set (&hr_tmp);
#if defined(__APPLE__) && defined(MISSING_CLOCK_GETTIME)
return (double) (((hr_tmp.tv_sec - (a).tv_sec) * 1000) + ((double) (hr_tmp.tv_usec - (a).tv_usec) / 1000));
#else
hc_timer_t s; hc_timer_t s;
s.tv_sec = hr_tmp.tv_sec - a.tv_sec; s.tv_sec = hr_tmp.tv_sec - a.tv_sec;
@ -74,6 +63,7 @@ inline double hc_timer_get (hc_timer_t a)
double r = ((double) s.tv_sec * 1000) + ((double) s.tv_nsec / 1000000); double r = ((double) s.tv_sec * 1000) + ((double) s.tv_nsec / 1000000);
return r; return r;
#endif
} }
#endif #endif