Skip to content

Commit 4c1dcf8

Browse files
authored
Simplify internal mmap API. NFC. (#16886)
We don't support this address hint ever (its not possible with WebAssembly today), so perform the check up front and skip passing this extra param. Minor code size and complexity saving.
1 parent 7214c29 commit 4c1dcf8

File tree

5 files changed

+13
-24
lines changed

5 files changed

+13
-24
lines changed

src/library_fs.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,10 +1224,7 @@ FS.staticInit();` +
12241224
}
12251225
stream.stream_ops.allocate(stream, offset, length);
12261226
},
1227-
mmap: (stream, address, length, position, prot, flags) => {
1228-
#if CAN_ADDRESS_2GB
1229-
address >>>= 0;
1230-
#endif
1227+
mmap: (stream, length, position, prot, flags) => {
12311228
// User requests writing to file (prot & PROT_WRITE != 0).
12321229
// Checking if we have permissions to write to the file unless
12331230
// MAP_PRIVATE flag is set. According to POSIX spec it is possible
@@ -1245,7 +1242,7 @@ FS.staticInit();` +
12451242
if (!stream.stream_ops.mmap) {
12461243
throw new FS.ErrnoError({{{ cDefine('ENODEV') }}});
12471244
}
1248-
return stream.stream_ops.mmap(stream, address, length, position, prot, flags);
1245+
return stream.stream_ops.mmap(stream, length, position, prot, flags);
12491246
},
12501247
msync: (stream, buffer, offset, length, mmapFlags) => {
12511248
#if CAN_ADDRESS_2GB

src/library_memfs.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,7 @@ mergeInto(LibraryManager.library, {
333333
MEMFS.expandFileStorage(stream.node, offset + length);
334334
stream.node.usedBytes = Math.max(stream.node.usedBytes, offset + length);
335335
},
336-
mmap: function(stream, address, length, position, prot, flags) {
337-
if (address !== 0) {
338-
// We don't currently support location hints for the address of the mapping
339-
throw new FS.ErrnoError({{{ cDefine('EINVAL') }}});
340-
}
336+
mmap: function(stream, length, position, prot, flags) {
341337
if (!FS.isFile(stream.node.mode)) {
342338
throw new FS.ErrnoError({{{ cDefine('ENODEV') }}});
343339
}

src/library_nodefs.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,7 @@ mergeInto(LibraryManager.library, {
298298

299299
return position;
300300
},
301-
mmap: (stream, address, length, position, prot, flags) => {
302-
if (address !== 0) {
303-
// We don't currently support location hints for the address of the mapping
304-
throw new FS.ErrnoError({{{ cDefine('EINVAL') }}});
305-
}
301+
mmap: (stream, length, position, prot, flags) => {
306302
if (!FS.isFile(stream.node.mode)) {
307303
throw new FS.ErrnoError({{{ cDefine('ENODEV') }}});
308304
}

src/library_noderawfs.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,10 @@ mergeInto(LibraryManager.library, {
174174
allocate: function() {
175175
throw new FS.ErrnoError({{{ cDefine('EOPNOTSUPP') }}});
176176
},
177-
mmap: function(stream, address, length, position, prot, flags) {
177+
mmap: function(stream, length, position, prot, flags) {
178178
if (stream.stream_ops) {
179179
// this stream is created by in-memory filesystem
180-
return VFS.mmap(stream, address, length, position, prot, flags);
181-
}
182-
if (address !== 0) {
183-
// We don't currently support location hints for the address of the mapping
184-
throw new FS.ErrnoError({{{ cDefine('EINVAL') }}});
180+
return VFS.mmap(stream, length, position, prot, flags);
185181
}
186182

187183
var ptr = mmapAlloc(length);

src/library_syscall.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,13 @@ var SyscallsLibrary = {
121121
],
122122
_mmap_js: function(addr, len, prot, flags, fd, off, allocated) {
123123
#if FILESYSTEM && SYSCALLS_REQUIRE_FILESYSTEM
124-
var info = FS.getStream(fd);
125-
if (!info) return -{{{ cDefine('EBADF') }}};
126-
var res = FS.mmap(info, addr, len, off, prot, flags);
124+
if (addr !== 0) {
125+
// We don't currently support location hints for the address of the mapping
126+
return -{{{ cDefine('EINVAL') }}};
127+
}
128+
var stream = FS.getStream(fd);
129+
if (!stream) return -{{{ cDefine('EBADF') }}};
130+
var res = FS.mmap(stream, len, off, prot, flags);
127131
var ptr = res.ptr;
128132
{{{ makeSetValue('allocated', 0, 'res.allocated', 'i32') }}};
129133
#if CAN_ADDRESS_2GB

0 commit comments

Comments
 (0)