Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/libsigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,13 @@ sigs = {
__syscall_ftruncate64__sig: 'iij',
__syscall_getcwd__sig: 'ipp',
__syscall_getdents64__sig: 'iipp',
__syscall_getegid32__sig: 'i',
__syscall_geteuid32__sig: 'i',
__syscall_getgid32__sig: 'i',
__syscall_getpeername__sig: 'iippiii',
__syscall_getsockname__sig: 'iippiii',
__syscall_getsockopt__sig: 'iiiippi',
__syscall_getuid32__sig: 'i',
__syscall_ioctl__sig: 'iiip',
__syscall_linkat__sig: 'iipipi',
__syscall_listen__sig: 'iiiiiii',
Expand Down
17 changes: 17 additions & 0 deletions src/lib/libsyscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,23 @@ var SyscallsLibrary = {
}
return 0;
},
__syscall_getuid32__nothrow: true,
__syscall_geteuid32__nothrow: true,
__syscall_getgid32__nothrow: true,
__syscall_getegid32__nothrow: true,
#if NODERAWFS
// NODERAWFS reports the real host process credentials (0 on Windows, which
// has no uid/gid concept).
__syscall_getuid32: () => process.getuid?.() ?? 0,
__syscall_geteuid32: () => process.geteuid?.() ?? 0,
__syscall_getgid32: () => process.getgid?.() ?? 0,
__syscall_getegid32: () => process.getegid?.() ?? 0,
#else
__syscall_getuid32: () => 0,
__syscall_geteuid32: () => 0,
__syscall_getgid32: () => 0,
__syscall_getegid32: () => 0,
#endif
__syscall_dup3: (fd, newfd, flags) => {
if (fd === newfd) return -{{{ cDefs.EINVAL }}};
if (flags & ~{{{ cDefs.O_CLOEXEC }}}) return -{{{ cDefs.EINVAL }}};
Expand Down
16 changes: 0 additions & 16 deletions system/lib/libc/emscripten_syscall_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,6 @@ weak int __syscall_setdomainname(const char *name, size_t len) {
return -EPERM;
}

weak uid_t __syscall_getuid32(void) {
return 0;
}

weak gid_t __syscall_getgid32(void) {
return 0;
}

weak uid_t __syscall_geteuid32(void) {
return 0;
}

weak gid_t __syscall_getegid32(void) {
return 0;
}

weak int __syscall_getresuid32(uid_t *ruid, uid_t *euid, uid_t *suid) {
*ruid = 0;
*euid = 0;
Expand Down
7 changes: 7 additions & 0 deletions system/lib/wasmfs/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,13 @@ int __syscall_linkat(int olddirfd,
return -EMLINK;
}

// NODERAWFS credential reporting is implemented in the legacy JS syscall layer
// only.
uid_t __syscall_getuid32(void) { return 0; }
uid_t __syscall_geteuid32(void) { return 0; }
gid_t __syscall_getgid32(void) { return 0; }
gid_t __syscall_getegid32(void) { return 0; }

// epoll is implemented in the legacy (non-WASMFS) JS syscall layer only.
int __syscall_epoll_create1(int flags) { return -ENOSYS; }

Expand Down
22 changes: 15 additions & 7 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 269157,
"a.out.nodebug.wasm": 588047,
"total": 857204,
"a.out.js": 269335,
"a.out.nodebug.wasm": 588128,
"total": 857463,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down Expand Up @@ -240,9 +240,13 @@
"__syscall_ftruncate64",
"__syscall_getcwd",
"__syscall_getdents64",
"__syscall_getegid32",
"__syscall_geteuid32",
"__syscall_getgid32",
"__syscall_getpeername",
"__syscall_getsockname",
"__syscall_getsockopt",
"__syscall_getuid32",
"__syscall_ioctl",
"__syscall_linkat",
"__syscall_listen",
Expand Down Expand Up @@ -1767,9 +1771,13 @@
"env.__syscall_ftruncate64",
"env.__syscall_getcwd",
"env.__syscall_getdents64",
"env.__syscall_getegid32",
"env.__syscall_geteuid32",
"env.__syscall_getgid32",
"env.__syscall_getpeername",
"env.__syscall_getsockname",
"env.__syscall_getsockopt",
"env.__syscall_getuid32",
"env.__syscall_ioctl",
"env.__syscall_linkat",
"env.__syscall_listen",
Expand Down Expand Up @@ -2209,9 +2217,6 @@
"__subvti3",
"__synccall",
"__syscall_acct",
"__syscall_getegid32",
"__syscall_geteuid32",
"__syscall_getgid32",
"__syscall_getgroups32",
"__syscall_getpgid",
"__syscall_getpid",
Expand All @@ -2221,7 +2226,6 @@
"__syscall_getresuid32",
"__syscall_getrusage",
"__syscall_getsid",
"__syscall_getuid32",
"__syscall_madvise",
"__syscall_mincore",
"__syscall_mlock",
Expand Down Expand Up @@ -4636,8 +4640,11 @@
"$getdelim",
"$getdents",
"$getdomainname",
"$getegid",
"$getentropy",
"$getenv",
"$geteuid",
"$getgid",
"$getgroups",
"$gethostbyaddr",
"$gethostbyaddr_r",
Expand Down Expand Up @@ -4678,6 +4685,7 @@
"$gettext",
"$gettid",
"$gettimeofday",
"$getuid",
"$getw",
"$getwchar",
"$glob",
Expand Down
23 changes: 23 additions & 0 deletions test/fs/test_getuid_noderawfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2026 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 <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <emscripten.h>

int main() {
// NODERAWFS reports the real host process credentials. Other backends report
// 0 and are covered by test/unistd/misc.c.
assert(getuid() == EM_ASM_INT({ return process.getuid(); }));
assert(geteuid() == EM_ASM_INT({ return process.geteuid(); }));
assert(getgid() == EM_ASM_INT({ return process.getgid(); }));
assert(getegid() == EM_ASM_INT({ return process.getegid(); }));

printf("done\n");
return 0;
}
7 changes: 7 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5987,6 +5987,13 @@ def test_fs_utimensat_nofollow(self):
def test_fs_fadvise_fallocate(self):
self.do_runf('fs/test_fadvise_fallocate.c', 'done\n')

@no_windows('no uid/gid concept on windows')
def test_fs_getuid_noderawfs(self):
# The default backends report 0 and are covered by unistd/misc.c. This test
# verifies NODERAWFS reports the real host process credentials.
self.setup_noderawfs_test()
self.do_runf('fs/test_getuid_noderawfs.c', 'done\n')

@no_windows('https://github.com/emscripten-core/emscripten/issues/8882')
@crossplatform
@also_with_nodefs_both
Expand Down