Skip to content

Commit e81c4e8

Browse files
authored
gh-127146: Report uid in Emscripten + node as native uid (#136509)
Corrects the handling of getuid on emscripten, which was consistently reporting as 0.
1 parent cb59eae commit e81c4e8

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Python/emscripten_syscalls.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "emscripten.h"
2+
3+
// If we're running in node, report the UID of the user in the native system as
4+
// the UID of the user. Since the nodefs will report the uid correctly, if we
5+
// don't make getuid report it correctly too we'll see some permission errors.
6+
// Normally __syscall_getuid32 is a stub that always returns 0 but it is
7+
// defined with weak linkage so we can override it.
8+
EM_JS(int, __syscall_getuid32_js, (void), {
9+
// If we're in node and we can, report the native uid
10+
if (typeof process !== "undefined" && typeof process.getuid === "function") {
11+
return process.getuid();
12+
}
13+
// Fall back to the stub case of returning 0.
14+
return 0;
15+
})
16+
17+
int __syscall_getuid32(void) {
18+
return __syscall_getuid32_js();
19+
}

Tools/c-analyzer/cpython/_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def clean_lines(text):
6666
Python/dynload_dl.c # dl.h
6767
Python/dynload_hpux.c # dl.h
6868
Python/emscripten_signal.c
69+
Python/emscripten_syscalls.c
6970
Python/thread_pthread.h
7071
Python/thread_pthread_stubs.h
7172

configure

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5121,7 +5121,7 @@ PLATFORM_OBJS=
51215121

51225122
AS_CASE([$ac_sys_system],
51235123
[Emscripten], [
5124-
AS_VAR_APPEND([PLATFORM_OBJS], [' Python/emscripten_signal.o Python/emscripten_trampoline.o'])
5124+
AS_VAR_APPEND([PLATFORM_OBJS], [' Python/emscripten_signal.o Python/emscripten_trampoline.o Python/emscripten_syscalls.o'])
51255125
AS_VAR_APPEND([PLATFORM_HEADERS], [' $(srcdir)/Include/internal/pycore_emscripten_signal.h $(srcdir)/Include/internal/pycore_emscripten_trampoline.h'])
51265126
],
51275127
)

0 commit comments

Comments
 (0)