mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-30 03:34:25 +03:00
Windows porting: port hyperscan and chimera tools to windows.
This commit is contained in:
@@ -74,7 +74,8 @@ if(HAVE_BACKTRACE)
|
||||
"${BACKTRACE_CFLAGS}")
|
||||
endif()
|
||||
else() # WIN32
|
||||
target_link_libraries(hscollider hs chimera ${PCRE_LDFLAGS} databaseutil
|
||||
set_target_properties(hscollider PROPERTIES LINK_FLAGS "/STACK:8388608,8388608")
|
||||
target_link_libraries(hscollider hs chimera pcre databaseutil
|
||||
expressionutil corpusomatic crosscompileutil)
|
||||
endif()
|
||||
|
||||
|
@@ -26,6 +26,9 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PCRE_STATIC
|
||||
#endif
|
||||
#include "config.h"
|
||||
|
||||
#include "common.h"
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Intel Corporation
|
||||
* Copyright (c) 2015-2018, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -35,8 +35,7 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
static const size_t COLLIDER_THREAD_STACK_SIZE = 8192 * 1024;
|
||||
|
||||
void Thread::start() {
|
||||
@@ -79,6 +78,16 @@ create_thread:
|
||||
}
|
||||
}
|
||||
|
||||
void Thread::join() { pthread_join(thread, nullptr); }
|
||||
|
||||
#else // windows
|
||||
|
||||
void Thread::start() { thread = std::thread(&runThread, this); }
|
||||
|
||||
void Thread::join() { thread.join(); }
|
||||
|
||||
#endif
|
||||
|
||||
// Dispatch
|
||||
void *Thread::runThread(void *thr) {
|
||||
if (!no_signal_handler) {
|
||||
@@ -88,7 +97,6 @@ void *Thread::runThread(void *thr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Thread::join() { pthread_join(thread, nullptr); }
|
||||
|
||||
Thread::Thread(size_t num) : thread_id(num) {}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Intel Corporation
|
||||
* Copyright (c) 2015-2018, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -31,7 +31,11 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <thread>
|
||||
#endif
|
||||
|
||||
#include <boost/core/noncopyable.hpp>
|
||||
|
||||
@@ -54,7 +58,11 @@ protected:
|
||||
const size_t thread_id;
|
||||
|
||||
private:
|
||||
#ifndef _WIN32
|
||||
pthread_t thread;
|
||||
#else
|
||||
std::thread thread;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // UE2COLLIDER_THREAD_H
|
||||
|
@@ -169,8 +169,9 @@ struct MultiContext {
|
||||
|
||||
// Callback used for all (both single and multi-mode) scans.
|
||||
static
|
||||
int callbackMulti(unsigned int id, unsigned long long from,
|
||||
unsigned long long to, UNUSED unsigned int flags, void *ctx) {
|
||||
int HS_CDECL callbackMulti(unsigned int id, unsigned long long from,
|
||||
unsigned long long to,
|
||||
UNUSED unsigned int flags, void *ctx) {
|
||||
MultiContext *mctx = static_cast<MultiContext *>(ctx);
|
||||
assert(mctx);
|
||||
assert(mctx->rs);
|
||||
@@ -269,7 +270,7 @@ int callbackMulti(unsigned int id, unsigned long long from,
|
||||
|
||||
// Hybrid matcher callback.
|
||||
static
|
||||
ch_callback_t callbackHybrid(unsigned id, unsigned long long from,
|
||||
ch_callback_t HS_CDECL callbackHybrid(unsigned id, unsigned long long from,
|
||||
unsigned long long to, unsigned, unsigned size,
|
||||
const ch_capture_t *captured, void *ctx) {
|
||||
MultiContext *mctx = static_cast<MultiContext *>(ctx);
|
||||
@@ -322,8 +323,9 @@ ch_callback_t callbackHybrid(unsigned id, unsigned long long from,
|
||||
|
||||
// Hybrid matcher error callback.
|
||||
static
|
||||
ch_callback_t errorCallback(UNUSED ch_error_event_t errorType, UNUSED unsigned int id, void *,
|
||||
void *ctx) {
|
||||
ch_callback_t HS_CDECL errorCallback(UNUSED ch_error_event_t errorType,
|
||||
UNUSED unsigned int id, void *,
|
||||
void *ctx) {
|
||||
UNUSED MultiContext *mctx = static_cast<MultiContext *>(ctx);
|
||||
assert(mctx);
|
||||
assert(mctx->rs);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
* Copyright (c) 2015-2018, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -46,7 +46,11 @@
|
||||
#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
|
||||
@@ -467,7 +471,7 @@ void processArgs(int argc, char *argv[], CorpusProperties &corpus_gen_prop,
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'Z':
|
||||
case 'Z': { // Parentheses save VS C2360
|
||||
static constexpr unsigned ALIGN_LIMIT = MAX_MAX_UE2_ALIGN - 1;
|
||||
if (optarg == string("R")) {
|
||||
// Random min alignment selected.
|
||||
@@ -481,6 +485,7 @@ void processArgs(int argc, char *argv[], CorpusProperties &corpus_gen_prop,
|
||||
}
|
||||
max_ue2_align = min_ue2_align + 1;
|
||||
break;
|
||||
}
|
||||
case '8':
|
||||
force_utf8 = true;
|
||||
break;
|
||||
|
@@ -1840,13 +1840,17 @@ unique_ptr<CorporaSource> buildCorpora(const vector<string> &corporaFiles,
|
||||
static
|
||||
bool needsQuotes(const char *s) {
|
||||
size_t len = strlen(s);
|
||||
// don't confuse the correct isblank for the one in locale
|
||||
int (*blank)(int) = &std::isblank;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1910,7 +1914,7 @@ bool runTests(CorporaSource &corpora_source, const ExpressionMap &exprMap,
|
||||
return !summary.hasFailure();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int HS_CDECL main(int argc, char *argv[]) {
|
||||
Grey grey;
|
||||
vector<string> corporaFiles;
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
* Copyright (c) 2015-2018, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <ctype.h>
|
||||
#include <string>
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
#if defined(HAVE_SIGACTION) || defined(_WIN32)
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
@@ -56,8 +56,12 @@ TLS_VARIABLE volatile size_t debug_corpus_len = 0;
|
||||
|
||||
extern std::string g_cmdline;
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
#if defined(_WIN32)
|
||||
static void __cdecl sighandler(int signum) {
|
||||
#elif 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
|
||||
@@ -141,7 +145,13 @@ static void sighandler(int signum) {
|
||||
#endif // HAVE_SIGACTION
|
||||
|
||||
void installSignalHandler(void) {
|
||||
#ifdef HAVE_SIGACTION
|
||||
|
||||
#ifdef _WIN32
|
||||
signal(SIGABRT, sighandler);
|
||||
signal(SIGFPE, sighandler);
|
||||
signal(SIGILL, sighandler);
|
||||
signal(SIGSEGV, sighandler);
|
||||
#elif defined(HAVE_SIGACTION)
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = sighandler;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Intel Corporation
|
||||
* Copyright (c) 2015-2018, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -40,7 +40,11 @@
|
||||
#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;
|
||||
|
Reference in New Issue
Block a user