Skip to content

Commit 124b942

Browse files
committed
try to enable MSAN support with JIT
1 parent bc3d1df commit 124b942

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
@@ -9752,7 +9758,7 @@ BACKTRACK_AS(recurse_backtrack)->matchingpath = LABEL();
97529758
return cc + 1 + LINK_SIZE;
97539759
}
97549760

9755-
static sljit_s32 SLJIT_FUNC do_callout_jit(struct jit_arguments *arguments, pcre2_callout_block *callout_block, PCRE2_SPTR *jit_ovector)
9761+
static sljit_s32 SLJIT_FUNC SLJIT_FUNC_ATTRIBUTE do_callout_jit(struct jit_arguments *arguments, pcre2_callout_block *callout_block, PCRE2_SPTR *jit_ovector)
97569762
{
97579763
PCRE2_SPTR begin;
97589764
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
@@ -522,6 +522,19 @@ typedef double sljit_f64;
522522
#define SLJIT_FUNC
523523
#endif /* !SLJIT_FUNC */
524524

525+
/* Disable instrumentation for these functions as they may not be sound */
526+
#ifndef SLJIT_FUNC_ATTRIBUTE
527+
#if defined(__has_feature)
528+
#if __has_feature(memory_sanitizer)
529+
#define SLJIT_FUNC_ATTRIBUTE __attribute__((no_sanitize("memory")))
530+
#endif /* __has_feature(memory_sanitizer) */
531+
#endif /* defined(__has_feature) */
532+
#endif
533+
534+
#ifndef SLJIT_FUNC_ATTRIBUTE
535+
#define SLJIT_FUNC_ATTRIBUTE
536+
#endif
537+
525538
#ifndef SLJIT_INDIRECT_CALL
526539
#if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (!defined _CALL_ELF || _CALL_ELF == 1)) \
527540
|| ((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;
@@ -484,6 +490,13 @@ static void execute_cpu_id(sljit_u32 info[4])
484490
}
485491

486492
#endif /* _MSC_VER && _MSC_VER >= 1400 */
493+
494+
#if defined(__has_feature)
495+
#if __has_feature(memory_sanitizer)
496+
__msan_unpoison(info, 4 * sizeof(sljit_u32));
497+
#endif /* __has_feature(memory_sanitizer) */
498+
#endif /* defined(__has_feature) */
499+
487500
}
488501

489502
static void get_cpu_features(void)

0 commit comments

Comments
 (0)