Skip to content

Instantly share code, notes, and snippets.

@michael-grunder
Created June 28, 2022 04:25
Show Gist options
  • Save michael-grunder/219abace92fa348b3c4af8bf1f264adf to your computer and use it in GitHub Desktop.
Save michael-grunder/219abace92fa348b3c4af8bf1f264adf to your computer and use it in GitHub Desktop.
Patch PHP 8.1 to revert the Valgrind change which causes crashes
From 6ff49450eef966153abda5522aec456dcd899b8c Mon Sep 17 00:00:00 2001
From: michael-grunder <[email protected]>
Date: Thu, 9 Jun 2022 10:13:42 -0700
Subject: [PATCH] Revert Valgrind commits
b3898e951
a0c44fbaf
---
Zend/zend_string.c | 72 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 61 insertions(+), 11 deletions(-)
diff --git a/Zend/zend_string.c b/Zend/zend_string.c
index 8e6a16c64a..c158850967 100644
--- a/Zend/zend_string.c
+++ b/Zend/zend_string.c
@@ -366,17 +366,6 @@ ZEND_API void zend_interned_strings_switch_storage(bool request)
}
}
-/* Even if we don't build with valgrind support, include the symbol so that valgrind available
- * only at runtime will not result in false positives. */
-#ifndef I_REPLACE_SONAME_FNNAME_ZU
-# define I_REPLACE_SONAME_FNNAME_ZU(soname, fnname) _vgr00000ZU_ ## soname ## _ ## fnname
-#endif
-
-ZEND_API bool ZEND_FASTCALL I_REPLACE_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
-{
- return !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1));
-}
-
#if defined(__GNUC__) && defined(__i386__)
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *s2)
{
@@ -415,6 +404,36 @@ ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *
return ret;
}
+#ifdef HAVE_VALGRIND
+ZEND_API bool ZEND_FASTCALL I_WRAP_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
+{
+ size_t len = ZSTR_LEN(s1);
+ char *ptr1 = ZSTR_VAL(s1);
+ char *ptr2 = ZSTR_VAL(s2);
+ zend_ulong ret;
+
+ __asm__ (
+ "test %1, %1\n\t"
+ "jnz .LL1%=\n\t"
+ "movl $0x1, %0\n\t"
+ "jmp .LL2%=\n\t"
+ ".LL1%=:\n\t"
+ "cld\n\t"
+ "rep\n\t"
+ "cmpsb\n\t"
+ "sete %b0\n\t"
+ "movzbl %b0, %0\n\t"
+ ".LL2%=:\n"
+ : "=a"(ret),
+ "+c"(len),
+ "+D"(ptr1),
+ "+S"(ptr2)
+ :
+ : "cc");
+ return ret;
+}
+#endif
+
#elif defined(__GNUC__) && defined(__x86_64__) && !defined(__ILP32__)
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *s2)
{
@@ -452,6 +471,37 @@ ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *
: "cc");
return ret;
}
+
+#ifdef HAVE_VALGRIND
+ZEND_API bool ZEND_FASTCALL I_WRAP_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
+{
+ size_t len = ZSTR_LEN(s1);
+ char *ptr1 = ZSTR_VAL(s1);
+ char *ptr2 = ZSTR_VAL(s2);
+ zend_ulong ret;
+
+ __asm__ (
+ "test %1, %1\n\t"
+ "jnz .LL1%=\n\t"
+ "movq $0x1, %0\n\t"
+ "jmp .LL2%=\n\t"
+ ".LL1%=:\n\t"
+ "cld\n\t"
+ "rep\n\t"
+ "cmpsb\n\t"
+ "sete %b0\n\t"
+ "movzbq %b0, %0\n\t"
+ ".LL2%=:\n"
+ : "=a"(ret),
+ "+c"(len),
+ "+D"(ptr1),
+ "+S"(ptr2)
+ :
+ : "cc");
+ return ret;
+}
+#endif
+
#endif
ZEND_API zend_string *zend_string_concat2(
--
2.30.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment