]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Try to allow disabling JIT in PCRE
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 4 May 2018 18:20:42 +0000 (19:20 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 4 May 2018 18:20:42 +0000 (19:20 +0100)
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libutil/regexp.c
src/libutil/regexp.h

index 74949e28335d315faf275a81f123db4ed6d61b62..a12b1647727acafc539fedd93edf0b523ca6a04b 100644 (file)
@@ -310,6 +310,7 @@ struct rspamd_config {
        gboolean ignore_received;                       /**< Ignore data from the first received header                 */
        gboolean enable_sessions_cache;                 /**< Enable session cache for debug                                             */
        gboolean enable_experimental;                   /**< Enable experimental plugins                                                */
+       gboolean disable_pcre_jit;                      /**< Disable pcre JIT                                           */
 
        gsize max_diff;                                 /**< maximum diff size for text parts                                   */
        gsize max_cores_size;                           /**< maximum size occupied by rspamd core files                 */
index 349bc5cf2349cfa7847e7dc45997afc24593e4d8..47e730af0bb53e68d86eae5836b7006891c39fec 100644 (file)
@@ -2026,6 +2026,12 @@ rspamd_rcl_config_init (struct rspamd_config *cfg)
                        G_STRUCT_OFFSET (struct rspamd_config, enable_experimental),
                        0,
                        "Enable experimental plugins");
+       rspamd_rcl_add_default_handler (sub,
+                       "enable_experimental",
+                       rspamd_rcl_parse_struct_boolean,
+                       G_STRUCT_OFFSET (struct rspamd_config, disable_pcre_jit),
+                       0,
+                       "Disable PCRE JIT");
        rspamd_rcl_add_default_handler (sub,
                        "all_filters",
                        rspamd_rcl_parse_struct_boolean,
index 3856c294bd788a2e363dfe782402c948c34ef447..76de54e1bfecb92b0a08f26f46ca32bd785148bd 100644 (file)
@@ -685,7 +685,7 @@ rspamd_config_post_load (struct rspamd_config *cfg,
                cfg->default_max_shots = 1;
        }
 
-       rspamd_regexp_library_init ();
+       rspamd_regexp_library_init (cfg);
        rspamd_multipattern_library_init (cfg->hs_cache_dir);
 
 #ifdef WITH_HYPERSCAN
index 8174a30fce3efb76b13f617e64310d8ca39cf77a..33bb5711e522ca071c2100a760d6848224a6db15 100644 (file)
@@ -82,6 +82,7 @@ struct rspamd_regexp_cache {
 
 static struct rspamd_regexp_cache *global_re_cache = NULL;
 static gboolean can_jit = FALSE;
+static gboolean check_jit = TRUE;
 
 #ifdef WITH_PCRE2
 static pcre2_compile_context *pcre2_ctx = NULL;
@@ -330,7 +331,7 @@ rspamd_regexp_new (const gchar *pattern, const gchar *flags,
        gint regexp_flags = 0, rspamd_flags = 0, err_code, ncaptures;
        gboolean strict_flags = FALSE;
 
-       rspamd_regexp_library_init ();
+       rspamd_regexp_library_init (NULL);
 
        if (flags == NULL) {
                /* We need to parse pattern and detect flags set */
@@ -963,7 +964,7 @@ rspamd_regexp_cache_query (struct rspamd_regexp_cache* cache,
        regexp_id_t id;
 
        if (cache == NULL) {
-               rspamd_regexp_library_init ();
+               rspamd_regexp_library_init (NULL);
                cache = global_re_cache;
        }
 
@@ -984,7 +985,7 @@ rspamd_regexp_cache_create (struct rspamd_regexp_cache *cache,
        rspamd_regexp_t *res;
 
        if (cache == NULL) {
-               rspamd_regexp_library_init ();
+               rspamd_regexp_library_init (NULL);
                cache = global_re_cache;
        }
 
@@ -1013,7 +1014,7 @@ void rspamd_regexp_cache_insert (struct rspamd_regexp_cache* cache,
        g_assert (pattern != NULL);
 
        if (cache == NULL) {
-               rspamd_regexp_library_init ();
+               rspamd_regexp_library_init (NULL);
                cache = global_re_cache;
        }
 
@@ -1048,58 +1049,65 @@ rspamd_regexp_cache_destroy (struct rspamd_regexp_cache *cache)
 }
 
 void
-rspamd_regexp_library_init (void)
+rspamd_regexp_library_init (struct rspamd_config *cfg)
 {
+       if (cfg) {
+               if (cfg->disable_pcre_jit) {
+                       can_jit = FALSE;
+                       check_jit = FALSE;
+               }
+       }
+
        if (global_re_cache == NULL) {
                global_re_cache = rspamd_regexp_cache_new ();
 #ifdef HAVE_PCRE_JIT
                gint jit, rc;
                gchar *str;
 
+               if (check_jit) {
 #ifdef WITH_PCRE2
-               pcre2_ctx = pcre2_compile_context_create (NULL);
-               pcre2_set_newline (pcre2_ctx, PCRE_FLAG(NEWLINE_ANY));
+                       pcre2_ctx = pcre2_compile_context_create (NULL);
+                       pcre2_set_newline (pcre2_ctx, PCRE_FLAG(NEWLINE_ANY));
 #endif
 #ifndef WITH_PCRE2
-               rc = pcre_config (PCRE_CONFIG_JIT, &jit);
+                       rc = pcre_config (PCRE_CONFIG_JIT, &jit);
 #else
-               rc = pcre2_config (PCRE2_CONFIG_JIT, &jit);
+                       rc = pcre2_config (PCRE2_CONFIG_JIT, &jit);
 #endif
 
-               if (rc == 0 && jit == 1) {
+                       if (rc == 0 && jit == 1) {
 #ifndef WITH_PCRE2
 #ifdef PCRE_CONFIG_JITTARGET
-                       pcre_config (PCRE_CONFIG_JITTARGET, &str);
-                       msg_info ("pcre is compiled with JIT for %s", str);
+                               pcre_config (PCRE_CONFIG_JITTARGET, &str);
+                               msg_info ("pcre is compiled with JIT for %s", str);
 #else
-                       msg_info ("pcre is compiled with JIT for unknown target");
+                               msg_info ("pcre is compiled with JIT for unknown target");
 #endif
 #else
-                       rc = pcre2_config (PCRE2_CONFIG_JITTARGET, NULL);
+                               rc = pcre2_config (PCRE2_CONFIG_JITTARGET, NULL);
 
-                       if (rc > 0) {
-                               str = g_alloca (rc);
-                               pcre2_config (PCRE2_CONFIG_JITTARGET, str);
-                               msg_info ("pcre2 is compiled with JIT for %s", str);
-                       }
-                       else {
-                               msg_info ("pcre2 is compiled with JIT for unknown");
-                       }
+                               if (rc > 0) {
+                                       str = g_alloca (rc);
+                                       pcre2_config (PCRE2_CONFIG_JITTARGET, str);
+                                       msg_info ("pcre2 is compiled with JIT for %s", str);
+                               }
+                               else {
+                                       msg_info ("pcre2 is compiled with JIT for unknown");
+                               }
 
 #endif /* WITH_PCRE2 */
 
-                       if (getenv ("VALGRIND") == NULL) {
-                               can_jit = TRUE;
-                       }
-                       else {
-                               msg_info ("disabling PCRE jit as it does not play well with valgrind");
-                               can_jit = FALSE;
+                               if (getenv ("VALGRIND") == NULL) {
+                                       can_jit = TRUE;
+                               } else {
+                                       msg_info ("disabling PCRE jit as it does not play well with valgrind");
+                                       can_jit = FALSE;
+                               }
+                       } else {
+                               msg_info ("pcre is compiled without JIT support, so many optimizations"
+                                                 " are impossible");
                        }
                }
-               else {
-                       msg_info ("pcre is compiled without JIT support, so many optimizations"
-                                       " are impossible");
-               }
 #else
                msg_info ("pcre is too old and has no JIT support, so many optimizations"
                                " are impossible");
index c85276b710475dc42b2a748a185842aa2a9fe11a..6b1bd50f9f15eeaea3f5fd07dcc921853002badd 100644 (file)
@@ -34,6 +34,8 @@
 #define RSPAMD_REGEXP_FLAG_PCRE_ONLY (1 << 4)
 #define RSPAMD_REGEXP_FLAG_DISABLE_JIT (1 << 5)
 
+struct rspamd_config;
+
 typedef struct rspamd_regexp_s rspamd_regexp_t;
 struct rspamd_regexp_cache;
 struct rspamd_re_capture {
@@ -250,7 +252,7 @@ gint rspamd_regexp_cmp (gconstpointer a, gconstpointer b);
 /**
  * Initialize superglobal regexp cache and library
  */
-void rspamd_regexp_library_init (void);
+void rspamd_regexp_library_init (struct rspamd_config *cfg);
 
 /**
  * Cleanup internal library structures