From ae696b30223bf9a6a1fc2eb3784411d88f68475e Mon Sep 17 00:00:00 2001 From: Richard Stotz Date: Fri, 20 Aug 2021 13:43:59 +0200 Subject: [PATCH] Restrict PThreadFS to persistent to /filesystemaccess folder --- pthreadfs/README.md | 9 +- .../examples/emscripten-tests/access.cpp | 58 ----- .../examples/emscripten-tests/access.out | 58 ----- pthreadfs/examples/emscripten-tests/close.cpp | 48 ---- pthreadfs/examples/emscripten-tests/close.out | 8 - .../examples/emscripten-tests/curdir.cpp | 114 --------- .../examples/emscripten-tests/curdir.out | 32 --- pthreadfs/examples/emscripten-tests/dup.cpp | 52 ----- pthreadfs/examples/emscripten-tests/dup.out | 20 -- pthreadfs/examples/emscripten-tests/io.cpp | 219 ------------------ pthreadfs/examples/emscripten-tests/io.out | 85 ------- .../examples/emscripten-tests/isatty.cpp | 37 --- pthreadfs/examples/emscripten-tests/links.cpp | 59 ----- pthreadfs/examples/emscripten-tests/links.out | 31 --- pthreadfs/examples/emscripten-tests/misc.cpp | 213 ----------------- pthreadfs/examples/emscripten-tests/misc.out | 52 ----- .../examples/emscripten-tests/truncate.cpp | 96 -------- .../examples/emscripten-tests/truncate.out | 25 -- pthreadfs/library_pthreadfs.js | 187 +-------------- pthreadfs/pthreadfs.cpp | 179 ++++---------- pthreadfs/pthreadfs.h | 145 +++++------- pthreadfs/src/Makefile | 2 +- pthreadfs/src/js/library_asyncfs.js | 35 +-- pthreadfs/src/js/library_syscall_async.js | 128 +--------- pthreadfs/src/js/pthreadfs.js | 24 -- pthreadfs/src/pthreadfs.cpp | 179 ++++---------- pthreadfs/src/pthreadfs.h | 145 +++++------- 27 files changed, 220 insertions(+), 2020 deletions(-) delete mode 100644 pthreadfs/examples/emscripten-tests/access.cpp delete mode 100644 pthreadfs/examples/emscripten-tests/access.out delete mode 100644 pthreadfs/examples/emscripten-tests/close.cpp delete mode 100644 pthreadfs/examples/emscripten-tests/close.out delete mode 100644 pthreadfs/examples/emscripten-tests/curdir.cpp delete mode 100644 pthreadfs/examples/emscripten-tests/curdir.out delete mode 100644 pthreadfs/examples/emscripten-tests/dup.cpp delete mode 100644 pthreadfs/examples/emscripten-tests/dup.out delete mode 100644 pthreadfs/examples/emscripten-tests/io.cpp delete mode 100644 pthreadfs/examples/emscripten-tests/io.out delete mode 100644 pthreadfs/examples/emscripten-tests/isatty.cpp delete mode 100644 pthreadfs/examples/emscripten-tests/links.cpp delete mode 100644 pthreadfs/examples/emscripten-tests/links.out delete mode 100644 pthreadfs/examples/emscripten-tests/misc.cpp delete mode 100644 pthreadfs/examples/emscripten-tests/misc.out delete mode 100644 pthreadfs/examples/emscripten-tests/truncate.cpp delete mode 100644 pthreadfs/examples/emscripten-tests/truncate.out diff --git a/pthreadfs/README.md b/pthreadfs/README.md index e727f58280bd9..29ba4d8ceb48f 100644 --- a/pthreadfs/README.md +++ b/pthreadfs/README.md @@ -97,21 +97,18 @@ EM_PTHREADFS_ASM( await PThreadFS.mkdir('mydirectory'); ); ``` -See `pthreadfs/examples/emscripten-tests/` for exemplary usage. +See `pthreadfs/examples/emscripten-tests/fsafs.cpp` for exemplary usage. ## Known Limitations +- All files to be stored using the file system access Access Handles must be stored in the `/filesystemaccess` folder. +- Files in the `/filesystemaccess` folder cannot interact through syscalls with other files (e.g. moving, copying, etc.). - The code is still prototype quality and **should not be used in a production environment** yet. It is possible that the use of PThreadFS might lead to subtle bugs in other libraries. - PThreadFS requires PROXY_TO_PTHREAD to be active. In particular, no system calls interacting with the file system should be called from the main thread. - Some functionality of the Emscripten File System API is missing, such as sockets, IndexedDB integration and support for XHRequests. - PThreadFS depends on C++ libraries. `EM_PTRHEADFS_ASM()` cannot be used within C files (although initializing through `emscripten_init_pthreadfs()` is possible, see the `pthreadfs/examples/sqlite-speedtest` for an example). -- Only in-memory storage (MEMFS) and OPFS Access Handles (FSAFS) are available as backends for PThreadFS. - - There is no support (yet) for persisting data into IndexedDB (the way IDBFS works). Limited support is available for the Storage Foundation API as backend. - Performance is good if and only if full optimizations (compiler option `-O3`) are enabled and DevTools are closed. -- Using stdout from C++ only prints to the Javascript console, not the Emscripten-generated html file. - ## Examples diff --git a/pthreadfs/examples/emscripten-tests/access.cpp b/pthreadfs/examples/emscripten-tests/access.cpp deleted file mode 100644 index cad6dd9b75bbd..0000000000000 --- a/pthreadfs/examples/emscripten-tests/access.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2011 The Emscripten Authors. All rights reserved. - * Emscripten is available under two separate licenses, the MIT license and the - * University of Illinois/NCSA Open Source License. Both these licenses can be - * found in the LICENSE file. - */ - -#include -#include -#include -#include -#include -#include -#include "pthreadfs.h" - -int main() { - emscripten_init_pthreadfs(); - EM_PTHREADFS_ASM( - await PThreadFS.mkdir('working'); - await PThreadFS.chdir('working'); - await PThreadFS.writeFile('forbidden', ""); await PThreadFS.chmod('forbidden', 0o000); - await PThreadFS.writeFile('readable', ""); await PThreadFS.chmod('readable', 0o444); - await PThreadFS.writeFile('writeable', ""); await PThreadFS.chmod('writeable', 0o222); - await PThreadFS.writeFile('allaccess', ""); await PThreadFS.chmod('allaccess', 0o777); - ); - // Empty path checks #9136 fix - char* files[] = {"readable", "writeable", - "allaccess", "forbidden", "nonexistent", ""}; - for (int i = 0; i < sizeof files / sizeof files[0]; i++) { - printf("F_OK(%s): %d\n", files[i], access(files[i], F_OK)); - printf("errno: %d\n", errno); - errno = 0; - printf("R_OK(%s): %d\n", files[i], access(files[i], R_OK)); - printf("errno: %d\n", errno); - errno = 0; - printf("X_OK(%s): %d\n", files[i], access(files[i], X_OK)); - printf("errno: %d\n", errno); - errno = 0; - printf("W_OK(%s): %d\n", files[i], access(files[i], W_OK)); - printf("errno: %d\n", errno); - errno = 0; - printf("\n"); - } - - EM_PTHREADFS_ASM( - await PThreadFS.writeFile('filetorename', 'renametest'); - ); - - rename("filetorename", "renamedfile"); - - errno = 0; - printf("F_OK(%s): %d\n", "filetorename", access("filetorename", F_OK)); - printf("errno: %d\n", errno); - errno = 0; - printf("F_OK(%s): %d\n", "renamedfile", access("renamedfile", F_OK)); - printf("errno: %d\n", errno); - return 0; -} diff --git a/pthreadfs/examples/emscripten-tests/access.out b/pthreadfs/examples/emscripten-tests/access.out deleted file mode 100644 index c5f0c24b9be45..0000000000000 --- a/pthreadfs/examples/emscripten-tests/access.out +++ /dev/null @@ -1,58 +0,0 @@ -F_OK(readable): 0 -errno: 0 -R_OK(readable): 0 -errno: 0 -X_OK(readable): -1 -errno: 2 -W_OK(readable): -1 -errno: 2 - -F_OK(writeable): 0 -errno: 0 -R_OK(writeable): -1 -errno: 2 -X_OK(writeable): -1 -errno: 2 -W_OK(writeable): 0 -errno: 0 - -F_OK(allaccess): 0 -errno: 0 -R_OK(allaccess): 0 -errno: 0 -X_OK(allaccess): 0 -errno: 0 -W_OK(allaccess): 0 -errno: 0 - -F_OK(forbidden): 0 -errno: 0 -R_OK(forbidden): -1 -errno: 2 -X_OK(forbidden): -1 -errno: 2 -W_OK(forbidden): -1 -errno: 2 - -F_OK(nonexistent): -1 -errno: 44 -R_OK(nonexistent): -1 -errno: 44 -X_OK(nonexistent): -1 -errno: 44 -W_OK(nonexistent): -1 -errno: 44 - -F_OK(): -1 -errno: 44 -R_OK(): -1 -errno: 44 -X_OK(): -1 -errno: 44 -W_OK(): -1 -errno: 44 - -F_OK(filetorename): -1 -errno: 44 -F_OK(renamedfile): 0 -errno: 0 diff --git a/pthreadfs/examples/emscripten-tests/close.cpp b/pthreadfs/examples/emscripten-tests/close.cpp deleted file mode 100644 index 0c252ae0a8d36..0000000000000 --- a/pthreadfs/examples/emscripten-tests/close.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2011 The Emscripten Authors. All rights reserved. - * Emscripten is available under two separate licenses, the MIT license and the - * University of Illinois/NCSA Open Source License. Both these licenses can be - * found in the LICENSE file. - */ - -#include -#include -#include -#include -#include -#include "pthreadfs.h" - -int main() { - emscripten_init_pthreadfs(); - int f = open(".", O_RDONLY); - - int ret = fsync(f); - printf("fsync(opened): %d\n", ret); - printf("errno: %d\n", errno); - assert(ret == 0); - assert(errno == 0); - errno = 0; - - ret = close(f); - printf("close(opened): %d\n", ret); - printf("errno: %d\n", errno); - assert(ret == 0); - assert(errno == 0); - errno = 0; - - ret = fsync(f); - printf("fsync(closed): %d\n", ret); - printf("errno: %d\n", errno); - assert(ret == -1); - assert(errno == EBADF); - errno = 0; - - ret = close(f); - printf("close(closed): %d\n", ret); - printf("errno: %d\n", errno); - assert(ret == -1); - assert(errno == EBADF); - errno = 0; - - return 0; -} diff --git a/pthreadfs/examples/emscripten-tests/close.out b/pthreadfs/examples/emscripten-tests/close.out deleted file mode 100644 index 5d7634b44e5ba..0000000000000 --- a/pthreadfs/examples/emscripten-tests/close.out +++ /dev/null @@ -1,8 +0,0 @@ -fsync(opened): 0 -errno: 0 -close(opened): 0 -errno: 0 -fsync(closed): -1 -errno: 8 -close(closed): -1 -errno: 8 diff --git a/pthreadfs/examples/emscripten-tests/curdir.cpp b/pthreadfs/examples/emscripten-tests/curdir.cpp deleted file mode 100644 index bbdb6db2b643f..0000000000000 --- a/pthreadfs/examples/emscripten-tests/curdir.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2011 The Emscripten Authors. All rights reserved. - * Emscripten is available under two separate licenses, the MIT license and the - * University of Illinois/NCSA Open Source License. Both these licenses can be - * found in the LICENSE file. - */ - -#include -#include -#include -#include -#include -#include "pthreadfs.h" - -int main() { - emscripten_init_pthreadfs(); - EM_PTHREADFS_ASM( - var dummy_device = await PThreadFS.makedev(64, 0); - await PThreadFS.registerDevice(dummy_device, {}); - await PThreadFS.mkdev('/device', dummy_device); - - await PThreadFS.mkdir('/folder'); - await PThreadFS.symlink('/folder', '/link'); - await PThreadFS.writeFile('/file', "", { mode: 0o777 }); - ); - - char buffer[256]; - printf("getcwd: %s\n", getcwd(buffer, 256)); - printf("errno: %d\n", errno); - errno = 0; - printf("\n"); - - printf("chdir(file): %d\n", chdir("/file")); - printf("errno: %d\n", errno); - if (!errno) { - errno = 0; - printf("getcwd: %s\n", getcwd(buffer, 256)); - printf("errno: %d\n", errno); - } - errno = 0; - printf("\n"); - - printf("chdir(dir): %d\n", chdir("/dir")); - printf("errno: %d\n", errno); - if (!errno) { - errno = 0; - printf("getcwd: %s\n", getcwd(buffer, 256)); - printf("errno: %d\n", errno); - } - errno = 2; - printf("\n"); - - printf("chdir(\"\"): %d\n", chdir("")); - printf("errno: %d\n", errno); - if (!errno) { - errno = 0; - printf("getcwd: %s\n", getcwd(buffer, 256)); - printf("errno: %d\n", errno); - } - errno = 2; - printf("\n"); - - printf("chdir(device): %d\n", chdir("/device")); - printf("errno: %d\n", errno); - if (!errno) { - errno = 0; - printf("getcwd: %s\n", getcwd(buffer, 256)); - printf("errno: %d\n", errno); - } - errno = 0; - printf("\n"); - - printf("chdir(folder): %d\n", chdir("/folder")); - printf("errno: %d\n", errno); - if (!errno) { - errno = 0; - printf("getcwd: %s\n", getcwd(buffer, 256)); - printf("errno: %d\n", errno); - } - errno = 0; - printf("\n"); - - printf("chdir(nonexistent): %d\n", chdir("/nonexistent")); - printf("errno: %d\n", errno); - if (!errno) { - errno = 0; - printf("getcwd: %s\n", getcwd(buffer, 256)); - printf("errno: %d\n", errno); - } - errno = 0; - printf("\n"); - - printf("chdir(link): %d\n", chdir("/link")); - printf("errno: %d\n", errno); - if (!errno) { - errno = 0; - printf("getcwd: %s\n", getcwd(buffer, 256)); - printf("errno: %d\n", errno); - } - errno = 0; - printf("\n"); - - errno = 0; - printf("fchdir(/): %d\n", fchdir(open("/", O_RDONLY, 0777))); - printf("errno: %d\n", errno); - if (!errno) { - errno = 0; - printf("getcwd: %s\n", getcwd(buffer, 256)); - printf("errno: %d\n", errno); - errno = 0; - } - - return 0; -} diff --git a/pthreadfs/examples/emscripten-tests/curdir.out b/pthreadfs/examples/emscripten-tests/curdir.out deleted file mode 100644 index d099284e05495..0000000000000 --- a/pthreadfs/examples/emscripten-tests/curdir.out +++ /dev/null @@ -1,32 +0,0 @@ -getcwd: / -errno: 0 - -chdir(file): -1 -errno: 54 - -chdir(dir): -1 -errno: 44 - -chdir(""): -1 -errno: 44 - -chdir(device): -1 -errno: 54 - -chdir(folder): 0 -errno: 0 -getcwd: /folder -errno: 0 - -chdir(nonexistent): -1 -errno: 44 - -chdir(link): 0 -errno: 0 -getcwd: /folder -errno: 0 - -fchdir(/): 0 -errno: 0 -getcwd: / -errno: 0 diff --git a/pthreadfs/examples/emscripten-tests/dup.cpp b/pthreadfs/examples/emscripten-tests/dup.cpp deleted file mode 100644 index 0e877882a1398..0000000000000 --- a/pthreadfs/examples/emscripten-tests/dup.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2011 The Emscripten Authors. All rights reserved. - * Emscripten is available under two separate licenses, the MIT license and the - * University of Illinois/NCSA Open Source License. Both these licenses can be - * found in the LICENSE file. - */ - -#include -#include -#include -#include -#include "pthreadfs.h" - -int main() { - emscripten_init_pthreadfs(); - int f, f2, f3; - - printf("DUP\n"); - f = open("/", O_RDONLY); - f2 = open("/", O_RDONLY); - f3 = dup(f); - printf("errno: %d\n", errno); - printf("f: %d\n", f != f2 && f != f3); - printf("f2,f3: %d\n", f2 != f3); - printf("close(f1): %d\n", close(f)); - printf("close(f2): %d\n", close(f2)); - printf("close(f3): %d\n", close(f3)); - printf("\n"); - errno = 0; - - printf("DUP2\n"); - f = open("/", O_RDONLY); - f2 = open("/", O_RDONLY); - f3 = dup2(f, f2); - printf("errno: %d\n", errno); - printf("f: %d\n", f != f2 && f != f3); - printf("f2,f3: %d\n", f2 == f3); - printf("close(f1): %d\n", close(f)); - printf("close(f2): %d\n", close(f2)); - printf("close(f3): %d\n", close(f3)); - printf("\n"); - errno = 0; - - printf("DUP2 err\n"); - f = dup2(-2, -2); - printf("f: %d\n", f == -1); - printf("errno: %d\n", errno); - printf("close(f): %d\n", close(f)); - errno = 0; - - return 0; -} diff --git a/pthreadfs/examples/emscripten-tests/dup.out b/pthreadfs/examples/emscripten-tests/dup.out deleted file mode 100644 index d35779f4b4fce..0000000000000 --- a/pthreadfs/examples/emscripten-tests/dup.out +++ /dev/null @@ -1,20 +0,0 @@ -DUP -errno: 0 -f: 1 -f2,f3: 1 -close(f1): 0 -close(f2): 0 -close(f3): 0 - -DUP2 -errno: 0 -f: 1 -f2,f3: 1 -close(f1): 0 -close(f2): 0 -close(f3): -1 - -DUP2 err -f: 1 -errno: 8 -close(f): -1 diff --git a/pthreadfs/examples/emscripten-tests/io.cpp b/pthreadfs/examples/emscripten-tests/io.cpp deleted file mode 100644 index b940440c545b8..0000000000000 --- a/pthreadfs/examples/emscripten-tests/io.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright 2011 The Emscripten Authors. All rights reserved. - * Emscripten is available under two separate licenses, the MIT license and the - * University of Illinois/NCSA Open Source License. Both these licenses can be - * found in the LICENSE file. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "pthreadfs.h" - -int main() { - emscripten_init_pthreadfs(); -// EIO is used by Emscripten, but is also defined (somewhere) as a C macro -#undef EIO - EM_PTHREADFS_ASM( - await PThreadFS.mkdir('/working'); - - var major = 80; - - var device = await PThreadFS.makedev(major++, 0); - await PThreadFS.registerDevice(device, { - open: function(stream) { - stream.payload = [65, 66, 67, 68]; - }, - read: function(stream, buffer, offset, length, pos) { - var bytesRead = 0; - for (var i = 0; i < length; i++) { - if (stream.payload.length) { - bytesRead++; - buffer[offset+i] = stream.payload.shift(); - } else { - break; - } - } - return bytesRead; - }, - write: function(stream, buffer, offset, length, pos) { - for (var i = 0; i < length; i++) { - out('TO DEVICE: ' + buffer[offset+i]); - } - return i; - } - }); - await PThreadFS.mkdev('/device', device); - - var broken_device = await PThreadFS.makedev(major++, 0); - await PThreadFS.registerDevice(broken_device, { - read: function(stream, buffer, offset, length, pos) { - throw new PThreadFS.ErrnoError(ERRNO_CODES.EIO); - }, - write: function(stream, buffer, offset, length, pos) { - throw new PThreadFS.ErrnoError(ERRNO_CODES.EIO); - } - }); - await PThreadFS.mkdev('/broken-device', broken_device); - - // NB: These are meant to test FS.createDevice specifically, - // and as such do not use registerDevice/mkdev - await PThreadFS.createDevice('/', 'createDevice-read-only', function() {}); - await PThreadFS.createDevice('/', 'createDevice-write-only', null, function() {}); - - await PThreadFS.mkdir('/working/folder'); - await PThreadFS.writeFile('/working/file', '1234567890'); - ); -#define EIO 5 - - char readBuffer[256] = {0}; - char writeBuffer[] = "writeme"; - - int fl = open("/working/folder", O_RDWR); - printf("read from folder: %zd\n", read(fl, readBuffer, sizeof readBuffer)); - printf("errno: %d\n", errno); - errno = 0; - printf("write to folder: %zd\n", write(fl, writeBuffer, sizeof writeBuffer)); - printf("errno: %d\n\n", errno); - errno = 0; - - int bd = open("/broken-device", O_RDWR); - printf("read from broken device: %zd\n", read(bd, readBuffer, sizeof readBuffer)); - printf("errno: %d\n", errno); - errno = 0; - printf("write to broken device: %zd\n", write(bd, writeBuffer, sizeof writeBuffer)); - printf("errno: %d\n\n", errno); - errno = 0; - - int d = open("/device", O_RDWR); - printf("read from device: %zd\n", read(d, readBuffer, sizeof readBuffer)); - printf("data: %s\n", readBuffer); - memset(readBuffer, 0, sizeof readBuffer); - printf("errno: %d\n", errno); - errno = 0; - printf("write to device: %zd\n", write(d, writeBuffer, sizeof writeBuffer)); - printf("errno: %d\n\n", errno); - errno = 0; - - int cd_ro_r = open("/createDevice-read-only", O_RDONLY); - printf("open read-only device from createDevice for read, errno: %d\n", errno); - errno = 0; - int cd_ro_w = open("/createDevice-read-only", O_WRONLY); - printf("open read-only device from createDevice for write, errno: %d\n", errno); - errno = 0; - int cd_wo_r = open("/createDevice-write-only", O_RDONLY); - printf("open write-only device from createDevice for read, errno: %d\n", errno); - errno = 0; - int cd_wo_w = open("/createDevice-write-only", O_WRONLY); - printf("open write-only device from createDevice for write, errno: %d\n\n", errno); - errno = 0; - - int f = open("/working/file", O_RDWR); - printf("read from file: %zd\n", read(f, readBuffer, sizeof readBuffer)); - printf("data: %s\n", readBuffer); - memset(readBuffer, 0, sizeof readBuffer); - printf("errno: %d\n\n", errno); - errno = 0; - - printf("pread past end of file: %zd\n", pread(f, readBuffer, sizeof readBuffer, 999999999)); - printf("data: %s\n", readBuffer); - memset(readBuffer, 0, sizeof readBuffer); - printf("errno: %d\n\n", errno); - errno = 0; - - printf("seek: %lld\n", lseek(f, 3, SEEK_SET)); - printf("errno: %d\n\n", errno); - printf("partial read from file: %zd\n", read(f, readBuffer, 3)); - printf("data: %s\n", readBuffer); - memset(readBuffer, 0, sizeof readBuffer); - printf("errno: %d\n\n", errno); - errno = 0; - - printf("seek: %lld\n", lseek(f, -2, SEEK_END)); - printf("errno: %d\n", errno); - errno = 0; - printf("partial read from end of file: %zd\n", read(f, readBuffer, 3)); - printf("data: %s\n", readBuffer); - memset(readBuffer, 0, sizeof readBuffer); - printf("errno: %d\n\n", errno); - errno = 0; - - printf("seek: %lld\n", lseek(f, -15, SEEK_CUR)); - printf("errno: %d\n", errno); - errno = 0; - printf("partial read from before start of file: %zd\n", read(f, readBuffer, 3)); - printf("data: %s\n", readBuffer); - memset(readBuffer, 0, sizeof readBuffer); - printf("errno: %d\n\n", errno); - errno = 0; - - printf("seek: %lld\n", lseek(f, 0, SEEK_SET)); - printf("write to start of file: %zd\n", write(f, writeBuffer, 3)); - printf("errno: %d\n\n", errno); - errno = 0; - - printf("seek: %lld\n", lseek(f, 0, SEEK_END)); - printf("write to end of file: %zd\n", write(f, writeBuffer, 3)); - printf("errno: %d\n\n", errno); - errno = 0; - - printf("seek: %lld\n", lseek(f, 10, SEEK_END)); - printf("write after end of file: %zd\n", write(f, writeBuffer, sizeof writeBuffer)); - printf("errno: %d\n\n", errno); - errno = 0; - - printf("pwrite to the middle of file: %zd\n", pwrite(f, writeBuffer + 2, 3, 17)); - printf("errno: %d\n", errno); - printf("seek: %lld\n\n", lseek(f, 0, SEEK_CUR)); - errno = 0; - - printf("pwrite past end of file: %zd\n", pwrite(f, writeBuffer, 5, 32)); - printf("errno: %d\n", errno); - printf("seek: %lld\n\n", lseek(f, 0, SEEK_CUR)); - errno = 0; - - ssize_t bytesRead; - printf("seek: %lld\n", lseek(f, 0, SEEK_SET)); - printf("read after write: %zd\n", bytesRead = read(f, readBuffer, sizeof readBuffer)); - printf("errno: %d\n", errno); - errno = 0; - printf("final: "); - for (ssize_t i = 0; i < bytesRead; i++) { - if (readBuffer[i] == 0) { - printf("\\0"); - } else { - printf("%c", readBuffer[i]); - } - } - printf("\n"); - - // readv - printf("\n"); - memset(readBuffer, 0, sizeof readBuffer); - struct iovec iov; - iov.iov_base = readBuffer; - iov.iov_len = sizeof readBuffer; - printf("seek: %lld\n", lseek(f, 0, SEEK_SET)); - printf("read after write: %zd\n", bytesRead = readv(f, &iov, 1)); - printf("errno: %d\n", errno); - errno = 0; - printf("final: "); - for (ssize_t i = 0; i < bytesRead; i++) { - if (readBuffer[i] == 0) { - printf("\\0"); - } else { - printf("%c", readBuffer[i]); - } - } - printf("\n"); - -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif - - return 0; -} diff --git a/pthreadfs/examples/emscripten-tests/io.out b/pthreadfs/examples/emscripten-tests/io.out deleted file mode 100644 index 7e45f650d1b7b..0000000000000 --- a/pthreadfs/examples/emscripten-tests/io.out +++ /dev/null @@ -1,85 +0,0 @@ -read from folder: -1 -errno: 8 -write to folder: -1 -errno: 8 - -read from broken device: -1 -errno: 29 -write to broken device: -1 -errno: 29 - -read from device: 4 -data: ABCD -errno: 0 -TO DEVICE: 119 -TO DEVICE: 114 -TO DEVICE: 105 -TO DEVICE: 116 -TO DEVICE: 101 -TO DEVICE: 109 -TO DEVICE: 101 -TO DEVICE: 0 -write to device: 8 -errno: 0 - -open read-only device from createDevice for read, errno: 0 -open read-only device from createDevice for write, errno: 2 -open write-only device from createDevice for read, errno: 2 -open write-only device from createDevice for write, errno: 0 - -read from file: 10 -data: 1234567890 -errno: 0 - -pread past end of file: 0 -data: -errno: 0 - -seek: 3 -errno: 0 - -partial read from file: 3 -data: 456 -errno: 0 - -seek: 8 -errno: 0 -partial read from end of file: 2 -data: 90 -errno: 0 - -seek: -1 -errno: 28 -partial read from before start of file: 0 -data: -errno: 0 - -seek: 0 -write to start of file: 3 -errno: 0 - -seek: 10 -write to end of file: 3 -errno: 0 - -seek: 23 -write after end of file: 8 -errno: 0 - -pwrite to the middle of file: 3 -errno: 0 -seek: 31 - -pwrite past end of file: 5 -errno: 0 -seek: 31 - -seek: 0 -read after write: 37 -errno: 0 -final: wri4567890wri\0\0\0\0ite\0\0\0writeme\0\0write - -seek: 0 -read after write: 37 -errno: 0 -final: wri4567890wri\0\0\0\0ite\0\0\0writeme\0\0write diff --git a/pthreadfs/examples/emscripten-tests/isatty.cpp b/pthreadfs/examples/emscripten-tests/isatty.cpp deleted file mode 100644 index 92300d7cfcd2d..0000000000000 --- a/pthreadfs/examples/emscripten-tests/isatty.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2011 The Emscripten Authors. All rights reserved. - * Emscripten is available under two separate licenses, the MIT license and the - * University of Illinois/NCSA Open Source License. Both these licenses can be - * found in the LICENSE file. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "pthreadfs.h" - -int main() { - emscripten_init_pthreadfs(); - int err; - - err = isatty(-1); - assert(!err); - assert(errno == EBADF); - - err = isatty(open("/dev/stdin", O_RDONLY)); - assert(err == 1); - - err = isatty(open("/dev/null", O_RDONLY)); - assert(!err); - - err = isatty(open("/dev", O_RDONLY)); - assert(!err); - - puts("success"); - - return EXIT_SUCCESS; -} \ No newline at end of file diff --git a/pthreadfs/examples/emscripten-tests/links.cpp b/pthreadfs/examples/emscripten-tests/links.cpp deleted file mode 100644 index 94ae1095af148..0000000000000 --- a/pthreadfs/examples/emscripten-tests/links.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2011 The Emscripten Authors. All rights reserved. - * Emscripten is available under two separate licenses, the MIT license and the - * University of Illinois/NCSA Open Source License. Both these licenses can be - * found in the LICENSE file. - */ - -#include -#include -#include -#include -#include "pthreadfs.h" - -int main () { - emscripten_init_pthreadfs(); - EM_PTHREADFS_ASM( - await PThreadFS.mkdir('working'); - await PThreadFS.chdir('working'); - await PThreadFS.symlink('../test/../there!', 'link'); - await PThreadFS.writeFile('file', 'test'); - await PThreadFS.mkdir('folder'); - ); - - char* files[] = {"link", "file", "folder"}; - char buffer[256] = {0}; - - for (int i = 0; i < sizeof files / sizeof files[0]; i++) { - printf("readlink(%s)\n", files[i]); - printf("ret: %zd\n", readlink(files[i], buffer, 256)); - printf("errno: %d\n", errno); - printf("result: %s\n\n", buffer); - errno = 0; - } - - printf("symlink/overwrite\n"); - printf("ret: %d\n", symlink("new-nonexistent-path", "link")); - printf("errno: %d\n\n", errno); - errno = 0; - - printf("symlink/normal\n"); - printf("ret: %d\n", symlink("new-nonexistent-path", "folder/link")); - printf("errno: %d\n", errno); - errno = 0; - - printf("readlink(created link)\n"); - printf("ret: %zd\n", readlink("folder/link", buffer, 256)); - printf("errno: %d\n", errno); - printf("result: %s\n\n", buffer); - errno = 0; - - buffer[0] = buffer[1] = buffer[2] = buffer[3] = buffer[4] = buffer[5] = '*'; - printf("readlink(short buffer)\n"); - printf("ret: %zd\n", readlink("link", buffer, 4)); - printf("errno: %d\n", errno); - printf("result: %s\n", buffer); - errno = 0; - - return 0; -} diff --git a/pthreadfs/examples/emscripten-tests/links.out b/pthreadfs/examples/emscripten-tests/links.out deleted file mode 100644 index 1b5915b0b4999..0000000000000 --- a/pthreadfs/examples/emscripten-tests/links.out +++ /dev/null @@ -1,31 +0,0 @@ -readlink(link) -ret: 7 -errno: 0 -result: /there! - -readlink(file) -ret: -1 -errno: 28 -result: /there! - -readlink(folder) -ret: -1 -errno: 28 -result: /there! - -symlink/overwrite -ret: -1 -errno: 20 - -symlink/normal -ret: 0 -errno: 0 -readlink(created link) -ret: 36 -errno: 0 -result: /working/folder/new-nonexistent-path - -readlink(short buffer) -ret: 4 -errno: 0 -result: /the**ng/folder/new-nonexistent-path diff --git a/pthreadfs/examples/emscripten-tests/misc.cpp b/pthreadfs/examples/emscripten-tests/misc.cpp deleted file mode 100644 index 1842d13f79863..0000000000000 --- a/pthreadfs/examples/emscripten-tests/misc.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 2011 The Emscripten Authors. All rights reserved. - * Emscripten is available under two separate licenses, the MIT license and the - * University of Illinois/NCSA Open Source License. Both these licenses can be - * found in the LICENSE file. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "pthreadfs.h" - -int main() { - emscripten_init_pthreadfs(); - EM_PTHREADFS_ASM( - await PThreadFS.mkdir('working'); - ); - - int f = open("working", O_RDONLY); - assert(f); - int t = open("/dev/stdin", O_RDONLY); - assert(t); - - sync(); - - printf("fsync(good): %d", fsync(f)); - printf(", errno: %d\n", errno); - errno = 0; - printf("fsync(bad): %d", fsync(42)); - printf(", errno: %d\n", errno); - errno = 0; - - printf("fdatasync(good): %d", fdatasync(f)); - printf(", errno: %d\n", errno); - errno = 0; - printf("fdatasync(bad): %d", fdatasync(42)); - printf(", errno: %d\n", errno); - errno = 0; - - printf("tcgetpgrp(good): %d", tcgetpgrp(t)); - printf(", errno: %d\n", errno); - errno = 0; - printf("tcgetpgrp(bad): %d", tcgetpgrp(42)); - printf(", errno: %d\n", errno); - errno = 0; - - printf("tcsetpgrp(good): %d", tcsetpgrp(t, 123)); - printf(", errno: %d\n", errno); - errno = 0; - printf("tcsetpgrp(bad): %d", tcsetpgrp(42, 123)); - printf(", errno: %d\n", errno); - errno = 0; - - printf("link: %d", link("working/here", "working/there")); - printf(", errno: %d\n", errno); - errno = 0; - - printf("lockf(good): %d", lockf(f, F_LOCK, 456)); - printf(", errno: %d\n", errno); - errno = 0; - printf("lockf(bad): %d", lockf(42, F_LOCK, 456)); - printf(", errno: %d\n", errno); - errno = 0; - - printf("nice: %d", nice(42)); - printf(", errno: %d\n", errno); - errno = 0; - - printf("pause: %d", pause()); - printf(", errno: %d\n", errno); - errno = 0; - - int pipe_arg[2]; - printf("pipe(good): %d", pipe(pipe_arg)); - printf(", errno: %d\n", errno); - errno = 0; - printf("pipe(bad): %d", pipe(0)); - printf(", errno: %d\n", errno); - errno = 0; - - char* exec_argv[] = {"arg", 0}; - char* exec_env[] = {"a=b", 0}; - printf("execl: %d", execl("working/program", "arg", 0)); - printf(", errno: %d\n", errno); - errno = 0; - printf("execle: %d", execle("working/program", "arg", 0, exec_env)); - printf(", errno: %d\n", errno); - errno = 0; - printf("execlp: %d", execlp("program", "arg", 0)); - printf(", errno: %d\n", errno); - errno = 0; - printf("execv: %d", execv("program", exec_argv)); - printf(", errno: %d\n", errno); - errno = 0; - printf("execve: %d", execve("program", exec_argv, exec_env)); - printf(", errno: %d\n", errno); - errno = 0; - printf("execvp: %d", execvp("program", exec_argv)); - printf(", errno: %d\n", errno); - errno = 0; - - printf("chown(good): %d", chown("working", 123, 456)); - printf(", errno: %d\n", errno); - errno = 0; - printf("chown(bad): %d", chown("working/noexist", 123, 456)); - printf(", errno: %d\n", errno); - errno = 0; - printf("lchown(good): %d", lchown("working", 123, 456)); - printf(", errno: %d\n", errno); - errno = 0; - printf("lchown(bad): %d", lchown("working/noexist", 123, 456)); - printf(", errno: %d\n", errno); - errno = 0; - printf("fchown(good): %d", fchown(f, 123, 456)); - printf(", errno: %d\n", errno); - errno = 0; - printf("fchown(bad): %d", fchown(42, 123, 456)); - printf(", errno: %d\n", errno); - errno = 0; - - printf("fork: %d", fork()); - printf(", errno: %d\n", errno); - errno = 0; - printf("vfork: %d", vfork()); - printf(", errno: %d\n", errno); - errno = 0; - - printf("crypt: %s", crypt("foo", "bar")); - printf(", errno: %d\n", errno); - errno = 0; - char encrypt_block[64] = {0}; - printf("encrypt"); - encrypt(encrypt_block, 42); - printf(", errno: %d\n", errno); - errno = 0; - - printf("getgid: %d", getgid()); - printf(", errno: %d\n", errno); - errno = 0; - printf("getegid: %d", getegid()); - printf(", errno: %d\n", errno); - errno = 0; - printf("getuid: %d", getuid()); - printf(", errno: %d\n", errno); - errno = 0; - printf("geteuid: %d", geteuid()); - printf(", errno: %d\n", errno); - errno = 0; - - printf("getpgrp: %d", getpgrp()); - printf(", errno: %d\n", errno); - errno = 0; - pid_t mypid = getpid(); - printf("getpid: %d", mypid); - printf(", errno: %d\n", errno); - errno = 0; - printf("getppid: %d", getppid()); - printf(", errno: %d\n", errno); - errno = 0; - printf("getpgid: %d", getpgid(mypid)); - printf(", errno: %d\n", errno); - errno = 0; - printf("getsid: %d", getsid(mypid)); - printf(", errno: %d\n", errno); - errno = 0; - printf("setgid: %d", setgid(0)); - printf(", errno: %d\n", errno); - errno = 0; - printf("setegid: %d", setegid(0)); - printf(", errno: %d\n", errno); - errno = 0; - printf("setuid: %d", setuid(0)); - printf(", errno: %d\n", errno); - errno = 0; - printf("seteuid: %d", seteuid(0)); - printf(", errno: %d\n", errno); - errno = 0; - printf("setpgrp: %d", setpgrp()); - printf(", errno: %d\n", errno); - errno = 0; - printf("setsid: %d", setsid()); - printf(", errno: %d\n", errno); - errno = 0; - printf("setpgid: %d", setpgid(mypid, mypid)); - printf(", errno: %d\n", errno); - errno = 0; - printf("setpgid: %d", setpgid(123, 456)); - printf(", errno: %d\n", errno); - errno = 0; - printf("setregid: %d", setregid(123, 456)); - printf(", errno: %d\n", errno); - errno = 0; - printf("setreuid: %d", setreuid(123, 456)); - printf(", errno: %d\n", errno); - errno = 0; - - gid_t groups[10] = {42}; - printf("getgroups: %d", getgroups(10, groups)); - printf(", result: %d", groups[0]); - printf(", errno: %d\n", errno); - errno = 0; - - gid_t groups2[1] = {0}; - printf("setgroups: %d", setgroups(1, groups2)); - printf(", errno: %d\n", errno); - errno = 0; - - return 0; -} diff --git a/pthreadfs/examples/emscripten-tests/misc.out b/pthreadfs/examples/emscripten-tests/misc.out deleted file mode 100644 index f25cf73eb9f94..0000000000000 --- a/pthreadfs/examples/emscripten-tests/misc.out +++ /dev/null @@ -1,52 +0,0 @@ -fsync(good): 0, errno: 0 -fsync(bad): -1, errno: 8 -fdatasync(good): 0, errno: 0 -fdatasync(bad): -1, errno: 8 -tcgetpgrp(good): 0, errno: 0 -tcgetpgrp(bad): -1, errno: 8 -tcsetpgrp(good): -1, errno: 28 -tcsetpgrp(bad): -1, errno: 8 -link: -1, errno: 34 -lockf(good): 0, errno: 0 -lockf(bad): -1, errno: 8 -nice: -1, errno: 63 -pause: -1, errno: 27 -pipe(good): 0, errno: 0 -pipe(bad): -1, errno: 21 -execl: -1, errno: 45 -execle: -1, errno: 45 -execlp: -1, errno: 45 -execv: -1, errno: 45 -execve: -1, errno: 45 -execvp: -1, errno: 45 -chown(good): 0, errno: 0 -chown(bad): -1, errno: 44 -lchown(good): 0, errno: 0 -lchown(bad): -1, errno: 44 -fchown(good): 0, errno: 0 -fchown(bad): -1, errno: 8 -fork: -1, errno: 52 -vfork: -1, errno: 52 -crypt: ba4TuD1iozTxw, errno: 0 -encrypt, errno: 0 -getgid: 0, errno: 0 -getegid: 0, errno: 0 -getuid: 0, errno: 0 -geteuid: 0, errno: 0 -getpgrp: 42, errno: 0 -getpid: 42, errno: 0 -getppid: 1, errno: 0 -getpgid: 42, errno: 0 -getsid: 42, errno: 0 -setgid: -1, errno: 63 -setegid: -1, errno: 63 -setuid: -1, errno: 63 -seteuid: -1, errno: 63 -setpgrp: 0, errno: 0 -setsid: 0, errno: 0 -setpgid: 0, errno: 0 -setpgid: -1, errno: 71 -setregid: -1, errno: 63 -setreuid: -1, errno: 63 -getgroups: 1, result: 0, errno: 0 -setgroups: -1, errno: 63 diff --git a/pthreadfs/examples/emscripten-tests/truncate.cpp b/pthreadfs/examples/emscripten-tests/truncate.cpp deleted file mode 100644 index e054601f76054..0000000000000 --- a/pthreadfs/examples/emscripten-tests/truncate.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2011 The Emscripten Authors. All rights reserved. - * Emscripten is available under two separate licenses, the MIT license and the - * University of Illinois/NCSA Open Source License. Both these licenses can be - * found in the LICENSE file. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "pthreadfs.h" - -void setup() { - EM_PTHREADFS_ASM( - await PThreadFS.mkdir('working'); - await PThreadFS.chdir('working'); - await PThreadFS.writeFile('towrite', 'abcdef'); - await PThreadFS.writeFile('toread', 'abcdef'); - await PThreadFS.chmod('toread', 0o444); - ); -} - -int main() { - emscripten_init_pthreadfs(); - setup(); - - struct stat s; - int f = open("towrite", O_WRONLY); - int f2 = open("toread", O_RDONLY); - printf("f2: %d\n", f2); - - fstat(f, &s); - printf("st_size: %lld\n", s.st_size); - memset(&s, 0, sizeof s); - errno = 0; - printf("\n"); - - printf("ftruncate(10): %d\n", ftruncate(f, 10)); - printf("errno: %s\n", strerror(errno)); - fstat(f, &s); - printf("st_size: %lld\n", s.st_size); - memset(&s, 0, sizeof s); - errno = 0; - printf("\n"); - - printf("ftruncate(4): %d\n", ftruncate(f, 4)); - printf("errno: %s\n", strerror(errno)); - fstat(f, &s); - printf("st_size: %lld\n", s.st_size); - memset(&s, 0, sizeof s); - errno = 0; - printf("\n"); - - printf("ftruncate(-1): %d\n", ftruncate(f, -1)); - printf("errno: %s\n", strerror(errno)); - fstat(f, &s); - printf("st_size: %lld\n", s.st_size); - memset(&s, 0, sizeof s); - errno = 0; - printf("\n"); - - printf("truncate(2): %d\n", truncate("towrite", 2)); - printf("errno: %s\n", strerror(errno)); - stat("towrite", &s); - printf("st_size: %lld\n", s.st_size); - memset(&s, 0, sizeof s); - errno = 0; - printf("\n"); - - printf("truncate(readonly, 2): %d\n", truncate("toread", 2)); - printf("errno: %s\n", strerror(errno)); - stat("toread", &s); - printf("st_size: %lld\n", s.st_size); - memset(&s, 0, sizeof s); - errno = 0; - printf("\n"); - - printf("ftruncate(readonly, 4): %d\n", ftruncate(f2, 4)); - printf("errno: %s\n", strerror(errno)); - fstat(f2, &s); - printf("st_size: %lld\n", s.st_size); - memset(&s, 0, sizeof s); - errno = 0; - - // Restore full permissions on all created files so that python test runner rmtree - // won't have problems on deleting the files. On Windows, calling shutil.rmtree() - // will fail if any of the files are read-only. - EM_PTHREADFS_ASM( - await PThreadFS.chmod('toread', 0o777); - ); - return 0; -} diff --git a/pthreadfs/examples/emscripten-tests/truncate.out b/pthreadfs/examples/emscripten-tests/truncate.out deleted file mode 100644 index c410cf655f254..0000000000000 --- a/pthreadfs/examples/emscripten-tests/truncate.out +++ /dev/null @@ -1,25 +0,0 @@ -st_size: 6 - -ftruncate(10): 0 -errno: No error information -st_size: 10 - -ftruncate(4): 0 -errno: No error information -st_size: 4 - -ftruncate(-1): -1 -errno: Invalid argument -st_size: 4 - -truncate(2): 0 -errno: No error information -st_size: 2 - -truncate(readonly, 2): -1 -errno: Permission denied -st_size: 6 - -ftruncate(readonly, 4): -1 -errno: Invalid argument -st_size: 6 diff --git a/pthreadfs/library_pthreadfs.js b/pthreadfs/library_pthreadfs.js index 96b1afd195ef7..038bd18eab43e 100644 --- a/pthreadfs/library_pthreadfs.js +++ b/pthreadfs/library_pthreadfs.js @@ -13,23 +13,13 @@ let SyscallsFunctions = [ {'name': 'mknod', 'args': ['path', 'mode', 'dev']}, {'name': 'chmod', 'args': ['path', 'mode']}, {'name': 'access', 'args': ['path', 'amode']}, - {'name': 'rename', 'args': ['old_path', 'new_path']}, {'name': 'mkdir', 'args': ['path', 'mode']}, {'name': 'rmdir', 'args': ['path']}, - {'name': 'dup', 'args': ['fd']}, {'name': 'ioctl', 'args': ['fd', 'request', 'varargs']}, - {'name': 'dup2', 'args': ['oldfd', 'newfd']}, - {'name': 'symlink', 'args': ['target', 'linkpath']}, {'name': 'readlink', 'args': ['path', 'buf', 'bufsize']}, - {'name': 'munmap', 'args': ['addr', 'len']}, {'name': 'fchmod', 'args': ['fd', 'mode']}, {'name': 'fchdir', 'args': ['fd']}, - {'name': '_newselect', 'args': ['nfds', 'readfds', 'writefds', 'exceptfds', 'timeout']}, - {'name': 'msync', 'args': ['addr', 'len', 'flags']}, {'name': 'fdatasync', 'args': ['fd']}, - {'name': 'poll', 'args': ['fds', 'nfds', 'timeout']}, - {'name': 'getcwd', 'args': ['buf', 'size']}, - {'name': 'mmap2', 'args': ['addr', 'len', 'prot', 'flags', 'fd', 'off']}, {'name': 'truncate64', 'args': ['path', 'zero', 'low', 'high']}, {'name': 'ftruncate64', 'args': ['fd', 'zero', 'low', 'high']}, {'name': 'stat64', 'args': ['path', 'buf']}, @@ -42,20 +32,7 @@ let SyscallsFunctions = [ {'name': 'fcntl64', 'args': ['fd', 'cmd', 'varargs']}, {'name': 'statfs64', 'args': ['path', 'size', 'buf']}, {'name': 'fstatfs64', 'args': ['fd', 'size', 'buf']}, - {'name': 'openat', 'args': ['dirfd', 'path', 'flags', 'varargs']}, - {'name': 'mkdirat', 'args': ['dirfd', 'path', 'mode']}, - {'name': 'mknodat', 'args': ['dirfd', 'path', 'mode', 'dev']}, - {'name': 'fchownat', 'args': ['dirfd', 'path', 'owner', 'group', 'flags']}, - {'name': 'fstatat64', 'args': ['dirfd', 'path', 'buf', 'flags']}, - {'name': 'unlinkat', 'args': ['dirfd', 'path', 'flags']}, - {'name': 'renameat', 'args': ['olddirfd', 'oldpath', 'newdirfd', 'newpath']}, - {'name': 'symlinkat', 'args': ['target', 'newdirfd', 'linkpath']}, - {'name': 'readlinkat', 'args': ['dirfd', 'path', 'bug', 'bufsize']}, - {'name': 'fchmodat', 'args': ['dirfd', 'path', 'mode', 'varargs']}, - {'name': 'faccessat', 'args': ['dirfd', 'path', 'amode', 'flags']}, - {'name': 'utimensat', 'args': ['dirfd', 'path', 'times', 'flags']}, {'name': 'fallocate', 'args': ['fd', 'mode', 'off_low', 'off_high', 'len_low', 'len_high']}, - {'name': 'dup3', 'args': ['fd', 'suggestfd', 'flags']}, ] let WasiFunctions = [ @@ -151,7 +128,6 @@ SyscallWrappers['init_pthreadfs'] = function (resume) { PThreadFS.FSNode = FSNode; PThreadFS.staticInit().then(async ()=> { - await PThreadFS.init(); PThreadFS.ignorePermissions = false; wasmTable.get(resume)(); }); @@ -196,23 +172,17 @@ List of implemented syscalls: {'name': 'mknod', 'args': ['path', 'mode', 'dev']}, {'name': 'chmod', 'args': ['path', 'mode']}, {'name': 'access', 'args': ['path', 'amode']}, - {'name': 'rename', 'args': ['old_path', 'new_path']}, {'name': 'mkdir', 'args': ['path', 'mode']}, - {'name': 'rmdir', 'args': ['path']}, - {'name': 'dup', 'args': ['fd']}, - {'name': 'ioctl', 'args': ['fd', 'request', 'varargs']}, - {'name': 'dup2', 'args': ['oldfd', 'newfd']}, + {'name': 'rmdir', 'args': ['path']},] + {'name': 'ioctl', 'args': ['fd', 'request', 'varargs']},] {'name': 'symlink', 'args': ['target', 'linkpath']}, {'name': 'readlink', 'args': ['path', 'buf', 'bufsize']}, - {'name': 'munmap', 'args': ['addr', 'len']}, {'name': 'fchmod', 'args': ['fd', 'mode']}, {'name': 'fchdir', 'args': ['fd']}, {'name': '_newselect', 'args': ['nfds', 'readfds', 'writefds', 'exceptfds', 'timeout']}, - {'name': 'msync', 'args': ['addr', 'len', 'flags']}, {'name': 'fdatasync', 'args': ['fd']}, {'name': 'poll', 'args': ['fds', 'nfds', 'timeout']}, {'name': 'getcwd', 'args': ['buf', 'size']}, - {'name': 'mmap2', 'args': ['addr', 'len', 'prot', 'flags', 'fd', 'off']}, {'name': 'truncate64', 'args': ['path', 'zero', 'low', 'high']}, {'name': 'ftruncate64', 'args': ['fd', 'zero', 'low', 'high']}, {'name': 'stat64', 'args': ['path', 'buf']}, @@ -231,14 +201,13 @@ List of implemented syscalls: {'name': 'fchownat', 'args': ['dirfd', 'path', 'owner', 'group', 'flags']}, {'name': 'fstatat64', 'args': ['dirfd', 'path', 'buf', 'flags']}, {'name': 'unlinkat', 'args': ['dirfd', 'path', 'flags']}, - {'name': 'renameat', 'args': ['olddirfd', 'oldpath', 'newdirfd', 'newpath']}, {'name': 'symlinkat', 'args': ['target', 'newdirfd', 'linkpath']}, {'name': 'readlinkat', 'args': ['dirfd', 'path', 'bug', 'bufsize']}, {'name': 'fchmodat', 'args': ['dirfd', 'path', 'mode', 'varargs']}, {'name': 'faccessat', 'args': ['dirfd', 'path', 'amode', 'flags']}, {'name': 'utimensat', 'args': ['dirfd', 'path', 'times', 'flags']}, {'name': 'fallocate', 'args': ['fd', 'mode', 'off_low', 'off_high', 'len_low', 'len_high']}, - {'name': 'dup3', 'args': ['fd', 'suggestfd', 'flags']}, + */ var SyscallsLibrary = { @@ -305,10 +274,6 @@ var SyscallsLibrary = { {{{ makeSetValue('buf', C_STRUCTS.stat.st_ino, 'stat.ino', 'i64') }}}; return 0; }, - doMsync: async function(addr, stream, len, flags, offset) { - var buffer = HEAPU8.slice(addr, addr + len); - await PThreadFS.msync(stream, buffer, offset, len, flags); - }, doMkdir: async function(path, mode) { // remove a trailing slash, if one - /a/b/ has basename of '', but // we want to create b in the context of this function @@ -365,12 +330,6 @@ var SyscallsLibrary = { } return 0; }, - doDup: async function(path, flags, suggestFD) { - var suggest = await PThreadFS.getStream(suggestFD); - if (suggest) await PThreadFS.close(suggest); - let stream = await PThreadFS.open(path, flags, 0, suggestFD, suggestFD); - return stream.fd; - }, doReadv: async function(stream, iov, iovcnt, offset) { var ret = 0; for (var i = 0; i < iovcnt; i++) { @@ -432,66 +391,7 @@ var SyscallsLibrary = { #endif return low; }, - - $syscallMmap2_async__deps: ['$ASYNCSYSCALLS', '$zeroMemory', '$mmapAlloc', '$PThreadFS', - ], - $syscallMmap2_async: async function(addr, len, prot, flags, fd, off) { - off <<= 12; // undo pgoffset - var ptr; - var allocated = false; - - // addr argument must be page aligned if MAP_FIXED flag is set. - if ((flags & {{{ cDefine('MAP_FIXED') }}}) !== 0 && (addr % {{{ WASM_PAGE_SIZE }}}) !== 0) { - return -{{{ cDefine('EINVAL') }}}; - } - - // MAP_ANONYMOUS (aka MAP_ANON) isn't actually defined by POSIX spec, - // but it is widely used way to allocate memory pages on Linux, BSD and Mac. - // In this case fd argument is ignored. - if ((flags & {{{ cDefine('MAP_ANONYMOUS') }}}) !== 0) { - ptr = mmapAlloc(len); - if (!ptr) return -{{{ cDefine('ENOMEM') }}}; - allocated = true; - } else { - var info = await PThreadFS.getStream(fd); - if (!info) return -{{{ cDefine('EBADF') }}}; - var res = await PThreadFS.mmap(info, addr, len, off, prot, flags); - ptr = res.ptr; - allocated = res.allocated; - } - #if CAN_ADDRESS_2GB - ptr >>>= 0; - #endif - ASYNCSYSCALLS.mappings[ptr] = { malloc: ptr, len: len, allocated: allocated, fd: fd, prot: prot, flags: flags, offset: off }; - return ptr; - }, }, - - $syscallMunmap_async__deps: ['$ASYNCSYSCALLS', '$PThreadFS'], - $syscallMunmap_async: async function(addr, len) { - #if CAN_ADDRESS_2GB - addr >>>= 0; - #endif - // TODO: support unmmap'ing parts of allocations - var info = ASYNCSYSCALLS.mappings[addr]; - if (len === 0 || !info) { - return -{{{ cDefine('EINVAL') }}}; - } - if (len === info.len) { - var stream = await PThreadFS.getStream(info.fd); - if (stream) { - if (info.prot & {{{ cDefine('PROT_WRITE') }}}) { - await ASYNCSYSCALLS.doMsync(addr, stream, len, info.flags, info.offset); - } - await PThreadFS.munmap(stream); - } - ASYNCSYSCALLS.mappings[addr] = null; - if (info.allocated) { - _free(info.malloc); - } - } - return 0; - }, // WASI fd_write_async: async function(fd, iov, iovcnt, pnum) { @@ -595,12 +495,6 @@ var SyscallsLibrary = { path = ASYNCSYSCALLS.getStr(path); return await ASYNCSYSCALLS.doAccess(path, amode); }, - rename_async : async function(old_path, new_path) { - old_path = ASYNCSYSCALLS.getStr(old_path); - new_path = ASYNCSYSCALLS.getStr(new_path); - await PThreadFS.rename(old_path, new_path); - return 0; - }, mkdir_async : async function(path, mode) { path = ASYNCSYSCALLS.getStr(path); return await ASYNCSYSCALLS.doMkdir(path, mode); @@ -610,11 +504,6 @@ var SyscallsLibrary = { await PThreadFS.rmdir(path); return 0; }, - dup_async : async function(fd) { - let old = await ASYNCSYSCALLS.getStreamFromFD(fd); - let stream = await PThreadFS.open(old.path, old.flags, 0); - return stream.fd; - }, ioctl_async: async function(fd, op, varargs) { var stream = await ASYNCSYSCALLS.getStreamFromFD(fd); switch (op) { @@ -662,11 +551,6 @@ var SyscallsLibrary = { default: abort('bad ioctl syscall ' + op); } }, - dup2_async : async function(oldfd, suggestFD) { - var old = await ASYNCSYSCALLS.getStreamFromFD(oldfd); - if (old.fd === suggestFD) return suggestFD; - return await ASYNCSYSCALLS.doDup(old.path, old.flags, suggestFD); - }, symlink_async : async function(target, linkpath) { target = ASYNCSYSCALLS.getStr(target); linkpath = ASYNCSYSCALLS.getStr(linkpath); @@ -677,10 +561,6 @@ var SyscallsLibrary = { path = ASYNCSYSCALLS.getStr(path); return await ASYNCSYSCALLS.doReadlink(path, buf, bufsize); }, - munmap_async__deps: ['$syscallMunmap_async'], - munmap_async : async function(addr, len) { - return await syscallMunmap_async(addr, len); - }, fchmod_async : async function(fd, mode) { await PThreadFS.fchmod(fd, mode); return 0; @@ -771,15 +651,6 @@ var SyscallsLibrary = { return total; }, - msync_async: async function(addr, len, flags) { - #if CAN_ADDRESS_2GB - addr >>>= 0; - #endif - var info = ASYNCSYSCALLS.mappings[addr]; - if (!info) return 0; - await ASYNCSYSCALLS.doMsync(addr, await PThreadFS.getStream(info.fd), len, info.flags, 0); - return 0; - }, fdatasync_async : async function(fd) { var stream = await ASYNCSYSCALLS.getStreamFromFD(fd); //TODO(rstz): Consider implementing this, since Storage Foundation supports flush(). @@ -813,10 +684,6 @@ var SyscallsLibrary = { stringToUTF8(cwd, buf, size); return buf; }, - mmap2_async__deps: ['$syscallMmap2'], - mmap2_async: async function(addr, len, prot, flags, fd, off) { - return await syscallMmap2(addr, len, prot, flags, fd, off); - }, truncate64_async: async function(path, zero, low, high) { path = ASYNCSYSCALLS.getStr(path); var length = ASYNCSYSCALLS.get64(low, high); @@ -1006,14 +873,6 @@ var SyscallsLibrary = { } return 0; }, - renameat_async: async function(olddirfd, oldpath, newdirfd, newpath) { - oldpath = ASYNCSYSCALLS.getStr(oldpath); - newpath = ASYNCSYSCALLS.getStr(newpath); - oldpath = ASYNCSYSCALLS.calculateAt(olddirfd, oldpath); - newpath = ASYNCSYSCALLS.calculateAt(newdirfd, newpath); - await PThreadFS.rename(oldpath, newpath); - return 0; - }, symlinkat_async: async function(target, newdirfd, linkpath) { linkpath = ASYNCSYSCALLS.calculateAt(newdirfd, linkpath); await PThreadFS.symlink(target, linkpath); @@ -1055,11 +914,6 @@ var SyscallsLibrary = { await PThreadFS.allocate(stream, offset, len); return 0; }, - dup3_async: async function(fd, suggestFD, flags) { - var old = await ASYNCSYSCALLS.getStreamFromFD(fd); - if (old.fd === suggestFD) return -{{{ cDefine('EINVAL') }}}; - return await ASYNCSYSCALLS.doDup(old.path, old.flags, suggestFD); - }, }; function wrapSyscallFunction(x, library, isWasi) { @@ -1435,10 +1289,11 @@ mergeInto(LibraryManager.library, SyscallsLibrary); // // streams // + MIN_FD: 4097, MAX_OPEN_FDS: 4096, nextfd: function(fd_start, fd_end) { - fd_start = fd_start || 0; - fd_end = fd_end || PThreadFS.MAX_OPEN_FDS; + fd_start = fd_start || PThreadFS.MIN_FD; + fd_end = fd_end || PThreadFS.MIN_FD + PThreadFS.MAX_OPEN_FDS; for (var fd = fd_start; fd <= fd_end; fd++) { if (!PThreadFS.streams[fd]) { return fd; @@ -2507,36 +2362,6 @@ mergeInto(LibraryManager.library, SyscallsLibrary); 'MEMFS_ASYNC': MEMFS_ASYNC, }; }, - init: async function(input, output, error) { -#if ASSERTIONS - assert(!PThreadFS.init.initialized, 'PThreadFS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)'); -#endif - PThreadFS.init.initialized = true; - - PThreadFS.ensureErrnoError(); - - // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here - Module['stdin'] = input || Module['stdin']; - Module['stdout'] = output || Module['stdout']; - Module['stderr'] = error || Module['stderr']; - - await PThreadFS.createStandardStreams(); - }, - quit: async function() { - // TODO(rstz): This function is never called. - PThreadFS.init.initialized = false; - // force-flush all streams, so we get musl std streams printed out - var fflush = Module['_fflush']; - if (fflush) fflush(0); - // close all of our streams - for (var i = 0; i < PThreadFS.streams.length; i++) { - var stream = PThreadFS.streams[i]; - if (!stream) { - continue; - } - await PThreadFS.close(stream); - } - }, // // old v1 compatibility functions diff --git a/pthreadfs/pthreadfs.cpp b/pthreadfs/pthreadfs.cpp index 514c8540bc13b..70033fcf48542 100644 --- a/pthreadfs/pthreadfs.cpp +++ b/pthreadfs/pthreadfs.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include @@ -102,10 +104,15 @@ void resumeWrapper_wasi(__wasi_errno_t retVal) g_resumeFct(); } +// File System Access collection +std::set fsa_file_descriptors; +std::set mounted_directories; + // Wasi definitions WASI_CAPI_DEF(write, const __wasi_ciovec_t *iovs, size_t iovs_len, __wasi_size_t *nwritten) { WASI_SYNCTOASYNC(write, iovs, iovs_len, nwritten); } + WASI_CAPI_DEF(read, const __wasi_iovec_t *iovs, size_t iovs_len, __wasi_size_t *nread) { WASI_SYNCTOASYNC(read, iovs, iovs_len, nread); } @@ -122,7 +129,17 @@ WASI_CAPI_DEF(fdstat_get, __wasi_fdstat_t *stat) { WASI_SYNCTOASYNC(fdstat_get, stat); } WASI_CAPI_NOARGS_DEF(close) { - WASI_SYNCTOASYNC_NOARGS(close); + if(fsa_file_descriptors.count(fd) > 0) { + g_synctoasync_helper.doWork([fd](SyncToAsync::Callback resume) { + g_resumeFct = [resume]() { resume(); }; + __fd_close_async(fd, &resumeWrapper_wasi); + }); + if (resume_result_wasi == __WASI_ERRNO_SUCCESS) { + fsa_file_descriptors.erase(fd); + } + return resume_result_wasi; + } + return fd_close(fd); } WASI_CAPI_NOARGS_DEF(sync) { WASI_SYNCTOASYNC_NOARGS(sync); @@ -135,43 +152,41 @@ SYS_CAPI_DEF(open, 5, long path, long flags, ...) { int varargs = va_arg(vl, int); va_end(vl); - SYS_SYNCTOASYNC(open, path, flags, varargs); + std::string pathname((char*) path); + if (pathname.rfind("/filesystemaccess", 0) == 0 || pathname.rfind("filesystemaccess", 0) == 0) { + SYS_SYNCTOASYNC_NORETURN(open, path, flags, varargs); + fsa_file_descriptors.insert(resume_result_long); + return resume_result_long; + } + return __sys_open(path, flags, varargs); } SYS_CAPI_DEF(unlink, 10, long path) { - SYS_SYNCTOASYNC(unlink, path); + SYS_SYNCTOASYNC_PATH(unlink, path); } SYS_CAPI_DEF(chdir, 12, long path) { - SYS_SYNCTOASYNC(chdir, path); + SYS_SYNCTOASYNC_PATH(chdir, path); } SYS_CAPI_DEF(mknod, 14, long path, long mode, long dev) { - SYS_SYNCTOASYNC(mknod, path, mode, dev); + SYS_SYNCTOASYNC_PATH(mknod, path, mode, dev); } SYS_CAPI_DEF(chmod, 15, long path, long mode) { - SYS_SYNCTOASYNC(chmod, path, mode); + SYS_SYNCTOASYNC_PATH(chmod, path, mode); } SYS_CAPI_DEF(access, 33, long path, long amode) { - SYS_SYNCTOASYNC(access, path, amode); -} - -SYS_CAPI_DEF(rename, 38, long old_path, long new_path) { - SYS_SYNCTOASYNC(rename, old_path, new_path); + SYS_SYNCTOASYNC_PATH(access, path, amode); } SYS_CAPI_DEF(mkdir, 39, long path, long mode) { - SYS_SYNCTOASYNC(mkdir, path, mode); + SYS_SYNCTOASYNC_PATH(mkdir, path, mode); } SYS_CAPI_DEF(rmdir, 40, long path) { - SYS_SYNCTOASYNC(rmdir, path); -} - -SYS_CAPI_DEF(dup, 41, long fd) { - SYS_SYNCTOASYNC(dup, fd); + SYS_SYNCTOASYNC_PATH(rmdir, path); } SYS_CAPI_DEF(ioctl, 54, long fd, long request, ...) { @@ -181,91 +196,59 @@ SYS_CAPI_DEF(ioctl, 54, long fd, long request, ...) { arg = va_arg(ap, void *); va_end(ap); - SYS_SYNCTOASYNC(ioctl, fd, request, arg); -} - -SYS_CAPI_DEF(dup2, 63, long oldfd, long newfd) { - SYS_SYNCTOASYNC(dup2, oldfd, newfd); -} - -SYS_CAPI_DEF(symlink, 83, long target, long linkpath) { - SYS_SYNCTOASYNC(symlink, target, linkpath); + SYS_SYNCTOASYNC_FD(ioctl, fd, request, arg); } SYS_CAPI_DEF(readlink, 85, long path, long buf, long bufsize) { - SYS_SYNCTOASYNC(readlink, path, buf, bufsize); -} - -SYS_CAPI_DEF(munmap, 91, long addr, long len) { - SYS_SYNCTOASYNC(munmap, addr, len); + SYS_SYNCTOASYNC_PATH(readlink, path, buf, bufsize); } SYS_CAPI_DEF(fchmod, 94, long fd, long mode) { - SYS_SYNCTOASYNC(fchmod, fd, mode); + SYS_SYNCTOASYNC_FD(fchmod, fd, mode); } SYS_CAPI_DEF(fchdir, 133, long fd) { - SYS_SYNCTOASYNC(fchdir, fd); -} - -SYS_CAPI_DEF(_newselect, 142, long nfds, long readfds, long writefds, long exceptfds, long timeout) { - SYS_SYNCTOASYNC(_newselect, nfds, readfds, writefds, exceptfds, timeout); -} - -SYS_CAPI_DEF(msync, 144, long addr, long len, long flags) { - SYS_SYNCTOASYNC(msync, addr, len, flags); + SYS_SYNCTOASYNC_FD(fchdir, fd); } SYS_CAPI_DEF(fdatasync, 148, long fd) { - SYS_SYNCTOASYNC(fdatasync, fd); -} - -SYS_CAPI_DEF(poll, 168, long fds, long nfds, long timeout) { - SYS_SYNCTOASYNC(poll, fds, nfds, timeout); -} - -SYS_CAPI_DEF(getcwd, 183, long buf, long size) { - SYS_SYNCTOASYNC(getcwd, buf, size); -} - -SYS_CAPI_DEF(mmap2, 192, long addr, long len, long prot, long flags, long fd, long off) { - SYS_SYNCTOASYNC(mmap2, addr, len, prot, flags, fd, off); + SYS_SYNCTOASYNC_FD(fdatasync, fd); } SYS_CAPI_DEF(truncate64, 193, long path, long zero, long low, long high) { - SYS_SYNCTOASYNC(truncate64, path, zero, low, high); + SYS_SYNCTOASYNC_PATH(truncate64, path, zero, low, high); } SYS_CAPI_DEF(ftruncate64, 194, long fd, long zero, long low, long high) { - SYS_SYNCTOASYNC(ftruncate64, fd, zero, low, high); + SYS_SYNCTOASYNC_FD(ftruncate64, fd, zero, low, high); } SYS_CAPI_DEF(stat64, 195, long path, long buf) { - SYS_SYNCTOASYNC(stat64, path, buf); + SYS_SYNCTOASYNC_PATH(stat64, path, buf); } SYS_CAPI_DEF(lstat64, 196, long path, long buf) { - SYS_SYNCTOASYNC(lstat64, path, buf); + SYS_SYNCTOASYNC_PATH(lstat64, path, buf); } SYS_CAPI_DEF(fstat64, 197, long fd, long buf) { - SYS_SYNCTOASYNC(fstat64, fd, buf); + SYS_SYNCTOASYNC_FD(fstat64, fd, buf); } SYS_CAPI_DEF(lchown32, 198, long path, long owner, long group) { - SYS_SYNCTOASYNC(lchown32, path, owner, group); + SYS_SYNCTOASYNC_PATH(lchown32, path, owner, group); } SYS_CAPI_DEF(fchown32, 207, long fd, long owner, long group) { - SYS_SYNCTOASYNC(fchown32, fd, owner, group); + SYS_SYNCTOASYNC_FD(fchown32, fd, owner, group); } SYS_CAPI_DEF(chown32, 212, long path, long owner, long group) { - SYS_SYNCTOASYNC(chown32, path, owner, group); + SYS_SYNCTOASYNC_PATH(chown32, path, owner, group); } SYS_CAPI_DEF(getdents64, 220, long fd, long dirp, long count) { - SYS_SYNCTOASYNC(getdents64, fd, dirp, count); + SYS_SYNCTOASYNC_FD(getdents64, fd, dirp, count); } SYS_CAPI_DEF(fcntl64, 221, long fd, long cmd, ...) { @@ -274,81 +257,19 @@ va_list vl; int varargs = va_arg(vl, int); va_end(vl); - SYS_SYNCTOASYNC(fcntl64, fd, cmd, varargs); + SYS_SYNCTOASYNC_FD(fcntl64, fd, cmd, varargs); } SYS_CAPI_DEF(statfs64, 268, long path, long size, long buf) { - SYS_SYNCTOASYNC(statfs64, path, size, buf); + SYS_SYNCTOASYNC_PATH(statfs64, path, size, buf); } SYS_CAPI_DEF(fstatfs64, 269, long fd, long size, long buf) { - SYS_SYNCTOASYNC(fstatfs64, fd, size, buf); -} - -SYS_CAPI_DEF(openat, 295, long dirfd, long path, long flags, ...) { -va_list vl; - va_start(vl, flags); - int varargs = va_arg(vl, int); - va_end(vl); - - SYS_SYNCTOASYNC(openat, dirfd, path, flags, varargs); -} - -SYS_CAPI_DEF(mkdirat, 296, long dirfd, long path, long mode) { - SYS_SYNCTOASYNC(mkdirat, dirfd, path, mode); -} - -SYS_CAPI_DEF(mknodat, 297, long dirfd, long path, long mode, long dev) { - SYS_SYNCTOASYNC(mknodat, dirfd, path, mode, dev); -} - -SYS_CAPI_DEF(fchownat, 298, long dirfd, long path, long owner, long group, long flags) { - SYS_SYNCTOASYNC(fchownat, dirfd, path, owner, group, flags); -} - -SYS_CAPI_DEF(fstatat64, 300, long dirfd, long path, long buf, long flags) { - SYS_SYNCTOASYNC(fstatat64, dirfd, path, buf, flags); -} - -SYS_CAPI_DEF(unlinkat, 301, long dirfd, long path, long flags) { - SYS_SYNCTOASYNC(unlinkat, dirfd, path, flags); -} - -SYS_CAPI_DEF(renameat, 302, long olddirfd, long oldpath, long newdirfd, long newpath) { - SYS_SYNCTOASYNC(renameat, olddirfd, oldpath, newdirfd, newpath); -} - -SYS_CAPI_DEF(symlinkat, 304, long target, long newdirfd, long linkpath) { - SYS_SYNCTOASYNC(symlinkat, target, newdirfd, linkpath); -} - -SYS_CAPI_DEF(readlinkat, 305, long dirfd, long path, long bug, long bufsize) { - SYS_SYNCTOASYNC(readlinkat, dirfd, path, bug, bufsize); -} - -SYS_CAPI_DEF(fchmodat, 306, long dirfd, long path, long mode, ...) { -va_list vl; - va_start(vl, mode); - int varargs = va_arg(vl, int); - va_end(vl); - - SYS_SYNCTOASYNC(fchmodat, dirfd, path, mode, varargs); -} - -SYS_CAPI_DEF(faccessat, 307, long dirfd, long path, long amode, long flags) { - SYS_SYNCTOASYNC(faccessat, dirfd, path, amode, flags); -} - -SYS_CAPI_DEF(utimensat, 320, long dirfd, long path, long times, long flags) { - SYS_SYNCTOASYNC(utimensat, dirfd, path, times, flags); + SYS_SYNCTOASYNC_FD(fstatfs64, fd, size, buf); } SYS_CAPI_DEF(fallocate, 324, long fd, long mode, long off_low, long off_high, long len_low, long len_high) { - SYS_SYNCTOASYNC(fallocate, fd, mode, off_low, off_high, len_low, len_high); -} - -SYS_CAPI_DEF(dup3, 330, long fd, long suggestfd, long flags) { - SYS_SYNCTOASYNC(dup3, fd, suggestfd, flags); + SYS_SYNCTOASYNC_FD(fallocate, fd, mode, off_low, off_high, len_low, len_high); } // Other helper code diff --git a/pthreadfs/pthreadfs.h b/pthreadfs/pthreadfs.h index f1220e644d276..6f2281d590c73 100644 --- a/pthreadfs/pthreadfs.h +++ b/pthreadfs/pthreadfs.h @@ -10,44 +10,73 @@ })();}, &resumeWrapper_v); \ }); -#define WASI_JSAPI_DEF(name, ...) extern void __fd_##name##_async(__wasi_fd_t fd, __VA_ARGS__, void (*fun)(__wasi_errno_t)); -#define WASI_JSAPI_NOARGS_DEF(name) extern void __fd_##name##_async(__wasi_fd_t fd, void (*fun)(__wasi_errno_t)); +#define WASI_JSAPI_DEF(name, ...) \ + extern void __fd_##name##_async(__wasi_fd_t fd, __VA_ARGS__, void (*fun)(__wasi_errno_t)); \ + extern __wasi_errno_t fd_##name(__wasi_fd_t fd, __VA_ARGS__); +#define WASI_JSAPI_NOARGS_DEF(name) \ + extern void __fd_##name##_async(__wasi_fd_t fd, void (*fun)(__wasi_errno_t)); \ + extern __wasi_errno_t fd_##name(__wasi_fd_t fd); #define WASI_CAPI_DEF(name, ...) __wasi_errno_t __wasi_fd_##name(__wasi_fd_t fd, __VA_ARGS__) #define WASI_CAPI_NOARGS_DEF(name) __wasi_errno_t __wasi_fd_##name(__wasi_fd_t fd) -#define WASI_JSAPI(name, ...) __fd_##name##_async(__VA_ARGS__) -#define WASI_SYNCTOASYNC(name, ...) g_synctoasync_helper.doWork([fd, __VA_ARGS__](SyncToAsync::Callback resume) { \ - g_resumeFct = [resume]() { resume(); }; \ - WASI_JSAPI(name, fd, __VA_ARGS__, &resumeWrapper_wasi); \ - }); \ - return resume_result_wasi; -#define WASI_SYNCTOASYNC_NOARGS(name) g_synctoasync_helper.doWork([fd](SyncToAsync::Callback resume) { \ - g_resumeFct = [resume]() { resume(); }; \ - WASI_JSAPI(name, fd, &resumeWrapper_wasi); \ - }); \ - return resume_result_wasi; +#define WASI_SYNCTOASYNC(name, ...) \ + if(fsa_file_descriptors.count(fd) > 0) { \ + g_synctoasync_helper.doWork([fd, __VA_ARGS__](SyncToAsync::Callback resume) { \ + g_resumeFct = [resume]() { resume(); }; \ + __fd_##name##_async(fd, __VA_ARGS__, &resumeWrapper_wasi); \ + }); \ + return resume_result_wasi; \ + } \ + return fd_##name(fd, __VA_ARGS__); +#define WASI_SYNCTOASYNC_NOARGS(name) \ + if(fsa_file_descriptors.count(fd) > 0) { \ + g_synctoasync_helper.doWork([fd](SyncToAsync::Callback resume) { \ + g_resumeFct = [resume]() { resume(); }; \ + __fd_##name##_async(fd, &resumeWrapper_wasi); \ + }); \ + return resume_result_wasi; \ + } \ + return fd_##name(fd); // Classic Syscalls -#define SYS_JSAPI_DEF(name, ...) extern void __sys_##name##_async(__VA_ARGS__, void (*fun)(long)); -#define SYS_JSAPI_NOARGS_DEF(name) extern void __sys_##name##_async(void (*fun)(long)); +#define SYS_JSAPI_DEF(name, ...) \ + extern void __sys_##name##_async(__VA_ARGS__, void (*fun)(long)); \ + extern long __sys_##name(__VA_ARGS__); + +#define SYS_JSAPI_NOARGS_DEF(name) \ + extern void __sys_##name##_async(void (*fun)(long)); \ + extern long __sys_##name(); #define SYS_CAPI_DEF(name, number, ...) long __syscall##number(__VA_ARGS__) #define SYS_DEF(name, number, ...) SYS_CAPI_DEF(name, number, __VA_ARGS__); SYS_JSAPI_DEF(name, __VA_ARGS__) #define SYS_JSAPI(name, ...) __sys_##name##_async(__VA_ARGS__) -#define SYS_SYNCTOASYNC(name, ...) g_synctoasync_helper.doWork([__VA_ARGS__](SyncToAsync::Callback resume) { \ +#define SYS_SYNCTOASYNC_NORETURN(name, ...) g_synctoasync_helper.doWork([__VA_ARGS__](SyncToAsync::Callback resume) { \ g_resumeFct = [resume]() { resume(); }; \ SYS_JSAPI(name, __VA_ARGS__, &resumeWrapper_l); \ - }); \ - return resume_result_long; -#define SYS_SYNCTOASYNC_NOARGS(name) g_synctoasync_helper.doWork([](SyncToAsync::Callback resume) { \ - g_resumeFct = [resume]() { resume(); }; \ - SYS_JSAPI(name, &resumeWrapper_l); \ - }); \ - return resume_result_long; + }); +#define SYS_SYNCTOASYNC_FD(name, ...) \ + if(fsa_file_descriptors.count(fd) > 0) { \ + g_synctoasync_helper.doWork([__VA_ARGS__](SyncToAsync::Callback resume) { \ + g_resumeFct = [resume]() { resume(); }; \ + __sys_##name##_async(__VA_ARGS__, &resumeWrapper_l); \ + }); \ + return resume_result_long; \ + } \ + return __sys_##name(__VA_ARGS__); +#define SYS_SYNCTOASYNC_PATH(name, ...) \ + std::string pathname((char*) path); \ + if (pathname.rfind("/filesystemaccess", 0) == 0 || pathname.rfind("filesystemaccess", 0) == 0) { \ + g_synctoasync_helper.doWork([__VA_ARGS__](SyncToAsync::Callback resume) { \ + g_resumeFct = [resume]() { resume(); }; \ + __sys_##name##_async(__VA_ARGS__, &resumeWrapper_l); \ + }); \ + return resume_result_long; \ + } \ + return __sys_##name(__VA_ARGS__); extern "C" { // Helpers @@ -86,57 +115,27 @@ SYS_JSAPI_DEF(chmod, long path, long mode) SYS_CAPI_DEF(access, 33, long path, long amode); SYS_JSAPI_DEF(access, long path, long amode) -SYS_CAPI_DEF(rename, 38, long old_path, long new_path); -SYS_JSAPI_DEF(rename, long old_path, long new_path) - SYS_CAPI_DEF(mkdir, 39, long path, long mode); SYS_JSAPI_DEF(mkdir, long path, long mode) SYS_CAPI_DEF(rmdir, 40, long path); SYS_JSAPI_DEF(rmdir, long path) -SYS_CAPI_DEF(dup, 41, long fd); -SYS_JSAPI_DEF(dup, long fd) - SYS_CAPI_DEF(ioctl, 54, long fd, long request, ...); SYS_JSAPI_DEF(ioctl, long fd, long request, void *const varargs) -SYS_CAPI_DEF(dup2, 63, long oldfd, long newfd); -SYS_JSAPI_DEF(dup2, long oldfd, long newfd) - -SYS_CAPI_DEF(symlink, 83, long target, long linkpath); -SYS_JSAPI_DEF(symlink, long target, long linkpath) - SYS_CAPI_DEF(readlink, 85, long path, long buf, long bufsize); SYS_JSAPI_DEF(readlink, long path, long buf, long bufsize) -SYS_CAPI_DEF(munmap, 91, long addr, long len); -SYS_JSAPI_DEF(munmap, long addr, long len) - SYS_CAPI_DEF(fchmod, 94, long fd, long mode); SYS_JSAPI_DEF(fchmod, long fd, long mode) SYS_CAPI_DEF(fchdir, 133, long fd); SYS_JSAPI_DEF(fchdir, long fd) -SYS_CAPI_DEF(_newselect, 142, long nfds, long readfds, long writefds, long exceptfds, long timeout); -SYS_JSAPI_DEF(_newselect, long nfds, long readfds, long writefds, long exceptfds, long timeout) - -SYS_CAPI_DEF(msync, 144, long addr, long len, long flags); -SYS_JSAPI_DEF(msync, long addr, long len, long flags) - SYS_CAPI_DEF(fdatasync, 148, long fd); SYS_JSAPI_DEF(fdatasync, long fd) -SYS_CAPI_DEF(poll, 168, long fds, long nfds, long timeout); -SYS_JSAPI_DEF(poll, long fds, long nfds, long timeout) - -SYS_CAPI_DEF(getcwd, 183, long buf, long size); -SYS_JSAPI_DEF(getcwd, long buf, long size) - -SYS_CAPI_DEF(mmap2, 192, long addr, long len, long prot, long flags, long fd, long off); -SYS_JSAPI_DEF(mmap2, long addr, long len, long prot, long flags, long fd, long off) - SYS_CAPI_DEF(truncate64, 193, long path, long zero, long low, long high); SYS_JSAPI_DEF(truncate64, long path, long zero, long low, long high) @@ -173,47 +172,9 @@ SYS_JSAPI_DEF(statfs64, long path, long size, long buf) SYS_CAPI_DEF(fstatfs64, 269, long fd, long size, long buf); SYS_JSAPI_DEF(fstatfs64, long fd, long size, long buf) -SYS_CAPI_DEF(openat, 295, long dirfd, long path, long flags, ...); -SYS_JSAPI_DEF(openat, long dirfd, long path, long flags, int varargs) - -SYS_CAPI_DEF(mkdirat, 296, long dirfd, long path, long mode); -SYS_JSAPI_DEF(mkdirat, long dirfd, long path, long mode) - -SYS_CAPI_DEF(mknodat, 297, long dirfd, long path, long mode, long dev); -SYS_JSAPI_DEF(mknodat, long dirfd, long path, long mode, long dev) - -SYS_CAPI_DEF(fchownat, 298, long dirfd, long path, long owner, long group, long flags); -SYS_JSAPI_DEF(fchownat, long dirfd, long path, long owner, long group, long flags) - -SYS_CAPI_DEF(fstatat64, 300, long dirfd, long path, long buf, long flags); -SYS_JSAPI_DEF(fstatat64, long dirfd, long path, long buf, long flags) - -SYS_CAPI_DEF(unlinkat, 301, long dirfd, long path, long flags); -SYS_JSAPI_DEF(unlinkat, long dirfd, long path, long flags) - -SYS_CAPI_DEF(renameat, 302, long olddirfd, long oldpath, long newdirfd, long newpath); -SYS_JSAPI_DEF(renameat, long olddirfd, long oldpath, long newdirfd, long newpath) - -SYS_CAPI_DEF(symlinkat, 304, long target, long newdirfd, long linkpath); -SYS_JSAPI_DEF(symlinkat, long target, long newdirfd, long linkpath) - -SYS_CAPI_DEF(readlinkat, 305, long dirfd, long path, long bug, long bufsize); -SYS_JSAPI_DEF(readlinkat, long dirfd, long path, long bug, long bufsize) - -SYS_CAPI_DEF(fchmodat, 306, long dirfd, long path, long mode, ...); -SYS_JSAPI_DEF(fchmodat, long dirfd, long path, long mode, int varargs) - -SYS_CAPI_DEF(faccessat, 307, long dirfd, long path, long amode, long flags); -SYS_JSAPI_DEF(faccessat, long dirfd, long path, long amode, long flags) - -SYS_CAPI_DEF(utimensat, 320, long dirfd, long path, long times, long flags); -SYS_JSAPI_DEF(utimensat, long dirfd, long path, long times, long flags) - SYS_CAPI_DEF(fallocate, 324, long fd, long mode, long off_low, long off_high, long len_low, long len_high); SYS_JSAPI_DEF(fallocate, long fd, long mode, long off_low, long off_high, long len_low, long len_high) -SYS_CAPI_DEF(dup3, 330, long fd, long suggestfd, long flags); -SYS_JSAPI_DEF(dup3, long fd, long suggestfd, long flags) } class SyncToAsync { @@ -260,6 +221,4 @@ void resumeWrapper_l(long retVal); void resumeWrapper_wasi(__wasi_errno_t retVal); -void emscripten_init_pthreadfs(); - #endif // PTHREADFS_H diff --git a/pthreadfs/src/Makefile b/pthreadfs/src/Makefile index 094cf2970b270..becdbcda7ac9f 100644 --- a/pthreadfs/src/Makefile +++ b/pthreadfs/src/Makefile @@ -11,4 +11,4 @@ LIB_TTY = $(JSLIB_SRC)/library_tty_async.js library_pthreadfs.js: $(LIB_WRAPPER) $(LIB_SYS) $(LIB_FS) $(LIB_MEMFS) $(LIB_FSAFS) $(LIB_TTY) rm -f $@ - cat $? > ../$@ + cat $^ > ../$@ diff --git a/pthreadfs/src/js/library_asyncfs.js b/pthreadfs/src/js/library_asyncfs.js index e00ef32fbb93d..98ecace7544c8 100644 --- a/pthreadfs/src/js/library_asyncfs.js +++ b/pthreadfs/src/js/library_asyncfs.js @@ -316,10 +316,11 @@ // // streams // + MIN_FD: 4097, MAX_OPEN_FDS: 4096, nextfd: function(fd_start, fd_end) { - fd_start = fd_start || 0; - fd_end = fd_end || PThreadFS.MAX_OPEN_FDS; + fd_start = fd_start || PThreadFS.MIN_FD; + fd_end = fd_end || PThreadFS.MIN_FD + PThreadFS.MAX_OPEN_FDS; for (var fd = fd_start; fd <= fd_end; fd++) { if (!PThreadFS.streams[fd]) { return fd; @@ -1388,36 +1389,6 @@ 'MEMFS_ASYNC': MEMFS_ASYNC, }; }, - init: async function(input, output, error) { -#if ASSERTIONS - assert(!PThreadFS.init.initialized, 'PThreadFS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)'); -#endif - PThreadFS.init.initialized = true; - - PThreadFS.ensureErrnoError(); - - // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here - Module['stdin'] = input || Module['stdin']; - Module['stdout'] = output || Module['stdout']; - Module['stderr'] = error || Module['stderr']; - - await PThreadFS.createStandardStreams(); - }, - quit: async function() { - // TODO(rstz): This function is never called. - PThreadFS.init.initialized = false; - // force-flush all streams, so we get musl std streams printed out - var fflush = Module['_fflush']; - if (fflush) fflush(0); - // close all of our streams - for (var i = 0; i < PThreadFS.streams.length; i++) { - var stream = PThreadFS.streams[i]; - if (!stream) { - continue; - } - await PThreadFS.close(stream); - } - }, // // old v1 compatibility functions diff --git a/pthreadfs/src/js/library_syscall_async.js b/pthreadfs/src/js/library_syscall_async.js index 73603f1f64c21..720ffcb1eeddf 100644 --- a/pthreadfs/src/js/library_syscall_async.js +++ b/pthreadfs/src/js/library_syscall_async.js @@ -12,23 +12,17 @@ List of implemented syscalls: {'name': 'mknod', 'args': ['path', 'mode', 'dev']}, {'name': 'chmod', 'args': ['path', 'mode']}, {'name': 'access', 'args': ['path', 'amode']}, - {'name': 'rename', 'args': ['old_path', 'new_path']}, {'name': 'mkdir', 'args': ['path', 'mode']}, - {'name': 'rmdir', 'args': ['path']}, - {'name': 'dup', 'args': ['fd']}, - {'name': 'ioctl', 'args': ['fd', 'request', 'varargs']}, - {'name': 'dup2', 'args': ['oldfd', 'newfd']}, + {'name': 'rmdir', 'args': ['path']},] + {'name': 'ioctl', 'args': ['fd', 'request', 'varargs']},] {'name': 'symlink', 'args': ['target', 'linkpath']}, {'name': 'readlink', 'args': ['path', 'buf', 'bufsize']}, - {'name': 'munmap', 'args': ['addr', 'len']}, {'name': 'fchmod', 'args': ['fd', 'mode']}, {'name': 'fchdir', 'args': ['fd']}, {'name': '_newselect', 'args': ['nfds', 'readfds', 'writefds', 'exceptfds', 'timeout']}, - {'name': 'msync', 'args': ['addr', 'len', 'flags']}, {'name': 'fdatasync', 'args': ['fd']}, {'name': 'poll', 'args': ['fds', 'nfds', 'timeout']}, {'name': 'getcwd', 'args': ['buf', 'size']}, - {'name': 'mmap2', 'args': ['addr', 'len', 'prot', 'flags', 'fd', 'off']}, {'name': 'truncate64', 'args': ['path', 'zero', 'low', 'high']}, {'name': 'ftruncate64', 'args': ['fd', 'zero', 'low', 'high']}, {'name': 'stat64', 'args': ['path', 'buf']}, @@ -47,14 +41,13 @@ List of implemented syscalls: {'name': 'fchownat', 'args': ['dirfd', 'path', 'owner', 'group', 'flags']}, {'name': 'fstatat64', 'args': ['dirfd', 'path', 'buf', 'flags']}, {'name': 'unlinkat', 'args': ['dirfd', 'path', 'flags']}, - {'name': 'renameat', 'args': ['olddirfd', 'oldpath', 'newdirfd', 'newpath']}, {'name': 'symlinkat', 'args': ['target', 'newdirfd', 'linkpath']}, {'name': 'readlinkat', 'args': ['dirfd', 'path', 'bug', 'bufsize']}, {'name': 'fchmodat', 'args': ['dirfd', 'path', 'mode', 'varargs']}, {'name': 'faccessat', 'args': ['dirfd', 'path', 'amode', 'flags']}, {'name': 'utimensat', 'args': ['dirfd', 'path', 'times', 'flags']}, {'name': 'fallocate', 'args': ['fd', 'mode', 'off_low', 'off_high', 'len_low', 'len_high']}, - {'name': 'dup3', 'args': ['fd', 'suggestfd', 'flags']}, + */ var SyscallsLibrary = { @@ -121,10 +114,6 @@ var SyscallsLibrary = { {{{ makeSetValue('buf', C_STRUCTS.stat.st_ino, 'stat.ino', 'i64') }}}; return 0; }, - doMsync: async function(addr, stream, len, flags, offset) { - var buffer = HEAPU8.slice(addr, addr + len); - await PThreadFS.msync(stream, buffer, offset, len, flags); - }, doMkdir: async function(path, mode) { // remove a trailing slash, if one - /a/b/ has basename of '', but // we want to create b in the context of this function @@ -181,12 +170,6 @@ var SyscallsLibrary = { } return 0; }, - doDup: async function(path, flags, suggestFD) { - var suggest = await PThreadFS.getStream(suggestFD); - if (suggest) await PThreadFS.close(suggest); - let stream = await PThreadFS.open(path, flags, 0, suggestFD, suggestFD); - return stream.fd; - }, doReadv: async function(stream, iov, iovcnt, offset) { var ret = 0; for (var i = 0; i < iovcnt; i++) { @@ -248,66 +231,7 @@ var SyscallsLibrary = { #endif return low; }, - - $syscallMmap2_async__deps: ['$ASYNCSYSCALLS', '$zeroMemory', '$mmapAlloc', '$PThreadFS', - ], - $syscallMmap2_async: async function(addr, len, prot, flags, fd, off) { - off <<= 12; // undo pgoffset - var ptr; - var allocated = false; - - // addr argument must be page aligned if MAP_FIXED flag is set. - if ((flags & {{{ cDefine('MAP_FIXED') }}}) !== 0 && (addr % {{{ WASM_PAGE_SIZE }}}) !== 0) { - return -{{{ cDefine('EINVAL') }}}; - } - - // MAP_ANONYMOUS (aka MAP_ANON) isn't actually defined by POSIX spec, - // but it is widely used way to allocate memory pages on Linux, BSD and Mac. - // In this case fd argument is ignored. - if ((flags & {{{ cDefine('MAP_ANONYMOUS') }}}) !== 0) { - ptr = mmapAlloc(len); - if (!ptr) return -{{{ cDefine('ENOMEM') }}}; - allocated = true; - } else { - var info = await PThreadFS.getStream(fd); - if (!info) return -{{{ cDefine('EBADF') }}}; - var res = await PThreadFS.mmap(info, addr, len, off, prot, flags); - ptr = res.ptr; - allocated = res.allocated; - } - #if CAN_ADDRESS_2GB - ptr >>>= 0; - #endif - ASYNCSYSCALLS.mappings[ptr] = { malloc: ptr, len: len, allocated: allocated, fd: fd, prot: prot, flags: flags, offset: off }; - return ptr; - }, }, - - $syscallMunmap_async__deps: ['$ASYNCSYSCALLS', '$PThreadFS'], - $syscallMunmap_async: async function(addr, len) { - #if CAN_ADDRESS_2GB - addr >>>= 0; - #endif - // TODO: support unmmap'ing parts of allocations - var info = ASYNCSYSCALLS.mappings[addr]; - if (len === 0 || !info) { - return -{{{ cDefine('EINVAL') }}}; - } - if (len === info.len) { - var stream = await PThreadFS.getStream(info.fd); - if (stream) { - if (info.prot & {{{ cDefine('PROT_WRITE') }}}) { - await ASYNCSYSCALLS.doMsync(addr, stream, len, info.flags, info.offset); - } - await PThreadFS.munmap(stream); - } - ASYNCSYSCALLS.mappings[addr] = null; - if (info.allocated) { - _free(info.malloc); - } - } - return 0; - }, // WASI fd_write_async: async function(fd, iov, iovcnt, pnum) { @@ -411,12 +335,6 @@ var SyscallsLibrary = { path = ASYNCSYSCALLS.getStr(path); return await ASYNCSYSCALLS.doAccess(path, amode); }, - rename_async : async function(old_path, new_path) { - old_path = ASYNCSYSCALLS.getStr(old_path); - new_path = ASYNCSYSCALLS.getStr(new_path); - await PThreadFS.rename(old_path, new_path); - return 0; - }, mkdir_async : async function(path, mode) { path = ASYNCSYSCALLS.getStr(path); return await ASYNCSYSCALLS.doMkdir(path, mode); @@ -426,11 +344,6 @@ var SyscallsLibrary = { await PThreadFS.rmdir(path); return 0; }, - dup_async : async function(fd) { - let old = await ASYNCSYSCALLS.getStreamFromFD(fd); - let stream = await PThreadFS.open(old.path, old.flags, 0); - return stream.fd; - }, ioctl_async: async function(fd, op, varargs) { var stream = await ASYNCSYSCALLS.getStreamFromFD(fd); switch (op) { @@ -478,11 +391,6 @@ var SyscallsLibrary = { default: abort('bad ioctl syscall ' + op); } }, - dup2_async : async function(oldfd, suggestFD) { - var old = await ASYNCSYSCALLS.getStreamFromFD(oldfd); - if (old.fd === suggestFD) return suggestFD; - return await ASYNCSYSCALLS.doDup(old.path, old.flags, suggestFD); - }, symlink_async : async function(target, linkpath) { target = ASYNCSYSCALLS.getStr(target); linkpath = ASYNCSYSCALLS.getStr(linkpath); @@ -493,10 +401,6 @@ var SyscallsLibrary = { path = ASYNCSYSCALLS.getStr(path); return await ASYNCSYSCALLS.doReadlink(path, buf, bufsize); }, - munmap_async__deps: ['$syscallMunmap_async'], - munmap_async : async function(addr, len) { - return await syscallMunmap_async(addr, len); - }, fchmod_async : async function(fd, mode) { await PThreadFS.fchmod(fd, mode); return 0; @@ -587,15 +491,6 @@ var SyscallsLibrary = { return total; }, - msync_async: async function(addr, len, flags) { - #if CAN_ADDRESS_2GB - addr >>>= 0; - #endif - var info = ASYNCSYSCALLS.mappings[addr]; - if (!info) return 0; - await ASYNCSYSCALLS.doMsync(addr, await PThreadFS.getStream(info.fd), len, info.flags, 0); - return 0; - }, fdatasync_async : async function(fd) { var stream = await ASYNCSYSCALLS.getStreamFromFD(fd); //TODO(rstz): Consider implementing this, since Storage Foundation supports flush(). @@ -629,10 +524,6 @@ var SyscallsLibrary = { stringToUTF8(cwd, buf, size); return buf; }, - mmap2_async__deps: ['$syscallMmap2'], - mmap2_async: async function(addr, len, prot, flags, fd, off) { - return await syscallMmap2(addr, len, prot, flags, fd, off); - }, truncate64_async: async function(path, zero, low, high) { path = ASYNCSYSCALLS.getStr(path); var length = ASYNCSYSCALLS.get64(low, high); @@ -822,14 +713,6 @@ var SyscallsLibrary = { } return 0; }, - renameat_async: async function(olddirfd, oldpath, newdirfd, newpath) { - oldpath = ASYNCSYSCALLS.getStr(oldpath); - newpath = ASYNCSYSCALLS.getStr(newpath); - oldpath = ASYNCSYSCALLS.calculateAt(olddirfd, oldpath); - newpath = ASYNCSYSCALLS.calculateAt(newdirfd, newpath); - await PThreadFS.rename(oldpath, newpath); - return 0; - }, symlinkat_async: async function(target, newdirfd, linkpath) { linkpath = ASYNCSYSCALLS.calculateAt(newdirfd, linkpath); await PThreadFS.symlink(target, linkpath); @@ -871,11 +754,6 @@ var SyscallsLibrary = { await PThreadFS.allocate(stream, offset, len); return 0; }, - dup3_async: async function(fd, suggestFD, flags) { - var old = await ASYNCSYSCALLS.getStreamFromFD(fd); - if (old.fd === suggestFD) return -{{{ cDefine('EINVAL') }}}; - return await ASYNCSYSCALLS.doDup(old.path, old.flags, suggestFD); - }, }; function wrapSyscallFunction(x, library, isWasi) { diff --git a/pthreadfs/src/js/pthreadfs.js b/pthreadfs/src/js/pthreadfs.js index 4e7d994e5e9dc..f4059b7120e3d 100644 --- a/pthreadfs/src/js/pthreadfs.js +++ b/pthreadfs/src/js/pthreadfs.js @@ -13,23 +13,13 @@ let SyscallsFunctions = [ {'name': 'mknod', 'args': ['path', 'mode', 'dev']}, {'name': 'chmod', 'args': ['path', 'mode']}, {'name': 'access', 'args': ['path', 'amode']}, - {'name': 'rename', 'args': ['old_path', 'new_path']}, {'name': 'mkdir', 'args': ['path', 'mode']}, {'name': 'rmdir', 'args': ['path']}, - {'name': 'dup', 'args': ['fd']}, {'name': 'ioctl', 'args': ['fd', 'request', 'varargs']}, - {'name': 'dup2', 'args': ['oldfd', 'newfd']}, - {'name': 'symlink', 'args': ['target', 'linkpath']}, {'name': 'readlink', 'args': ['path', 'buf', 'bufsize']}, - {'name': 'munmap', 'args': ['addr', 'len']}, {'name': 'fchmod', 'args': ['fd', 'mode']}, {'name': 'fchdir', 'args': ['fd']}, - {'name': '_newselect', 'args': ['nfds', 'readfds', 'writefds', 'exceptfds', 'timeout']}, - {'name': 'msync', 'args': ['addr', 'len', 'flags']}, {'name': 'fdatasync', 'args': ['fd']}, - {'name': 'poll', 'args': ['fds', 'nfds', 'timeout']}, - {'name': 'getcwd', 'args': ['buf', 'size']}, - {'name': 'mmap2', 'args': ['addr', 'len', 'prot', 'flags', 'fd', 'off']}, {'name': 'truncate64', 'args': ['path', 'zero', 'low', 'high']}, {'name': 'ftruncate64', 'args': ['fd', 'zero', 'low', 'high']}, {'name': 'stat64', 'args': ['path', 'buf']}, @@ -42,20 +32,7 @@ let SyscallsFunctions = [ {'name': 'fcntl64', 'args': ['fd', 'cmd', 'varargs']}, {'name': 'statfs64', 'args': ['path', 'size', 'buf']}, {'name': 'fstatfs64', 'args': ['fd', 'size', 'buf']}, - {'name': 'openat', 'args': ['dirfd', 'path', 'flags', 'varargs']}, - {'name': 'mkdirat', 'args': ['dirfd', 'path', 'mode']}, - {'name': 'mknodat', 'args': ['dirfd', 'path', 'mode', 'dev']}, - {'name': 'fchownat', 'args': ['dirfd', 'path', 'owner', 'group', 'flags']}, - {'name': 'fstatat64', 'args': ['dirfd', 'path', 'buf', 'flags']}, - {'name': 'unlinkat', 'args': ['dirfd', 'path', 'flags']}, - {'name': 'renameat', 'args': ['olddirfd', 'oldpath', 'newdirfd', 'newpath']}, - {'name': 'symlinkat', 'args': ['target', 'newdirfd', 'linkpath']}, - {'name': 'readlinkat', 'args': ['dirfd', 'path', 'bug', 'bufsize']}, - {'name': 'fchmodat', 'args': ['dirfd', 'path', 'mode', 'varargs']}, - {'name': 'faccessat', 'args': ['dirfd', 'path', 'amode', 'flags']}, - {'name': 'utimensat', 'args': ['dirfd', 'path', 'times', 'flags']}, {'name': 'fallocate', 'args': ['fd', 'mode', 'off_low', 'off_high', 'len_low', 'len_high']}, - {'name': 'dup3', 'args': ['fd', 'suggestfd', 'flags']}, ] let WasiFunctions = [ @@ -151,7 +128,6 @@ SyscallWrappers['init_pthreadfs'] = function (resume) { PThreadFS.FSNode = FSNode; PThreadFS.staticInit().then(async ()=> { - await PThreadFS.init(); PThreadFS.ignorePermissions = false; wasmTable.get(resume)(); }); diff --git a/pthreadfs/src/pthreadfs.cpp b/pthreadfs/src/pthreadfs.cpp index 514c8540bc13b..70033fcf48542 100644 --- a/pthreadfs/src/pthreadfs.cpp +++ b/pthreadfs/src/pthreadfs.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include @@ -102,10 +104,15 @@ void resumeWrapper_wasi(__wasi_errno_t retVal) g_resumeFct(); } +// File System Access collection +std::set fsa_file_descriptors; +std::set mounted_directories; + // Wasi definitions WASI_CAPI_DEF(write, const __wasi_ciovec_t *iovs, size_t iovs_len, __wasi_size_t *nwritten) { WASI_SYNCTOASYNC(write, iovs, iovs_len, nwritten); } + WASI_CAPI_DEF(read, const __wasi_iovec_t *iovs, size_t iovs_len, __wasi_size_t *nread) { WASI_SYNCTOASYNC(read, iovs, iovs_len, nread); } @@ -122,7 +129,17 @@ WASI_CAPI_DEF(fdstat_get, __wasi_fdstat_t *stat) { WASI_SYNCTOASYNC(fdstat_get, stat); } WASI_CAPI_NOARGS_DEF(close) { - WASI_SYNCTOASYNC_NOARGS(close); + if(fsa_file_descriptors.count(fd) > 0) { + g_synctoasync_helper.doWork([fd](SyncToAsync::Callback resume) { + g_resumeFct = [resume]() { resume(); }; + __fd_close_async(fd, &resumeWrapper_wasi); + }); + if (resume_result_wasi == __WASI_ERRNO_SUCCESS) { + fsa_file_descriptors.erase(fd); + } + return resume_result_wasi; + } + return fd_close(fd); } WASI_CAPI_NOARGS_DEF(sync) { WASI_SYNCTOASYNC_NOARGS(sync); @@ -135,43 +152,41 @@ SYS_CAPI_DEF(open, 5, long path, long flags, ...) { int varargs = va_arg(vl, int); va_end(vl); - SYS_SYNCTOASYNC(open, path, flags, varargs); + std::string pathname((char*) path); + if (pathname.rfind("/filesystemaccess", 0) == 0 || pathname.rfind("filesystemaccess", 0) == 0) { + SYS_SYNCTOASYNC_NORETURN(open, path, flags, varargs); + fsa_file_descriptors.insert(resume_result_long); + return resume_result_long; + } + return __sys_open(path, flags, varargs); } SYS_CAPI_DEF(unlink, 10, long path) { - SYS_SYNCTOASYNC(unlink, path); + SYS_SYNCTOASYNC_PATH(unlink, path); } SYS_CAPI_DEF(chdir, 12, long path) { - SYS_SYNCTOASYNC(chdir, path); + SYS_SYNCTOASYNC_PATH(chdir, path); } SYS_CAPI_DEF(mknod, 14, long path, long mode, long dev) { - SYS_SYNCTOASYNC(mknod, path, mode, dev); + SYS_SYNCTOASYNC_PATH(mknod, path, mode, dev); } SYS_CAPI_DEF(chmod, 15, long path, long mode) { - SYS_SYNCTOASYNC(chmod, path, mode); + SYS_SYNCTOASYNC_PATH(chmod, path, mode); } SYS_CAPI_DEF(access, 33, long path, long amode) { - SYS_SYNCTOASYNC(access, path, amode); -} - -SYS_CAPI_DEF(rename, 38, long old_path, long new_path) { - SYS_SYNCTOASYNC(rename, old_path, new_path); + SYS_SYNCTOASYNC_PATH(access, path, amode); } SYS_CAPI_DEF(mkdir, 39, long path, long mode) { - SYS_SYNCTOASYNC(mkdir, path, mode); + SYS_SYNCTOASYNC_PATH(mkdir, path, mode); } SYS_CAPI_DEF(rmdir, 40, long path) { - SYS_SYNCTOASYNC(rmdir, path); -} - -SYS_CAPI_DEF(dup, 41, long fd) { - SYS_SYNCTOASYNC(dup, fd); + SYS_SYNCTOASYNC_PATH(rmdir, path); } SYS_CAPI_DEF(ioctl, 54, long fd, long request, ...) { @@ -181,91 +196,59 @@ SYS_CAPI_DEF(ioctl, 54, long fd, long request, ...) { arg = va_arg(ap, void *); va_end(ap); - SYS_SYNCTOASYNC(ioctl, fd, request, arg); -} - -SYS_CAPI_DEF(dup2, 63, long oldfd, long newfd) { - SYS_SYNCTOASYNC(dup2, oldfd, newfd); -} - -SYS_CAPI_DEF(symlink, 83, long target, long linkpath) { - SYS_SYNCTOASYNC(symlink, target, linkpath); + SYS_SYNCTOASYNC_FD(ioctl, fd, request, arg); } SYS_CAPI_DEF(readlink, 85, long path, long buf, long bufsize) { - SYS_SYNCTOASYNC(readlink, path, buf, bufsize); -} - -SYS_CAPI_DEF(munmap, 91, long addr, long len) { - SYS_SYNCTOASYNC(munmap, addr, len); + SYS_SYNCTOASYNC_PATH(readlink, path, buf, bufsize); } SYS_CAPI_DEF(fchmod, 94, long fd, long mode) { - SYS_SYNCTOASYNC(fchmod, fd, mode); + SYS_SYNCTOASYNC_FD(fchmod, fd, mode); } SYS_CAPI_DEF(fchdir, 133, long fd) { - SYS_SYNCTOASYNC(fchdir, fd); -} - -SYS_CAPI_DEF(_newselect, 142, long nfds, long readfds, long writefds, long exceptfds, long timeout) { - SYS_SYNCTOASYNC(_newselect, nfds, readfds, writefds, exceptfds, timeout); -} - -SYS_CAPI_DEF(msync, 144, long addr, long len, long flags) { - SYS_SYNCTOASYNC(msync, addr, len, flags); + SYS_SYNCTOASYNC_FD(fchdir, fd); } SYS_CAPI_DEF(fdatasync, 148, long fd) { - SYS_SYNCTOASYNC(fdatasync, fd); -} - -SYS_CAPI_DEF(poll, 168, long fds, long nfds, long timeout) { - SYS_SYNCTOASYNC(poll, fds, nfds, timeout); -} - -SYS_CAPI_DEF(getcwd, 183, long buf, long size) { - SYS_SYNCTOASYNC(getcwd, buf, size); -} - -SYS_CAPI_DEF(mmap2, 192, long addr, long len, long prot, long flags, long fd, long off) { - SYS_SYNCTOASYNC(mmap2, addr, len, prot, flags, fd, off); + SYS_SYNCTOASYNC_FD(fdatasync, fd); } SYS_CAPI_DEF(truncate64, 193, long path, long zero, long low, long high) { - SYS_SYNCTOASYNC(truncate64, path, zero, low, high); + SYS_SYNCTOASYNC_PATH(truncate64, path, zero, low, high); } SYS_CAPI_DEF(ftruncate64, 194, long fd, long zero, long low, long high) { - SYS_SYNCTOASYNC(ftruncate64, fd, zero, low, high); + SYS_SYNCTOASYNC_FD(ftruncate64, fd, zero, low, high); } SYS_CAPI_DEF(stat64, 195, long path, long buf) { - SYS_SYNCTOASYNC(stat64, path, buf); + SYS_SYNCTOASYNC_PATH(stat64, path, buf); } SYS_CAPI_DEF(lstat64, 196, long path, long buf) { - SYS_SYNCTOASYNC(lstat64, path, buf); + SYS_SYNCTOASYNC_PATH(lstat64, path, buf); } SYS_CAPI_DEF(fstat64, 197, long fd, long buf) { - SYS_SYNCTOASYNC(fstat64, fd, buf); + SYS_SYNCTOASYNC_FD(fstat64, fd, buf); } SYS_CAPI_DEF(lchown32, 198, long path, long owner, long group) { - SYS_SYNCTOASYNC(lchown32, path, owner, group); + SYS_SYNCTOASYNC_PATH(lchown32, path, owner, group); } SYS_CAPI_DEF(fchown32, 207, long fd, long owner, long group) { - SYS_SYNCTOASYNC(fchown32, fd, owner, group); + SYS_SYNCTOASYNC_FD(fchown32, fd, owner, group); } SYS_CAPI_DEF(chown32, 212, long path, long owner, long group) { - SYS_SYNCTOASYNC(chown32, path, owner, group); + SYS_SYNCTOASYNC_PATH(chown32, path, owner, group); } SYS_CAPI_DEF(getdents64, 220, long fd, long dirp, long count) { - SYS_SYNCTOASYNC(getdents64, fd, dirp, count); + SYS_SYNCTOASYNC_FD(getdents64, fd, dirp, count); } SYS_CAPI_DEF(fcntl64, 221, long fd, long cmd, ...) { @@ -274,81 +257,19 @@ va_list vl; int varargs = va_arg(vl, int); va_end(vl); - SYS_SYNCTOASYNC(fcntl64, fd, cmd, varargs); + SYS_SYNCTOASYNC_FD(fcntl64, fd, cmd, varargs); } SYS_CAPI_DEF(statfs64, 268, long path, long size, long buf) { - SYS_SYNCTOASYNC(statfs64, path, size, buf); + SYS_SYNCTOASYNC_PATH(statfs64, path, size, buf); } SYS_CAPI_DEF(fstatfs64, 269, long fd, long size, long buf) { - SYS_SYNCTOASYNC(fstatfs64, fd, size, buf); -} - -SYS_CAPI_DEF(openat, 295, long dirfd, long path, long flags, ...) { -va_list vl; - va_start(vl, flags); - int varargs = va_arg(vl, int); - va_end(vl); - - SYS_SYNCTOASYNC(openat, dirfd, path, flags, varargs); -} - -SYS_CAPI_DEF(mkdirat, 296, long dirfd, long path, long mode) { - SYS_SYNCTOASYNC(mkdirat, dirfd, path, mode); -} - -SYS_CAPI_DEF(mknodat, 297, long dirfd, long path, long mode, long dev) { - SYS_SYNCTOASYNC(mknodat, dirfd, path, mode, dev); -} - -SYS_CAPI_DEF(fchownat, 298, long dirfd, long path, long owner, long group, long flags) { - SYS_SYNCTOASYNC(fchownat, dirfd, path, owner, group, flags); -} - -SYS_CAPI_DEF(fstatat64, 300, long dirfd, long path, long buf, long flags) { - SYS_SYNCTOASYNC(fstatat64, dirfd, path, buf, flags); -} - -SYS_CAPI_DEF(unlinkat, 301, long dirfd, long path, long flags) { - SYS_SYNCTOASYNC(unlinkat, dirfd, path, flags); -} - -SYS_CAPI_DEF(renameat, 302, long olddirfd, long oldpath, long newdirfd, long newpath) { - SYS_SYNCTOASYNC(renameat, olddirfd, oldpath, newdirfd, newpath); -} - -SYS_CAPI_DEF(symlinkat, 304, long target, long newdirfd, long linkpath) { - SYS_SYNCTOASYNC(symlinkat, target, newdirfd, linkpath); -} - -SYS_CAPI_DEF(readlinkat, 305, long dirfd, long path, long bug, long bufsize) { - SYS_SYNCTOASYNC(readlinkat, dirfd, path, bug, bufsize); -} - -SYS_CAPI_DEF(fchmodat, 306, long dirfd, long path, long mode, ...) { -va_list vl; - va_start(vl, mode); - int varargs = va_arg(vl, int); - va_end(vl); - - SYS_SYNCTOASYNC(fchmodat, dirfd, path, mode, varargs); -} - -SYS_CAPI_DEF(faccessat, 307, long dirfd, long path, long amode, long flags) { - SYS_SYNCTOASYNC(faccessat, dirfd, path, amode, flags); -} - -SYS_CAPI_DEF(utimensat, 320, long dirfd, long path, long times, long flags) { - SYS_SYNCTOASYNC(utimensat, dirfd, path, times, flags); + SYS_SYNCTOASYNC_FD(fstatfs64, fd, size, buf); } SYS_CAPI_DEF(fallocate, 324, long fd, long mode, long off_low, long off_high, long len_low, long len_high) { - SYS_SYNCTOASYNC(fallocate, fd, mode, off_low, off_high, len_low, len_high); -} - -SYS_CAPI_DEF(dup3, 330, long fd, long suggestfd, long flags) { - SYS_SYNCTOASYNC(dup3, fd, suggestfd, flags); + SYS_SYNCTOASYNC_FD(fallocate, fd, mode, off_low, off_high, len_low, len_high); } // Other helper code diff --git a/pthreadfs/src/pthreadfs.h b/pthreadfs/src/pthreadfs.h index f1220e644d276..6f2281d590c73 100644 --- a/pthreadfs/src/pthreadfs.h +++ b/pthreadfs/src/pthreadfs.h @@ -10,44 +10,73 @@ })();}, &resumeWrapper_v); \ }); -#define WASI_JSAPI_DEF(name, ...) extern void __fd_##name##_async(__wasi_fd_t fd, __VA_ARGS__, void (*fun)(__wasi_errno_t)); -#define WASI_JSAPI_NOARGS_DEF(name) extern void __fd_##name##_async(__wasi_fd_t fd, void (*fun)(__wasi_errno_t)); +#define WASI_JSAPI_DEF(name, ...) \ + extern void __fd_##name##_async(__wasi_fd_t fd, __VA_ARGS__, void (*fun)(__wasi_errno_t)); \ + extern __wasi_errno_t fd_##name(__wasi_fd_t fd, __VA_ARGS__); +#define WASI_JSAPI_NOARGS_DEF(name) \ + extern void __fd_##name##_async(__wasi_fd_t fd, void (*fun)(__wasi_errno_t)); \ + extern __wasi_errno_t fd_##name(__wasi_fd_t fd); #define WASI_CAPI_DEF(name, ...) __wasi_errno_t __wasi_fd_##name(__wasi_fd_t fd, __VA_ARGS__) #define WASI_CAPI_NOARGS_DEF(name) __wasi_errno_t __wasi_fd_##name(__wasi_fd_t fd) -#define WASI_JSAPI(name, ...) __fd_##name##_async(__VA_ARGS__) -#define WASI_SYNCTOASYNC(name, ...) g_synctoasync_helper.doWork([fd, __VA_ARGS__](SyncToAsync::Callback resume) { \ - g_resumeFct = [resume]() { resume(); }; \ - WASI_JSAPI(name, fd, __VA_ARGS__, &resumeWrapper_wasi); \ - }); \ - return resume_result_wasi; -#define WASI_SYNCTOASYNC_NOARGS(name) g_synctoasync_helper.doWork([fd](SyncToAsync::Callback resume) { \ - g_resumeFct = [resume]() { resume(); }; \ - WASI_JSAPI(name, fd, &resumeWrapper_wasi); \ - }); \ - return resume_result_wasi; +#define WASI_SYNCTOASYNC(name, ...) \ + if(fsa_file_descriptors.count(fd) > 0) { \ + g_synctoasync_helper.doWork([fd, __VA_ARGS__](SyncToAsync::Callback resume) { \ + g_resumeFct = [resume]() { resume(); }; \ + __fd_##name##_async(fd, __VA_ARGS__, &resumeWrapper_wasi); \ + }); \ + return resume_result_wasi; \ + } \ + return fd_##name(fd, __VA_ARGS__); +#define WASI_SYNCTOASYNC_NOARGS(name) \ + if(fsa_file_descriptors.count(fd) > 0) { \ + g_synctoasync_helper.doWork([fd](SyncToAsync::Callback resume) { \ + g_resumeFct = [resume]() { resume(); }; \ + __fd_##name##_async(fd, &resumeWrapper_wasi); \ + }); \ + return resume_result_wasi; \ + } \ + return fd_##name(fd); // Classic Syscalls -#define SYS_JSAPI_DEF(name, ...) extern void __sys_##name##_async(__VA_ARGS__, void (*fun)(long)); -#define SYS_JSAPI_NOARGS_DEF(name) extern void __sys_##name##_async(void (*fun)(long)); +#define SYS_JSAPI_DEF(name, ...) \ + extern void __sys_##name##_async(__VA_ARGS__, void (*fun)(long)); \ + extern long __sys_##name(__VA_ARGS__); + +#define SYS_JSAPI_NOARGS_DEF(name) \ + extern void __sys_##name##_async(void (*fun)(long)); \ + extern long __sys_##name(); #define SYS_CAPI_DEF(name, number, ...) long __syscall##number(__VA_ARGS__) #define SYS_DEF(name, number, ...) SYS_CAPI_DEF(name, number, __VA_ARGS__); SYS_JSAPI_DEF(name, __VA_ARGS__) #define SYS_JSAPI(name, ...) __sys_##name##_async(__VA_ARGS__) -#define SYS_SYNCTOASYNC(name, ...) g_synctoasync_helper.doWork([__VA_ARGS__](SyncToAsync::Callback resume) { \ +#define SYS_SYNCTOASYNC_NORETURN(name, ...) g_synctoasync_helper.doWork([__VA_ARGS__](SyncToAsync::Callback resume) { \ g_resumeFct = [resume]() { resume(); }; \ SYS_JSAPI(name, __VA_ARGS__, &resumeWrapper_l); \ - }); \ - return resume_result_long; -#define SYS_SYNCTOASYNC_NOARGS(name) g_synctoasync_helper.doWork([](SyncToAsync::Callback resume) { \ - g_resumeFct = [resume]() { resume(); }; \ - SYS_JSAPI(name, &resumeWrapper_l); \ - }); \ - return resume_result_long; + }); +#define SYS_SYNCTOASYNC_FD(name, ...) \ + if(fsa_file_descriptors.count(fd) > 0) { \ + g_synctoasync_helper.doWork([__VA_ARGS__](SyncToAsync::Callback resume) { \ + g_resumeFct = [resume]() { resume(); }; \ + __sys_##name##_async(__VA_ARGS__, &resumeWrapper_l); \ + }); \ + return resume_result_long; \ + } \ + return __sys_##name(__VA_ARGS__); +#define SYS_SYNCTOASYNC_PATH(name, ...) \ + std::string pathname((char*) path); \ + if (pathname.rfind("/filesystemaccess", 0) == 0 || pathname.rfind("filesystemaccess", 0) == 0) { \ + g_synctoasync_helper.doWork([__VA_ARGS__](SyncToAsync::Callback resume) { \ + g_resumeFct = [resume]() { resume(); }; \ + __sys_##name##_async(__VA_ARGS__, &resumeWrapper_l); \ + }); \ + return resume_result_long; \ + } \ + return __sys_##name(__VA_ARGS__); extern "C" { // Helpers @@ -86,57 +115,27 @@ SYS_JSAPI_DEF(chmod, long path, long mode) SYS_CAPI_DEF(access, 33, long path, long amode); SYS_JSAPI_DEF(access, long path, long amode) -SYS_CAPI_DEF(rename, 38, long old_path, long new_path); -SYS_JSAPI_DEF(rename, long old_path, long new_path) - SYS_CAPI_DEF(mkdir, 39, long path, long mode); SYS_JSAPI_DEF(mkdir, long path, long mode) SYS_CAPI_DEF(rmdir, 40, long path); SYS_JSAPI_DEF(rmdir, long path) -SYS_CAPI_DEF(dup, 41, long fd); -SYS_JSAPI_DEF(dup, long fd) - SYS_CAPI_DEF(ioctl, 54, long fd, long request, ...); SYS_JSAPI_DEF(ioctl, long fd, long request, void *const varargs) -SYS_CAPI_DEF(dup2, 63, long oldfd, long newfd); -SYS_JSAPI_DEF(dup2, long oldfd, long newfd) - -SYS_CAPI_DEF(symlink, 83, long target, long linkpath); -SYS_JSAPI_DEF(symlink, long target, long linkpath) - SYS_CAPI_DEF(readlink, 85, long path, long buf, long bufsize); SYS_JSAPI_DEF(readlink, long path, long buf, long bufsize) -SYS_CAPI_DEF(munmap, 91, long addr, long len); -SYS_JSAPI_DEF(munmap, long addr, long len) - SYS_CAPI_DEF(fchmod, 94, long fd, long mode); SYS_JSAPI_DEF(fchmod, long fd, long mode) SYS_CAPI_DEF(fchdir, 133, long fd); SYS_JSAPI_DEF(fchdir, long fd) -SYS_CAPI_DEF(_newselect, 142, long nfds, long readfds, long writefds, long exceptfds, long timeout); -SYS_JSAPI_DEF(_newselect, long nfds, long readfds, long writefds, long exceptfds, long timeout) - -SYS_CAPI_DEF(msync, 144, long addr, long len, long flags); -SYS_JSAPI_DEF(msync, long addr, long len, long flags) - SYS_CAPI_DEF(fdatasync, 148, long fd); SYS_JSAPI_DEF(fdatasync, long fd) -SYS_CAPI_DEF(poll, 168, long fds, long nfds, long timeout); -SYS_JSAPI_DEF(poll, long fds, long nfds, long timeout) - -SYS_CAPI_DEF(getcwd, 183, long buf, long size); -SYS_JSAPI_DEF(getcwd, long buf, long size) - -SYS_CAPI_DEF(mmap2, 192, long addr, long len, long prot, long flags, long fd, long off); -SYS_JSAPI_DEF(mmap2, long addr, long len, long prot, long flags, long fd, long off) - SYS_CAPI_DEF(truncate64, 193, long path, long zero, long low, long high); SYS_JSAPI_DEF(truncate64, long path, long zero, long low, long high) @@ -173,47 +172,9 @@ SYS_JSAPI_DEF(statfs64, long path, long size, long buf) SYS_CAPI_DEF(fstatfs64, 269, long fd, long size, long buf); SYS_JSAPI_DEF(fstatfs64, long fd, long size, long buf) -SYS_CAPI_DEF(openat, 295, long dirfd, long path, long flags, ...); -SYS_JSAPI_DEF(openat, long dirfd, long path, long flags, int varargs) - -SYS_CAPI_DEF(mkdirat, 296, long dirfd, long path, long mode); -SYS_JSAPI_DEF(mkdirat, long dirfd, long path, long mode) - -SYS_CAPI_DEF(mknodat, 297, long dirfd, long path, long mode, long dev); -SYS_JSAPI_DEF(mknodat, long dirfd, long path, long mode, long dev) - -SYS_CAPI_DEF(fchownat, 298, long dirfd, long path, long owner, long group, long flags); -SYS_JSAPI_DEF(fchownat, long dirfd, long path, long owner, long group, long flags) - -SYS_CAPI_DEF(fstatat64, 300, long dirfd, long path, long buf, long flags); -SYS_JSAPI_DEF(fstatat64, long dirfd, long path, long buf, long flags) - -SYS_CAPI_DEF(unlinkat, 301, long dirfd, long path, long flags); -SYS_JSAPI_DEF(unlinkat, long dirfd, long path, long flags) - -SYS_CAPI_DEF(renameat, 302, long olddirfd, long oldpath, long newdirfd, long newpath); -SYS_JSAPI_DEF(renameat, long olddirfd, long oldpath, long newdirfd, long newpath) - -SYS_CAPI_DEF(symlinkat, 304, long target, long newdirfd, long linkpath); -SYS_JSAPI_DEF(symlinkat, long target, long newdirfd, long linkpath) - -SYS_CAPI_DEF(readlinkat, 305, long dirfd, long path, long bug, long bufsize); -SYS_JSAPI_DEF(readlinkat, long dirfd, long path, long bug, long bufsize) - -SYS_CAPI_DEF(fchmodat, 306, long dirfd, long path, long mode, ...); -SYS_JSAPI_DEF(fchmodat, long dirfd, long path, long mode, int varargs) - -SYS_CAPI_DEF(faccessat, 307, long dirfd, long path, long amode, long flags); -SYS_JSAPI_DEF(faccessat, long dirfd, long path, long amode, long flags) - -SYS_CAPI_DEF(utimensat, 320, long dirfd, long path, long times, long flags); -SYS_JSAPI_DEF(utimensat, long dirfd, long path, long times, long flags) - SYS_CAPI_DEF(fallocate, 324, long fd, long mode, long off_low, long off_high, long len_low, long len_high); SYS_JSAPI_DEF(fallocate, long fd, long mode, long off_low, long off_high, long len_low, long len_high) -SYS_CAPI_DEF(dup3, 330, long fd, long suggestfd, long flags); -SYS_JSAPI_DEF(dup3, long fd, long suggestfd, long flags) } class SyncToAsync { @@ -260,6 +221,4 @@ void resumeWrapper_l(long retVal); void resumeWrapper_wasi(__wasi_errno_t retVal); -void emscripten_init_pthreadfs(); - #endif // PTHREADFS_H