Skip to content

Commit 188a7bf

Browse files
webghost009Kudo
authored andcommitted
Fix DebugHeap Crash (#109)
Previously JSC's debug heap would crash when activated by using tools like ASAN. This was due to a call to posix_memalign() being patched out during the build process which caused DebugHeap::memalign() to unconditionally call BCRASH(). The call to posix_memalign() was originally patched out because it is not offered in Android API <= 16 and jsc-android targets API >= 16. This change replaces the original patch with one that adds an implementation of posix_memalign() borrowed from the Android Support Library source.
1 parent a079585 commit 188a7bf

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed
Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1-
diff -aur target-org/webkit/Source/bmalloc/bmalloc/DebugHeap.cpp target/webkit/Source/bmalloc/bmalloc/DebugHeap.cpp
2-
--- target-org/webkit/Source/bmalloc/bmalloc/DebugHeap.cpp 2017-02-03 22:59:08.000000000 +0100
3-
+++ target/webkit/Source/bmalloc/bmalloc/DebugHeap.cpp 2017-08-02 10:07:11.000383124 +0200
4-
@@ -89,13 +89,8 @@
1+
diff -aur target-org/webkit/Source/bmalloc/CMakeLists.txt target/webkit/Source/bmalloc/CMakeLists.txt
2+
--- target-org/webkit/Source/bmalloc/CMakeLists.txt 2018-07-12 11:27:26.185794000 -0700
3+
+++ target/webkit/Source/bmalloc/CMakeLists.txt 2019-06-11 12:20:28.556676100 -0700
4+
@@ -32,6 +32,7 @@
5+
bmalloc/VMHeap.cpp
6+
bmalloc/bmalloc.cpp
7+
bmalloc/mbmalloc.cpp
8+
+ bmalloc/posix_memalign.cpp
9+
)
510

6-
void* DebugHeap::memalign(size_t alignment, size_t size, bool crashOnFailure)
7-
{
8-
- void* result;
9-
- if (posix_memalign(&result, alignment, size)) {
10-
- if (crashOnFailure)
11-
- BCRASH();
12-
- return nullptr;
13-
- }
14-
- return result;
15-
+ BCRASH();
16-
+ return nullptr;
17-
}
11+
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
1812

19-
void* DebugHeap::realloc(void* object, size_t size)
13+
14+
diff -aur /dev/null target/webkit/Source/bmalloc/bmalloc/posix_memalign.cpp
15+
--- /dev/null 2019-06-11 10:46:36.937580800 -0700
16+
+++ target/webkit/Source/bmalloc/bmalloc/posix_memalign.cpp 2019-06-11 14:47:32.119738900 -0700
17+
@@ -0,0 +1,23 @@
18+
+#if defined(__ANDROID__) && __ANDROID_API__ < 17
19+
+//
20+
+// Implementation borrowed from the Android Support Library
21+
+// https://android.googlesource.com/platform/ndk/+/c066f37aeadeb8a8b21468ad8c82f4469fb5a70d/sources/android/support/src/posix_memalign.cpp
22+
+//
23+
+#include <errno.h>
24+
+#include <malloc.h>
25+
+#include <stdlib.h>
26+
+
27+
+int posix_memalign(void** memptr, size_t alignment, size_t size) {
28+
+ if ((alignment & (alignment - 1)) != 0 || alignment == 0) {
29+
+ return EINVAL;
30+
+ }
31+
+ if (alignment % sizeof(void*) != 0) {
32+
+ return EINVAL;
33+
+ }
34+
+ *memptr = memalign(alignment, size);
35+
+ if (*memptr == NULL) {
36+
+ return errno;
37+
+ }
38+
+ return 0;
39+
+}
40+
+#endif

0 commit comments

Comments
 (0)