Skip to content

Commit 2fd1453

Browse files
committed
Use correct types for syscalls
1 parent 48b0645 commit 2fd1453

File tree

4 files changed

+71
-70
lines changed

4 files changed

+71
-70
lines changed

system/lib/libc/emscripten_syscall_stubs.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#include <emscripten/console.h>
2525
#include <emscripten/version.h>
2626

27-
static int g_pid = 42;
28-
static int g_pgid = 42;
29-
static int g_ppid = 1;
30-
static int g_sid = 42;
27+
static pid_t g_pid = 42;
28+
static pid_t g_pgid = 42;
29+
static pid_t g_ppid = 1;
30+
static pid_t g_sid = 42;
3131
static mode_t g_umask = S_IRWXU | S_IRWXG | S_IRWXO;
3232

3333
#ifdef NDEBUG
@@ -68,7 +68,7 @@ weak int __syscall_uname(intptr_t buf) {
6868
return 0;
6969
}
7070

71-
weak int __syscall_setpgid(int pid, int pgid) {
71+
weak int __syscall_setpgid(pid_t pid, pid_t pgid) {
7272
if (pid && pid != g_pid) {
7373
return -ESRCH;
7474
}
@@ -82,46 +82,46 @@ weak int __syscall_sync() {
8282
return 0;
8383
}
8484

85-
weak int __syscall_getsid(int pid) {
85+
weak pid_t __syscall_getsid(pid_t pid) {
8686
if (pid && pid != g_pid) {
8787
return -ESRCH;
8888
}
8989
return g_sid;
9090
}
9191

92-
weak int __syscall_getpgid(int pid) {
92+
weak pid_t __syscall_getpgid(pid_t pid) {
9393
if (pid && pid != g_pid) {
9494
return -ESRCH;
9595
}
9696
return g_pgid;
9797
}
9898

99-
weak int __syscall_getpid() {
99+
weak pid_t __syscall_getpid() {
100100
return g_pid;
101101
}
102102

103-
weak int __syscall_getppid() {
103+
weak pid_t __syscall_getppid() {
104104
return g_ppid;
105105
}
106106

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

111-
weak int __syscall_getgroups32(int size, intptr_t list) {
112-
if (size < 1) {
111+
weak int __syscall_getgroups32(int count, intptr_t list) {
112+
if (count < 1) {
113113
return -EINVAL;
114114
}
115115
((gid_t*)list)[0] = 0;
116116
return 1;
117117
}
118118

119-
weak int __syscall_setsid() {
119+
weak pid_t __syscall_setsid() {
120120
return 0; // no-op
121121
}
122122

123-
weak int __syscall_umask(int mask) {
124-
int old = g_umask;
123+
weak mode_t __syscall_umask(mode_t mask) {
124+
mode_t old = g_umask;
125125
g_umask = mask;
126126
return old;
127127
}
@@ -141,31 +141,31 @@ weak int __syscall_getrusage(int who, intptr_t usage) {
141141
return 0;
142142
}
143143

144-
weak int __syscall_getpriority(int which, int who) {
144+
weak int __syscall_getpriority(int which, id_t who) {
145145
return 0;
146146
}
147147

148-
weak int __syscall_setpriority(int which, int who, int prio) {
148+
weak int __syscall_setpriority(int which, id_t who, int prio) {
149149
return -EPERM;
150150
}
151151

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

156-
weak int __syscall_getuid32(void) {
156+
weak uid_t __syscall_getuid32(void) {
157157
return 0;
158158
}
159159

160-
weak int __syscall_getgid32(void) {
160+
weak gid_t __syscall_getgid32(void) {
161161
return 0;
162162
}
163163

164-
weak int __syscall_geteuid32(void) {
164+
weak uid_t __syscall_geteuid32(void) {
165165
return 0;
166166
}
167167

168-
weak int __syscall_getegid32(void) {
168+
weak gid_t __syscall_getegid32(void) {
169169
return 0;
170170
}
171171

@@ -225,7 +225,7 @@ weak int __syscall_munlockall() {
225225
return 0;
226226
}
227227

228-
weak int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t old_limit) {
228+
weak int __syscall_prlimit64(pid_t pid, int resource, intptr_t new_limit, intptr_t old_limit) {
229229
REPORT(prlimit64);
230230
struct rlimit *old = (struct rlimit *)old_limit;
231231
if (old) { // just report no limits
@@ -256,4 +256,4 @@ UNIMPLEMENTED(recvmmsg, (int sockfd, intptr_t msgvec, size_t vlen, int flags, ..
256256
UNIMPLEMENTED(sendmmsg, (int sockfd, intptr_t msgvec, size_t vlen, int flags, ...))
257257
UNIMPLEMENTED(shutdown, (int sockfd, int how, int dummy, int dummy2, int dummy3, int dummy4))
258258
UNIMPLEMENTED(socketpair, (int domain, int type, int protocol, intptr_t fds, int dummy, int dummy2))
259-
UNIMPLEMENTED(wait4,(int pid, intptr_t wstatus, int options, int rusage))
259+
UNIMPLEMENTED(wait4,(pid_t pid, intptr_t wstatus, int options, int rusage))

system/lib/libc/musl/arch/emscripten/syscall_arch.h

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <sys/types.h>
12
#include <wasi/api.h>
23
#include <wasi/wasi-helpers.h>
34
#include <emscripten/em_macros.h>
@@ -13,9 +14,9 @@ extern "C" {
1314
#endif
1415

1516
int __syscall_chdir(intptr_t path);
16-
int __syscall_mknod(intptr_t path, int mode, int dev);
17-
int __syscall_chmod(intptr_t path, int mode);
18-
int __syscall_getpid(void);
17+
int __syscall_mknod(intptr_t path, mode_t mode, dev_t dev);
18+
int __syscall_chmod(intptr_t path, mode_t mode);
19+
pid_t __syscall_getpid(void);
1920
int __syscall_pause(void);
2021
int __syscall_access(intptr_t path, int amode);
2122
int __syscall_sync(void);
@@ -24,28 +25,28 @@ int __syscall_dup(int fd);
2425
int __syscall_pipe(intptr_t fd);
2526
int __syscall_acct(intptr_t filename);
2627
int __syscall_ioctl(int fd, int request, ...);
27-
int __syscall_setpgid(int pid, int gpid);
28-
int __syscall_umask(int mask);
29-
int __syscall_getppid(void);
30-
int __syscall_getpgrp(void);
31-
int __syscall_setsid(void);
28+
int __syscall_setpgid(pid_t pid, pid_t gpid);
29+
mode_t __syscall_umask(mode_t mask);
30+
pid_t __syscall_getppid(void);
31+
pid_t __syscall_getpgrp(void);
32+
pid_t __syscall_setsid(void);
3233
int __syscall_setrlimit(int resource, intptr_t limit);
3334
int __syscall_getrusage(int who, intptr_t usage);
3435
int __syscall_symlink(intptr_t target, intptr_t linkpath);
3536
int __syscall_munmap(intptr_t addr, size_t len);
36-
int __syscall_fchmod(int fd, int mode);
37-
int __syscall_getpriority(int which, int who);
38-
int __syscall_setpriority(int which, int who, int prio);
37+
int __syscall_fchmod(int fd, mode_t mode);
38+
int __syscall_getpriority(int which, id_t who);
39+
int __syscall_setpriority(int which, id_t who, int prio);
3940
int __syscall_socketcall(int call, intptr_t args);
40-
int __syscall_wait4(int pid, intptr_t wstatus, int options, int rusage);
41+
pid_t __syscall_wait4(pid_t pid, intptr_t wstatus, int options, int rusage);
4142
int __syscall_setdomainname(intptr_t name, size_t size);
4243
int __syscall_uname(intptr_t buf);
4344
int __syscall_mprotect(size_t addr, size_t len, int prot);
44-
int __syscall_getpgid(int pid);
45+
pid_t __syscall_getpgid(pid_t pid);
4546
int __syscall_fchdir(int fd);
4647
int __syscall__newselect(int nfds, intptr_t readfds, intptr_t writefds, intptr_t exceptfds, intptr_t timeout);
4748
int __syscall_msync(intptr_t addr, size_t len, int flags);
48-
int __syscall_getsid(int pid);
49+
pid_t __syscall_getsid(pid_t pid);
4950
int __syscall_fdatasync(int fd);
5051
int __syscall_mlock(intptr_t addr, size_t len);
5152
int __syscall_munlock(intptr_t addr, size_t len);
@@ -56,51 +57,51 @@ int __syscall_poll(intptr_t fds, int nfds, int timeout);
5657
int __syscall_getcwd(intptr_t buf, size_t size);
5758
int __syscall_ugetrlimit(int resource, intptr_t rlim);
5859
intptr_t __syscall_mmap2(intptr_t addr, size_t len, int prot, int flags, int fd, size_t off);
59-
int __syscall_truncate64(intptr_t path, uint64_t length);
60-
int __syscall_ftruncate64(int fd, uint64_t length);
60+
int __syscall_truncate64(intptr_t path, off_t length);
61+
int __syscall_ftruncate64(int fd, off_t length);
6162
int __syscall_stat64(intptr_t path, intptr_t buf);
6263
int __syscall_lstat64(intptr_t path, intptr_t buf);
6364
int __syscall_fstat64(int fd, intptr_t buf);
64-
int __syscall_getuid32(void);
65-
int __syscall_getgid32(void);
66-
int __syscall_geteuid32(void);
67-
int __syscall_getegid32(void);
68-
int __syscall_setreuid32(int ruid, int euid);
69-
int __syscall_setregid32(int rgid, int egid);
70-
int __syscall_getgroups32(int size, intptr_t list);
71-
int __syscall_fchown32(int fd, int owner, int group);
72-
int __syscall_setresuid32(int ruid, int euid, int suid);
65+
uid_t __syscall_getuid32(void);
66+
gid_t __syscall_getgid32(void);
67+
uid_t __syscall_geteuid32(void);
68+
gid_t __syscall_getegid32(void);
69+
int __syscall_setreuid32(uid_t ruid, uid_t euid);
70+
int __syscall_setregid32(gid_t rgid, gid_t egid);
71+
int __syscall_getgroups32(int count, intptr_t list);
72+
int __syscall_fchown32(int fd, uid_t owner, gid_t group);
73+
int __syscall_setresuid32(int ruid, uid_t euid, uid_t suid);
7374
int __syscall_getresuid32(intptr_t ruid, intptr_t euid, intptr_t suid);
74-
int __syscall_setresgid32(int rgid, int egid, int sgid);
75+
int __syscall_setresgid32(int rgid, uid_t egid, uid_t sgid);
7576
int __syscall_getresgid32(intptr_t rgid, intptr_t egid, intptr_t sgid);
76-
int __syscall_setuid32(int uid);
77-
int __syscall_setgid32(int uid);
77+
int __syscall_setuid32(uid_t uid);
78+
int __syscall_setgid32(gid_t gid);
7879
int __syscall_mincore(intptr_t addr, size_t length, intptr_t vec);
7980
int __syscall_madvise(intptr_t addr, size_t length, int advice);
8081
int __syscall_getdents64(int fd, intptr_t dirp, size_t count);
8182
int __syscall_fcntl64(int fd, int cmd, ...);
8283
int __syscall_statfs64(intptr_t path, size_t size, intptr_t buf);
8384
int __syscall_fstatfs64(int fd, size_t size, intptr_t buf);
84-
int __syscall_fadvise64(int fd, uint64_t offset, uint64_t length, int advice);
85+
int __syscall_fadvise64(int fd, off_t offset, off_t length, int advice);
8586
int __syscall_openat(int dirfd, intptr_t path, int flags, ...); // mode is optional
86-
int __syscall_mkdirat(int dirfd, intptr_t path, int mode);
87-
int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev);
88-
int __syscall_fchownat(int dirfd, intptr_t path, int owner, int group, int flags);
87+
int __syscall_mkdirat(int dirfd, intptr_t path, mode_t mode);
88+
int __syscall_mknodat(int dirfd, intptr_t path, mode_t mode, dev_t dev);
89+
int __syscall_fchownat(int dirfd, intptr_t path, uid_t owner, gid_t group, int flags);
8990
int __syscall_newfstatat(int dirfd, intptr_t path, intptr_t buf, int flags);
9091
int __syscall_unlinkat(int dirfd, intptr_t path, int flags);
9192
int __syscall_renameat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath);
9293
int __syscall_linkat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath, int flags);
9394
int __syscall_symlinkat(intptr_t target, int newdirfd, intptr_t linkpath);
9495
int __syscall_readlinkat(int dirfd, intptr_t path, intptr_t buf, size_t bufsize);
95-
int __syscall_fchmodat(int dirfd, intptr_t path, int mode, ...);
96+
int __syscall_fchmodat(int dirfd, intptr_t path, mode_t mode, ...);
9697
int __syscall_faccessat(int dirfd, intptr_t path, int amode, int flags);
9798
int __syscall_pselect6(int nfds, intptr_t readfds, intptr_t writefds, intptr_t exceptfds, intptr_t timeout, intptr_t sigmaks);
9899
int __syscall_utimensat(int dirfd, intptr_t path, intptr_t times, int flags);
99-
int __syscall_fallocate(int fd, int mode, uint64_t off, uint64_t len);
100+
int __syscall_fallocate(int fd, int mode, off_t off, off_t len);
100101
int __syscall_dup3(int fd, int suggestfd, int flags);
101102
int __syscall_pipe2(intptr_t fds, int flags);
102103
int __syscall_recvmmsg(int sockfd, intptr_t msgvec, size_t vlen, int flags, ...);
103-
int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t old_limit);
104+
int __syscall_prlimit64(pid_t pid, int resource, intptr_t new_limit, intptr_t old_limit);
104105
int __syscall_sendmmsg(int sockfd, intptr_t msgvec, size_t vlen, int flags, ...);
105106
int __syscall_socket(int domain, int type, int protocol, int dummy1, int dummy2, int dummy3);
106107
int __syscall_socketpair(int domain, int type, int protocol, intptr_t fds, int dummy, int dummy2);

system/lib/wasmfs/js_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
119119
return data_size;
120120
}
121121

122-
int _wasmfs_mkdir(char* path, int mode) {
122+
int _wasmfs_mkdir(char* path, mode_t mode) {
123123
return __syscall_mkdirat(AT_FDCWD, (intptr_t)path, mode);
124124
}
125125

system/lib/wasmfs/syscalls.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ int __syscall_openat(int dirfd, intptr_t path, int flags, ...) {
572572
return doOpen(path::parseParent((char*)path, dirfd), flags, mode);
573573
}
574574

575-
int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev) {
575+
int __syscall_mknodat(int dirfd, intptr_t path, mode_t mode, dev_t dev) {
576576
assert(dev == 0); // TODO: support special devices
577577
if (mode & S_IFDIR) {
578578
return -EINVAL;
@@ -588,7 +588,7 @@ int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev) {
588588
}
589589

590590
static int
591-
doMkdir(path::ParsedParent parsed, int mode, backend_t backend = NullBackend) {
591+
doMkdir(path::ParsedParent parsed, mode_t mode, backend_t backend = NullBackend) {
592592
if (auto err = parsed.getError()) {
593593
return err;
594594
}
@@ -645,14 +645,14 @@ doMkdir(path::ParsedParent parsed, int mode, backend_t backend = NullBackend) {
645645

646646
// This function is exposed to users and allows users to specify a particular
647647
// backend that a directory should be created within.
648-
int wasmfs_create_directory(char* path, int mode, backend_t backend) {
648+
int wasmfs_create_directory(char* path, mode_t mode, backend_t backend) {
649649
static_assert(std::is_same_v<decltype(doMkdir(0, 0, 0)), int>,
650650
"unexpected conversion from result of doMkdir to int");
651651
return doMkdir(path::parseParent(path), mode, backend);
652652
}
653653

654654
// TODO: Test this.
655-
int __syscall_mkdirat(int dirfd, intptr_t path, int mode) {
655+
int __syscall_mkdirat(int dirfd, intptr_t path, mode_t mode) {
656656
return doMkdir(path::parseParent((char*)path, dirfd), mode);
657657
}
658658

@@ -1121,7 +1121,7 @@ int __syscall_utimensat(int dirFD, intptr_t path_, intptr_t times_, int flags) {
11211121
}
11221122

11231123
// TODO: Test this with non-AT_FDCWD values.
1124-
int __syscall_fchmodat(int dirfd, intptr_t path, int mode, ...) {
1124+
int __syscall_fchmodat(int dirfd, intptr_t path, mode_t mode, ...) {
11251125
int flags = 0;
11261126
va_list v1;
11271127
va_start(v1, mode);
@@ -1143,11 +1143,11 @@ int __syscall_fchmodat(int dirfd, intptr_t path, int mode, ...) {
11431143
return 0;
11441144
}
11451145

1146-
int __syscall_chmod(intptr_t path, int mode) {
1146+
int __syscall_chmod(intptr_t path, mode_t mode) {
11471147
return __syscall_fchmodat(AT_FDCWD, path, mode, 0);
11481148
}
11491149

1150-
int __syscall_fchmod(int fd, int mode) {
1150+
int __syscall_fchmod(int fd, mode_t mode) {
11511151
auto openFile = wasmFS.getFileTable().locked().getEntry(fd);
11521152
if (!openFile) {
11531153
return -EBADF;
@@ -1159,7 +1159,7 @@ int __syscall_fchmod(int fd, int mode) {
11591159
}
11601160

11611161
int __syscall_fchownat(
1162-
int dirfd, intptr_t path, int owner, int group, int flags) {
1162+
int dirfd, intptr_t path, uid_t owner, gid_t group, int flags) {
11631163
// Only accept valid flags.
11641164
if (flags & ~(AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW)) {
11651165
// TODO: Test this case.
@@ -1175,7 +1175,7 @@ int __syscall_fchownat(
11751175
return 0;
11761176
}
11771177

1178-
int __syscall_fchown32(int fd, int owner, int group) {
1178+
int __syscall_fchown32(int fd, uid_t owner, gid_t group) {
11791179
return __syscall_fchownat(fd, (intptr_t) "", owner, group, AT_EMPTY_PATH);
11801180
}
11811181

@@ -1234,15 +1234,15 @@ static int doTruncate(std::shared_ptr<File>& file, off_t size) {
12341234
return ret;
12351235
}
12361236

1237-
int __syscall_truncate64(intptr_t path, uint64_t size) {
1237+
int __syscall_truncate64(intptr_t path, off_t size) {
12381238
auto parsed = path::parseFile((char*)path);
12391239
if (auto err = parsed.getError()) {
12401240
return err;
12411241
}
12421242
return doTruncate(parsed.getFile(), size);
12431243
}
12441244

1245-
int __syscall_ftruncate64(int fd, uint64_t size) {
1245+
int __syscall_ftruncate64(int fd, off_t size) {
12461246
auto openFile = wasmFS.getFileTable().locked().getEntry(fd);
12471247
if (!openFile) {
12481248
return -EBADF;
@@ -1366,7 +1366,7 @@ int __syscall_poll(intptr_t fds_, int nfds, int timeout) {
13661366
return nonzero;
13671367
}
13681368

1369-
int __syscall_fallocate(int fd, int mode, uint64_t off, uint64_t len) {
1369+
int __syscall_fallocate(int fd, int mode, off_t off, off_t len) {
13701370
assert(mode == 0); // TODO, but other modes were never supported in the old FS
13711371

13721372
auto fileTable = wasmFS.getFileTable().locked();

0 commit comments

Comments
 (0)