From 9057a0026ea9b40744f2eaa91d9540c9bd410079 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 10 Apr 2021 17:44:27 +0200 Subject: [PATCH] CLEANUP: pattern: make all pattern tables read-only Interestingly, all arrays used to declare patterns were read-write while only hard-coded. Let's mark them const so that they move from data to rodata and don't risk to experience false sharing. --- include/haproxy/pattern.h | 12 ++++++------ src/pattern.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/haproxy/pattern.h b/include/haproxy/pattern.h index 5b64c0d29..aaa8964ff 100644 --- a/include/haproxy/pattern.h +++ b/include/haproxy/pattern.h @@ -29,13 +29,13 @@ #include /* pattern management function arrays */ -extern char *pat_match_names[PAT_MATCH_NUM]; -extern int pat_match_types[PAT_MATCH_NUM]; +extern const char *const pat_match_names[PAT_MATCH_NUM]; +extern int const pat_match_types[PAT_MATCH_NUM]; -extern int (*pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char **); -extern int (*pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **); -extern void (*pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *); -extern struct pattern *(*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern_expr *, int); +extern int (*const pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char **); +extern int (*const pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **); +extern void (*const pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *); +extern struct pattern *(*const pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern_expr *, int); /* This is the root of the list of all pattern_ref avalaibles. */ extern struct list pattern_reference; diff --git a/src/pattern.c b/src/pattern.c index 6394470a3..e6892f62a 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -28,7 +28,7 @@ #include -char *pat_match_names[PAT_MATCH_NUM] = { +const char *const pat_match_names[PAT_MATCH_NUM] = { [PAT_MATCH_FOUND] = "found", [PAT_MATCH_BOOL] = "bool", [PAT_MATCH_INT] = "int", @@ -45,7 +45,7 @@ char *pat_match_names[PAT_MATCH_NUM] = { [PAT_MATCH_REGM] = "regm", }; -int (*pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char **) = { +int (*const pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char **) = { [PAT_MATCH_FOUND] = pat_parse_nothing, [PAT_MATCH_BOOL] = pat_parse_nothing, [PAT_MATCH_INT] = pat_parse_int, @@ -62,7 +62,7 @@ int (*pat_parse_fcts[PAT_MATCH_NUM])(const char *, struct pattern *, int, char * [PAT_MATCH_REGM] = pat_parse_reg, }; -int (*pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **) = { +int (*const pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, char **) = { [PAT_MATCH_FOUND] = pat_idx_list_val, [PAT_MATCH_BOOL] = pat_idx_list_val, [PAT_MATCH_INT] = pat_idx_list_val, @@ -79,7 +79,7 @@ int (*pat_index_fcts[PAT_MATCH_NUM])(struct pattern_expr *, struct pattern *, ch [PAT_MATCH_REGM] = pat_idx_list_regm, }; -void (*pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *) = { +void (*const pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *) = { [PAT_MATCH_FOUND] = pat_prune_gen, [PAT_MATCH_BOOL] = pat_prune_gen, [PAT_MATCH_INT] = pat_prune_gen, @@ -96,7 +96,7 @@ void (*pat_prune_fcts[PAT_MATCH_NUM])(struct pattern_expr *) = { [PAT_MATCH_REGM] = pat_prune_gen, }; -struct pattern *(*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern_expr *, int) = { +struct pattern *(*const pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern_expr *, int) = { [PAT_MATCH_FOUND] = NULL, [PAT_MATCH_BOOL] = pat_match_nothing, [PAT_MATCH_INT] = pat_match_int, @@ -114,7 +114,7 @@ struct pattern *(*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern }; /* Just used for checking configuration compatibility */ -int pat_match_types[PAT_MATCH_NUM] = { +int const pat_match_types[PAT_MATCH_NUM] = { [PAT_MATCH_FOUND] = SMP_T_SINT, [PAT_MATCH_BOOL] = SMP_T_SINT, [PAT_MATCH_INT] = SMP_T_SINT,