Skip to content

Commit 96986d0

Browse files
authored
Don't export memory views by default (#24079)
These memory view are all still available internally within the module code (i.e. in JS library code, `--pre-js`/`--post-js` code and `EM_ASM`/`EM_JS`), but to access them externally they now need to be added to `-sEXPORTED_RUNTIME_METHODS`. This matches the existing behavior of `-sSTRICT` and `-sMINIMAL_RUNTIME`. Anyone trying to access one of these symbols will see the a warning. e.g. `'HEAP8' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)`
1 parent 2245635 commit 96986d0

File tree

80 files changed

+100
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+100
-201
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions

src/lib/libwasmfs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,23 +358,23 @@ addToLibrary({
358358
// Devices cannot be resized.
359359
setSize: (file, size) => 0,
360360
read: (file, buffer, length, offset) => {
361-
var bufferArray = Module.HEAP8.subarray(buffer, buffer + length);
361+
var bufferArray = HEAP8.subarray(buffer, buffer + length);
362362
try {
363363
var bytesRead = definedOps.userRead(wasmFSDeviceStreams[file], bufferArray, 0, length, offset);
364364
} catch (e) {
365365
return -e.errno;
366366
}
367-
Module.HEAP8.set(bufferArray, buffer);
367+
HEAP8.set(bufferArray, buffer);
368368
return bytesRead;
369369
},
370370
write: (file, buffer, length, offset) => {
371-
var bufferArray = Module.HEAP8.subarray(buffer, buffer + length);
371+
var bufferArray = HEAP8.subarray(buffer, buffer + length);
372372
try {
373373
var bytesWritten = definedOps.userWrite(wasmFSDeviceStreams[file], bufferArray, 0, length, offset);
374374
} catch (e) {
375375
return -e.errno;
376376
}
377-
Module.HEAP8.set(bufferArray, buffer);
377+
HEAP8.set(bufferArray, buffer);
378378
return bytesWritten;
379379
},
380380
};

src/runtime_shared.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,16 @@ var wasmOffsetConverter;
3939
// Helper function to export a heap symbol on the module object,
4040
// if requested.
4141
const shouldExportHeap = (x) => {
42-
let shouldExport = !MINIMAL_RUNTIME && !STRICT;
43-
if (!shouldExport) {
44-
if (MODULARIZE && EXPORT_ALL) {
45-
shouldExport = true;
46-
} else if (AUDIO_WORKLET && (x == 'HEAPU32' || x == 'HEAPF32')) {
47-
// Export to the AudioWorkletGlobalScope the needed variables to access
48-
// the heap. AudioWorkletGlobalScope is unable to access global JS vars
49-
// in the compiled main JS file.
50-
shouldExport = true;
51-
} else if (EXPORTED_RUNTIME_METHODS.includes(x)) {
52-
shouldExport = true;
53-
}
42+
let shouldExport = false;
43+
if (MODULARIZE && EXPORT_ALL) {
44+
shouldExport = true;
45+
} else if (AUDIO_WORKLET && (x == 'HEAPU32' || x == 'HEAPF32')) {
46+
// Export to the AudioWorkletGlobalScope the needed variables to access
47+
// the heap. AudioWorkletGlobalScope is unable to access global JS vars
48+
// in the compiled main JS file.
49+
shouldExport = true;
50+
} else if (EXPORTED_RUNTIME_METHODS.includes(x)) {
51+
shouldExport = true;
5452
}
5553
return shouldExport;
5654
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4091
1+
3996

test/embind/embind_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ std::u32string get_literal_u32string() {
224224

225225
void force_memory_growth() {
226226
std::size_t old_size = emscripten_get_heap_size();
227-
EM_ASM({"globalThis.oldheap = HEAPU8;"});
227+
EM_ASM({"globalThis.oldheap = HEAP8;"});
228228
assert(val::global("oldheap")["byteLength"].as<size_t>() == old_size);
229229
emscripten_resize_heap(old_size + EMSCRIPTEN_PAGE_SIZE);
230230
assert(emscripten_get_heap_size() > old_size);
231-
// HEAPU8 on the module should now be rebound, and our oldheap should be
231+
// HEAP8 on the module should now be rebound, and our oldheap should be
232232
// detached
233-
assert(val::module_property("HEAPU8")["byteLength"].as<size_t>() > old_size);
233+
assert(val::module_property("HEAP8")["byteLength"].as<size_t>() > old_size);
234234
assert(val::global("oldheap")["byteLength"].as<size_t>() == 0);
235235
}
236236

test/fs/test_fs_js_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void test_fs_mmap() {
330330
assert(stream);
331331

332332
var mapped = FS.mmap(stream, 12, 0, 1 | 2 /* PROT_READ | PROT_WRITE */, 1 /* MAP_SHARED */);
333-
var ret = new Uint8Array(Module.HEAPU8.subarray(mapped.ptr, mapped.ptr + 12));
333+
var ret = new Uint8Array(HEAPU8.subarray(mapped.ptr, mapped.ptr + 12));
334334
var fileContents = "";
335335
for (var i = 0; i < 12; i++) {
336336
fileContents += String.fromCharCode(ret[i]);
@@ -341,7 +341,7 @@ void test_fs_mmap() {
341341
ret[9] = 'x'.charCodeAt(0);
342342
ret[10] = 'y'.charCodeAt(0);
343343
ret[11] = 'z'.charCodeAt(0);
344-
Module.HEAPU8.set(ret, mapped.ptr);
344+
HEAPU8.set(ret, mapped.ptr);
345345

346346
// The WasmFS msync syscall requires a pointer to the mapped memory, while the legacy JS API takes in any Uint8Array
347347
// buffer to write to a file.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8271
1+
8240
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20032
1+
19938
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8258
1+
8229
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20010
1+
19916

0 commit comments

Comments
 (0)