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>
|
|
|
|
|
2013-12-04 00:19:58 +04:00
|
|
|
#if defined(__MACOSX__) || defined(__IOS__) || \
|
2013-01-24 04:37:50 +04:00
|
|
|
defined(__FreeBSD__) || defined(__NetBSD__) || \
|
|
|
|
defined(__OpenBSD__) || defined(__DragonFly__)
|
|
|
|
#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)
|
|
|
|
{
|
|
|
|
case ANDROID_CPU_FAMILY_ARM:
|
|
|
|
return PROCESSOR_ARCHITECTURE_ARM;
|
|
|
|
|
|
|
|
case ANDROID_CPU_FAMILY_X86:
|
|
|
|
return PROCESSOR_ARCHITECTURE_INTEL;
|
|
|
|
|
|
|
|
case ANDROID_CPU_FAMILY_MIPS:
|
|
|
|
return PROCESSOR_ARCHITECTURE_MIPS;
|
|
|
|
|
|
|
|
case ANDROID_CPU_FAMILY_ARM64:
|
|
|
|
return PROCESSOR_ARCHITECTURE_ARM64;
|
|
|
|
|
|
|
|
case ANDROID_CPU_FAMILY_X86_64:
|
|
|
|
return PROCESSOR_ARCHITECTURE_AMD64;
|
|
|
|
|
|
|
|
case ANDROID_CPU_FAMILY_MIPS64:
|
|
|
|
return PROCESSOR_ARCHITECTURE_MIPS64;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return PROCESSOR_ARCHITECTURE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
#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)
|
2013-01-24 04:21:14 +04:00
|
|
|
numCPUs = (DWORD) sysconf(_SC_NPROCESSORS_ONLN);
|
2013-01-24 04:37:50 +04:00
|
|
|
#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)
|
|
|
|
numCPUs = (DWORD) mpctl(MPC_GETNUMSPUS, NULL, NULL);
|
|
|
|
#elif defined(__sgi)
|
|
|
|
numCPUs = (DWORD) sysconf(_SC_NPROC_ONLN);
|
|
|
|
#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)
|
|
|
|
dwPageSize = (DWORD) sc_page_size;
|
|
|
|
|
|
|
|
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;
|
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);
|
2014-05-29 20:39:09 +04:00
|
|
|
stm = gmtime(&ct);
|
|
|
|
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);
|
2014-05-29 20:39:09 +04: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;
|
|
|
|
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;
|
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);
|
2014-05-29 20:39:09 +04:00
|
|
|
ltm = localtime(&ct);
|
|
|
|
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);
|
2014-05-29 20:39:09 +04: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;
|
|
|
|
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 */
|
|
|
|
time64.QuadPart *= 10000000; /* Convert timestamp to tenths of a microsecond */
|
|
|
|
lpSystemTimeAsFileTime->dwLowDateTime = time64.LowPart;
|
|
|
|
lpSystemTimeAsFileTime->dwHighDateTime = time64.HighPart;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
#define CLOCK_MONOTONIC_RAW 4
|
|
|
|
#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:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833
|
|
|
|
*/
|
|
|
|
|
|
|
|
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));
|
|
|
|
return GetVersionExA((LPOSVERSIONINFOA) lpVersionInformation);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(_WIN32) || defined(_UWP)
|
|
|
|
|
2016-02-08 18:19:36 +03:00
|
|
|
BOOL GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
|
|
|
|
{
|
|
|
|
char* dot;
|
|
|
|
int length;
|
|
|
|
char hostname[256];
|
|
|
|
|
|
|
|
if (gethostname(hostname, sizeof(hostname)) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
length = (int) strlen(hostname);
|
|
|
|
dot = strchr(hostname, '.');
|
|
|
|
|
|
|
|
if (dot)
|
2017-01-24 11:28:27 +03:00
|
|
|
length = (int)(dot - hostname);
|
2016-02-08 18:19:36 +03:00
|
|
|
|
|
|
|
if (*lpnSize <= (DWORD) length)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
|
|
|
*lpnSize = length + 1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lpBuffer)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
CopyMemory(lpBuffer, hostname, length);
|
|
|
|
lpBuffer[length] = '\0';
|
|
|
|
*lpnSize = length;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD lpnSize)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
char hostname[256];
|
|
|
|
|
|
|
|
if ((NameType == ComputerNameNetBIOS) || (NameType == ComputerNamePhysicalNetBIOS))
|
|
|
|
return GetComputerNameA(lpBuffer, lpnSize);
|
|
|
|
|
|
|
|
if (gethostname(hostname, sizeof(hostname)) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
length = (int) strlen(hostname);
|
|
|
|
|
|
|
|
switch (NameType)
|
|
|
|
{
|
2017-01-24 11:56:45 +03:00
|
|
|
case ComputerNameDnsHostname:
|
|
|
|
case ComputerNameDnsDomain:
|
|
|
|
case ComputerNameDnsFullyQualified:
|
|
|
|
case ComputerNamePhysicalDnsHostname:
|
|
|
|
case ComputerNamePhysicalDnsDomain:
|
|
|
|
case ComputerNamePhysicalDnsFullyQualified:
|
|
|
|
if (*lpnSize <= (DWORD) length)
|
2016-02-08 18:19:36 +03:00
|
|
|
{
|
|
|
|
*lpnSize = length + 1;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lpBuffer)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
CopyMemory(lpBuffer, hostname, length);
|
|
|
|
lpBuffer[length] = '\0';
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2016-02-08 18:19:36 +03:00
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
default:
|
|
|
|
return FALSE;
|
2016-02-08 18:19:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "GetComputerNameExW unimplemented");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-02-06 00:28:45 +03:00
|
|
|
#if defined(_UWP)
|
|
|
|
|
|
|
|
DWORD GetTickCount(void)
|
|
|
|
{
|
|
|
|
return (DWORD) GetTickCount64();
|
|
|
|
}
|
|
|
|
|
|
|
|
#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)
|
|
|
|
ticks = (ULONGLONG) GetTickCount();
|
|
|
|
#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_) \
|
2014-08-18 19:22:22 +04:00
|
|
|
__asm__ __volatile__ ("xgetbv" : "=a" (_lo_), "=d" (_hi_) : "c" (_func_))
|
2013-02-27 13:17:24 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#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)
|
2013-03-15 04:06:33 +04:00
|
|
|
#define C_BIT_PCLMULQDQ (1<<1)
|
2014-10-06 23:50:49 +04:00
|
|
|
#define C81_BIT_LZCNT (1<<5)
|
2013-03-15 04:06:33 +04:00
|
|
|
#define C_BIT_3DNP (1<<8)
|
2013-02-27 13:17:24 +04:00
|
|
|
#define C_BIT_3DNP (1<<8)
|
|
|
|
#define C_BIT_SSSE3 (1<<9)
|
|
|
|
#define C_BIT_SSE41 (1<<19)
|
|
|
|
#define C_BIT_SSE42 (1<<20)
|
2013-03-15 04:06:33 +04:00
|
|
|
#define C_BIT_FMA (1<<12)
|
|
|
|
#define C_BIT_AES (1<<25)
|
|
|
|
#define C_BIT_XGETBV (1<<27)
|
2013-02-27 13:17:24 +04:00
|
|
|
#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(
|
2017-01-24 11:28:27 +03:00
|
|
|
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;
|
|
|
|
__asm volatile
|
|
|
|
(
|
2017-01-24 11:28:27 +03:00
|
|
|
/* The EBX (or RBX register on x86_64) is used for the PIC base address
|
2017-01-24 11:56:45 +03:00
|
|
|
* 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)
|
|
|
|
: "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)
|
|
|
|
#define HWCAP_HALF (1 << 1)
|
|
|
|
#define HWCAP_THUMB (1 << 2)
|
|
|
|
#define HWCAP_26BIT (1 << 3) /* Play it safe */
|
|
|
|
#define HWCAP_FAST_MULT (1 << 4)
|
|
|
|
#define HWCAP_FPA (1 << 5)
|
|
|
|
#define HWCAP_VFP (1 << 6)
|
|
|
|
#define HWCAP_EDSP (1 << 7)
|
|
|
|
#define HWCAP_JAVA (1 << 8)
|
|
|
|
#define HWCAP_IWMMXT (1 << 9)
|
|
|
|
#define HWCAP_CRUNCH (1 << 10)
|
|
|
|
#define HWCAP_THUMBEE (1 << 11)
|
|
|
|
#define HWCAP_NEON (1 << 12)
|
|
|
|
#define HWCAP_VFPv3 (1 << 13)
|
|
|
|
#define HWCAP_VFPv3D16 (1 << 14) /* also set for VFPv4-D16 */
|
|
|
|
#define HWCAP_TLS (1 << 15)
|
|
|
|
#define HWCAP_VFPv4 (1 << 16)
|
|
|
|
#define HWCAP_IDIVA (1 << 17)
|
|
|
|
#define HWCAP_IDIVT (1 << 18)
|
|
|
|
#define HWCAP_VFPD32 (1 << 19) /* set if VFP has 32 regs (not 16) */
|
|
|
|
#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
|
|
|
unsigned a_type; /* Entry type */
|
|
|
|
unsigned a_val; /* Integer value */
|
|
|
|
} 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)
|
|
|
|
{
|
|
|
|
case PF_ARM_NEON_INSTRUCTIONS_AVAILABLE:
|
|
|
|
case PF_ARM_NEON:
|
|
|
|
return features & ANDROID_CPU_ARM_FEATURE_NEON;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2017-01-24 11:56:45 +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)
|
|
|
|
{
|
2017-01-24 11:56:45 +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)
|
|
|
|
{
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2017-01-24 11:56:45 +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)
|
|
|
|
{
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +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)
|
|
|
|
{
|
2017-01-24 11:56:45 +03:00
|
|
|
case PF_EX_LZCNT:
|
|
|
|
{
|
|
|
|
unsigned a81, b81, c81, d81;
|
2014-10-06 23:50:49 +04:00
|
|
|
cpuid(0x80000001, &a81, &b81, &c81, &d81);
|
2017-01-24 11:28:27 +03:00
|
|
|
|
2014-10-06 23:50:49 +04:00
|
|
|
if (c81 & C81_BIT_LZCNT)
|
|
|
|
ret = TRUE;
|
2017-01-24 11:56:45 +03:00
|
|
|
}
|
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +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
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2013-03-04 12:40:26 +04:00
|
|
|
#if defined(__GNUC__) && defined(__AVX__)
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2017-01-24 11:56:45 +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)
|
2013-03-15 02:18:21 +04:00
|
|
|
break;
|
2013-02-27 13:17:24 +04:00
|
|
|
|
2013-03-15 02:18:21 +04:00
|
|
|
int e, f;
|
|
|
|
xgetbv(0, e, f);
|
2013-02-27 13:17:24 +04:00
|
|
|
|
2013-03-15 04:06:33 +04:00
|
|
|
/* XGETBV enabled for applications and XMM/YMM states enabled */
|
2013-03-15 02:18:21 +04:00
|
|
|
if ((e & E_BITS_AVX) == E_BITS_AVX)
|
|
|
|
{
|
|
|
|
switch (ProcessorFeature)
|
2013-02-27 13:17:24 +04:00
|
|
|
{
|
2017-01-24 11:56:45 +03:00
|
|
|
case PF_EX_AVX:
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
case PF_EX_FMA:
|
|
|
|
if (c & C_BIT_FMA)
|
2013-03-15 02:18:21 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
case PF_EX_AVX_AES:
|
|
|
|
if (c & C_BIT_AES)
|
2013-03-15 04:06:33 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
case PF_EX_AVX_PCLMULQDQ:
|
|
|
|
if (c & C_BIT_PCLMULQDQ)
|
2013-03-15 02:18:21 +04:00
|
|
|
ret = TRUE;
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2017-01-24 11:56:45 +03:00
|
|
|
break;
|
2013-03-15 02:18:21 +04:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 11:56:45 +03:00
|
|
|
}
|
|
|
|
break;
|
2013-02-27 13:17:24 +04:00
|
|
|
#endif //__AVX__
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2017-01-24 11:56:45 +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;
|
|
|
|
}
|