libwinpr-sysinfo: added platform-specific macro definitions
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Wed, 23 Jan 2013 22:46:32 +0000 (17:46 -0500)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Wed, 23 Jan 2013 22:46:32 +0000 (17:46 -0500)
libfreerdp/primitives/primitives.c
winpr/include/winpr/platform.h [new file with mode: 0644]
winpr/include/winpr/sysinfo.h
winpr/libwinpr/sysinfo/CMakeLists.txt
winpr/libwinpr/sysinfo/sysinfo.c
winpr/libwinpr/sysinfo/test/.gitignore [new file with mode: 0644]
winpr/libwinpr/sysinfo/test/CMakeLists.txt [new file with mode: 0644]
winpr/libwinpr/sysinfo/test/TestGetNativeSystemInfo.c [new file with mode: 0644]

index 29f6f70..acff06e 100644 (file)
@@ -22,6 +22,8 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <winpr/platform.h>
+
 #include <freerdp/primitives.h>
 
 #include "prim_internal.h"
diff --git a/winpr/include/winpr/platform.h b/winpr/include/winpr/platform.h
new file mode 100644 (file)
index 0000000..945e1a0
--- /dev/null
@@ -0,0 +1,253 @@
+/**
+ * WinPR: Windows Portable Runtime
+ * Platform-Specific Definitions
+ *
+ * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * 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.
+ */
+
+#ifndef WINPR_PLATFORM_H
+#define WINPR_PLATFORM_H
+
+#include <stdlib.h>
+
+#include <winpr/winpr.h>
+#include <winpr/wtypes.h>
+
+/*
+ * Processor Architectures:
+ * http://sourceforge.net/p/predef/wiki/Architectures/
+ *
+ * Visual Studio Predefined Macros:
+ * http://msdn.microsoft.com/en-ca/library/vstudio/b0084kay.aspx
+ */
+
+/* Intel x86 (_M_IX86) */
+
+#if defined(i386) || defined(__i386) || defined(__i386__) || \
+       defined(__i486__) || defined(__i586__) || defined(__i686__) || \
+       defined(__X86__) || defined(_X86_) || defined(__I86__) || \
+       defined(__IA32__) || defined(__THW_INTEL__) || defined(__INTEL__)
+#ifndef _M_IX86
+#define _M_IX86                1
+#endif
+#endif
+
+/* AMD64 (_M_AMD64) */
+
+#if defined(__amd64) || defined(__amd64__) || \
+       defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
+#ifndef _M_AMD64
+#define _M_AMD64       1
+#endif
+#endif
+
+/* ARM (_M_ARM) */
+
+#if defined(__arm__) || defined(__thumb__) || \
+       defined(__TARGET_ARCH_ARM) || defined(__TARGET_ARCH_THUMB)
+#ifndef _M_ARM
+#define _M_ARM         1
+#endif
+#endif
+
+/* ARM64 (_M_ARM64) */
+
+#if defined(__aarch64__)
+#ifndef _M_ARM64
+#define _M_ARM64       1
+#endif
+#endif
+
+/* MIPS (_M_MIPS) */
+
+#if defined(mips) || defined(__mips) || \
+       defined(__mips__) || defined(__MIPS__)
+#ifndef _M_MIPS
+#define         _M_MIPS        1
+#endif
+#endif
+
+/* PowerPC (_M_PPC) */
+
+#if defined(__ppc__) || defined(__powerpc) || \
+       defined(__powerpc__) || defined(__POWERPC__) || defined(_ARCH_PPC)
+#ifndef _M_PPC
+#define         _M_PPC         1
+#endif
+#endif
+
+/* Intel Itanium (_M_IA64) */
+
+#if defined(__ia64) || defined(__ia64__) || \
+       defined(_IA64) || defined(__IA64__)
+#ifndef _M_IA64
+#define _M_IA64                1
+#endif
+#endif
+
+/* Alpha (_M_ALPHA) */
+
+#if defined(__alpha) || defined(__alpha__)
+#ifndef _M_ALPHA
+#define _M_ALPHA       1
+#endif
+#endif
+
+/* SPARC (_M_SPARC) */
+
+#if defined(__sparc) || defined(__sparc__)
+#ifndef _M_SPARC
+#define _M_SPARC       1
+#endif
+#endif
+
+/**
+ * Operating Systems:
+ * http://sourceforge.net/p/predef/wiki/OperatingSystems/
+ */
+
+/* Windows (_WIN32) */
+
+/* Linux (__linux__) */
+
+#if defined(linux) || defined(__linux)
+#ifndef __linux__
+#define __linux__      1
+#endif
+#endif
+
+/* GNU/Linux (__gnu_linux__) */
+
+/* Mac OS X (__MACOSX__) */
+
+#if (__APPLE__ && __MACH__)
+#ifndef __MACOSX__
+#define __MACOSX__     1
+#endif
+#endif
+
+/* iOS (__IOS__)*/
+
+#if (__APPLE__ && TARGET_OS_IPHONE)
+#ifndef __IOS__
+#define __IOS__                1
+#endif
+#endif
+
+/* Android (__ANDROID__) */
+
+/* Cygwin (__CYGWIN__) */
+
+/* FreeBSD (__FreeBSD__) */
+
+/* NetBSD (__NetBSD__) */
+
+/* OpenBSD (__OpenBSD__) */
+
+/* DragonFly (__DragonFly__) */
+
+/* Solaris (__sun) */
+
+#if defined(sun)
+#ifndef __sun
+#define __sun  1
+#endif
+#endif
+
+/* IRIX (__sgi) */
+
+#if defined(sgi)
+#ifndef __sgi
+#define __sgi          1
+#endif
+#endif
+
+/* AIX (_AIX) */
+
+#if defined(__TOS_AIX__)
+#ifndef _AIX
+#define _AIX           1
+#endif
+#endif
+
+/* HP-UX (__hpux) */
+
+#if defined(hpux) || defined(_hpux)
+#ifndef __hpux
+#define __hpux         1
+#endif
+#endif
+
+/* BeOS (__BEOS__) */
+
+/* QNX (__QNXNTO__) */
+
+/**
+ * Endianness:
+ * http://sourceforge.net/p/predef/wiki/Endianness/
+ */
+
+#if defined(__gnu_linux__)
+#include <endian.h>
+#endif
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || \
+       defined(__OpenBSD__) || defined(__DragonFly__)
+#include <sys/param.h>
+#endif
+
+/* Big-Endian */
+
+#ifdef __BYTE_ORDER
+
+#if (__BYTE_ORDER == __BIG_ENDIAN)
+#ifndef __BIG_ENDIAN__
+#define __BIG_ENDIAN__         1
+#endif
+#endif
+
+#else
+
+#if defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) \
+       defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
+#ifndef __BIG_ENDIAN__
+#define __BIG_ENDIAN__         1
+#endif
+#endif
+
+#endif /* __BYTE_ORDER */
+
+/* Little-Endian */
+
+#ifdef __BYTE_ORDER
+
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+#ifndef __LITTLE_ENDIAN__
+#define __LITTLE_ENDIAN__      1
+#endif
+#endif
+
+#else
+
+#if defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) \
+       defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
+#ifndef __LITTLE_ENDIAN__
+#define __LITTLE_ENDIAN__      1
+#endif
+#endif
+
+#endif /* __BYTE_ORDER */
+
+#endif /* WINPR_PLATFORM_H */
index efb97e7..a4d483e 100644 (file)
 
 #ifndef _WIN32
 
+#define PROCESSOR_ARCHITECTURE_INTEL                   0
+#define PROCESSOR_ARCHITECTURE_MIPS                    1
+#define PROCESSOR_ARCHITECTURE_ALPHA                   2
+#define PROCESSOR_ARCHITECTURE_PPC                     3
+#define PROCESSOR_ARCHITECTURE_SHX                     4
+#define PROCESSOR_ARCHITECTURE_ARM                     5
+#define PROCESSOR_ARCHITECTURE_IA64                    6
+#define PROCESSOR_ARCHITECTURE_ALPHA64                 7
+#define PROCESSOR_ARCHITECTURE_MSIL                    8
+#define PROCESSOR_ARCHITECTURE_AMD64                   9
+#define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64           10
+#define PROCESSOR_ARCHITECTURE_NEUTRAL                 11
+#define PROCESSOR_ARCHITECTURE_UNKNOWN                 0xFFFF
+
+#define PROCESSOR_INTEL_386                            386
+#define PROCESSOR_INTEL_486                            486
+#define PROCESSOR_INTEL_PENTIUM                                586
+#define PROCESSOR_INTEL_IA64                           2200
+#define PROCESSOR_AMD_X8664                            8664
+#define PROCESSOR_MIPS_R4000                           4000
+#define PROCESSOR_ALPHA_21064                          21064
+#define PROCESSOR_PPC_601                              601
+#define PROCESSOR_PPC_603                              603
+#define PROCESSOR_PPC_604                              604
+#define PROCESSOR_PPC_620                              620
+#define PROCESSOR_HITACHI_SH3                          10003
+#define PROCESSOR_HITACHI_SH3E                         10004
+#define PROCESSOR_HITACHI_SH4                          10005
+#define PROCESSOR_MOTOROLA_821                         821
+#define PROCESSOR_SHx_SH3                              103
+#define PROCESSOR_SHx_SH4                              104
+#define PROCESSOR_STRONGARM                            2577
+#define PROCESSOR_ARM720                               1824
+#define PROCESSOR_ARM820                               2080
+#define PROCESSOR_ARM920                               2336
+#define PROCESSOR_ARM_7TDMI                            70001
+#define PROCESSOR_OPTIL                                        0x494F
+
+#define PF_FLOATING_POINT_PRECISION_ERRATA             0
+#define PF_FLOATING_POINT_EMULATED                     1
+#define PF_COMPARE_EXCHANGE_DOUBLE                     2
+#define PF_MMX_INSTRUCTIONS_AVAILABLE                  3
+#define PF_PPC_MOVEMEM_64BIT_OK                                4
+#define PF_ALPHA_BYTE_INSTRUCTIONS                     5
+#define PF_XMMI_INSTRUCTIONS_AVAILABLE                 6
+#define PF_3DNOW_INSTRUCTIONS_AVAILABLE                        7
+#define PF_RDTSC_INSTRUCTION_AVAILABLE                 8
+#define PF_PAE_ENABLED                                 9
+#define PF_XMMI64_INSTRUCTIONS_AVAILABLE               10
+#define PF_SSE_DAZ_MODE_AVAILABLE                      11
+#define PF_NX_ENABLED                                  12
+#define PF_SSE3_INSTRUCTIONS_AVAILABLE                 13
+#define PF_COMPARE_EXCHANGE128                         14
+#define PF_COMPARE64_EXCHANGE128                       15
+#define PF_CHANNELS_ENABLED                            16
+#define PF_XSAVE_ENABLED                               17
+#define PF_ARM_VFP_32_REGISTERS_AVAILABLE              18
+#define PF_ARM_NEON_INSTRUCTIONS_AVAILABLE             19
+#define PF_SECOND_LEVEL_ADDRESS_TRANSLATION            20
+#define PF_VIRT_FIRMWARE_ENABLED                       21
+#define PF_RDWRFSGSBASE_AVAILABLE                      22
+#define PF_FASTFAIL_AVAILABLE                          23
+#define PF_ARM_DIVIDE_INSTRUCTION_AVAILABLE            24
+#define PF_ARM_64BIT_LOADSTORE_ATOMIC                  25
+#define PF_ARM_EXTERNAL_CACHE_AVAILABLE                        26
+#define PF_ARM_FMAC_INSTRUCTIONS_AVAILABLE             27
+
+typedef struct _SYSTEM_INFO
+{
+       union
+       {
+               DWORD dwOemId;
+
+               struct
+               {
+                       WORD wProcessorArchitecture;
+                       WORD wReserved;
+               };
+       };
+
+       DWORD dwPageSize;
+       LPVOID lpMinimumApplicationAddress;
+       LPVOID lpMaximumApplicationAddress;
+       DWORD_PTR dwActiveProcessorMask;
+       DWORD dwNumberOfProcessors;
+       DWORD dwProcessorType;
+       DWORD dwAllocationGranularity;
+       WORD wProcessorLevel;
+       WORD wProcessorRevision;
+} SYSTEM_INFO, *LPSYSTEM_INFO;
+
+WINPR_API void GetSystemInfo(LPSYSTEM_INFO lpSystemInfo);
+WINPR_API void GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo);
+
 typedef enum _COMPUTER_NAME_FORMAT
 {
        ComputerNameNetBIOS,
index c235c75..e0a65dd 100644 (file)
@@ -38,3 +38,8 @@ else()
 endif()
 
 set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR")
+
+if(BUILD_TESTING)
+       add_subdirectory(test)
+endif()
+
index 34832d8..dccef1c 100644 (file)
  * GetLocalTime
  * GetLogicalProcessorInformation
  * GetLogicalProcessorInformationEx
+ * GetSystemInfo
  * GetNativeSystemInfo
  * GetProductInfo
  * GetSystemDirectoryA
  * GetSystemDirectoryW
  * GetSystemFirmwareTable
- * GetSystemInfo
  * GetSystemTime
  * GetSystemTimeAdjustment
  * GetSystemTimeAsFileTime
 
 #include <time.h>
 #include <unistd.h>
+
 #include <winpr/crt.h>
 
+void GetSystemInfo(LPSYSTEM_INFO lpSystemInfo)
+{
+       lpSystemInfo->wProcessorArchitecture = 0;
+       lpSystemInfo->wReserved = 0;
+
+       lpSystemInfo->dwPageSize = 0;
+       lpSystemInfo->lpMinimumApplicationAddress = NULL;
+       lpSystemInfo->lpMaximumApplicationAddress = NULL;
+       lpSystemInfo->dwActiveProcessorMask = NULL;
+
+       lpSystemInfo->dwNumberOfProcessors = 0;
+       lpSystemInfo->dwProcessorType = 0;
+
+       lpSystemInfo->dwAllocationGranularity = 0;
+
+       lpSystemInfo->wProcessorLevel = 0;
+       lpSystemInfo->wProcessorRevision = 0;
+}
+
+void GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo)
+{
+       GetSystemInfo(lpSystemInfo);
+}
+
 BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD nSize)
 {
        char hostname[256];
diff --git a/winpr/libwinpr/sysinfo/test/.gitignore b/winpr/libwinpr/sysinfo/test/.gitignore
new file mode 100644 (file)
index 0000000..2bafaaf
--- /dev/null
@@ -0,0 +1,3 @@
+TestSysInfo
+TestSysInfo.c
+
diff --git a/winpr/libwinpr/sysinfo/test/CMakeLists.txt b/winpr/libwinpr/sysinfo/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..79ba944
--- /dev/null
@@ -0,0 +1,31 @@
+
+set(MODULE_NAME "TestSysInfo")
+set(MODULE_PREFIX "TEST_SYSINFO")
+
+set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
+
+set(${MODULE_PREFIX}_TESTS
+       TestGetNativeSystemInfo.c)
+
+create_test_sourcelist(${MODULE_PREFIX}_SRCS
+       ${${MODULE_PREFIX}_DRIVER}
+       ${${MODULE_PREFIX}_TESTS})
+
+add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
+
+set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
+       MONOLITHIC ${MONOLITHIC_BUILD}
+       MODULE winpr
+       MODULES winpr-crt winpr-sysinfo)
+
+target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
+
+set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
+
+foreach(test ${${MODULE_PREFIX}_TESTS})
+       get_filename_component(TestName ${test} NAME_WE)
+       add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
+endforeach()
+
+set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
+
diff --git a/winpr/libwinpr/sysinfo/test/TestGetNativeSystemInfo.c b/winpr/libwinpr/sysinfo/test/TestGetNativeSystemInfo.c
new file mode 100644 (file)
index 0000000..b4b2f8f
--- /dev/null
@@ -0,0 +1,9 @@
+
+#include <winpr/crt.h>
+#include <winpr/sysinfo.h>
+
+int TestGetNativeSystemInfo(int argc, char* argv[])
+{
+       return 0;
+}
+