Skip to content

Commit 44361c1

Browse files
committed
try to enable MSAN support with JIT
1 parent fb1723c commit 44361c1

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/pcre2_jit_compile.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ POSSIBILITY OF SUCH DAMAGE.
4343
#include "config.h"
4444
#endif
4545

46+
#if defined(__has_feature)
47+
#if __has_feature(memory_sanitizer)
48+
#include <sanitizer/msan_interface.h>
49+
#endif /* __has_feature(memory_sanitizer) */
50+
#endif /* defined(__has_feature) */
51+
4652
#include "pcre2_internal.h"
4753

4854
#ifdef SUPPORT_JIT
@@ -9740,7 +9746,7 @@ BACKTRACK_AS(recurse_backtrack)->matchingpath = LABEL();
97409746
return cc + 1 + LINK_SIZE;
97419747
}
97429748

9743-
static sljit_s32 SLJIT_FUNC do_callout_jit(struct jit_arguments *arguments, pcre2_callout_block *callout_block, PCRE2_SPTR *jit_ovector)
9749+
static sljit_s32 SLJIT_FUNC SLJIT_FUNC_ATTRIBUTE do_callout_jit(struct jit_arguments *arguments, pcre2_callout_block *callout_block, PCRE2_SPTR *jit_ovector)
97449750
{
97459751
PCRE2_SPTR begin;
97469752
PCRE2_SIZE *ovector;

src/pcre2_jit_match.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ POSSIBILITY OF SUCH DAMAGE.
4242
#error This file must be included from pcre2_jit_compile.c.
4343
#endif
4444

45+
#if defined(__has_feature)
46+
#if __has_feature(memory_sanitizer)
47+
#include <sanitizer/msan_interface.h>
48+
#endif /* __has_feature(memory_sanitizer) */
49+
#endif /* defined(__has_feature) */
50+
4551
#ifdef SUPPORT_JIT
4652

4753
static SLJIT_NOINLINE int jit_machine_stack_exec(jit_arguments *arguments, jit_function executable_func)
@@ -178,6 +184,13 @@ match_data->rightchar = 0;
178184
match_data->mark = arguments.mark_ptr;
179185
match_data->matchedby = PCRE2_MATCHEDBY_JIT;
180186

187+
#if defined(__has_feature)
188+
#if __has_feature(memory_sanitizer)
189+
if (rc > 0)
190+
__msan_unpoison(match_data->ovector, 2 * rc * sizeof(match_data->ovector[0]));
191+
#endif /* __has_feature(memory_sanitizer) */
192+
#endif /* defined(__has_feature) */
193+
181194
return match_data->rc;
182195

183196
#endif /* SUPPORT_JIT */

src/sljit/sljitConfigInternal.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,19 @@ typedef double sljit_f64;
475475
#define SLJIT_FUNC
476476
#endif /* !SLJIT_FUNC */
477477

478+
/* Disable instrumentation for these functions as they may not be sound */
479+
#ifndef SLJIT_FUNC_ATTRIBUTE
480+
#if defined(__has_feature)
481+
#if __has_feature(memory_sanitizer)
482+
#define SLJIT_FUNC_ATTRIBUTE __attribute__((no_sanitize("memory")))
483+
#endif /* __has_feature(memory_sanitizer) */
484+
#endif /* defined(__has_feature) */
485+
#endif
486+
487+
#ifndef SLJIT_FUNC_ATTRIBUTE
488+
#define SLJIT_FUNC_ATTRIBUTE
489+
#endif
490+
478491
#ifndef SLJIT_INDIRECT_CALL
479492
#if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (!defined _CALL_ELF || _CALL_ELF == 1)) \
480493
|| ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX)

src/sljit/sljitNativeX86_common.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
*/
2626

27+
#if defined(__has_feature)
28+
#if __has_feature(memory_sanitizer)
29+
#include <sanitizer/msan_interface.h>
30+
#endif /* __has_feature(memory_sanitizer) */
31+
#endif /* defined(__has_feature) */
32+
2733
SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
2834
{
2935
return "x86" SLJIT_CPUINFO;
@@ -476,6 +482,13 @@ static void execute_cpu_id(sljit_u32 info[4])
476482
}
477483

478484
#endif /* _MSC_VER && _MSC_VER >= 1400 */
485+
486+
#if defined(__has_feature)
487+
#if __has_feature(memory_sanitizer)
488+
__msan_unpoison(info, 4 * sizeof(sljit_u32));
489+
#endif /* __has_feature(memory_sanitizer) */
490+
#endif /* defined(__has_feature) */
491+
479492
}
480493

481494
static void get_cpu_features(void)

0 commit comments

Comments
 (0)