@@ -875,6 +875,8 @@ def create_module(sending, receiving, invoke_funcs, metadata):
875
875
876
876
module .append (receiving )
877
877
module .append (invoke_wrappers )
878
+ if settings .MEMORY64 :
879
+ module .append (create_wasm64_wrappers (metadata ))
878
880
return module
879
881
880
882
@@ -929,6 +931,62 @@ def create_invoke_wrappers(invoke_funcs):
929
931
return invoke_wrappers
930
932
931
933
934
+ def create_wasm64_wrappers (metadata ):
935
+ # TODO(sbc): Move this into somewhere less static. Maybe it can become
936
+ # part of library.js file, even though this metadata relates specifically
937
+ # to native (non-JS) functions.
938
+ #
939
+ # The signature format here is similar to the one used for JS libraries
940
+ # but with the following as the only valid char:
941
+ # '_' - non-pointer argument (pass through unchanged)
942
+ # 'p' - pointer/int53 argument (convert to/from BigInt)
943
+ # 'P' - same as above but allow `undefined` too (requires extra check)
944
+ mapping = {
945
+ 'sbrk' : 'pP' ,
946
+ 'stackAlloc' : 'pp' ,
947
+ 'emscripten_builtin_malloc' : 'pp' ,
948
+ 'malloc' : 'pp' ,
949
+ '__getTypeName' : 'pp' ,
950
+ 'setThrew' : '_p' ,
951
+ 'free' : '_p' ,
952
+ 'stackRestore' : '_p' ,
953
+ '__cxa_is_pointer_type' : '_p' ,
954
+ 'stackSave' : 'p' ,
955
+ 'fflush' : '_p' ,
956
+ 'emscripten_stack_get_end' : 'p' ,
957
+ 'emscripten_stack_get_base' : 'p' ,
958
+ 'pthread_self' : 'p' ,
959
+ 'emscripten_stack_get_current' : 'p' ,
960
+ '__errno_location' : 'p' ,
961
+ 'emscripten_builtin_memalign' : 'ppp' ,
962
+ 'main' : '__PP' ,
963
+ 'emscripten_stack_set_limits' : '_pp' ,
964
+ '__set_stack_limits' : '_pp' ,
965
+ '__cxa_can_catch' : '_ppp' ,
966
+ }
967
+
968
+ wasm64_wrappers = '''
969
+ function instrumentWasmExportsForMemory64(exports) {
970
+ // First, make a copy of the incoming exports object
971
+ exports = Object.assign({}, exports);'''
972
+
973
+ sigs_seen = set ()
974
+ wrap_functions = []
975
+ for exp in metadata ['exports' ]:
976
+ sig = mapping .get (exp )
977
+ if sig :
978
+ if sig not in sigs_seen :
979
+ sigs_seen .add (sig )
980
+ wasm64_wrappers += js_manipulation .make_wasm64_wrapper (sig )
981
+ wrap_functions .append (exp )
982
+
983
+ for f in wrap_functions :
984
+ sig = mapping [f ]
985
+ wasm64_wrappers += f"\n exports['{ f } '] = wasm64Wrapper_{ sig } (exports['{ f } ']);"
986
+ wasm64_wrappers += '\n return exports\n }'
987
+ return wasm64_wrappers
988
+
989
+
932
990
def normalize_line_endings (text ):
933
991
"""Normalize to UNIX line endings.
934
992
0 commit comments