+#if defined (CLOCK_PROF) && ! defined (CLOCK_PROCESS_CPUTIME_ID)
+#define CLOCK_PROCESS_CPUTIME_ID CLOCK_PROF
+#endif
+
+#if defined(__APPLE__) && defined(__MACH__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <mach/mach_init.h>
+#include <mach/mach_host.h>
+#include <mach/mach_port.h>
+#include <mach/mach_traps.h>
+#include <mach/task_info.h>
+#include <mach/thread_info.h>
+#include <mach/thread_act.h>
+#include <mach/vm_region.h>
+#include <mach/vm_map.h>
+#include <mach/task.h>
+#endif
+
+#ifdef _WIN32
+static void w32_time_to_timeval(struct timeval* tv, const FILETIME* ft)
+{
+ unsigned __int64 tm;
+ tm = (unsigned __int64)ft->dwHighDateTime << 32;
+ tm |= ft->dwLowDateTime;
+ tm /= 10;
+ tm -= 11644473600000000ULL;
+ tv->tv_sec = (long)(tm / 1000000L);
+ tv->tv_usec = (long)(tm % 1000000L);
+}
+
+static void w32_times_to_timeval(struct timeval* tv, const FILETIME* kernel_time, const FILETIME* user_time)
+{
+ unsigned __int64 ktm, utm;
+ ktm = (unsigned __int64)kernel_time->dwHighDateTime << 32;
+ ktm |= kernel_time->dwLowDateTime;
+ ktm /= 10;
+ utm = (unsigned __int64)user_time->dwHighDateTime << 32;
+ utm |= user_time->dwLowDateTime;
+ utm /= 10;
+ tv->tv_sec = (long)(ktm / 1000000L) + (long)(utm / 1000000L);
+ tv->tv_usec = (long)(ktm % 1000000L) + (long)(utm % 1000000L);
+}