diff options
author | Pascal Quantin <pascal.quantin@gmail.com> | 2015-02-12 09:07:02 +0100 |
---|---|---|
committer | Pascal Quantin <pascal.quantin@gmail.com> | 2015-02-12 16:37:55 +0000 |
commit | bdcac172eaa2ec4998c9f2775e691460b9b7a2d0 (patch) | |
tree | fce8f3fc4cee653f0edfe8ed93f1133474e66ea8 | |
parent | 678a9b6463b3661660da2e8a99781332c23cf78c (diff) |
Fix crash at startup in SSE4.2 code when running a 32 bits Windows build
There is no guarantee that a g_malloc'ed memory block will be aligned on a 128 bits boundary
Instead use a static variable definition (at the cost of exposing the HAVE_SSE4_2 compilation flag in ws_mempbrk.h)
Change-Id: I661bf479a9d458d64c96bafc940c519d29a4780b
Reviewed-on: https://code.wireshark.org/review/7070
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
-rw-r--r-- | epan/dissectors/packet-cups.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-irc.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-megaco.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-sdp.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-sip.c | 18 | ||||
-rw-r--r-- | epan/tvbuff.c | 4 | ||||
-rw-r--r-- | wsutil/ws_mempbrk.h | 16 | ||||
-rw-r--r-- | wsutil/ws_mempbrk_sse42.c | 18 |
8 files changed, 33 insertions, 35 deletions
diff --git a/epan/dissectors/packet-cups.c b/epan/dissectors/packet-cups.c index 255bf970c5..42359bb741 100644 --- a/epan/dissectors/packet-cups.c +++ b/epan/dissectors/packet-cups.c @@ -104,7 +104,7 @@ static gint ett_cups = -1; static gint ett_cups_ptype = -1; /* patterns used for tvb_pbrk_pattern_guint8 */ -static tvb_pbrk_pattern pbrk_whitespace = INIT_PBRK_PATTERN; +static tvb_pbrk_pattern pbrk_whitespace; /* This protocol is heavily related to IPP, but it is CUPS-specific and non-standard. */ diff --git a/epan/dissectors/packet-irc.c b/epan/dissectors/packet-irc.c index de201c235e..2d0b66f479 100644 --- a/epan/dissectors/packet-irc.c +++ b/epan/dissectors/packet-irc.c @@ -76,7 +76,7 @@ static expert_field ei_irc_tag_data_invalid = EI_INIT; /* This must be a null-terminated string */ static const guint8 TAG_DELIMITER[] = {0x01, 0x00}; /* patterns used for tvb_pbrk_pattern_guint8 */ -static tvb_pbrk_pattern pbrk_tag_delimiter = INIT_PBRK_PATTERN; +static tvb_pbrk_pattern pbrk_tag_delimiter; #define TCP_PORT_IRC 6667 diff --git a/epan/dissectors/packet-megaco.c b/epan/dissectors/packet-megaco.c index 84bd157f56..91af614297 100644 --- a/epan/dissectors/packet-megaco.c +++ b/epan/dissectors/packet-megaco.c @@ -140,8 +140,8 @@ static dissector_handle_t megaco_text_handle; static int megaco_tap = -1; /* patterns used for tvb_pbrk_pattern_guint8 */ -static tvb_pbrk_pattern pbrk_whitespace = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_braces = INIT_PBRK_PATTERN; +static tvb_pbrk_pattern pbrk_whitespace; +static tvb_pbrk_pattern pbrk_braces; /* diff --git a/epan/dissectors/packet-sdp.c b/epan/dissectors/packet-sdp.c index cf7897dda7..166b8c30a1 100644 --- a/epan/dissectors/packet-sdp.c +++ b/epan/dissectors/packet-sdp.c @@ -198,8 +198,8 @@ static expert_field ei_sdp_invalid_line_space = EI_INIT; static expert_field ei_sdp_invalid_conversion = EI_INIT; /* patterns used for tvb_pbrk_pattern_guint8 */ -static tvb_pbrk_pattern pbrk_digits = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_alpha = INIT_PBRK_PATTERN; +static tvb_pbrk_pattern pbrk_digits; +static tvb_pbrk_pattern pbrk_alpha; #define SDP_RTP_PROTO 0x00000001 #define SDP_SRTP_PROTO 0x00000002 diff --git a/epan/dissectors/packet-sip.c b/epan/dissectors/packet-sip.c index f34a157295..9fa6932045 100644 --- a/epan/dissectors/packet-sip.c +++ b/epan/dissectors/packet-sip.c @@ -238,15 +238,15 @@ static expert_field ei_sip_odd_register_response = EI_INIT; static expert_field ei_sip_sipsec_malformed = EI_INIT; /* patterns used for tvb_pbrk_pattern_guint8 */ -static tvb_pbrk_pattern pbrk_comma_semi = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_whitespace = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_param_end = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_param_end_colon_brackets = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_header_end_dquote = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_quotes = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_tab_sp_fslash = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_addr_end = INIT_PBRK_PATTERN; -static tvb_pbrk_pattern pbrk_via_param_end = INIT_PBRK_PATTERN; +static tvb_pbrk_pattern pbrk_comma_semi; +static tvb_pbrk_pattern pbrk_whitespace; +static tvb_pbrk_pattern pbrk_param_end; +static tvb_pbrk_pattern pbrk_param_end_colon_brackets; +static tvb_pbrk_pattern pbrk_header_end_dquote; +static tvb_pbrk_pattern pbrk_quotes; +static tvb_pbrk_pattern pbrk_tab_sp_fslash; +static tvb_pbrk_pattern pbrk_addr_end; +static tvb_pbrk_pattern pbrk_via_param_end; /* PUBLISH method added as per http://www.ietf.org/internet-drafts/draft-ietf-sip-publish-01.txt */ diff --git a/epan/tvbuff.c b/epan/tvbuff.c index d37859acbc..4be4f1a1fa 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -3039,7 +3039,7 @@ tvb_get_nstringz0(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8* } -static tvb_pbrk_pattern pbrk_crlf = INIT_PBRK_PATTERN; +static tvb_pbrk_pattern pbrk_crlf; /* * Given a tvbuff, an offset into the tvbuff, and a length that starts * at that offset (which may be -1 for "all the way to the end of the @@ -3164,7 +3164,7 @@ tvb_find_line_end(tvbuff_t *tvb, const gint offset, int len, gint *next_offset, return linelen; } -static tvb_pbrk_pattern pbrk_crlf_dquote = INIT_PBRK_PATTERN; +static tvb_pbrk_pattern pbrk_crlf_dquote; /* * Given a tvbuff, an offset into the tvbuff, and a length that starts * at that offset (which may be -1 for "all the way to the end of the diff --git a/wsutil/ws_mempbrk.h b/wsutil/ws_mempbrk.h index 708d53cfff..40c7e5595c 100644 --- a/wsutil/ws_mempbrk.h +++ b/wsutil/ws_mempbrk.h @@ -24,28 +24,30 @@ #include "ws_symbol_export.h" +#ifdef HAVE_SSE4_2 +#include <emmintrin.h> +#endif + /** The pattern object used for tvb_pbrk_pattern_guint8(). */ typedef struct { gchar patt[256]; +#ifdef HAVE_SSE4_2 gboolean use_sse42; - void *mask; + __m128i mask; +#endif } tvb_pbrk_pattern; -/** The value to use when initializing a tvb_pbrk_pattern variable. - * For example: - * static tvb_pbrk_pattern pbrk_mypattern = INIT_PBRK_PATTERN; - */ -#define INIT_PBRK_PATTERN { { 0 }, FALSE, NULL } - /** Compile the pattern for the needles to find using tvb_pbrk_pattern_guint8(). */ WS_DLL_PUBLIC void tvb_pbrk_compile(tvb_pbrk_pattern* pattern, const gchar *needles); WS_DLL_PUBLIC const guint8 *tvb_pbrk_exec(const guint8* haystack, size_t haystacklen, const tvb_pbrk_pattern* pattern, guchar *found_needle); +#ifdef HAVE_SSE4_2 void ws_mempbrk_sse42_compile(tvb_pbrk_pattern* pattern, const gchar *needles); const char *ws_mempbrk_sse42_exec(const char* haystack, size_t haystacklen, const tvb_pbrk_pattern* pattern, guchar *found_needle); +#endif const guint8 *ws_mempbrk_exec(const guint8* haystack, size_t haystacklen, const tvb_pbrk_pattern* pattern, guchar *found_needle); diff --git a/wsutil/ws_mempbrk_sse42.c b/wsutil/ws_mempbrk_sse42.c index da37a665aa..4fd3ef0701 100644 --- a/wsutil/ws_mempbrk_sse42.c +++ b/wsutil/ws_mempbrk_sse42.c @@ -68,11 +68,8 @@ ws_mempbrk_sse42_compile(tvb_pbrk_pattern* pattern, const gchar *needles) pattern->use_sse42 = ws_cpuid_sse42() && (length <= 16); if (pattern->use_sse42) { - __m128i *pmask = NULL; - pattern->mask = g_malloc(sizeof(__m128i)); - pmask = (__m128i *) pattern->mask; - *pmask = _mm_setzero_si128(); - memcpy(pmask, needles, length); + pattern->mask = _mm_setzero_si128(); + memcpy(&(pattern->mask), needles, length); } } @@ -112,7 +109,6 @@ const char * ws_mempbrk_sse42_exec(const char *s, size_t slen, const tvb_pbrk_pattern* pattern, guchar *found_needle) { const char *aligned; - __m128i *pmask = (__m128i *) pattern->mask; int offset; offset = (int) ((size_t) s & 15); @@ -122,9 +118,9 @@ ws_mempbrk_sse42_exec(const char *s, size_t slen, const tvb_pbrk_pattern* patter /* Check partial string. cast safe it's 16B aligned */ __m128i value = __m128i_shift_right (_mm_load_si128 (cast_128aligned__m128i(aligned)), offset); - int length = _mm_cmpistri (*pmask, value, 0x2); + int length = _mm_cmpistri (pattern->mask, value, 0x2); /* No need to check ZFlag since ZFlag is always 1. */ - int cflag = _mm_cmpistrc (*pmask, value, 0x2); + int cflag = _mm_cmpistrc (pattern->mask, value, 0x2); /* XXX: why does this compare value with value? */ int idx = _mm_cmpistri (value, value, 0x3a); @@ -149,9 +145,9 @@ ws_mempbrk_sse42_exec(const char *s, size_t slen, const tvb_pbrk_pattern* patter while (slen >= 16) { __m128i value = _mm_load_si128 (cast_128aligned__m128i(aligned)); - int idx = _mm_cmpistri (*pmask, value, 0x2); - int cflag = _mm_cmpistrc (*pmask, value, 0x2); - int zflag = _mm_cmpistrz (*pmask, value, 0x2); + int idx = _mm_cmpistri (pattern->mask, value, 0x2); + int cflag = _mm_cmpistrc (pattern->mask, value, 0x2); + int zflag = _mm_cmpistrz (pattern->mask, value, 0x2); if (cflag) { if (found_needle) |