remove Windows/ICC support

This commit is contained in:
Konstantinos Margaritis 2021-07-30 12:49:38 +03:00 committed by Konstantinos Margaritis
parent 8cff876962
commit 08357a096c
41 changed files with 94 additions and 892 deletions

View File

@ -142,42 +142,8 @@ if (BUILD_AVX512VBMI)
set(BUILD_AVX512 ON)
endif ()
option(WINDOWS_ICC "Use Intel C++ Compiler on Windows, default off, requires ICC to be set in project" OFF)
# TODO: per platform config files?
# TODO: windows generator on cmake always uses msvc, even if we plan to build with icc
if(MSVC OR MSVC_IDE)
message(STATUS "Building for Windows")
if (MSVC_VERSION LESS 1700)
message(FATAL_ERROR "The project requires C++11 features.")
else()
if (WINDOWS_ICC)
set(ARCH_C_FLAGS "/QxHost")
set(ARCH_CXX_FLAGS "/QxHost")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O3 /Qstd=c99 /Qrestrict /wd4267 /Qdiag-disable:remark")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Qstd=c++11 /Qrestrict /QxHost /wd4267 /wd4800 /Qdiag-disable:remark -DBOOST_DETAIL_NO_CONTAINER_FWD -D_SCL_SECURE_NO_WARNINGS")
else()
set(MSVC_WARNS "/wd4101 /wd4146 /wd4172 /wd4200 /wd4244 /wd4267 /wd4307 /wd4334 /wd4805 /wd4996 -D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2 ${MSVC_WARNS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 ${MSVC_WARNS} /wd4800 -DBOOST_DETAIL_NO_CONTAINER_FWD")
endif()
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/RTC1" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
if (DISABLE_ASSERTS)
set(CMAKE_C_FLAGS_DEBUG "/DNDEBUG ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_DEBUG "/DNDEBUG ${CMAKE_CXX_FLAGS_DEBUG}")
endif ()
# flags only used to build hs libs
set(HS_C_FLAGS "/Gv")
set(HS_CXX_FLAGS "/Gv")
endif()
else()
# remove CMake's idea of optimisation
foreach (CONFIG ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES})
string(REGEX REPLACE "-O[^ ]*" "" CMAKE_C_FLAGS_${CONFIG} "${CMAKE_C_FLAGS_${CONFIG}}")
@ -300,7 +266,6 @@ else()
set(SKYLAKE_FLAG "-march=skylake-avx512")
set(ICELAKE_FLAG "-march=icelake-server")
endif ()
endif()
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
if (ARCH_IA32 OR ARCH_X86_64)
@ -370,7 +335,6 @@ CHECK_C_SOURCE_COMPILES("void *aa_test(void *x) { return __builtin_assume_aligne
CHECK_CXX_SOURCE_COMPILES("void *aa_test(void *x) { return __builtin_assume_aligned(x, 16);}\nint main(void) { return 0; }" HAVE_CXX_BUILTIN_ASSUME_ALIGNED)
CHECK_C_SOURCE_COMPILES("int main(void) { __builtin_constant_p(0); }" HAVE__BUILTIN_CONSTANT_P)
if (NOT WIN32)
set(C_FLAGS_TO_CHECK
# Variable length arrays are way bad, most especially at run time
"-Wvla"
@ -458,8 +422,6 @@ if(CC_STRINGOP_OVERFLOW)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-stringop-overflow")
endif()
endif()
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
@ -470,15 +432,6 @@ if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(FREEBSD true)
endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
if(NOT WIN32)
if(CMAKE_C_COMPILER_ID MATCHES "Intel")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -diag-error 10006 -diag-disable 68 -diag-disable 177 -diag-disable 186 -diag-disable 2304 -diag-disable 2305 -diag-disable 2338 -diag-disable 1418 -diag-disable 279 -diag-disable=remark")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -diag-error 10006 -diag-disable 68 -diag-disable 177 -diag-disable 186 -diag-disable 2304 -diag-disable 2305 -diag-disable 2338 -diag-disable 1418 -diag-disable 1170 -diag-disable 3373 -diag-disable 279 -diag-disable=remark")
endif()
endif()
if (NOT FAT_RUNTIME)
if (CROSS_COMPILE_AARCH64)
message(STATUS "Building for target CPU: ${ARCH_C_FLAGS}")
@ -496,7 +449,6 @@ endif()
add_subdirectory(util)
add_subdirectory(doc/dev-reference)
if (NOT WIN32)
# PCRE check, we have a fixed requirement for PCRE to use Chimera
# and hscollider
set(PCRE_REQUIRED_MAJOR_VERSION 8)
@ -519,25 +471,23 @@ endif()
if (EXISTS ${CMAKE_SOURCE_DIR}/chimera/CMakeLists.txt AND BUILD_CHIMERA)
add_subdirectory(chimera)
endif()
endif()
# do substitutions
configure_file(${CMAKE_MODULE_PATH}/config.h.in ${PROJECT_BINARY_DIR}/config.h)
configure_file(src/hs_version.h.in ${PROJECT_BINARY_DIR}/hs_version.h)
if (NOT WIN32)
# expand out library names for pkgconfig static link info
foreach (LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
# this is fragile, but protects us from toolchain specific files
if (NOT EXISTS ${LIB})
set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
endif()
endforeach()
configure_file(libhs.pc.in libhs.pc @ONLY) # only replace @ quoted vars
install(FILES ${CMAKE_BINARY_DIR}/libhs.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
# expand out library names for pkgconfig static link info
foreach (LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
# this is fragile, but protects us from toolchain specific files
if (NOT EXISTS ${LIB})
set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
endif()
endforeach()
configure_file(libhs.pc.in libhs.pc @ONLY) # only replace @ quoted vars
install(FILES ${CMAKE_BINARY_DIR}/libhs.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
# only set these after all tests are done
if (NOT FAT_RUNTIME)
@ -548,34 +498,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}")
endif()
if (WIN32)
# PCRE check, we have a fixed requirement for PCRE to use Chimera
# and hscollider
set(PCRE_REQUIRED_MAJOR_VERSION 8)
set(PCRE_REQUIRED_MINOR_VERSION 41)
set(PCRE_REQUIRED_VERSION ${PCRE_REQUIRED_MAJOR_VERSION}.${PCRE_REQUIRED_MINOR_VERSION})
include (${CMAKE_MODULE_PATH}/pcre.cmake)
if (NOT CORRECT_PCRE_VERSION)
message(STATUS "PCRE ${PCRE_REQUIRED_VERSION} or above not found")
endif()
# we need static libs for Chimera - too much deep magic for shared libs
if (CORRECT_PCRE_VERSION AND PCRE_BUILD_SOURCE AND BUILD_STATIC_LIBS)
set(BUILD_CHIMERA TRUE)
endif()
add_subdirectory(unit)
if (EXISTS ${CMAKE_SOURCE_DIR}/tools/CMakeLists.txt)
add_subdirectory(tools)
endif()
if (EXISTS ${CMAKE_SOURCE_DIR}/chimera/CMakeLists.txt AND BUILD_CHIMERA)
add_subdirectory(chimera)
endif()
endif()
if(NOT WIN32)
set(RAGEL_C_FLAGS "-Wno-unused")
endif()
set_source_files_properties(
${CMAKE_BINARY_DIR}/src/parser/Parser.cpp
@ -780,7 +703,6 @@ set (hs_exec_avx2_SRCS
src/util/arch/x86/masked_move.h
)
SET (hs_compile_SRCS
${hs_HEADERS}
src/crc32.h
@ -1475,6 +1397,6 @@ if (NOT BUILD_STATIC_LIBS)
endif ()
option(BUILD_EXAMPLES "Build Hyperscan example code (default TRUE)" TRUE)
if(NOT WIN32 AND BUILD_EXAMPLES)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

View File

@ -33,17 +33,15 @@ target_link_libraries(chimera hs pcre)
install(TARGETS chimera DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (NOT WIN32)
# expand out library names for pkgconfig static link info
foreach (LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
# this is fragile, but protects us from toolchain specific files
if (NOT EXISTS ${LIB})
set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
endif()
endforeach()
set(PRIVATE_LIBS "${PRIVATE_LIBS} -L${LIBDIR} -lpcre")
# expand out library names for pkgconfig static link info
foreach (LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
# this is fragile, but protects us from toolchain specific files
if (NOT EXISTS ${LIB})
set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
endif()
endforeach()
set(PRIVATE_LIBS "${PRIVATE_LIBS} -L${LIBDIR} -lpcre")
configure_file(libch.pc.in libch.pc @ONLY) # only replace @ quoted vars
install(FILES ${CMAKE_BINARY_DIR}/chimera/libch.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
configure_file(libch.pc.in libch.pc @ONLY) # only replace @ quoted vars
install(FILES ${CMAKE_BINARY_DIR}/chimera/libch.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

View File

@ -4,7 +4,7 @@
option(SQLITE_PREFER_STATIC "Build sqlite3 statically instead of using an installed lib" OFF)
if(NOT WIN32 AND NOT SQLITE_PREFER_STATIC)
if(NOT SQLITE_PREFER_STATIC)
find_package(PkgConfig QUIET)
# first check for sqlite on the system
@ -43,9 +43,7 @@ else()
if (NOT TARGET sqlite3_static)
# build sqlite as a static lib to compile into our test programs
add_library(sqlite3_static STATIC "${PROJECT_SOURCE_DIR}/sqlite3/sqlite3.c")
if (NOT WIN32)
set_target_properties(sqlite3_static PROPERTIES COMPILE_FLAGS "-Wno-error -Wno-extra -Wno-unused -Wno-cast-qual -DSQLITE_OMIT_LOAD_EXTENSION")
endif()
set_target_properties(sqlite3_static PROPERTIES COMPILE_FLAGS "-Wno-error -Wno-extra -Wno-unused -Wno-cast-qual -DSQLITE_OMIT_LOAD_EXTENSION")
endif()
endif()
endif()

View File

@ -353,12 +353,6 @@ hs_error_t dbIsValid(const hs_database_t *db) {
return HS_SUCCESS;
}
#if defined(_WIN32)
#define SNPRINTF_COMPAT _snprintf
#else
#define SNPRINTF_COMPAT snprintf
#endif
/** Allocate a buffer and prints the database info into it. Returns an
* appropriate error code on failure, or HS_SUCCESS on success. */
static
@ -400,9 +394,7 @@ hs_error_t print_database_string(char **s, u32 version, const platform_t plat,
return ret;
}
// Note: SNPRINTF_COMPAT is a macro defined above, to cope with systems
// that don't have snprintf but have a workalike.
int p_len = SNPRINTF_COMPAT(
int p_len = snprintf(
buf, len, "Version: %u.%u.%u Features: %s Mode: %s",
major, minor, release, features, mode);
if (p_len < 0) {

View File

@ -29,11 +29,7 @@
#ifndef HS_COMMON_H_
#define HS_COMMON_H_
#if defined(_WIN32)
#define HS_CDECL __cdecl
#else
#define HS_CDECL
#endif
#include <stdlib.h>
/**

View File

@ -242,7 +242,6 @@ int isMultiTopType(u8 t) {
/** Macros used in place of unimplemented NFA API functions for a given
* engine. */
#if !defined(_WIN32)
/* Use for functions that return an integer. */
#define NFA_API_NO_IMPL(...) \
@ -258,14 +257,6 @@ int isMultiTopType(u8 t) {
NFA_ZOMBIE_NO; \
})
#else
/* Simpler implementation for compilers that don't like the GCC extension used
* above. */
#define NFA_API_NO_IMPL(...) 0
#define NFA_API_ZOMBIE_NO_IMPL(...) NFA_ZOMBIE_NO
#endif
#ifdef __cplusplus
}

View File

@ -2116,7 +2116,6 @@ hwlmcb_rv_t checkPurelyNegatives(const struct RoseEngine *t,
return HWLM_CONTINUE_MATCHING;
}
#if !defined(_WIN32)
#define PROGRAM_CASE(name) \
case ROSE_INSTR_##name: { \
LABEL_ROSE_INSTR_##name: \
@ -2132,21 +2131,6 @@ hwlmcb_rv_t checkPurelyNegatives(const struct RoseEngine *t,
#define PROGRAM_NEXT_INSTRUCTION_JUMP \
goto *(next_instr[*(const u8 *)pc]);
#else
#define PROGRAM_CASE(name) \
case ROSE_INSTR_##name: { \
DEBUG_PRINTF("instruction: " #name " (pc=%u)\n", \
programOffset + (u32)(pc - pc_base)); \
const struct ROSE_STRUCT_##name *ri = \
(const struct ROSE_STRUCT_##name *)pc;
#define PROGRAM_NEXT_INSTRUCTION \
pc += ROUNDUP_N(sizeof(*ri), ROSE_INSTR_MIN_ALIGN); \
break; \
}
#define PROGRAM_NEXT_INSTRUCTION_JUMP continue;
#endif
hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t,
struct hs_scratch *scratch, u32 programOffset,
@ -2178,7 +2162,6 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t,
assert(*(const u8 *)pc != ROSE_INSTR_END);
#if !defined(_WIN32)
static const void *next_instr[] = {
&&LABEL_ROSE_INSTR_END, //!< End of program.
&&LABEL_ROSE_INSTR_ANCHORED_DELAY, //!< Delay until after anchored matcher.
@ -2254,7 +2237,6 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t,
&&LABEL_ROSE_INSTR_CHECK_MASK_64 //!< 64-bytes and/cmp/neg mask check.
#endif
};
#endif
for (;;) {
assert(ISALIGNED_N(pc, ROSE_INSTR_MIN_ALIGN));

View File

@ -1437,19 +1437,7 @@ void mergeLeftfixesVariableLag(RoseBuildImpl &build) {
assert(!parents.empty());
#ifndef _WIN32
engine_groups[MergeKey(left, parents)].emplace_back(left);
#else
// On windows, when passing MergeKey object into map 'engine_groups',
// it will not be copied, but will be freed along with
// engine_groups.clear().
// If we construct MergeKey object on the stack, it will be destructed
// on its life cycle ending, then on engine_groups.clear(), which
// will cause is_block_type_valid() assertion error in MergeKey
// destructor.
MergeKey *mk = new MergeKey(left, parents);
engine_groups[*mk].emplace_back(left);
#endif
}
vector<vector<left_id>> chunks;

View File

@ -45,12 +45,7 @@
// stdint.h for things like uintptr_t and friends
#include <stdint.h>
/* ick */
#if defined(_WIN32)
#define ALIGN_ATTR(x) __declspec(align(x))
#else
#define ALIGN_ATTR(x) __attribute__((aligned((x))))
#endif
#define ALIGN_DIRECTIVE ALIGN_ATTR(16)
#define ALIGN_AVX_DIRECTIVE ALIGN_ATTR(32)
@ -66,13 +61,8 @@ typedef signed int s32;
/* We append the 'a' for aligned, since these aren't common, garden variety
* 64 bit values. The alignment is necessary for structs on some platforms,
* so we don't end up performing accidental unaligned accesses. */
#if defined(_WIN32) && ! defined(_WIN64)
typedef unsigned long long ALIGN_ATTR(4) u64a;
typedef signed long long ALIGN_ATTR(4) s64a;
#else
typedef unsigned long long ALIGN_ATTR(8) u64a;
typedef signed long long ALIGN_ATTR(8) s64a;
#endif
/* get the SIMD types */
#include "util/simd_types.h"
@ -83,24 +73,14 @@ typedef u32 ReportID;
/* Shorthand for attribute to mark a function as part of our public API.
* Functions without this attribute will be hidden. */
#if !defined(_WIN32)
#define HS_PUBLIC_API __attribute__((visibility("default")))
#else
// TODO: dllexport defines for windows
#define HS_PUBLIC_API
#endif
#define ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0]))
/** \brief Shorthand for the attribute to shut gcc about unused parameters */
#if !defined(_WIN32)
#define UNUSED __attribute__ ((unused))
#else
#define UNUSED
#endif
/* really_inline forces inlining always */
#if !defined(_WIN32)
#if defined(HS_OPTIMIZE)
#define really_inline inline __attribute__ ((always_inline, unused))
#else
@ -113,33 +93,9 @@ typedef u32 ReportID;
#define alignof __alignof
#define HAVE_TYPEOF 1
#else // ms windows
#define really_inline __forceinline
#define really_really_inline __forceinline
#define never_inline
#define __builtin_prefetch(...) do {} while(0)
#if defined(__cplusplus)
#define __typeof__ decltype
#define HAVE_TYPEOF 1
#else // C
/* msvc doesn't have decltype or typeof in C */
#define inline __inline
#define alignof __alignof
#endif
#endif
// We use C99-style "restrict".
#ifdef _WIN32
#ifdef __cplusplus
#define restrict
#else
#define restrict __restrict
#endif
#else
#define restrict __restrict
#endif
// Align to 16-byte boundary
#define ROUNDUP_16(a) (((a) + 0xf) & ~0xf)
@ -186,25 +142,16 @@ typedef u32 ReportID;
#define LIMIT_TO_AT_MOST(a, b) (*(a) = MIN(*(a),(b)))
#define ENSURE_AT_LEAST(a, b) (*(a) = MAX(*(a),(b)))
#ifndef _WIN32
#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
#else
#define likely(x) (x)
#define unlikely(x) (x)
#endif
#if !defined(RELEASE_BUILD) || defined(DEBUG)
#ifdef _WIN32
#define PATH_SEP '\\'
#else
#define PATH_SEP '/'
#endif
#endif
#if defined(DEBUG) && !defined(DEBUG_PRINTF)
#include <string.h>

View File

@ -61,20 +61,12 @@ namespace ue2 {
void *aligned_malloc_internal(size_t size, size_t align) {
void *mem;
#if !defined(_WIN32)
int rv = posix_memalign(&mem, align, size);
if (rv != 0) {
DEBUG_PRINTF("posix_memalign returned %d when asked for %zu bytes\n",
rv, size);
return nullptr;
}
#else
if (nullptr == (mem = _aligned_malloc(size, align))) {
DEBUG_PRINTF("_aligned_malloc failed when asked for %zu bytes\n",
size);
return nullptr;
}
#endif
assert(mem);
return mem;
@ -85,11 +77,7 @@ void aligned_free_internal(void *ptr) {
return;
}
#if defined(_WIN32)
_aligned_free(ptr);
#else
free(ptr);
#endif
}
/** \brief 64-byte aligned, zeroed malloc.

View File

@ -31,7 +31,7 @@
#include "ue2common.h"
#if (defined(ARCH_IA32) || defined(ARCH_X86_64)) && !defined(_WIN32) && !defined(CPUID_H_)
#if (defined(ARCH_IA32) || defined(ARCH_X86_64)) && !defined(CPUID_H_)
#include <cpuid.h>
/* system header doesn't have a header guard */
#define CPUID_H_

View File

@ -42,64 +42,23 @@
static really_inline
u32 clz32_impl(u32 x) {
#if defined(_WIN32)
unsigned long r;
_BitScanReverse(&r, x);
return 31 - r;
#else
return clz32_impl_c(x);
#endif
}
static really_inline
u32 clz64_impl(u64a x) {
#if defined(_WIN64)
unsigned long r;
_BitScanReverse64(&r, x);
return 63 - r;
#elif defined(_WIN32)
unsigned long x1 = (u32)x;
unsigned long x2 = (u32)(x >> 32);
unsigned long r;
if (x2) {
_BitScanReverse(&r, x2);
return (u32)(31 - r);
}
_BitScanReverse(&r, (u32)x1);
return (u32)(63 - r);
#else
return clz64_impl_c(x);
#endif
}
// CTZ (count trailing zero) implementations.
static really_inline
u32 ctz32_impl(u32 x) {
#if defined(_WIN32)
unsigned long r;
_BitScanForward(&r, x);
return r;
#else
return ctz32_impl_c(x);
#endif
}
static really_inline
u32 ctz64_impl(u64a x) {
#if defined(_WIN64)
unsigned long r;
_BitScanForward64(&r, x);
return r;
#elif defined(_WIN32)
unsigned long r;
if (_BitScanForward(&r, (u32)x)) {
return (u32)r;
}
_BitScanForward(&r, x >> 32);
return (u32)(r + 32);
#else
return ctz64_impl_c(x);
#endif
}
static really_inline

View File

@ -33,7 +33,7 @@
#include "hs_internal.h"
#include "util/arch.h"
#if !defined(_WIN32) && !defined(CPUID_H_)
#if !defined(CPUID_H_)
#include <cpuid.h>
#endif

View File

@ -32,7 +32,7 @@
#include "ue2common.h"
#include "util/arch/common/cpuid_flags.h"
#if !defined(_WIN32) && !defined(CPUID_H_)
#if !defined(CPUID_H_)
#include <cpuid.h>
/* system header doesn't have a header guard */
#define CPUID_H_
@ -46,16 +46,7 @@ extern "C"
static inline
void cpuid(unsigned int op, unsigned int leaf, unsigned int *eax,
unsigned int *ebx, unsigned int *ecx, unsigned int *edx) {
#ifndef _WIN32
__cpuid_count(op, leaf, *eax, *ebx, *ecx, *edx);
#else
int a[4];
__cpuidex(a, op, leaf);
*eax = a[0];
*ebx = a[1];
*ecx = a[2];
*edx = a[3];
#endif
}
// ECX
@ -95,9 +86,6 @@ void cpuid(unsigned int op, unsigned int leaf, unsigned int *eax,
static inline
u64a xgetbv(u32 op) {
#if defined(_WIN32) || defined(__INTEL_COMPILER)
return _xgetbv(op);
#else
u32 a, d;
__asm__ volatile (
"xgetbv\n"
@ -105,14 +93,10 @@ u64a xgetbv(u32 op) {
"=d"(d)
: "c"(op));
return ((u64a)d << 32) + a;
#endif
}
static inline
int check_avx2(void) {
#if defined(__INTEL_COMPILER)
return _may_i_use_cpu_feature(_FEATURE_AVX2);
#else
unsigned int eax, ebx, ecx, edx;
cpuid(1, 0, &eax, &ebx, &ecx, &edx);
@ -141,7 +125,6 @@ int check_avx2(void) {
}
return 0;
#endif
}
static inline
@ -149,9 +132,6 @@ int check_avx512(void) {
/*
* For our purposes, having avx512 really means "can we use AVX512BW?"
*/
#if defined(__INTEL_COMPILER)
return _may_i_use_cpu_feature(_FEATURE_AVX512BW | _FEATURE_AVX512VL);
#else
unsigned int eax, ebx, ecx, edx;
cpuid(1, 0, &eax, &ebx, &ecx, &edx);
@ -184,14 +164,10 @@ int check_avx512(void) {
}
return 0;
#endif
}
static inline
int check_avx512vbmi(void) {
#if defined(__INTEL_COMPILER)
return _may_i_use_cpu_feature(_FEATURE_AVX512VBMI);
#else
unsigned int eax, ebx, ecx, edx;
cpuid(1, 0, &eax, &ebx, &ecx, &edx);
@ -229,7 +205,6 @@ int check_avx512vbmi(void) {
}
return 0;
#endif
}
static inline

View File

@ -38,12 +38,12 @@
#define HAVE_SIMD_128_BITS
#endif
#if defined(__SSE4_1__) || (defined(_WIN32) && defined(__AVX__))
#if defined(__SSE4_1__) || defined(__AVX__)
#define HAVE_SSE41
#define HAVE_SIMD_128_BITS
#endif
#if defined(__SSE4_2__) || (defined(_WIN32) && defined(__AVX__))
#if defined(__SSE4_2__) || defined(__AVX__)
#define HAVE_SSE42
#define HAVE_SIMD_128_BITS
#endif
@ -78,30 +78,16 @@
#define VECTORSIZE 16
#endif
/*
* ICC and MSVC don't break out POPCNT or BMI/2 as separate pre-def macros
*/
#if defined(__POPCNT__) || \
(defined(__INTEL_COMPILER) && defined(__SSE4_2__)) || \
(defined(_WIN32) && defined(__AVX__))
#if defined(__POPCNT__)
#define HAVE_POPCOUNT_INSTR
#endif
#if defined(__BMI__) || (defined(_WIN32) && defined(__AVX2__)) || \
(defined(__INTEL_COMPILER) && defined(__AVX2__))
#if defined(__BMI__)
#define HAVE_BMI
#endif
#if defined(__BMI2__) || (defined(_WIN32) && defined(__AVX2__)) || \
(defined(__INTEL_COMPILER) && defined(__AVX2__))
#if defined(__BMI2__)
#define HAVE_BMI2
#endif
/*
* MSVC uses a different form of inline asm
*/
#if defined(_WIN32) && defined(_MSC_VER)
#define NO_ASM
#endif
#endif // UTIL_ARCH_X86_H_

View File

@ -56,11 +56,7 @@ void describeChar(ostream &os, char c, enum cc_output_t out_type) {
const string backslash((out_type == CC_OUT_DOT ? 2 : 1), '\\');
#ifdef _WIN32
if (c >= 0x21 && c < 0x7F && c != '\\') {
#else
if (isgraph(c) && c != '\\') {
#endif
if (escaped.find(c) != string::npos) {
os << backslash << c;
} else if (out_type == CC_OUT_DOT

View File

@ -1197,11 +1197,7 @@ u32 mmbit_sparse_iter_begin(const u8 *bits, u32 total_bits, u32 *idx,
assert(ISALIGNED_N(it_root, alignof(struct mmbit_sparse_iter)));
// Our state _may_ be on the stack
#ifndef _WIN32
assert(ISALIGNED_N(s, alignof(struct mmbit_sparse_state)));
#else
assert(ISALIGNED_N(s, 4));
#endif
MDEBUG_PRINTF("%p total_bits %u\n", bits, total_bits);
// iterator should have _something_ at the root level
@ -1309,11 +1305,7 @@ u32 mmbit_sparse_iter_next(const u8 *bits, u32 total_bits, u32 last_key,
assert(ISALIGNED_N(it_root, alignof(struct mmbit_sparse_iter)));
// Our state _may_ be on the stack
#ifndef _WIN32
assert(ISALIGNED_N(s, alignof(struct mmbit_sparse_state)));
#else
assert(ISALIGNED_N(s, 4));
#endif
MDEBUG_PRINTF("%p total_bits %u\n", bits, total_bits);
MDEBUG_PRINTF("NEXT (total_bits=%u, last_key=%u)\n", total_bits, last_key);
@ -1466,11 +1458,7 @@ void mmbit_sparse_iter_unset(u8 *bits, u32 total_bits,
assert(ISALIGNED_N(it, alignof(struct mmbit_sparse_iter)));
// Our state _may_ be on the stack
#ifndef _WIN32
assert(ISALIGNED_N(s, alignof(struct mmbit_sparse_state)));
#else
assert(ISALIGNED_N(s, 4));
#endif
MDEBUG_PRINTF("%p total_bits %u\n", bits, total_bits);

View File

@ -38,36 +38,38 @@
static really_inline
u32 popcount32(u32 x) {
#if defined(HAVE_POPCOUNT_INSTR)
// Single-instruction builtin.
return _mm_popcnt_u32(x);
#else
// Fast branch-free version from bit-twiddling hacks as older Intel
// processors do not have a POPCNT instruction.
x -= (x >> 1) & 0x55555555;
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24;
#endif
return __builtin_popcount(x);
// #if defined(HAVE_POPCOUNT_INSTR)
// // Single-instruction builtin.
// return _mm_popcnt_u32(x);
// #else
// // Fast branch-free version from bit-twiddling hacks as older Intel
// // processors do not have a POPCNT instruction.
// x -= (x >> 1) & 0x55555555;
// x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
// return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24;
// #endif
}
static really_inline
u32 popcount64(u64a x) {
#if defined(ARCH_X86_64)
# if defined(HAVE_POPCOUNT_INSTR)
// Single-instruction builtin.
return (u32)_mm_popcnt_u64(x);
# else
// Fast branch-free version from bit-twiddling hacks as older Intel
// processors do not have a POPCNT instruction.
x -= (x >> 1) & 0x5555555555555555;
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333);
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f;
return (x * 0x0101010101010101) >> 56;
# endif
#else
// Synthesise from two 32-bit cases.
return popcount32(x >> 32) + popcount32(x);
#endif
return __builtin_popcountll(x);
// #if defined(ARCH_X86_64)
// # if defined(HAVE_POPCOUNT_INSTR)
// // Single-instruction builtin.
// return (u32)_mm_popcnt_u64(x);
// # else
// // Fast branch-free version from bit-twiddling hacks as older Intel
// // processors do not have a POPCNT instruction.
// x -= (x >> 1) & 0x5555555555555555;
// x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333);
// x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f;
// return (x * 0x0101010101010101) >> 56;
// # endif
// #else
// // Synthesise from two 32-bit cases.
// return popcount32(x >> 32) + popcount32(x);
// #endif
}
#endif /* UTIL_POPCOUNT_H_ */

View File

@ -35,12 +35,7 @@
#include "ue2common.h"
#if !defined(_WIN32)
#define PACKED__MAY_ALIAS __attribute__((packed, may_alias))
#else
#define PACKED__MAY_ALIAS
#pragma pack(push, 1) // pack everything until told otherwise
#endif
/// Perform an unaligned 16-bit load
static really_inline
@ -89,9 +84,6 @@ void unaligned_store_u64a(void *ptr, u64a val) {
struct unaligned *uptr = (struct unaligned *)ptr;
uptr->u = val;
}
#if defined(_WIN32)
#pragma pack(pop)
#endif // win32
#undef PACKED__MAY_ALIAS

View File

@ -9,18 +9,11 @@ include_directories(${PROJECT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/util)
if (WIN32)
add_subdirectory(hscheck)
add_subdirectory(hsbench)
add_subdirectory(hsdump)
add_subdirectory(hscollider)
else()
# add any subdir with a cmake file
file(GLOB dirents RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
foreach(e ${dirents})
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${e} AND
EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${e}/CMakeLists.txt)
add_subdirectory(${e})
endif ()
endforeach ()
endif()
# add any subdir with a cmake file
file(GLOB dirents RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
foreach(e ${dirents})
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${e} AND
EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${e}/CMakeLists.txt)
add_subdirectory(${e})
endif ()
endforeach ()

View File

@ -58,19 +58,10 @@ if (BUILD_CHIMERA)
)
add_executable(hsbench ${hsbench_SOURCES})
include_directories(${PCRE_INCLUDE_DIRS})
if(NOT WIN32)
target_link_libraries(hsbench hs chimera ${PCRE_LDFLAGS} databaseutil
expressionutil ${SQLITE3_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT})
else()
target_link_libraries(hsbench hs chimera pcre databaseutil
expressionutil ${SQLITE3_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT})
endif()
target_link_libraries(hsbench hs chimera ${PCRE_LDFLAGS} databaseutil
expressionutil ${SQLITE3_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT})
else()
if(WIN32 AND (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS))
add_executable(hsbench ${hsbench_SOURCES} $<TARGET_OBJECTS:hs_compile_shared> $<TARGET_OBJECTS:hs_exec_shared>)
else()
add_executable(hsbench ${hsbench_SOURCES})
endif()
add_executable(hsbench ${hsbench_SOURCES})
target_link_libraries(hsbench hs databaseutil expressionutil
${SQLITE3_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT})
endif()

View File

@ -166,23 +166,12 @@ void EngineChimera::printStats() const {
}
printf("Signatures: %s\n", compile_stats.signatures.c_str());
printf("Chimera info: %s\n", compile_stats.db_info.c_str());
#ifndef _WIN32
printf("Expression count: %'zu\n", compile_stats.expressionCount);
printf("Bytecode size: %'zu bytes\n", compile_stats.compiledSize);
#else
printf("Expression count: %zu\n", compile_stats.expressionCount);
printf("Bytecode size: %zu bytes\n", compile_stats.compiledSize);
#endif
printf("Database CRC: 0x%x\n", compile_stats.crc32);
#ifndef _WIN32
printf("Scratch size: %'zu bytes\n", compile_stats.scratchSize);
printf("Compile time: %'0.3Lf seconds\n", compile_stats.compileSecs);
printf("Peak heap usage: %'u bytes\n", compile_stats.peakMemorySize);
#else
printf("Scratch size: %zu bytes\n", compile_stats.scratchSize);
printf("Compile time: %0.3Lf seconds\n", compile_stats.compileSecs);
printf("Peak heap usage: %u bytes\n", compile_stats.peakMemorySize);
#endif
}
void EngineChimera::printCsvStats() const {

View File

@ -249,30 +249,15 @@ void EngineHyperscan::printStats() const {
}
printf("Signatures: %s\n", compile_stats.signatures.c_str());
printf("Hyperscan info: %s\n", compile_stats.db_info.c_str());
#ifndef _WIN32
printf("Expression count: %'zu\n", compile_stats.expressionCount);
printf("Bytecode size: %'zu bytes\n", compile_stats.compiledSize);
#else
printf("Expression count: %zu\n", compile_stats.expressionCount);
printf("Bytecode size: %zu bytes\n", compile_stats.compiledSize);
#endif
printf("Database CRC: 0x%x\n", compile_stats.crc32);
if (compile_stats.streaming) {
#ifndef _WIN32
printf("Stream state size: %'zu bytes\n", compile_stats.streamSize);
#else
printf("Stream state size: %zu bytes\n", compile_stats.streamSize);
#endif
}
#ifndef _WIN32
printf("Scratch size: %'zu bytes\n", compile_stats.scratchSize);
printf("Compile time: %'0.3Lf seconds\n", compile_stats.compileSecs);
printf("Peak heap usage: %'u bytes\n", compile_stats.peakMemorySize);
#else
printf("Scratch size: %zu bytes\n", compile_stats.scratchSize);
printf("Compile time: %0.3Lf seconds\n", compile_stats.compileSecs);
printf("Peak heap usage: %u bytes\n", compile_stats.peakMemorySize);
#endif
}
void EngineHyperscan::printCsvStats() const {

View File

@ -26,9 +26,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef _WIN32
#define PCRE_STATIC
#endif
#include "config.h"
#include "common.h"
@ -211,19 +208,11 @@ void EnginePCRE::printStats() const {
}
printf("Signatures: %s\n", compile_stats.signatures.c_str());
printf("PCRE info: %s\n", compile_stats.db_info.c_str());
#ifndef _WIN32
printf("Expression count: %'zu\n", compile_stats.expressionCount);
printf("Bytecode size: %'zu bytes\n", compile_stats.compiledSize);
printf("Scratch size: %'zu bytes\n", compile_stats.scratchSize);
printf("Compile time: %'0.3Lf seconds\n", compile_stats.compileSecs);
printf("Peak heap usage: %'u bytes\n", compile_stats.peakMemorySize);
#else
printf("Expression count: %zu\n", compile_stats.expressionCount);
printf("Bytecode size: %zu bytes\n", compile_stats.compiledSize);
printf("Scratch size: %zu bytes\n", compile_stats.scratchSize);
printf("Compile time: %0.3Lf seconds\n", compile_stats.compileSecs);
printf("Peak heap usage: %u bytes\n", compile_stats.peakMemorySize);
#endif
}
void EnginePCRE::printCsvStats() const {

View File

@ -34,7 +34,6 @@
#include "common.h"
#include "huge.h"
#ifndef _WIN32
#include <cstdio>
#include <cstring>
#include <errno.h>
@ -189,13 +188,3 @@ long gethugepagesize(void) {
return hpage_size;
}
#else
/* No huge page support on WIN32. */
hs_database_t *get_huge(hs_database_t *db) { return db; }
void release_huge(hs_database_t *db) { hs_free_database(db); }
#endif

View File

@ -57,18 +57,12 @@
#include <set>
#include <thread>
#ifndef _WIN32
#include <getopt.h>
#else
#include "win_getopt.h"
#endif
#ifndef _WIN32
#include <pthread.h>
#if defined(HAVE_PTHREAD_NP_H)
#include <pthread_np.h>
#endif
#include <unistd.h>
#endif
#include <boost/core/noncopyable.hpp>
#include <boost/range/adaptor/map.hpp>
@ -144,15 +138,6 @@ public:
// Apply processor affinity (if available) to this thread.
bool affine(UNUSED int cpu) {
#if defined(_WIN32)
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
assert(cpu >= 0 && (DWORD)cpu < system_info.dwNumberOfProcessors);
DWORD_PTR mask = 1 << cpu;
DWORD_PTR rv = SetThreadAffinityMask(thr.native_handle(), mask);
return rv != 0;
#endif
#ifdef HAVE_DECL_PTHREAD_SETAFFINITY_NP
#if defined(__FreeBSD__)
cpuset_t cpuset;
@ -206,7 +191,7 @@ void usage(const char *error) {
printf(" -H Benchmark using Chimera (if supported).\n");
printf(" -P Benchmark using PCRE (if supported).\n");
#endif
#if defined(HAVE_DECL_PTHREAD_SETAFFINITY_NP) || defined(_WIN32)
#if defined(HAVE_DECL_PTHREAD_SETAFFINITY_NP)
printf(" -T CPU,CPU,... or -T CPU-CPU\n");
printf(" Benchmark with threads on specified CPUs or CPU"
" range.\n");
@ -244,7 +229,7 @@ static
void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
UNUSED unique_ptr<Grey> &grey) {
const char options[] = "-b:c:Cd:e:E:G:hHi:n:No:p:PsS:Vw:z:"
#if defined(HAVE_DECL_PTHREAD_SETAFFINITY_NP) || defined(_WIN32)
#if defined(HAVE_DECL_PTHREAD_SETAFFINITY_NP)
"T:" // add the thread flag
#endif
;
@ -356,7 +341,7 @@ void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
case 'S':
sigName.assign(optarg);
break;
#if defined(HAVE_DECL_PTHREAD_SETAFFINITY_NP) || defined(_WIN32)
#if defined(HAVE_DECL_PTHREAD_SETAFFINITY_NP)
case 'T':
if (!strToList(optarg, threadCores)) {
usage("Couldn't parse argument to -T flag, should be"
@ -731,11 +716,7 @@ void displayPerScanResults(const vector<unique_ptr<ThreadContext>> &threads,
for (size_t j = 0; j != results.size(); j++) {
const auto &r = results[j];
double mbps = calc_mbps(r.seconds, bytesPerRun);
#ifndef _WIN32
printf("T %2u Scan %2zu: %'0.2f Mbit/sec\n", t->num, j, mbps);
#else
printf("T %2u Scan %2zu: %0.2f Mbit/sec\n", t->num, j, mbps);
#endif
}
}
printf("\n");
@ -780,7 +761,6 @@ void displayResults(const vector<unique_ptr<ThreadContext>> &threads,
}
}
#ifndef _WIN32
printf("Time spent scanning: %'0.3f seconds\n", totalSecs);
printf("Corpus size: %'llu bytes ", bytesPerRun);
switch (scan_mode) {
@ -796,56 +776,22 @@ void displayResults(const vector<unique_ptr<ThreadContext>> &threads,
printf("(%'zu blocks)\n", corpus_blocks.size());
break;
}
#else
printf("Time spent scanning: %0.3f seconds\n", totalSecs);
printf("Corpus size: %llu bytes ", bytesPerRun);
switch (scan_mode) {
case ScanMode::STREAMING:
printf("(%zu blocks in %llu streams)\n", corpus_blocks.size(),
count_streams(corpus_blocks));
break;
case ScanMode::VECTORED:
printf("(%zu blocks in %llu vectors)\n", corpus_blocks.size(),
count_streams(corpus_blocks));
break;
case ScanMode::BLOCK:
printf("(%zu blocks)\n", corpus_blocks.size());
break;
}
#endif
u64a totalBytes = bytesPerRun * repeats * threads.size();
u64a totalBlocks = corpus_blocks.size() * repeats * threads.size();
double matchRate = ((double)matchesPerRun * 1024) / bytesPerRun;
#ifndef _WIN32
printf("Matches per iteration: %'llu (%'0.3f matches/kilobyte)\n",
matchesPerRun, matchRate);
#else
printf("Matches per iteration: %llu (%0.3f matches/kilobyte)\n",
matchesPerRun, matchRate);
#endif
double blockRate = (double)totalBlocks / (double)totalSecs;
#ifndef _WIN32
printf("Overall block rate: %'0.2f blocks/sec\n", blockRate);
printf("Mean throughput (overall): %'0.2Lf Mbit/sec\n",
calc_mbps(totalSecs, totalBytes));
#else
printf("Overall block rate: %0.2f blocks/sec\n", blockRate);
printf("Mean throughput (overall): %0.2Lf Mbit/sec\n",
calc_mbps(totalSecs, totalBytes));
#endif
double lowestScanTime = fastestResult(threads);
#ifndef _WIN32
printf("Max throughput (per core): %'0.2Lf Mbit/sec\n",
calc_mbps(lowestScanTime, bytesPerRun));
#else
printf("Max throughput (per core): %0.2Lf Mbit/sec\n",
calc_mbps(lowestScanTime, bytesPerRun));
#endif
printf("\n");
if (display_per_scan) {
@ -992,7 +938,7 @@ void runBenchmark(const Engine &db,
numThreads = 1;
} else {
numThreads = threadCores.size();
#if defined(HAVE_DECL_PTHREAD_SETAFFINITY_NP) || defined(_WIN32)
#if defined(HAVE_DECL_PTHREAD_SETAFFINITY_NP)
useAffinity = true;
#else
useAffinity = false;

View File

@ -10,20 +10,8 @@ if (BUILD_CHIMERA)
include_directories(${PCRE_INCLUDE_DIRS})
add_definitions(-DHS_HYBRID)
add_executable(hscheck ${hscheck_SOURCES})
if(NOT WIN32)
target_link_libraries(hscheck hs chimera ${PCRE_LDFLAGS} expressionutil pthread)
else()
target_link_libraries(hscheck hs chimera pcre expressionutil)
endif()
target_link_libraries(hscheck hs chimera ${PCRE_LDFLAGS} expressionutil pthread)
else()
if(WIN32 AND (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS))
add_executable(hscheck ${hscheck_SOURCES} $<TARGET_OBJECTS:hs_compile_shared> $<TARGET_OBJECTS:hs_exec_shared>)
else()
add_executable(hscheck ${hscheck_SOURCES})
endif()
if(NOT WIN32)
target_link_libraries(hscheck hs expressionutil pthread)
else()
target_link_libraries(hscheck hs expressionutil)
endif()
add_executable(hscheck ${hscheck_SOURCES})
target_link_libraries(hscheck hs expressionutil pthread)
endif()

View File

@ -69,11 +69,8 @@
#include <stdexcept>
#include <string>
#include <thread>
#ifndef _WIN32
#include <getopt.h>
#else
#include "win_getopt.h"
#endif
#include <boost/algorithm/string/trim.hpp>
using namespace std;

View File

@ -65,31 +65,20 @@ set_source_files_properties(${hscollider_SOURCES} PROPERTIES
add_executable(hscollider ${hscollider_SOURCES})
add_dependencies(hscollider ragel_ColliderCorporaParser)
if(NOT WIN32)
if (BUILD_CHIMERA)
target_link_libraries(hscollider hs chimera ${PCRE_LDFLAGS} databaseutil
expressionutil corpusomatic crosscompileutil pthread
"${BACKTRACE_LDFLAGS}")
else()
target_link_libraries(hscollider hs ${PCRE_LDFLAGS} databaseutil
expressionutil corpusomatic crosscompileutil pthread
"${BACKTRACE_LDFLAGS}")
endif()
if (BUILD_CHIMERA)
target_link_libraries(hscollider hs chimera ${PCRE_LDFLAGS} databaseutil
expressionutil corpusomatic crosscompileutil pthread
"${BACKTRACE_LDFLAGS}")
else()
target_link_libraries(hscollider hs ${PCRE_LDFLAGS} databaseutil
expressionutil corpusomatic crosscompileutil pthread
"${BACKTRACE_LDFLAGS}")
endif()
if(HAVE_BACKTRACE)
set_source_files_properties(hscollider_SOURCES COMPILE_FLAGS
"${BACKTRACE_CFLAGS}")
endif()
else() # WIN32
set_target_properties(hscollider PROPERTIES LINK_FLAGS "/STACK:8388608,8388608")
if (BUILD_CHIMERA)
target_link_libraries(hscollider hs chimera pcre databaseutil
expressionutil corpusomatic crosscompileutil)
else()
target_link_libraries(hscollider hs pcre databaseutil
expressionutil corpusomatic crosscompileutil)
endif()
endif()
add_custom_target(
collide_quick_test

View File

@ -26,9 +26,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef _WIN32
#define PCRE_STATIC
#endif
#include "config.h"
#include "common.h"

View File

@ -46,11 +46,7 @@
#include <sstream>
#include <string>
#include <vector>
#ifndef _WIN32
#include <getopt.h>
#else
#include "win_getopt.h"
#endif
#define xstr(s) str(s)
#define str(s) #s

View File

@ -1845,13 +1845,9 @@ bool needsQuotes(const char *s) {
if (len == 0) {
return true;
}
#ifndef _WIN32
// don't confuse the correct isblank for the one in locale
int (*blank)(int) = &std::isblank;
if (find_if(s, s + len, blank) != s + len) {
#else
if (find_if(s, s + len, [](unsigned char c){ return std::isblank(c); }) != s + len) {
#endif
return true;
}

View File

@ -36,7 +36,7 @@
#include <ctype.h>
#include <string>
#if defined(HAVE_SIGACTION) || defined(_WIN32)
#if defined(HAVE_SIGACTION)
#include <signal.h>
#endif
@ -59,12 +59,8 @@ TLS_VARIABLE volatile size_t debug_corpus_len = 0;
extern std::string g_cmdline;
#if defined(_WIN32)
static void __cdecl sighandler(int signum) {
#elif defined(HAVE_SIGACTION)
#if defined(HAVE_SIGACTION)
static void sighandler(int signum) {
#endif
#if defined(HAVE_SIGACTION) || defined(_WIN32)
/* NOTE: This signal handler is designed solely to provide more information
* when a crash occurs in ue2collider -- it makes calls to signal-unsafe
* functions like printf() and backtrace() by design, since we're already
@ -149,12 +145,7 @@ static void sighandler(int signum) {
void installSignalHandler(void) {
#ifdef _WIN32
signal(SIGABRT, sighandler);
signal(SIGFPE, sighandler);
signal(SIGILL, sighandler);
signal(SIGSEGV, sighandler);
#elif defined(HAVE_SIGACTION)
#if defined(HAVE_SIGACTION)
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = sighandler;

View File

@ -40,11 +40,7 @@
#define STAGE_GRAPH_COMPILE 6
#define STAGE_GRAPH_RUN 7
#ifndef WIN32
#define TLS_VARIABLE __thread
#else
#define TLS_VARIABLE __declspec(thread)
#endif
extern TLS_VARIABLE volatile int debug_stage;
extern TLS_VARIABLE volatile int debug_expr;

View File

@ -10,10 +10,6 @@ include_directories(${PROJECT_SOURCE_DIR}/util)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}")
if(WIN32 AND (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS))
add_executable(hsdump main.cpp $<TARGET_OBJECTS:hs_compile_shared> $<TARGET_OBJECTS:hs_exec_shared>)
else()
add_executable(hsdump main.cpp)
endif()
add_executable(hsdump main.cpp)
target_link_libraries(hsdump hs expressionutil crosscompileutil)

View File

@ -58,19 +58,9 @@
#include <string>
#include <vector>
#ifndef _WIN32
#include <getopt.h>
#else
#include "win_getopt.h"
#endif
#include <sys/stat.h>
#ifndef _WIN32
#include <dirent.h>
#else
#include <direct.h>
#define stat _stat
#endif
#include <boost/ptr_container/ptr_vector.hpp>
@ -332,7 +322,6 @@ u32 buildDumpFlags(void) {
return flags;
}
#ifndef _WIN32
static
void clearDir(const string &path) {
DIR *dir = opendir(path.c_str());
@ -356,46 +345,12 @@ void clearDir(const string &path) {
}
closedir(dir);
}
#else // windows
static
void clearDir(const string &path) {
WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
string glob = path + "/*";
hFind = FindFirstFile(glob.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) {
printf("ERROR: couldn't open location %s\n", path.c_str());
exit(1);
}
do {
string basename(ffd.cFileName);
string fname(path);
fname.push_back('/');
fname.append(basename);
// Ignore '.' and '..'
if (basename == "." || basename == "..") {
continue;
}
if (!DeleteFile(fname.c_str())) {
printf("ERROR: couldn't remove file %s\n", fname.c_str());
}
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
}
#endif
static
int makeDirectory(const string &dirName) {
#ifndef _WIN32
mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP |
S_IROTH | S_IXOTH;
return mkdir(dirName.c_str(), mode);
#else
return _mkdir(dirName.c_str());
#endif
}
static

View File

@ -1,13 +1,6 @@
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}")
if(CMAKE_C_FLAGS MATCHES "/Gv" )
string(REPLACE "/Gv" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
endif()
if(CMAKE_CXX_FLAGS MATCHES "/Gv" )
string(REPLACE "/Gv" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
set(gtest_SOURCES gtest/gtest-all.cc gtest/gtest.h)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR})
@ -38,10 +31,6 @@ endif()
add_definitions(-DGTEST_HAS_PTHREAD=0 -DSRCDIR=${PROJECT_SOURCE_DIR})
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4309 /wd4018")
endif()
set(unit_hyperscan_SOURCES
${gtest_SOURCES}
hyperscan/allocators.cpp
@ -135,11 +124,7 @@ set(unit_internal_SOURCES
)
endif(BUILD_AVX2)
if(WIN32 AND (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS))
add_executable(unit-internal ${unit_internal_SOURCES} $<TARGET_OBJECTS:hs_compile_shared> $<TARGET_OBJECTS:hs_exec_shared>)
else()
add_executable(unit-internal ${unit_internal_SOURCES})
endif()
set_target_properties(unit-internal PROPERTIES COMPILE_FLAGS "${HS_CXX_FLAGS}")
target_link_libraries(unit-internal hs corpusomatic)
endif(NOT (RELEASE_BUILD OR FAT_RUNTIME))

View File

@ -37,9 +37,6 @@
#include <vector>
#ifndef UNUSED
#if defined(_WIN32) || defined(_WIN64)
#define UNUSED
#else
#define UNUSED __attribute__ ((unused))
#endif
#endif
@ -124,5 +121,3 @@ void *count_malloc(size_t n);
void *count_malloc_b(size_t n);
void count_free(void *p);
void count_free_b(void *p);
#endif

View File

@ -38,10 +38,8 @@
#include <vector>
#include <sys/stat.h>
#if !defined(_WIN32)
#include <unistd.h>
#include <libgen.h>
#endif
//
// Utility functions
@ -52,7 +50,6 @@
*/
static inline
std::string inferExpressionPath(const std::string &sigFile) {
#ifndef _WIN32
// POSIX variant.
// dirname() may modify its argument, so we must make a copy.
@ -60,25 +57,11 @@ std::string inferExpressionPath(const std::string &sigFile) {
path.push_back(0); // ensure null termination.
std::string rv = dirname(path.data());
#else
// Windows variant.
if (sigFile.size() >= _MAX_DIR) {
return std::string();
}
char path[_MAX_DIR];
_splitpath(sigFile.c_str(), nullptr, path, nullptr, nullptr);
std::string rv(path);
#endif
rv += "/../pcre";
return rv;
}
#if defined(_WIN32)
#define stat _stat
#define S_IFREG _S_IFREG
#endif
static inline
bool isDir(const std::string &filename) {
struct stat s;

View File

@ -40,14 +40,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#if !defined(_WIN32)
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#else
// Windows support is probably very fragile
#include <windows.h>
#endif
#include <boost/algorithm/string/trim.hpp>
@ -98,11 +93,6 @@ void processLine(string &line, unsigned lineNum,
}
}
#if defined(_WIN32)
#define stat _stat
#define S_ISDIR(st_m) (_S_IFDIR & (st_m))
#define S_ISREG(st_m) (_S_IFREG & (st_m))
#endif
void HS_CDECL loadExpressionsFromFile(const string &fname, ExpressionMap &exprMap) {
struct stat st;
if (stat(fname.c_str(), &st) != 0) {
@ -143,7 +133,6 @@ bool isIgnorable(const std::string &f) {
return false;
}
#ifndef _WIN32
void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
// Is our input path a file or a directory?
struct stat st;
@ -197,62 +186,6 @@ void loadExpressions(const string &inPath, ExpressionMap &exprMap) {
exit(1);
}
}
#else // windows TODO: improve
void HS_CDECL loadExpressions(const string &inPath, ExpressionMap &exprMap) {
// Is our input path a file or a directory?
struct stat st;
if (stat(inPath.c_str(), &st) != 0) {
cerr << "Can't stat path: '" << inPath << "'" << endl;
exit(1);
}
if (S_ISREG(st.st_mode)) {
// process file
try {
loadExpressionsFromFile(inPath, exprMap);
} catch (runtime_error &e) {
cerr << e.what() << ": '" << inPath << "'" << endl;
exit(1);
}
} else if (S_ISDIR(st.st_mode)) {
WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
string glob = inPath + "/*";
hFind = FindFirstFile(glob.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) {
cerr << "Can't open directory: '" << inPath << "'" << endl;
exit(1);
}
do {
string basename(ffd.cFileName);
string fname(inPath);
fname.push_back('/');
fname.append(basename);
// Ignore '.' and '..'
if (basename == "." || basename == "..") {
continue;
}
// Skip emacs backup files, dotfiles (such as VIM swap).
if (isIgnorable(basename)) {
cerr << "Ignoring signature file " << fname << endl;
continue;
}
try {
loadExpressionsFromFile(fname, exprMap);
} catch (runtime_error &e) {
cerr << e.what() << ": '" << fname << "'" << endl;
exit(1);
}
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
} else {
cerr << "Can't stat path: '" << inPath << "'" << endl;
exit(1);
}
}
#endif
void HS_CDECL loadSignatureList(const string &inFile,
SignatureSet &signatures) {

View File

@ -1,177 +0,0 @@
/*
* Copyright (c) 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WIN_GETOPT_H
#define WIN_GETOPT_H
#include <windows.h>
#define ILLEGAL (int)'?'
#define END -1
#define SPECIAL_OPT 1
int optind = 0;
char *optarg;
static char EMPT[] = "";
static char *ptr = EMPT;
static int no_argument = 0;
static int required_argument = 1;
static const char no_arg[] = "option doesn't take an argument --%.*s";
static const char non_opt_string[] = "not an option : %s";
static const char ill_shortopt_char[] = "unknown option -%c";
static const char ill_longopt_string[] = "unknown option --%s";
static const char req_arg_string[] = "option requires an argument --%s";
static const char req_arg_char[] = "option requires an argument -%c";
struct option {
const char *name;
int has_arg;
int *flag;
int value;
};
static
void warn(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stdout, fmt, args);
fprintf(stdout, "\n");
va_end(args);
}
int getopt_long(int nargc, char *const *nargv, const char *options,
const struct option *long_options, int *idx) {
char *check, *equal;
size_t current_opt_len;
bool all_flag = false;
int match = -1;
// illegal
if (options == NULL) {
return ILLEGAL;
}
if (optind == 0) {
optind = 1;
}
if (optind >= nargc) {
return END;
}
if (*options == '-') {
all_flag = true;
++options;
}
optarg = NULL;
// illegal
if (*(ptr = nargv[optind]) != '-') {
ptr = EMPT;
if (all_flag) {
optarg = nargv[optind++];
return SPECIAL_OPT;
} else {
warn(non_opt_string, nargv[optind]);
return ILLEGAL;
}
}
// likely a short option ?
if (ptr[1] != '\0' && *++ptr != '-' && ptr[1] == '\0') {
char opt_char = *ptr;
ptr = EMPT;
// really short option ?
if ((check = (char *)strchr(options, opt_char)) != NULL) {
if (check[1] == ':') {
++optind;
if (optind >= nargc) {
warn(req_arg_char, opt_char);
return ILLEGAL;
} else {
optarg = nargv[optind];
}
}
++optind;
return opt_char;
} else { // illegal
warn(ill_shortopt_char, opt_char);
return ILLEGAL;
}
}
// we meet '--'
if (*ptr == '-' && ptr[1] == '\0') {
ptr = EMPT;
return END;
}
// we meet '--foo' , long option
if (long_options != NULL && *ptr == '-' && ptr[1] != '\0') {
++ptr;
if ((equal = strchr(ptr, '=')) != NULL) {
// found --option=arg
current_opt_len = equal - ptr;
++equal;
} else {
current_opt_len = strlen(ptr);
}
for (int i = 0; long_options[i].name; i++) {
if (!strcmp(ptr, long_options[i].name )) {
match = i;
break;
}
}
if (match == -1) { // don't match
warn(ill_longopt_string, ptr);
ptr = EMPT;
return ILLEGAL;
} else {
++optind;
if (long_options[match].has_arg == required_argument) {
if (equal) {
optarg = equal;
} else if (optind < nargc) {
optarg = nargv[optind++];
} else {
warn(req_arg_string, ptr);
ptr = EMPT;
return ILLEGAL;
}
}
if (long_options[match].has_arg == no_argument && equal) {
warn(no_arg, (int)current_opt_len, ptr);
ptr = EMPT;
return ILLEGAL;
}
ptr = EMPT;
if (long_options[match].flag) {
*long_options[match].flag = long_options[match].value;
return 0;
} else {
return (long_options[match].value);
}
}
}
warn(non_opt_string, ptr);
ptr = EMPT;
return ILLEGAL;
}
#endif