Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

/dev/zero is missing #21569

Open
EvenOAndersen opened this issue Mar 20, 2024 · 1 comment
Open

/dev/zero is missing #21569

EvenOAndersen opened this issue Mar 20, 2024 · 1 comment

Comments

@EvenOAndersen
Copy link

Please include the following in your bug report:

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.50 (047b825)
clang version 18.0.0 (https://github.com/llvm/llvm-project 14028ec0a62210d68a4dd7a046ac79c8c3b7727e)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\emsdk\upstream\bin

int fd = open("/dev/zero", O_RDONLY);
assert(fd != -1);
@sbc100
Copy link
Collaborator

sbc100 commented Mar 20, 2024

Emscripten doesn't have full support for the linux/unix /dev/ filesystem.

You can see the ones that we do support here:

emscripten/src/library_fs.js

Lines 1347 to 1365 in be8f1d1

FS.mkdev('/dev/null', FS.makedev(1, 3));
// setup /dev/tty and /dev/tty1
// stderr needs to print output using err() rather than out()
// so we register a second tty just for it.
TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
FS.mkdev('/dev/tty', FS.makedev(5, 0));
FS.mkdev('/dev/tty1', FS.makedev(6, 0));
// setup /dev/[u]random
// use a buffer to avoid overhead of individual crypto calls per byte
var randomBuffer = new Uint8Array(1024), randomLeft = 0;
var randomByte = () => {
if (randomLeft === 0) {
randomLeft = randomFill(randomBuffer).byteLength;
}
return randomBuffer[--randomLeft];
};
FS.createDevice('/dev', 'random', randomByte);
FS.createDevice('/dev', 'urandom', randomByte);

It should be able to create it yourself using FS.createDevice. Howeever, it might be simpler and result if smaller code size if you modify your code to avoid using this file in the emscripten build. Its likely that something like memset(..., 0, ..) is going to be better in almost every way under emscripten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants