Skip to content

Avoid using EM_ASM in sbrk.c #15945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/library_memoryprofiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var memoryProfiler = {
emscripten_memprof_sbrk_grow: function(old_brk, new_brk) {
#if MEMORYPROFILER
emscriptenMemoryProfiler.onSbrkGrow(old_brk, new_brk);
#endif
},
};

mergeInto(LibraryManager.library, memoryProfiler);
4 changes: 4 additions & 0 deletions src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ global.LibraryManager = {
libraries.push('library_html5_webgl.js');
}

if (EMSCRIPTEN_TRACING) {
libraries.push('library_memoryprofiler.js');
}

if (FILESYSTEM) {
// Core filesystem libraries (always linked against, unless -s FILESYSTEM=0 is specified)
libraries = libraries.concat([
Expand Down
4 changes: 2 additions & 2 deletions system/lib/sbrk.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#endif

#ifdef __EMSCRIPTEN_TRACING__
#include <emscripten/em_asm.h>
void emscripten_memprof_sbrk_grow(intptr_t old, intptr_t new);
#endif

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

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

Expand Down