Skip to content

Commit aa7fe36

Browse files
committed
Avoid using EM_ASM in sbrk.c
I ran into some issues with the use of EM_ASM here related to SAFE_HEAP. Its probably not a great idea to use EM_ASM in such a low level context.
1 parent 2885620 commit aa7fe36

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/library_memoryprofiler.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var memoryProfiler = {
2+
emscripten_memprof_sbrk_grow: function(old_brk, new_brk) {
3+
#if MEMORYPROFILER
4+
emscriptenMemoryProfiler.onSbrkGrow(old_brk, new_brk);
5+
#endif
6+
},
7+
};
8+
9+
mergeInto(LibraryManager.library, memoryProfiler);

src/modules.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ global.LibraryManager = {
7272
libraries.push('library_html5_webgl.js');
7373
}
7474

75+
if (EMSCRIPTEN_TRACING) {
76+
libraries.push('library_memoryprofiler.js');
77+
}
78+
7579
if (FILESYSTEM) {
7680
// Core filesystem libraries (always linked against, unless -s FILESYSTEM=0 is specified)
7781
libraries = libraries.concat([

system/lib/sbrk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#endif
1919

2020
#ifdef __EMSCRIPTEN_TRACING__
21-
#include <emscripten/em_asm.h>
21+
void emscripten_memprof_sbrk_grow(intptr_t old, intptr_t new);
2222
#endif
2323

2424
#include <emscripten/heap.h>
@@ -96,7 +96,7 @@ void *sbrk(intptr_t increment_) {
9696
#endif // __EMSCRIPTEN_PTHREADS__
9797

9898
#ifdef __EMSCRIPTEN_TRACING__
99-
EM_ASM({if (typeof emscriptenMemoryProfiler !== 'undefined') emscriptenMemoryProfiler.onSbrkGrow($0, $1)}, old_brk, old_brk + increment );
99+
emscripten_memprof_sbrk_grow(old_brk, new_brk);
100100
#endif
101101
return (void*)old_brk;
102102

0 commit comments

Comments
 (0)