OPTION(ENABLE_CLANG_PLUGIN "Enable clang static analysing plugin [default: OFF]" OFF)
OPTION(ENABLE_HYPERSCAN "Enable hyperscan for fast regexp processing [default: OFF]" OFF)
+
+IF (ENABLE_HYPERSCAN MATCHES "ON")
+ ENABLE_LANGUAGE(CXX)
+ENDIF()
# Build optimized code for following CPU (default i386)
#SET(CPU_TUNE "i686")
CMAKE_FLAGS CMAKE_C_FLAGS="-pthread")
IF(_CAN_RUN EQUAL 1)
SET(HAVE_PTHREAD_PROCESS_SHARED 1 CACHE INTERNAL "")
+ SET(RSPAMD_REQUIRED_LIBRARIES "${RSPAMD_REQUIRED_LIBRARIES} -lpthread")
ENDIF(_CAN_RUN EQUAL 1)
IF(HAVE_PTHREAD_PROCESS_SHARED)
MESSAGE(STATUS "pthread_mutexattr_setpshared is supported")
#include "libserver/url.h"
#include "libserver/task.h"
#include "libutil/util.h"
+#ifdef WITH_HYPERSCAN
+#include "hs.h"
+#endif
struct rspamd_re_class {
guint64 id;
gsize type_len;
GHashTable *re;
gchar hash[rspamd_cryptobox_HASHBYTES * 2 + 1];
+#ifdef WITH_HYPERSCAN
+ hs_database_t *hs_db;
+
+#endif
};
struct rspamd_re_cache {
ref_entry_t ref;
guint nre;
guint max_re_data;
+#ifdef WITH_HYPERSCAN
+ hs_platform_info_t plt;
+#endif
};
struct rspamd_re_runtime {
rspamd_snprintf (re_class->hash, sizeof (re_class->hash), "%*xs",
(gint)rspamd_cryptobox_HASHBYTES, hash_out);
}
+
+#ifdef WITH_HYPERSCAN
+ const gchar *platform = "generic";
+ rspamd_fstring_t *features = rspamd_fstring_new ();
+
+ g_assert (hs_populate_platform (&cache->plt) == HS_SUCCESS);
+
+ /* Now decode what we do have */
+ switch (cache->plt.tune) {
+ case HS_TUNE_FAMILY_HSW:
+ platform = "haswell";
+ break;
+ case HS_TUNE_FAMILY_SNB:
+ platform = "sandy";
+ break;
+ case HS_TUNE_FAMILY_BDW:
+ platform = "broadwell";
+ break;
+ case HS_TUNE_FAMILY_IVB:
+ platform = "ivy";
+ break;
+ default:
+ break;
+ }
+
+ if (cache->plt.cpu_features & HS_CPU_FEATURES_AVX2) {
+ features = rspamd_fstring_append (features, "AVX2", 4);
+ }
+
+ msg_info ("loaded hyperscan engine witch cpu tune '%s' and features '%V'",
+ platform, features);
+
+ rspamd_fstring_free (features);
+#endif
}
struct rspamd_re_runtime *
IF (NOT DEBIAN_BUILD)
SET_TARGET_PROPERTIES(rspamadm PROPERTIES VERSION ${RSPAMD_VERSION})
ENDIF (NOT DEBIAN_BUILD)
+IF (ENABLE_HYPERSCAN MATCHES "ON")
+ TARGET_LINK_LIBRARIES(rspamadm hs)
+ SET_TARGET_PROPERTIES(rspamadm PROPERTIES LINKER_LANGUAGE CXX)
+ENDIF ()
-INSTALL(TARGETS rspamadm RUNTIME DESTINATION bin)
\ No newline at end of file
+INSTALL(TARGETS rspamadm RUNTIME DESTINATION bin)