gh-127146: Report uid in Emscripten + node as native uid (#136509)

Corrects the handling of getuid on emscripten, which was consistently reporting as 0.
This commit is contained in:
Hood Chatham 2025-07-16 06:17:16 +02:00 committed by GitHub
parent cb59eaefed
commit e81c4e84b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 2 deletions

View file

@ -0,0 +1,19 @@
#include "emscripten.h"
// If we're running in node, report the UID of the user in the native system as
// the UID of the user. Since the nodefs will report the uid correctly, if we
// don't make getuid report it correctly too we'll see some permission errors.
// Normally __syscall_getuid32 is a stub that always returns 0 but it is
// defined with weak linkage so we can override it.
EM_JS(int, __syscall_getuid32_js, (void), {
// If we're in node and we can, report the native uid
if (typeof process !== "undefined" && typeof process.getuid === "function") {
return process.getuid();
}
// Fall back to the stub case of returning 0.
return 0;
})
int __syscall_getuid32(void) {
return __syscall_getuid32_js();
}