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
12 changes: 6 additions & 6 deletions src/lib/libsigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ sigs = {
__pthread_create_js__sig: 'ipppp',
__resumeException__sig: 'vp',
__syscall_accept4__sig: 'iippiii',
__syscall_bind__sig: 'iippiii',
__syscall_bind__sig: 'iipiiii',
__syscall_chdir__sig: 'ip',
__syscall_chmod__sig: 'ipi',
__syscall_connect__sig: 'iippiii',
__syscall_connect__sig: 'iipiiii',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did these syscalls work under wasm64 before if the type of arg 3 was not p?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait.. I see socklet_t is acually smaller than size_t.. that is good. One less pointer conversion.

__syscall_dup__sig: 'ii',
__syscall_dup3__sig: 'iiii',
__syscall_faccessat__sig: 'iipii',
Expand Down Expand Up @@ -265,12 +265,12 @@ sigs = {
__syscall_poll__sig: 'ipii',
__syscall_poll_nonblocking__sig: 'ipi',
__syscall_readlinkat__sig: 'iippp',
__syscall_recvfrom__sig: 'iippipp',
__syscall_recvmsg__sig: 'iipiiii',
__syscall_recvfrom__sig: 'pippipp',
__syscall_recvmsg__sig: 'pipiiii',
__syscall_renameat__sig: 'iipip',
__syscall_rmdir__sig: 'ip',
__syscall_sendmsg__sig: 'iipippi',
__syscall_sendto__sig: 'iippipp',
__syscall_sendmsg__sig: 'pipippi',
__syscall_sendto__sig: 'pippipi',
__syscall_shutdown__sig: 'iiiiiii',
__syscall_socket__sig: 'iiiiiii',
__syscall_stat64__sig: 'ipp',
Expand Down
86 changes: 44 additions & 42 deletions system/include/emscripten/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,74 @@

#pragma once

#include <poll.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

int __syscall_chdir(intptr_t path);
int __syscall_mknod(intptr_t path, int mode, int dev);
int __syscall_chmod(intptr_t path, int mode);
int __syscall_getpid(void);
int __syscall_mknod(intptr_t path, mode_t mode, dev_t dev);
int __syscall_chmod(intptr_t path, mode_t mode);
pid_t __syscall_getpid(void);
int __syscall_access(intptr_t path, int amode);
int __syscall_sync(void);
int __syscall_rmdir(intptr_t path);
int __syscall_dup(int fd);
int __syscall_acct(intptr_t filename);
int __syscall_ioctl(int fd, int request, ...);
int __syscall_setpgid(int pid, int gpid);
int __syscall_umask(int mask);
int __syscall_getppid(void);
int __syscall_getpgrp(void);
int __syscall_setsid(void);
int __syscall_setpgid(pid_t pid, pid_t gpid);
mode_t __syscall_umask(mode_t mask);
pid_t __syscall_getppid(void);
pid_t __syscall_getpgrp(void);
pid_t __syscall_setsid(void);
int __syscall_getrusage(int who, intptr_t usage);
int __syscall_munmap(intptr_t addr, size_t len);
int __syscall_fchmod(int fd, int mode);
int __syscall_getpriority(int which, int who);
int __syscall_setpriority(int which, int who, int prio);
int __syscall_fchmod(int fd, mode_t mode);
int __syscall_getpriority(int which, id_t who);
int __syscall_setpriority(int which, id_t who, int prio);
int __syscall_socketcall(int call, intptr_t args);
int __syscall_wait4(int pid, intptr_t wstatus, int options, int rusage);
pid_t __syscall_wait4(pid_t pid, intptr_t wstatus, int options, int rusage);
int __syscall_setdomainname(intptr_t name, size_t size);
int __syscall_uname(intptr_t buf);
int __syscall_mprotect(size_t addr, size_t len, int prot);
int __syscall_getpgid(int pid);
pid_t __syscall_getpgid(pid_t pid);
int __syscall_fchdir(int fd);
int __syscall_msync(intptr_t addr, size_t len, int flags);
int __syscall_getsid(int pid);
pid_t __syscall_getsid(pid_t pid);
int __syscall_fdatasync(int fd);
int __syscall_mlock(intptr_t addr, size_t len);
int __syscall_munlock(intptr_t addr, size_t len);
int __syscall_mlockall(int flags);
int __syscall_munlockall(void);
int __syscall_mremap(intptr_t old_addr, size_t old_size, size_t new_size, int flags, intptr_t new_addr);
int __syscall_poll(intptr_t fds, int nfds, int timeout);
int __syscall_poll_nonblocking(intptr_t fds, int nfds);
int __syscall_poll(intptr_t fds, nfds_t nfds, int timeout);
int __syscall_poll_nonblocking(intptr_t fds, nfds_t nfds);
int __syscall_getcwd(intptr_t buf, size_t size);
intptr_t __syscall_mmap2(intptr_t addr, size_t len, int prot, int flags, int fd, off_t offset);
int __syscall_truncate64(intptr_t path, off_t length);
int __syscall_ftruncate64(int fd, off_t length);
int __syscall_stat64(intptr_t path, intptr_t buf);
int __syscall_lstat64(intptr_t path, intptr_t buf);
int __syscall_fstat64(int fd, intptr_t buf);
int __syscall_getuid32(void);
int __syscall_getgid32(void);
int __syscall_geteuid32(void);
int __syscall_getegid32(void);
int __syscall_setreuid32(int ruid, int euid);
int __syscall_setregid32(int rgid, int egid);
int __syscall_getgroups32(int size, intptr_t list);
int __syscall_fchown32(int fd, int owner, int group);
int __syscall_setresuid32(int ruid, int euid, int suid);
uid_t __syscall_getuid32(void);
gid_t __syscall_getgid32(void);
uid_t __syscall_geteuid32(void);
gid_t __syscall_getegid32(void);
int __syscall_setreuid32(uid_t ruid, uid_t euid);
int __syscall_setregid32(gid_t rgid, gid_t egid);
int __syscall_getgroups32(int count, intptr_t list);
int __syscall_fchown32(int fd, uid_t owner, gid_t group);
int __syscall_setresuid32(uid_t ruid, uid_t euid, uid_t suid);
int __syscall_getresuid32(intptr_t ruid, intptr_t euid, intptr_t suid);
int __syscall_setresgid32(int rgid, int egid, int sgid);
int __syscall_setresgid32(gid_t rgid, gid_t egid, gid_t sgid);
int __syscall_getresgid32(intptr_t rgid, intptr_t egid, intptr_t sgid);
int __syscall_setuid32(int uid);
int __syscall_setgid32(int uid);
int __syscall_setuid32(uid_t uid);
int __syscall_setgid32(gid_t gid);
int __syscall_mincore(intptr_t addr, size_t length, intptr_t vec);
int __syscall_madvise(intptr_t addr, size_t length, int advice);
int __syscall_getdents64(int fd, intptr_t dirp, size_t count);
Expand All @@ -81,38 +83,38 @@ int __syscall_statfs64(intptr_t path, size_t size, intptr_t buf);
int __syscall_fstatfs64(int fd, size_t size, intptr_t buf);
int __syscall_fadvise64(int fd, off_t offset, off_t length, int advice);
int __syscall_openat(int dirfd, intptr_t path, int flags, ...); // mode is optional
int __syscall_mkdirat(int dirfd, intptr_t path, int mode);
int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev);
int __syscall_fchownat(int dirfd, intptr_t path, int owner, int group, int flags);
int __syscall_mkdirat(int dirfd, intptr_t path, mode_t mode);
int __syscall_mknodat(int dirfd, intptr_t path, mode_t mode, dev_t dev);
int __syscall_fchownat(int dirfd, intptr_t path, uid_t owner, gid_t group, int flags);
int __syscall_newfstatat(int dirfd, intptr_t path, intptr_t buf, int flags);
int __syscall_unlinkat(int dirfd, intptr_t path, int flags);
int __syscall_renameat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath);
int __syscall_linkat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath, int flags);
int __syscall_symlinkat(intptr_t target, int newdirfd, intptr_t linkpath);
int __syscall_readlinkat(int dirfd, intptr_t path, intptr_t buf, size_t bufsize);
int __syscall_fchmodat2(int dirfd, intptr_t path, int mode, int flags);
int __syscall_fchmodat2(int dirfd, intptr_t path, mode_t mode, int flags);
int __syscall_faccessat(int dirfd, intptr_t path, int amode, int flags);
int __syscall_utimensat(int dirfd, intptr_t path, intptr_t times, int flags);
int __syscall_fallocate(int fd, int mode, off_t offset, off_t len);
int __syscall_dup3(int fd, int suggestfd, int flags);
int __syscall_pipe2(intptr_t fds, int flags);
int __syscall_recvmmsg(int sockfd, intptr_t msgvec, size_t vlen, int flags, ...);
int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t old_limit);
int __syscall_sendmmsg(int sockfd, intptr_t msgvec, size_t vlen, int flags, ...);
int __syscall_recvmmsg(int sockfd, intptr_t msgvec, unsigned int vlen, unsigned int flags, ...);
int __syscall_prlimit64(pid_t pid, int resource, intptr_t new_limit, intptr_t old_limit);
int __syscall_sendmmsg(int sockfd, intptr_t msgvec, unsigned int vlen, unsigned int flags, ...);
int __syscall_socket(int domain, int type, int protocol, int dummy1, int dummy2, int dummy3);
int __syscall_socketpair(int domain, int type, int protocol, intptr_t fds, int dummy, int dummy2);
int __syscall_bind(int sockfd, intptr_t addr, size_t alen, int dummy, int dummy2, int dummy3);
int __syscall_connect(int sockfd, intptr_t addr, size_t len, int dummy, int dummy2, int dummy3);
int __syscall_bind(int sockfd, intptr_t addr, socklen_t alen, int dummy, int dummy2, int dummy3);
int __syscall_connect(int sockfd, intptr_t addr, socklen_t len, int dummy, int dummy2, int dummy3);
int __syscall_listen(int sockfd, int backlog, int dummy1, int dummy2, int dummy3, int dummy4);
int __syscall_accept4(int sockfd, intptr_t addr, intptr_t addrlen, int flags, int dummy1, int dummy2);
int __syscall_getsockopt(int sockfd, int level, int optname, intptr_t optval, intptr_t optlen, int dummy);
int __syscall_setsockopt(int sockfd, int level, int optname, intptr_t optval, size_t optlen, int dummy);
int __syscall_setsockopt(int sockfd, int level, int optname, intptr_t optval, socklen_t optlen, int dummy);
int __syscall_getsockname(int sockfd, intptr_t addr, intptr_t len, int dummy, int dummy2, int dummy3);
int __syscall_getpeername(int sockfd, intptr_t addr, intptr_t len, int dummy, int dummy2, int dummy3);
int __syscall_sendto(int sockfd, intptr_t msg, size_t len, int flags, intptr_t addr, size_t alen);
int __syscall_sendmsg(int sockfd, intptr_t msg , int flags, intptr_t addr, size_t alen, int dummy);
int __syscall_recvfrom(int sockfd, intptr_t msg, size_t len, int flags, intptr_t addr, intptr_t alen);
int __syscall_recvmsg(int sockfd, intptr_t msg, int flags, int dummy, int dummy2, int dummy3);
ssize_t __syscall_sendto(int sockfd, intptr_t msg, size_t len, int flags, intptr_t addr, socklen_t alen);
ssize_t __syscall_sendmsg(int sockfd, intptr_t msg , int flags, intptr_t addr, size_t alen, int dummy);
ssize_t __syscall_recvfrom(int sockfd, intptr_t msg, size_t len, int flags, intptr_t addr, intptr_t alen);
ssize_t __syscall_recvmsg(int sockfd, intptr_t msg, int flags, int dummy, int dummy2, int dummy3);
int __syscall_shutdown(int sockfd, int how, int dummy, int dummy2, int dummy3, int dummy4);

#ifdef __cplusplus
Expand Down
50 changes: 27 additions & 23 deletions system/lib/libc/emscripten_syscall_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#include <emscripten/version.h>
#include <emscripten/stack.h>

static int g_pid = 42;
static int g_pgid = 42;
static int g_ppid = 1;
static int g_sid = 42;
static pid_t g_pid = 42;
static pid_t g_pgid = 42;
static pid_t g_ppid = 1;
static pid_t g_sid = 42;

#ifdef NDEBUG
#define REPORT(name)
Expand Down Expand Up @@ -68,7 +68,7 @@ weak int __syscall_uname(intptr_t buf) {
return 0;
}

weak int __syscall_setpgid(int pid, int pgid) {
weak int __syscall_setpgid(pid_t pid, pid_t pgid) {
if (pid && pid != g_pid) {
return -ESRCH;
}
Expand All @@ -82,41 +82,41 @@ weak int __syscall_sync() {
return 0;
}

weak int __syscall_getsid(int pid) {
weak pid_t __syscall_getsid(pid_t pid) {
if (pid && pid != g_pid) {
return -ESRCH;
}
return g_sid;
}

weak int __syscall_getpgid(int pid) {
weak pid_t __syscall_getpgid(pid_t pid) {
if (pid && pid != g_pid) {
return -ESRCH;
}
return g_pgid;
}

weak int __syscall_getpid() {
weak pid_t __syscall_getpid() {
return g_pid;
}

weak int __syscall_getppid() {
weak pid_t __syscall_getppid() {
return g_ppid;
}

weak int __syscall_linkat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath, int flags) {
return -EMLINK; // no hardlinks for us
}

weak int __syscall_getgroups32(int size, intptr_t list) {
if (size < 1) {
weak int __syscall_getgroups32(int count, intptr_t list) {
if (count < 1) {
return -EINVAL;
}
((gid_t*)list)[0] = 0;
return 1;
}

weak int __syscall_setsid() {
weak pid_t __syscall_setsid() {
return 0; // no-op
}

Expand All @@ -137,31 +137,31 @@ weak int __syscall_getrusage(int who, intptr_t usage) {
return 0;
}

weak int __syscall_getpriority(int which, int who) {
weak int __syscall_getpriority(int which, id_t who) {
return 0;
}

weak int __syscall_setpriority(int which, int who, int prio) {
weak int __syscall_setpriority(int which, id_t who, int prio) {
return -EPERM;
}

weak int __syscall_setdomainname(intptr_t name, size_t size) {
return -EPERM;
}

weak int __syscall_getuid32(void) {
weak uid_t __syscall_getuid32(void) {
return 0;
}

weak int __syscall_getgid32(void) {
weak gid_t __syscall_getgid32(void) {
return 0;
}

weak int __syscall_geteuid32(void) {
weak uid_t __syscall_geteuid32(void) {
return 0;
}

weak int __syscall_getegid32(void) {
weak gid_t __syscall_getegid32(void) {
return 0;
}

Expand Down Expand Up @@ -221,7 +221,7 @@ weak int __syscall_munlockall() {
return 0;
}

weak int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t old_limit) {
weak int __syscall_prlimit64(pid_t pid, int resource, intptr_t new_limit, intptr_t old_limit) {
REPORT(prlimit64);
struct rlimit *old = (struct rlimit *)old_limit;
if (new_limit) {
Expand All @@ -248,15 +248,19 @@ weak int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t
return 0;
}

weak int __syscall_setsockopt(int sockfd, int level, int optname, intptr_t optval, size_t optlen, int dummy) {
weak int __syscall_setsockopt(int sockfd, int level, int optname, intptr_t optval, socklen_t optlen, int dummy) {
REPORT(setsockopt);
return -ENOPROTOOPT; // The option is unknown at the level indicated.
}

weak pid_t __syscall_wait4(pid_t pid, intptr_t wstatus, int options, int rusage) {
REPORT(wait4);
return (pid_t)-1;
}

UNIMPLEMENTED(acct, (intptr_t filename))
UNIMPLEMENTED(mincore, (intptr_t addr, size_t length, intptr_t vec))
UNIMPLEMENTED(recvmmsg, (int sockfd, intptr_t msgvec, size_t vlen, int flags, ...))
UNIMPLEMENTED(sendmmsg, (int sockfd, intptr_t msgvec, size_t vlen, int flags, ...))
UNIMPLEMENTED(recvmmsg, (int sockfd, intptr_t msgvec, unsigned int vlen, unsigned int flags, ...))
UNIMPLEMENTED(sendmmsg, (int sockfd, intptr_t msgvec, unsigned int vlen, unsigned int flags, ...))
UNIMPLEMENTED(shutdown, (int sockfd, int how, int dummy, int dummy2, int dummy3, int dummy4))
UNIMPLEMENTED(socketpair, (int domain, int type, int protocol, intptr_t fds, int dummy, int dummy2))
UNIMPLEMENTED(wait4,(int pid, intptr_t wstatus, int options, int rusage))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

@kleisauke kleisauke Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UNIMPLEMENTED macro currently always returns an int, but the wait4 syscall requires a return type of pid_t.

6 changes: 3 additions & 3 deletions system/lib/standalone/standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ weak int _munmap_js(
return -ENOSYS;
}

weak int __syscall_poll(intptr_t fds, int nfds, int timeout) {
weak int __syscall_poll(intptr_t fds, nfds_t nfds, int timeout) {
return -ENOSYS;
}

weak int __syscall_poll_nonblocking(intptr_t fds, int nfds) {
weak int __syscall_poll_nonblocking(intptr_t fds, nfds_t nfds) {
return -ENOSYS;
}

Expand Down Expand Up @@ -111,7 +111,7 @@ weak int __syscall_dup(int fd) {
return -ENOSYS;
}

weak int __syscall_mkdirat(int dirfd, intptr_t path, int mode) {
weak int __syscall_mkdirat(int dirfd, intptr_t path, mode_t mode) {
return -ENOSYS;
}

Expand Down
2 changes: 1 addition & 1 deletion system/lib/wasmfs/js_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int _wasmfs_write_file(const char* pathname, const uint8_t* data, size_t data_si
return data_size;
}

int _wasmfs_mkdir(const char* path, int mode) {
int _wasmfs_mkdir(const char* path, mode_t mode) {
return __syscall_mkdirat(AT_FDCWD, (intptr_t)path, mode);
}

Expand Down
Loading
Loading