2012-06-19 06:22:39 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* System Information
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2013-12-04 14:37:57 +04:00
|
|
|
* Copyright 2013 Bernhard Miklautz <bernhard.miklautz@thincast.com>
|
2012-06-19 06:22:39 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-06-19 06:22:39 +04:00
|
|
|
#include <winpr/sysinfo.h>
|
2013-02-27 13:17:24 +04:00
|
|
|
#include <winpr/platform.h>
|
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
#if defined(ANDROID)
|
|
|
|
#include "cpufeatures/cpu-features.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__linux__)
|
2013-02-27 13:17:24 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
2012-06-19 06:22:39 +04:00
|
|
|
|
2016-02-08 18:19:36 +03:00
|
|
|
#include "../log.h"
|
|
|
|
#define TAG WINPR_TAG("sysinfo")
|
|
|
|
|
2012-06-19 06:22:39 +04:00
|
|
|
/**
|
|
|
|
* api-ms-win-core-sysinfo-l1-1-1.dll:
|
|
|
|
*
|
|
|
|
* EnumSystemFirmwareTables
|
2014-05-29 19:58:53 +04:00
|
|
|
* GetSystemFirmwareTable
|
2012-06-19 06:22:39 +04:00
|
|
|
* GetLogicalProcessorInformation
|
|
|
|
* GetLogicalProcessorInformationEx
|
|
|
|
* GetProductInfo
|
|
|
|
* GetSystemDirectoryA
|
|
|
|
* GetSystemDirectoryW
|
|
|
|
* GetSystemTimeAdjustment
|
|
|
|
* GetSystemWindowsDirectoryA
|
|
|
|
* GetSystemWindowsDirectoryW
|
|
|
|
* GetWindowsDirectoryA
|
|
|
|
* GetWindowsDirectoryW
|
|
|
|
* GlobalMemoryStatusEx
|
|
|
|
* SetComputerNameExW
|
|
|
|
* VerSetConditionMask
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
2012-06-30 00:43:07 +04:00
|
|
|
#include <time.h>
|
2015-03-10 01:21:28 +03:00
|
|
|
#include <sys/time.h>
|
2013-01-24 04:37:50 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2012-06-20 01:26:37 +04:00
|
|
|
#include <unistd.h>
|
2013-01-24 04:37:50 +04:00
|
|
|
#endif
|
2013-01-24 02:46:32 +04:00
|
|
|
|
2012-06-19 06:22:39 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-01-24 04:21:14 +04:00
|
|
|
#include <winpr/platform.h>
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#if defined(__MACOSX__) || defined(__IOS__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
|
|
|
|
defined(__OpenBSD__) || defined(__DragonFly__)
|
2013-01-24 04:37:50 +04:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
|
|
|
|
2017-01-24 11:28:27 +03:00
|
|
|
static DWORD GetProcessorArchitecture(void)
|
2013-01-24 04:21:14 +04:00
|
|
|
{
|
|
|
|
DWORD cpuArch = PROCESSOR_ARCHITECTURE_UNKNOWN;
|
2017-01-24 11:56:45 +03:00
|
|
|
#if defined(ANDROID)
|
|
|
|
AndroidCpuFamily family = android_getCpuFamily();
|
|
|
|
|
|
|
|
switch (family)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case ANDROID_CPU_FAMILY_ARM:
|
|
|
|
return PROCESSOR_ARCHITECTURE_ARM;
|
2017-01-24 11:56:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case ANDROID_CPU_FAMILY_X86:
|
|
|
|
return PROCESSOR_ARCHITECTURE_INTEL;
|
2017-01-24 11:56:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case ANDROID_CPU_FAMILY_MIPS:
|
|
|
|
return PROCESSOR_ARCHITECTURE_MIPS;
|
2017-01-24 11:56:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case ANDROID_CPU_FAMILY_ARM64:
|
|
|
|
return PROCESSOR_ARCHITECTURE_ARM64;
|
2017-01-24 11:56:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case ANDROID_CPU_FAMILY_X86_64:
|
|
|
|
return PROCESSOR_ARCHITECTURE_AMD64;
|
2017-01-24 11:56:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case ANDROID_CPU_FAMILY_MIPS64:
|
|
|
|
return PROCESSOR_ARCHITECTURE_MIPS64;
|
2017-01-24 11:56:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
default:
|
|
|
|
return PROCESSOR_ARCHITECTURE_UNKNOWN;
|
2017-01-24 11:56:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(_M_ARM)
|
2017-01-24 11:28:27 +03:00
|
|
|
cpuArch = PROCESSOR_ARCHITECTURE_ARM;
|
2013-01-24 04:21:14 +04:00
|
|
|
#elif defined(_M_IX86)
|
|
|
|
cpuArch = PROCESSOR_ARCHITECTURE_INTEL;
|
2017-01-24 11:28:27 +03:00
|
|
|
#elif defined(_M_MIPS64)
|
|
|
|
/* Needs to be before __mips__ since the compiler defines both */
|
|
|
|
cpuArch = PROCESSOR_ARCHITECTURE_MIPS64;
|
2013-01-24 04:21:14 +04:00
|
|
|
#elif defined(_M_MIPS)
|
|
|
|
cpuArch = PROCESSOR_ARCHITECTURE_MIPS;
|
2017-01-24 11:28:27 +03:00
|
|
|
#elif defined(_M_ARM64)
|
|
|
|
cpuArch = PROCESSOR_ARCHITECTURE_ARM64;
|
|
|
|
#elif defined(_M_AMD64)
|
|
|
|
cpuArch = PROCESSOR_ARCHITECTURE_AMD64;
|
2013-01-24 04:21:14 +04:00
|
|
|
#elif defined(_M_PPC)
|
|
|
|
cpuArch = PROCESSOR_ARCHITECTURE_PPC;
|
|
|
|
#elif defined(_M_ALPHA)
|
|
|
|
cpuArch = PROCESSOR_ARCHITECTURE_ALPHA;
|
|
|
|
#endif
|
|
|
|
return cpuArch;
|
|
|
|
}
|
|
|
|
|
2017-01-24 11:28:27 +03:00
|
|
|
static DWORD GetNumberOfProcessors(void)
|
2013-01-24 04:21:14 +04:00
|
|
|
{
|
|
|
|
DWORD numCPUs = 1;
|
2017-01-24 11:56:45 +03:00
|
|
|
#if defined(ANDROID)
|
|
|
|
return android_getCpuCount();
|
2013-02-27 13:17:24 +04:00
|
|
|
/* TODO: iOS */
|
2017-01-24 11:56:45 +03:00
|
|
|
#elif defined(__linux__) || defined(__sun) || defined(_AIX)
|
2019-11-06 17:24:51 +03:00
|
|
|
numCPUs = (DWORD)sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
|
#elif defined(__MACOSX__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
|
|
|
|
defined(__OpenBSD__) || defined(__DragonFly__)
|
2013-01-24 04:21:14 +04:00
|
|
|
{
|
|
|
|
int mib[4];
|
2013-01-24 04:37:50 +04:00
|
|
|
size_t length = sizeof(numCPUs);
|
2013-01-24 04:21:14 +04:00
|
|
|
mib[0] = CTL_HW;
|
2015-04-21 21:42:06 +03:00
|
|
|
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
2014-08-18 19:22:22 +04:00
|
|
|
mib[1] = HW_NCPU;
|
|
|
|
#else
|
|
|
|
mib[1] = HW_AVAILCPU;
|
|
|
|
#endif
|
2013-01-24 04:21:14 +04:00
|
|
|
sysctl(mib, 2, &numCPUs, &length, NULL, 0);
|
|
|
|
|
|
|
|
if (numCPUs < 1)
|
|
|
|
{
|
|
|
|
mib[1] = HW_NCPU;
|
|
|
|
sysctl(mib, 2, &numCPUs, &length, NULL, 0);
|
|
|
|
|
|
|
|
if (numCPUs < 1)
|
|
|
|
numCPUs = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(__hpux)
|
2019-11-06 17:24:51 +03:00
|
|
|
numCPUs = (DWORD)mpctl(MPC_GETNUMSPUS, NULL, NULL);
|
2013-01-24 04:21:14 +04:00
|
|
|
#elif defined(__sgi)
|
2019-11-06 17:24:51 +03:00
|
|
|
numCPUs = (DWORD)sysconf(_SC_NPROC_ONLN);
|
2013-01-24 04:21:14 +04:00
|
|
|
#endif
|
|
|
|
return numCPUs;
|
|
|
|
}
|
2012-06-19 06:22:39 +04:00
|
|
|
|
2017-01-24 11:28:27 +03:00
|
|
|
static DWORD GetSystemPageSize(void)
|
2015-03-14 01:37:48 +03:00
|
|
|
{
|
|
|
|
DWORD dwPageSize = 0;
|
|
|
|
long sc_page_size = -1;
|
|
|
|
#if defined(_SC_PAGESIZE)
|
2017-01-24 11:28:27 +03:00
|
|
|
|
2015-03-14 01:37:48 +03:00
|
|
|
if (sc_page_size < 0)
|
|
|
|
sc_page_size = sysconf(_SC_PAGESIZE);
|
|
|
|
|
2017-01-24 11:28:27 +03:00
|
|
|
#endif
|
2015-03-14 01:37:48 +03:00
|
|
|
#if defined(_SC_PAGE_SIZE)
|
2017-01-24 11:28:27 +03:00
|
|
|
|
2015-03-14 01:37:48 +03:00
|
|
|
if (sc_page_size < 0)
|
|
|
|
sc_page_size = sysconf(_SC_PAGE_SIZE);
|
2017-01-24 11:28:27 +03:00
|
|
|
|
2015-03-14 01:37:48 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (sc_page_size > 0)
|
2019-11-06 17:24:51 +03:00
|
|
|
dwPageSize = (DWORD)sc_page_size;
|
2015-03-14 01:37:48 +03:00
|
|
|
|
|
|
|
if (dwPageSize < 4096)
|
|
|
|
dwPageSize = 4096;
|
|
|
|
|
|
|
|
return dwPageSize;
|
|
|
|
}
|
|
|
|
|
2013-01-24 02:46:32 +04:00
|
|
|
void GetSystemInfo(LPSYSTEM_INFO lpSystemInfo)
|
|
|
|
{
|
2013-01-24 04:21:14 +04:00
|
|
|
lpSystemInfo->wProcessorArchitecture = GetProcessorArchitecture();
|
2013-01-24 02:46:32 +04:00
|
|
|
lpSystemInfo->wReserved = 0;
|
2015-03-14 01:37:48 +03:00
|
|
|
lpSystemInfo->dwPageSize = GetSystemPageSize();
|
2013-01-24 02:46:32 +04:00
|
|
|
lpSystemInfo->lpMinimumApplicationAddress = NULL;
|
|
|
|
lpSystemInfo->lpMaximumApplicationAddress = NULL;
|
2013-01-24 03:39:48 +04:00
|
|
|
lpSystemInfo->dwActiveProcessorMask = 0;
|
2013-01-24 04:21:14 +04:00
|
|
|
lpSystemInfo->dwNumberOfProcessors = GetNumberOfProcessors();
|
2013-01-24 02:46:32 +04:00
|
|
|
lpSystemInfo->dwProcessorType = 0;
|
|
|
|
lpSystemInfo->dwAllocationGranularity = 0;
|
|
|
|
lpSystemInfo->wProcessorLevel = 0;
|
|
|
|
lpSystemInfo->wProcessorRevision = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo)
|
|
|
|
{
|
|
|
|
GetSystemInfo(lpSystemInfo);
|
|
|
|
}
|
|
|
|
|
2014-05-28 18:38:32 +04:00
|
|
|
void GetSystemTime(LPSYSTEMTIME lpSystemTime)
|
|
|
|
{
|
2014-05-29 20:39:09 +04:00
|
|
|
time_t ct = 0;
|
2020-05-25 15:07:31 +03:00
|
|
|
struct tm tres;
|
2014-08-18 21:34:47 +04:00
|
|
|
struct tm* stm = NULL;
|
2014-05-29 20:39:09 +04:00
|
|
|
WORD wMilliseconds = 0;
|
|
|
|
ct = time(NULL);
|
2014-08-18 19:22:22 +04:00
|
|
|
wMilliseconds = (WORD)(GetTickCount() % 1000);
|
2020-05-25 15:07:31 +03:00
|
|
|
stm = gmtime_r(&ct, &tres);
|
2014-05-29 20:39:09 +04:00
|
|
|
ZeroMemory(lpSystemTime, sizeof(SYSTEMTIME));
|
|
|
|
|
|
|
|
if (stm)
|
|
|
|
{
|
2014-08-18 19:22:22 +04:00
|
|
|
lpSystemTime->wYear = (WORD)(stm->tm_year + 1900);
|
|
|
|
lpSystemTime->wMonth = (WORD)(stm->tm_mon + 1);
|
2019-11-06 17:24:51 +03:00
|
|
|
lpSystemTime->wDayOfWeek = (WORD)stm->tm_wday;
|
|
|
|
lpSystemTime->wDay = (WORD)stm->tm_mday;
|
|
|
|
lpSystemTime->wHour = (WORD)stm->tm_hour;
|
|
|
|
lpSystemTime->wMinute = (WORD)stm->tm_min;
|
|
|
|
lpSystemTime->wSecond = (WORD)stm->tm_sec;
|
2014-05-29 20:39:09 +04:00
|
|
|
lpSystemTime->wMilliseconds = wMilliseconds;
|
|
|
|
}
|
2014-05-28 18:38:32 +04:00
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
BOOL SetSystemTime(CONST SYSTEMTIME* lpSystemTime)
|
2014-05-29 19:58:53 +04:00
|
|
|
{
|
2017-01-24 11:56:45 +03:00
|
|
|
/* TODO: Implement */
|
2014-05-29 19:58:53 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID GetLocalTime(LPSYSTEMTIME lpSystemTime)
|
|
|
|
{
|
2014-05-29 20:39:09 +04:00
|
|
|
time_t ct = 0;
|
2020-05-25 14:56:24 +03:00
|
|
|
struct tm tres;
|
2014-08-18 21:34:47 +04:00
|
|
|
struct tm* ltm = NULL;
|
2014-05-29 20:39:09 +04:00
|
|
|
WORD wMilliseconds = 0;
|
|
|
|
ct = time(NULL);
|
2014-08-18 19:22:22 +04:00
|
|
|
wMilliseconds = (WORD)(GetTickCount() % 1000);
|
2020-05-25 14:56:24 +03:00
|
|
|
ltm = localtime_r(&ct, &tres);
|
2014-05-29 20:39:09 +04:00
|
|
|
ZeroMemory(lpSystemTime, sizeof(SYSTEMTIME));
|
|
|
|
|
|
|
|
if (ltm)
|
|
|
|
{
|
2014-08-18 19:22:22 +04:00
|
|
|
lpSystemTime->wYear = (WORD)(ltm->tm_year + 1900);
|
|
|
|
lpSystemTime->wMonth = (WORD)(ltm->tm_mon + 1);
|
2019-11-06 17:24:51 +03:00
|
|
|
lpSystemTime->wDayOfWeek = (WORD)ltm->tm_wday;
|
|
|
|
lpSystemTime->wDay = (WORD)ltm->tm_mday;
|
|
|
|
lpSystemTime->wHour = (WORD)ltm->tm_hour;
|
|
|
|
lpSystemTime->wMinute = (WORD)ltm->tm_min;
|
|
|
|
lpSystemTime->wSecond = (WORD)ltm->tm_sec;
|
2014-05-29 20:39:09 +04:00
|
|
|
lpSystemTime->wMilliseconds = wMilliseconds;
|
|
|
|
}
|
2014-05-29 19:58:53 +04:00
|
|
|
}
|
|
|
|
|
2014-08-18 21:34:47 +04:00
|
|
|
BOOL SetLocalTime(CONST SYSTEMTIME* lpSystemTime)
|
2014-05-29 19:58:53 +04:00
|
|
|
{
|
2017-01-24 11:56:45 +03:00
|
|
|
/* TODO: Implement */
|
2014-05-29 19:58:53 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-30 00:43:07 +04:00
|
|
|
VOID GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER time64;
|
2012-09-06 21:22:31 +04:00
|
|
|
time64.u.HighPart = 0;
|
2012-06-30 00:43:07 +04:00
|
|
|
/* time represented in tenths of microseconds since midnight of January 1, 1601 */
|
|
|
|
time64.QuadPart = time(NULL) + 11644473600LL; /* Seconds since January 1, 1601 */
|
2019-11-06 17:24:51 +03:00
|
|
|
time64.QuadPart *= 10000000; /* Convert timestamp to tenths of a microsecond */
|
2019-11-25 15:05:09 +03:00
|
|
|
lpSystemTimeAsFileTime->dwLowDateTime = time64.u.LowPart;
|
|
|
|
lpSystemTimeAsFileTime->dwHighDateTime = time64.u.HighPart;
|
2012-06-30 00:43:07 +04:00
|
|
|
}
|
|
|
|
|
2017-01-24 11:28:27 +03:00
|
|
|
BOOL GetSystemTimeAdjustment(PDWORD lpTimeAdjustment, PDWORD lpTimeIncrement,
|
|
|
|
PBOOL lpTimeAdjustmentDisabled)
|
2014-05-28 18:38:32 +04:00
|
|
|
{
|
2017-01-24 11:56:45 +03:00
|
|
|
/* TODO: Implement */
|
2014-05-28 18:38:32 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-20 06:21:20 +04:00
|
|
|
#ifndef CLOCK_MONOTONIC_RAW
|
2019-11-06 17:24:51 +03:00
|
|
|
#define CLOCK_MONOTONIC_RAW 4
|
2013-02-20 06:21:20 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
DWORD GetTickCount(void)
|
|
|
|
{
|
|
|
|
DWORD ticks = 0;
|
|
|
|
#ifdef __linux__
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
if (!clock_gettime(CLOCK_MONOTONIC_RAW, &ts))
|
|
|
|
ticks = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
|
|
|
|
|
|
|
|
#else
|
|
|
|
/**
|
|
|
|
* FIXME: this is relative to the Epoch time, and we
|
|
|
|
* need to return a value relative to the system uptime.
|
|
|
|
*/
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
if (!gettimeofday(&tv, NULL))
|
|
|
|
ticks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return ticks;
|
|
|
|
}
|
2013-03-04 12:40:26 +04:00
|
|
|
#endif // _WIN32
|
2013-02-20 06:21:20 +04:00
|
|
|
|
2016-02-08 18:19:36 +03:00
|
|
|
#if !defined(_WIN32) || defined(_UWP)
|
|
|
|
|
2016-03-29 23:03:15 +03:00
|
|
|
/* OSVERSIONINFOEX Structure:
|
2019-11-06 17:24:51 +03:00
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833
|
|
|
|
*/
|
2016-03-29 23:03:15 +03:00
|
|
|
|
|
|
|
BOOL GetVersionExA(LPOSVERSIONINFOA lpVersionInformation)
|
|
|
|
{
|
|
|
|
#ifdef _UWP
|
2017-01-24 11:28:27 +03:00
|
|
|
|
2016-03-29 23:03:15 +03:00
|
|
|
/* Windows 10 Version Info */
|
|
|
|
if ((lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA)) ||
|
2017-01-24 11:28:27 +03:00
|
|
|
(lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)))
|
2016-03-29 23:03:15 +03:00
|
|
|
{
|
|
|
|
lpVersionInformation->dwMajorVersion = 10;
|
|
|
|
lpVersionInformation->dwMinorVersion = 0;
|
|
|
|
lpVersionInformation->dwBuildNumber = 0;
|
|
|
|
lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT;
|
|
|
|
ZeroMemory(lpVersionInformation->szCSDVersion, sizeof(lpVersionInformation->szCSDVersion));
|
|
|
|
|
|
|
|
if (lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
|
|
|
|
{
|
|
|
|
LPOSVERSIONINFOEXA lpVersionInformationEx = (LPOSVERSIONINFOEXA)lpVersionInformation;
|
|
|
|
lpVersionInformationEx->wServicePackMajor = 0;
|
|
|
|
lpVersionInformationEx->wServicePackMinor = 0;
|
|
|
|
lpVersionInformationEx->wSuiteMask = 0;
|
|
|
|
lpVersionInformationEx->wProductType = VER_NT_WORKSTATION;
|
|
|
|
lpVersionInformationEx->wReserved = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-01-24 11:28:27 +03:00
|
|
|
|
2016-03-29 23:03:15 +03:00
|
|
|
#else
|
2017-01-24 11:28:27 +03:00
|
|
|
|
2016-03-29 23:03:15 +03:00
|
|
|
/* Windows 7 SP1 Version Info */
|
|
|
|
if ((lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA)) ||
|
2017-01-24 11:28:27 +03:00
|
|
|
(lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)))
|
2016-03-29 23:03:15 +03:00
|
|
|
{
|
|
|
|
lpVersionInformation->dwMajorVersion = 6;
|
|
|
|
lpVersionInformation->dwMinorVersion = 1;
|
|
|
|
lpVersionInformation->dwBuildNumber = 7601;
|
|
|
|
lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT;
|
|
|
|
ZeroMemory(lpVersionInformation->szCSDVersion, sizeof(lpVersionInformation->szCSDVersion));
|
|
|
|
|
|
|
|
if (lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
|
|
|
|
{
|
|
|
|
LPOSVERSIONINFOEXA lpVersionInformationEx = (LPOSVERSIONINFOEXA)lpVersionInformation;
|
|
|
|
lpVersionInformationEx->wServicePackMajor = 1;
|
|
|
|
lpVersionInformationEx->wServicePackMinor = 0;
|
|
|
|
lpVersionInformationEx->wSuiteMask = 0;
|
|
|
|
lpVersionInformationEx->wProductType = VER_NT_WORKSTATION;
|
|
|
|
lpVersionInformationEx->wReserved = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-01-24 11:28:27 +03:00
|
|
|
#endif
|
2016-03-29 23:03:15 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL GetVersionExW(LPOSVERSIONINFOW lpVersionInformation)
|
|
|
|
{
|
|
|
|
ZeroMemory(lpVersionInformation->szCSDVersion, sizeof(lpVersionInformation->szCSDVersion));
|
2019-11-06 17:24:51 +03:00
|
|
|
return GetVersionExA((LPOSVERSIONINFOA)lpVersionInformation);
|
2016-03-29 23:03:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(_WIN32) || defined(_UWP)
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
BOOL GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
|
|
|
|
{
|
|
|
|
BOOL rc;
|
|
|
|
LPSTR buffer = NULL;
|
|
|
|
if (!lpnSize || (*lpnSize > INT_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (*lpnSize > 0)
|
|
|
|
{
|
|
|
|
buffer = malloc(*lpnSize);
|
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
rc = GetComputerNameA(buffer, lpnSize);
|
|
|
|
|
|
|
|
if (rc && (*lpnSize > 0))
|
|
|
|
ConvertToUnicode(CP_UTF8, 0, buffer, (int)*lpnSize, &lpBuffer, (int)*lpnSize);
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-02-08 18:19:36 +03:00
|
|
|
BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
|
|
|
|
{
|
|
|
|
char* dot;
|
2019-10-29 13:29:47 +03:00
|
|
|
size_t length;
|
2016-02-08 18:19:36 +03:00
|
|
|
char hostname[256];
|
|
|
|
|
2017-02-27 12:52:59 +03:00
|
|
|
if (!lpnSize)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_BAD_ARGUMENTS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-02-08 18:19:36 +03:00
|
|
|
if (gethostname(hostname, sizeof(hostname)) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-10-29 13:29:47 +03:00
|
|
|
length = strnlen(hostname, sizeof(hostname));
|
2016-02-08 18:19:36 +03:00
|
|
|
dot = strchr(hostname, '.');
|
|
|
|
|
|
|
|
if (dot)
|
2019-10-29 13:29:47 +03:00
|
|
|
length = (dot - hostname);
|
2016-02-08 18:19:36 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((*lpnSize <= (DWORD)length) || !lpBuffer)
|
2016-02-08 18:19:36 +03:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
2019-10-29 13:29:47 +03:00
|
|
|
*lpnSize = (DWORD)(length + 1);
|
2016-02-08 18:19:36 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMemory(lpBuffer, hostname, length);
|
|
|
|
lpBuffer[length] = '\0';
|
2019-10-29 13:29:47 +03:00
|
|
|
*lpnSize = (DWORD)length;
|
2016-02-08 18:19:36 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD lpnSize)
|
|
|
|
{
|
2019-10-29 13:33:27 +03:00
|
|
|
size_t length;
|
2016-02-08 18:19:36 +03:00
|
|
|
char hostname[256];
|
|
|
|
|
2017-02-27 12:52:59 +03:00
|
|
|
if (!lpnSize)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_BAD_ARGUMENTS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-02-08 18:19:36 +03:00
|
|
|
if ((NameType == ComputerNameNetBIOS) || (NameType == ComputerNamePhysicalNetBIOS))
|
2017-02-27 12:52:59 +03:00
|
|
|
{
|
|
|
|
BOOL rc = GetComputerNameA(lpBuffer, lpnSize);
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
if (GetLastError() == ERROR_BUFFER_OVERFLOW)
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2016-02-08 18:19:36 +03:00
|
|
|
|
|
|
|
if (gethostname(hostname, sizeof(hostname)) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-10-29 13:33:27 +03:00
|
|
|
length = strnlen(hostname, sizeof(hostname));
|
2016-02-08 18:19:36 +03:00
|
|
|
|
|
|
|
switch (NameType)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case ComputerNameDnsHostname:
|
|
|
|
case ComputerNameDnsDomain:
|
|
|
|
case ComputerNameDnsFullyQualified:
|
|
|
|
case ComputerNamePhysicalDnsHostname:
|
|
|
|
case ComputerNamePhysicalDnsDomain:
|
|
|
|
case ComputerNamePhysicalDnsFullyQualified:
|
|
|
|
if ((*lpnSize <= (DWORD)length) || !lpBuffer)
|
2016-02-08 18:19:36 +03:00
|
|
|
{
|
2019-10-29 13:33:27 +03:00
|
|
|
*lpnSize = (DWORD)(length + 1);
|
2016-02-08 18:19:36 +03:00
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMemory(lpBuffer, hostname, length);
|
|
|
|
lpBuffer[length] = '\0';
|
2019-10-29 13:33:27 +03:00
|
|
|
*lpnSize = (DWORD)length;
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2016-02-08 18:19:36 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
default:
|
|
|
|
return FALSE;
|
2016-02-08 18:19:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-27 12:52:59 +03:00
|
|
|
BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD lpnSize)
|
2016-02-08 18:19:36 +03:00
|
|
|
{
|
2017-02-27 12:52:59 +03:00
|
|
|
BOOL rc;
|
|
|
|
LPSTR lpABuffer = NULL;
|
|
|
|
|
|
|
|
if (!lpnSize)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_BAD_ARGUMENTS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*lpnSize > 0)
|
|
|
|
{
|
|
|
|
lpABuffer = calloc(*lpnSize, sizeof(CHAR));
|
|
|
|
|
|
|
|
if (!lpABuffer)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = GetComputerNameExA(NameType, lpABuffer, lpnSize);
|
|
|
|
|
|
|
|
if (rc && (*lpnSize > 0))
|
|
|
|
ConvertToUnicode(CP_UTF8, 0, lpABuffer, *lpnSize, &lpBuffer, *lpnSize);
|
|
|
|
|
|
|
|
free(lpABuffer);
|
|
|
|
return rc;
|
2016-02-08 18:19:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
#if defined(_UWP)
|
|
|
|
|
|
|
|
DWORD GetTickCount(void)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return (DWORD)GetTickCount64();
|
2016-02-06 00:28:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-03-13 08:26:10 +04:00
|
|
|
#if (!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
|
|
|
|
|
2016-06-16 12:47:33 +03:00
|
|
|
ULONGLONG winpr_GetTickCount64(void)
|
2013-03-13 08:26:10 +04:00
|
|
|
{
|
|
|
|
ULONGLONG ticks = 0;
|
|
|
|
#if defined(__linux__)
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
if (!clock_gettime(CLOCK_MONOTONIC_RAW, &ts))
|
|
|
|
ticks = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
|
|
|
|
|
|
|
|
#elif defined(_WIN32)
|
2019-08-13 10:52:42 +03:00
|
|
|
FILETIME ft;
|
|
|
|
ULARGE_INTEGER ul;
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
ul.LowPart = ft.dwLowDateTime;
|
|
|
|
ul.HighPart = ft.dwHighDateTime;
|
|
|
|
ticks = ul.QuadPart;
|
2013-03-13 08:26:10 +04:00
|
|
|
#else
|
|
|
|
/**
|
|
|
|
* FIXME: this is relative to the Epoch time, and we
|
|
|
|
* need to return a value relative to the system uptime.
|
|
|
|
*/
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
if (!gettimeofday(&tv, NULL))
|
|
|
|
ticks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return ticks;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-03-04 12:40:26 +04:00
|
|
|
/* If x86 */
|
2013-02-27 13:17:24 +04:00
|
|
|
#ifdef _M_IX86_AMD64
|
|
|
|
|
2013-03-04 12:40:26 +04:00
|
|
|
#if defined(__GNUC__) && defined(__AVX__)
|
2013-02-27 13:17:24 +04:00
|
|
|
#define xgetbv(_func_, _lo_, _hi_) \
|
2019-11-06 17:24:51 +03:00
|
|
|
__asm__ __volatile__("xgetbv" : "=a"(_lo_), "=d"(_hi_) : "c"(_func_))
|
2013-02-27 13:17:24 +04:00
|
|
|
#endif
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#define D_BIT_MMX (1 << 23)
|
|
|
|
#define D_BIT_SSE (1 << 25)
|
|
|
|
#define D_BIT_SSE2 (1 << 26)
|
|
|
|
#define D_BIT_3DN (1 << 30)
|
|
|
|
#define C_BIT_SSE3 (1 << 0)
|
|
|
|
#define C_BIT_PCLMULQDQ (1 << 1)
|
|
|
|
#define C81_BIT_LZCNT (1 << 5)
|
|
|
|
#define C_BIT_3DNP (1 << 8)
|
|
|
|
#define C_BIT_3DNP (1 << 8)
|
|
|
|
#define C_BIT_SSSE3 (1 << 9)
|
|
|
|
#define C_BIT_SSE41 (1 << 19)
|
|
|
|
#define C_BIT_SSE42 (1 << 20)
|
|
|
|
#define C_BIT_FMA (1 << 12)
|
|
|
|
#define C_BIT_AES (1 << 25)
|
|
|
|
#define C_BIT_XGETBV (1 << 27)
|
|
|
|
#define C_BIT_AVX (1 << 28)
|
|
|
|
#define C_BITS_AVX (C_BIT_XGETBV | C_BIT_AVX)
|
|
|
|
#define E_BIT_XMM (1 << 1)
|
|
|
|
#define E_BIT_YMM (1 << 2)
|
|
|
|
#define E_BITS_AVX (E_BIT_XMM | E_BIT_YMM)
|
|
|
|
|
|
|
|
static void cpuid(unsigned info, unsigned* eax, unsigned* ebx, unsigned* ecx, unsigned* edx)
|
2013-02-27 13:17:24 +04:00
|
|
|
{
|
2013-03-04 12:40:26 +04:00
|
|
|
#ifdef __GNUC__
|
2014-08-18 19:22:22 +04:00
|
|
|
*eax = *ebx = *ecx = *edx = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
__asm volatile(
|
|
|
|
/* The EBX (or RBX register on x86_64) is used for the PIC base address
|
|
|
|
* and must not be corrupted by our inline assembly.
|
|
|
|
*/
|
2013-02-27 13:17:24 +04:00
|
|
|
#ifdef _M_IX86
|
2017-01-24 11:28:27 +03:00
|
|
|
"mov %%ebx, %%esi;"
|
|
|
|
"cpuid;"
|
|
|
|
"xchg %%ebx, %%esi;"
|
2013-02-27 13:17:24 +04:00
|
|
|
#else
|
2017-01-24 11:28:27 +03:00
|
|
|
"mov %%rbx, %%rsi;"
|
|
|
|
"cpuid;"
|
|
|
|
"xchg %%rbx, %%rsi;"
|
2013-02-27 13:17:24 +04:00
|
|
|
#endif
|
2017-01-24 11:28:27 +03:00
|
|
|
: "=a"(*eax), "=S"(*ebx), "=c"(*ecx), "=d"(*edx)
|
2019-11-06 17:24:51 +03:00
|
|
|
: "0"(info));
|
2013-03-04 12:40:26 +04:00
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
int a[4];
|
|
|
|
__cpuid(a, info);
|
|
|
|
*eax = a[0];
|
|
|
|
*ebx = a[1];
|
|
|
|
*ecx = a[2];
|
|
|
|
*edx = a[3];
|
|
|
|
#endif
|
2013-02-27 13:17:24 +04:00
|
|
|
}
|
|
|
|
#elif defined(_M_ARM)
|
|
|
|
#if defined(__linux__)
|
|
|
|
// HWCAP flags from linux kernel - uapi/asm/hwcap.h
|
|
|
|
#define HWCAP_SWP (1 << 0)
|
2019-11-06 17:24:51 +03:00
|
|
|
#define HWCAP_HALF (1 << 1)
|
2013-02-27 13:17:24 +04:00
|
|
|
#define HWCAP_THUMB (1 << 2)
|
2019-11-06 17:24:51 +03:00
|
|
|
#define HWCAP_26BIT (1 << 3) /* Play it safe */
|
2013-02-27 13:17:24 +04:00
|
|
|
#define HWCAP_FAST_MULT (1 << 4)
|
|
|
|
#define HWCAP_FPA (1 << 5)
|
|
|
|
#define HWCAP_VFP (1 << 6)
|
2019-11-06 17:24:51 +03:00
|
|
|
#define HWCAP_EDSP (1 << 7)
|
|
|
|
#define HWCAP_JAVA (1 << 8)
|
|
|
|
#define HWCAP_IWMMXT (1 << 9)
|
|
|
|
#define HWCAP_CRUNCH (1 << 10)
|
2013-02-27 13:17:24 +04:00
|
|
|
#define HWCAP_THUMBEE (1 << 11)
|
2019-11-06 17:24:51 +03:00
|
|
|
#define HWCAP_NEON (1 << 12)
|
2013-02-27 13:17:24 +04:00
|
|
|
#define HWCAP_VFPv3 (1 << 13)
|
2019-11-06 17:24:51 +03:00
|
|
|
#define HWCAP_VFPv3D16 (1 << 14) /* also set for VFPv4-D16 */
|
2013-02-27 13:17:24 +04:00
|
|
|
#define HWCAP_TLS (1 << 15)
|
|
|
|
#define HWCAP_VFPv4 (1 << 16)
|
|
|
|
#define HWCAP_IDIVA (1 << 17)
|
|
|
|
#define HWCAP_IDIVT (1 << 18)
|
2019-11-06 17:24:51 +03:00
|
|
|
#define HWCAP_VFPD32 (1 << 19) /* set if VFP has 32 regs (not 16) */
|
|
|
|
#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT)
|
2013-02-27 13:17:24 +04:00
|
|
|
|
|
|
|
// From linux kernel uapi/linux/auxvec.h
|
|
|
|
#define AT_HWCAP 16
|
|
|
|
|
2014-08-18 19:22:22 +04:00
|
|
|
static unsigned GetARMCPUCaps(void)
|
|
|
|
{
|
2013-02-27 13:17:24 +04:00
|
|
|
unsigned caps = 0;
|
2014-08-18 19:22:22 +04:00
|
|
|
int fd = open("/proc/self/auxv", O_RDONLY);
|
2013-02-27 13:17:24 +04:00
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
unsigned a_type; /* Entry type */
|
|
|
|
unsigned a_val; /* Integer value */
|
2013-02-27 13:17:24 +04:00
|
|
|
} auxvec;
|
|
|
|
|
2014-08-18 19:22:22 +04:00
|
|
|
while (1)
|
|
|
|
{
|
2013-02-27 13:17:24 +04:00
|
|
|
int num;
|
2014-08-18 21:34:47 +04:00
|
|
|
num = read(fd, (char*)&auxvec, sizeof(auxvec));
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2013-02-27 13:17:24 +04:00
|
|
|
if (num < 1 || (auxvec.a_type == 0 && auxvec.a_val == 0))
|
2014-08-18 19:22:22 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (auxvec.a_type == AT_HWCAP)
|
2013-02-27 13:17:24 +04:00
|
|
|
{
|
2014-08-18 19:22:22 +04:00
|
|
|
caps = auxvec.a_val;
|
2013-02-27 13:17:24 +04:00
|
|
|
}
|
|
|
|
}
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2013-02-27 13:17:24 +04:00
|
|
|
close(fd);
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(__linux__)
|
|
|
|
#endif // _M_IX86_AMD64
|
|
|
|
|
2013-03-04 12:40:26 +04:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2013-02-27 13:17:24 +04:00
|
|
|
BOOL IsProcessorFeaturePresent(DWORD ProcessorFeature)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2017-01-24 11:56:45 +03:00
|
|
|
#if defined(ANDROID)
|
|
|
|
const uint64_t features = android_getCpuFeatures();
|
|
|
|
|
|
|
|
switch (ProcessorFeature)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_NEON_INSTRUCTIONS_AVAILABLE:
|
|
|
|
case PF_ARM_NEON:
|
|
|
|
return features & ANDROID_CPU_ARM_FEATURE_NEON;
|
2017-01-24 11:56:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
default:
|
|
|
|
return FALSE;
|
2017-01-24 11:56:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(_M_ARM)
|
2013-02-27 13:17:24 +04:00
|
|
|
#ifdef __linux__
|
2017-01-24 11:28:27 +03:00
|
|
|
const unsigned caps = GetARMCPUCaps();
|
2013-02-27 13:17:24 +04:00
|
|
|
|
|
|
|
switch (ProcessorFeature)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_NEON_INSTRUCTIONS_AVAILABLE:
|
|
|
|
case PF_ARM_NEON:
|
|
|
|
if (caps & HWCAP_NEON)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_THUMB:
|
|
|
|
if (caps & HWCAP_THUMB)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_VFP_32_REGISTERS_AVAILABLE:
|
|
|
|
if (caps & HWCAP_VFPD32)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_DIVIDE_INSTRUCTION_AVAILABLE:
|
|
|
|
if ((caps & HWCAP_IDIVA) || (caps & HWCAP_IDIVT))
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_VFP3:
|
|
|
|
if (caps & HWCAP_VFPv3)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_JAZELLE:
|
|
|
|
if (caps & HWCAP_JAVA)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_DSP:
|
|
|
|
if (caps & HWCAP_EDSP)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_MPU:
|
|
|
|
if (caps & HWCAP_EDSP)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_THUMB2:
|
|
|
|
if ((caps & HWCAP_IDIVT) || (caps & HWCAP_VFPv4))
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_T2EE:
|
|
|
|
if (caps & HWCAP_THUMBEE)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_INTEL_WMMX:
|
|
|
|
if (caps & HWCAP_IWMMXT)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
2013-02-27 13:17:24 +04:00
|
|
|
}
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2013-02-28 16:45:32 +04:00
|
|
|
#elif defined(__APPLE__) // __linux__
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2013-02-28 16:45:32 +04:00
|
|
|
switch (ProcessorFeature)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_ARM_NEON_INSTRUCTIONS_AVAILABLE:
|
|
|
|
case PF_ARM_NEON:
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
2013-02-28 16:45:32 +04:00
|
|
|
}
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2013-02-28 16:45:32 +04:00
|
|
|
#endif // __linux__
|
2013-02-27 13:17:24 +04:00
|
|
|
#elif defined(_M_IX86_AMD64)
|
|
|
|
#ifdef __GNUC__
|
|
|
|
unsigned a, b, c, d;
|
|
|
|
cpuid(1, &a, &b, &c, &d);
|
|
|
|
|
|
|
|
switch (ProcessorFeature)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_MMX_INSTRUCTIONS_AVAILABLE:
|
|
|
|
if (d & D_BIT_MMX)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_XMMI_INSTRUCTIONS_AVAILABLE:
|
|
|
|
if (d & D_BIT_SSE)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_XMMI64_INSTRUCTIONS_AVAILABLE:
|
|
|
|
if (d & D_BIT_SSE2)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_3DNOW_INSTRUCTIONS_AVAILABLE:
|
|
|
|
if (d & D_BIT_3DN)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_SSE3_INSTRUCTIONS_AVAILABLE:
|
|
|
|
if (c & C_BIT_SSE3)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
2013-02-27 13:17:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __GNUC__
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
2014-05-28 18:38:32 +04:00
|
|
|
|
2013-03-01 11:45:44 +04:00
|
|
|
#endif //_WIN32
|
2013-02-27 13:17:24 +04:00
|
|
|
|
2015-06-11 10:11:19 +03:00
|
|
|
DWORD GetTickCountPrecise(void)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
LARGE_INTEGER freq;
|
|
|
|
LARGE_INTEGER current;
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
QueryPerformanceCounter(¤t);
|
2017-01-24 11:28:27 +03:00
|
|
|
return (DWORD)(current.QuadPart * 1000LL / freq.QuadPart);
|
2015-06-11 10:11:19 +03:00
|
|
|
#else
|
|
|
|
return GetTickCount();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-02-27 13:17:24 +04:00
|
|
|
BOOL IsProcessorFeaturePresentEx(DWORD ProcessorFeature)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
#ifdef _M_ARM
|
|
|
|
#ifdef __linux__
|
|
|
|
unsigned caps;
|
|
|
|
caps = GetARMCPUCaps();
|
|
|
|
|
|
|
|
switch (ProcessorFeature)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_ARM_VFP1:
|
|
|
|
if (caps & HWCAP_VFP)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_ARM_VFP3D16:
|
|
|
|
if (caps & HWCAP_VFPv3D16)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_ARM_VFP4:
|
|
|
|
if (caps & HWCAP_VFPv4)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_ARM_IDIVA:
|
|
|
|
if (caps & HWCAP_IDIVA)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_ARM_IDIVT:
|
|
|
|
if (caps & HWCAP_IDIVT)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2013-02-27 13:17:24 +04:00
|
|
|
}
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2013-02-27 13:17:24 +04:00
|
|
|
#endif // __linux__
|
|
|
|
#elif defined(_M_IX86_AMD64)
|
|
|
|
unsigned a, b, c, d;
|
|
|
|
cpuid(1, &a, &b, &c, &d);
|
|
|
|
|
|
|
|
switch (ProcessorFeature)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_LZCNT:
|
|
|
|
{
|
|
|
|
unsigned a81, b81, c81, d81;
|
|
|
|
cpuid(0x80000001, &a81, &b81, &c81, &d81);
|
|
|
|
|
|
|
|
if (c81 & C81_BIT_LZCNT)
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PF_EX_3DNOW_PREFETCH:
|
|
|
|
if (c & C_BIT_3DNP)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_SSSE3:
|
|
|
|
if (c & C_BIT_SSSE3)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_SSE41:
|
|
|
|
if (c & C_BIT_SSE41)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_SSE42:
|
|
|
|
if (c & C_BIT_SSE42)
|
2013-02-27 13:17:24 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2013-03-04 12:40:26 +04:00
|
|
|
#if defined(__GNUC__) && defined(__AVX__)
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_AVX:
|
|
|
|
case PF_EX_FMA:
|
|
|
|
case PF_EX_AVX_AES:
|
|
|
|
case PF_EX_AVX_PCLMULQDQ:
|
|
|
|
{
|
|
|
|
/* Check for general AVX support */
|
|
|
|
if ((c & C_BITS_AVX) != C_BITS_AVX)
|
|
|
|
break;
|
2013-02-27 13:17:24 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
int e, f;
|
|
|
|
xgetbv(0, e, f);
|
2013-02-27 13:17:24 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
/* XGETBV enabled for applications and XMM/YMM states enabled */
|
|
|
|
if ((e & E_BITS_AVX) == E_BITS_AVX)
|
|
|
|
{
|
|
|
|
switch (ProcessorFeature)
|
2013-03-15 02:18:21 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_AVX:
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_FMA:
|
|
|
|
if (c & C_BIT_FMA)
|
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_AVX_AES:
|
|
|
|
if (c & C_BIT_AES)
|
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case PF_EX_AVX_PCLMULQDQ:
|
|
|
|
if (c & C_BIT_PCLMULQDQ)
|
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2013-03-15 02:18:21 +04:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-02-27 13:17:24 +04:00
|
|
|
#endif //__AVX__
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
2013-02-27 13:17:24 +04:00
|
|
|
}
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2012-06-19 06:22:39 +04:00
|
|
|
#endif
|
2013-02-27 13:17:24 +04:00
|
|
|
return ret;
|
|
|
|
}
|