Skip to content

Commit 8ee08ed

Browse files
committed
Use correct types for syscalls
1 parent 302d38a commit 8ee08ed

File tree

5 files changed

+64
-64
lines changed

5 files changed

+64
-64
lines changed

system/lib/libc/emscripten_syscall_stubs.c

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

28-
static int g_pid = 42;
29-
static int g_pgid = 42;
30-
static int g_ppid = 1;
31-
static int g_sid = 42;
28+
static pid_t g_pid = 42;
29+
static pid_t g_pgid = 42;
30+
static pid_t g_ppid = 1;
31+
static pid_t g_sid = 42;
3232
static mode_t g_umask = S_IWGRP | S_IWOTH;
3333

3434
#ifdef NDEBUG
@@ -69,7 +69,7 @@ weak int __syscall_uname(intptr_t buf) {
6969
return 0;
7070
}
7171

72-
weak int __syscall_setpgid(int pid, int pgid) {
72+
weak int __syscall_setpgid(pid_t pid, pid_t pgid) {
7373
if (pid && pid != g_pid) {
7474
return -ESRCH;
7575
}
@@ -83,46 +83,46 @@ weak int __syscall_sync() {
8383
return 0;
8484
}
8585

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

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

100-
weak int __syscall_getpid() {
100+
weak pid_t __syscall_getpid() {
101101
return g_pid;
102102
}
103103

104-
weak int __syscall_getppid() {
104+
weak pid_t __syscall_getppid() {
105105
return g_ppid;
106106
}
107107

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

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

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

124-
weak int __syscall_umask(int mask) {
125-
int old = g_umask;
124+
weak mode_t __syscall_umask(mode_t mask) {
125+
mode_t old = g_umask;
126126
g_umask = mask;
127127
return old;
128128
}
@@ -138,31 +138,31 @@ weak int __syscall_getrusage(int who, intptr_t usage) {
138138
return 0;
139139
}
140140

141-
weak int __syscall_getpriority(int which, int who) {
141+
weak int __syscall_getpriority(int which, id_t who) {
142142
return 0;
143143
}
144144

145-
weak int __syscall_setpriority(int which, int who, int prio) {
145+
weak int __syscall_setpriority(int which, id_t who, int prio) {
146146
return -EPERM;
147147
}
148148

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

153-
weak int __syscall_getuid32(void) {
153+
weak uid_t __syscall_getuid32(void) {
154154
return 0;
155155
}
156156

157-
weak int __syscall_getgid32(void) {
157+
weak gid_t __syscall_getgid32(void) {
158158
return 0;
159159
}
160160

161-
weak int __syscall_geteuid32(void) {
161+
weak uid_t __syscall_geteuid32(void) {
162162
return 0;
163163
}
164164

165-
weak int __syscall_getegid32(void) {
165+
weak gid_t __syscall_getegid32(void) {
166166
return 0;
167167
}
168168

@@ -222,7 +222,7 @@ weak int __syscall_munlockall() {
222222
return 0;
223223
}
224224

225-
weak int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t old_limit) {
225+
weak int __syscall_prlimit64(pid_t pid, int resource, intptr_t new_limit, intptr_t old_limit) {
226226
REPORT(prlimit64);
227227
struct rlimit *old = (struct rlimit *)old_limit;
228228
if (new_limit) {
@@ -262,4 +262,4 @@ UNIMPLEMENTED(recvmmsg, (int sockfd, intptr_t msgvec, size_t vlen, int flags, ..
262262
UNIMPLEMENTED(sendmmsg, (int sockfd, intptr_t msgvec, size_t vlen, int flags, ...))
263263
UNIMPLEMENTED(shutdown, (int sockfd, int how, int dummy, int dummy2, int dummy3, int dummy4))
264264
UNIMPLEMENTED(socketpair, (int domain, int type, int protocol, intptr_t fds, int dummy, int dummy2))
265-
UNIMPLEMENTED(wait4,(int pid, intptr_t wstatus, int options, int rusage))
265+
UNIMPLEMENTED(wait4,(pid_t pid, intptr_t wstatus, int options, int rusage))

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ extern "C" {
1313
#endif
1414

1515
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);
16+
int __syscall_mknod(intptr_t path, mode_t mode, dev_t dev);
17+
int __syscall_chmod(intptr_t path, mode_t mode);
18+
pid_t __syscall_getpid(void);
1919
int __syscall_pause(void);
2020
int __syscall_access(intptr_t path, int amode);
2121
int __syscall_sync(void);
@@ -24,26 +24,26 @@ int __syscall_dup(int fd);
2424
int __syscall_pipe(intptr_t fd);
2525
int __syscall_acct(intptr_t filename);
2626
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);
27+
int __syscall_setpgid(pid_t pid, pid_t gpid);
28+
mode_t __syscall_umask(mode_t mask);
29+
pid_t __syscall_getppid(void);
30+
pid_t __syscall_getpgrp(void);
31+
pid_t __syscall_setsid(void);
3232
int __syscall_getrusage(int who, intptr_t usage);
3333
int __syscall_munmap(intptr_t addr, size_t len);
34-
int __syscall_fchmod(int fd, int mode);
35-
int __syscall_getpriority(int which, int who);
36-
int __syscall_setpriority(int which, int who, int prio);
34+
int __syscall_fchmod(int fd, mode_t mode);
35+
int __syscall_getpriority(int which, id_t who);
36+
int __syscall_setpriority(int which, id_t who, int prio);
3737
int __syscall_socketcall(int call, intptr_t args);
38-
int __syscall_wait4(int pid, intptr_t wstatus, int options, int rusage);
38+
pid_t __syscall_wait4(pid_t pid, intptr_t wstatus, int options, int rusage);
3939
int __syscall_setdomainname(intptr_t name, size_t size);
4040
int __syscall_uname(intptr_t buf);
4141
int __syscall_mprotect(size_t addr, size_t len, int prot);
42-
int __syscall_getpgid(int pid);
42+
pid_t __syscall_getpgid(pid_t pid);
4343
int __syscall_fchdir(int fd);
4444
int __syscall__newselect(int nfds, intptr_t readfds, intptr_t writefds, intptr_t exceptfds, intptr_t timeout);
4545
int __syscall_msync(intptr_t addr, size_t len, int flags);
46-
int __syscall_getsid(int pid);
46+
pid_t __syscall_getsid(pid_t pid);
4747
int __syscall_fdatasync(int fd);
4848
int __syscall_mlock(intptr_t addr, size_t len);
4949
int __syscall_munlock(intptr_t addr, size_t len);
@@ -58,20 +58,20 @@ int __syscall_ftruncate64(int fd, off_t length);
5858
int __syscall_stat64(intptr_t path, intptr_t buf);
5959
int __syscall_lstat64(intptr_t path, intptr_t buf);
6060
int __syscall_fstat64(int fd, intptr_t buf);
61-
int __syscall_getuid32(void);
62-
int __syscall_getgid32(void);
63-
int __syscall_geteuid32(void);
64-
int __syscall_getegid32(void);
65-
int __syscall_setreuid32(int ruid, int euid);
66-
int __syscall_setregid32(int rgid, int egid);
67-
int __syscall_getgroups32(int size, intptr_t list);
68-
int __syscall_fchown32(int fd, int owner, int group);
69-
int __syscall_setresuid32(int ruid, int euid, int suid);
61+
uid_t __syscall_getuid32(void);
62+
gid_t __syscall_getgid32(void);
63+
uid_t __syscall_geteuid32(void);
64+
gid_t __syscall_getegid32(void);
65+
int __syscall_setreuid32(uid_t ruid, uid_t euid);
66+
int __syscall_setregid32(gid_t rgid, gid_t egid);
67+
int __syscall_getgroups32(int count, intptr_t list);
68+
int __syscall_fchown32(int fd, uid_t owner, gid_t group);
69+
int __syscall_setresuid32(uid_t ruid, uid_t euid, uid_t suid);
7070
int __syscall_getresuid32(intptr_t ruid, intptr_t euid, intptr_t suid);
71-
int __syscall_setresgid32(int rgid, int egid, int sgid);
71+
int __syscall_setresgid32(gid_t rgid, gid_t egid, gid_t sgid);
7272
int __syscall_getresgid32(intptr_t rgid, intptr_t egid, intptr_t sgid);
73-
int __syscall_setuid32(int uid);
74-
int __syscall_setgid32(int uid);
73+
int __syscall_setuid32(uid_t uid);
74+
int __syscall_setgid32(gid_t gid);
7575
int __syscall_mincore(intptr_t addr, size_t length, intptr_t vec);
7676
int __syscall_madvise(intptr_t addr, size_t length, int advice);
7777
int __syscall_getdents64(int fd, intptr_t dirp, size_t count);
@@ -80,24 +80,24 @@ int __syscall_statfs64(intptr_t path, size_t size, intptr_t buf);
8080
int __syscall_fstatfs64(int fd, size_t size, intptr_t buf);
8181
int __syscall_fadvise64(int fd, off_t offset, off_t length, int advice);
8282
int __syscall_openat(int dirfd, intptr_t path, int flags, ...); // mode is optional
83-
int __syscall_mkdirat(int dirfd, intptr_t path, int mode);
84-
int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev);
85-
int __syscall_fchownat(int dirfd, intptr_t path, int owner, int group, int flags);
83+
int __syscall_mkdirat(int dirfd, intptr_t path, mode_t mode);
84+
int __syscall_mknodat(int dirfd, intptr_t path, mode_t mode, dev_t dev);
85+
int __syscall_fchownat(int dirfd, intptr_t path, uid_t owner, gid_t group, int flags);
8686
int __syscall_newfstatat(int dirfd, intptr_t path, intptr_t buf, int flags);
8787
int __syscall_unlinkat(int dirfd, intptr_t path, int flags);
8888
int __syscall_renameat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath);
8989
int __syscall_linkat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath, int flags);
9090
int __syscall_symlinkat(intptr_t target, int newdirfd, intptr_t linkpath);
9191
int __syscall_readlinkat(int dirfd, intptr_t path, intptr_t buf, size_t bufsize);
92-
int __syscall_fchmodat2(int dirfd, intptr_t path, int mode, int flags);
92+
int __syscall_fchmodat2(int dirfd, intptr_t path, mode_t mode, int flags);
9393
int __syscall_faccessat(int dirfd, intptr_t path, int amode, int flags);
9494
int __syscall_pselect6(int nfds, intptr_t readfds, intptr_t writefds, intptr_t exceptfds, intptr_t timeout, intptr_t sigmaks);
9595
int __syscall_utimensat(int dirfd, intptr_t path, intptr_t times, int flags);
9696
int __syscall_fallocate(int fd, int mode, off_t offset, off_t len);
9797
int __syscall_dup3(int fd, int suggestfd, int flags);
9898
int __syscall_pipe2(intptr_t fds, int flags);
9999
int __syscall_recvmmsg(int sockfd, intptr_t msgvec, size_t vlen, int flags, ...);
100-
int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t old_limit);
100+
int __syscall_prlimit64(pid_t pid, int resource, intptr_t new_limit, intptr_t old_limit);
101101
int __syscall_sendmmsg(int sockfd, intptr_t msgvec, size_t vlen, int flags, ...);
102102
int __syscall_socket(int domain, int type, int protocol, int dummy1, int dummy2, int dummy3);
103103
int __syscall_socketpair(int domain, int type, int protocol, intptr_t fds, int dummy, int dummy2);

system/lib/standalone/standalone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ weak int __syscall_dup(int fd) {
102102
return -ENOSYS;
103103
}
104104

105-
weak int __syscall_mkdirat(int dirfd, intptr_t path, int mode) {
105+
weak int __syscall_mkdirat(int dirfd, intptr_t path, mode_t mode) {
106106
return -ENOSYS;
107107
}
108108

system/lib/wasmfs/js_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int _wasmfs_write_file(const char* pathname, char* data, size_t data_size) {
114114
return data_size;
115115
}
116116

117-
int _wasmfs_mkdir(const char* path, int mode) {
117+
int _wasmfs_mkdir(const char* path, mode_t mode) {
118118
return __syscall_mkdirat(AT_FDCWD, (intptr_t)path, mode);
119119
}
120120

system/lib/wasmfs/syscalls.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ int __syscall_openat(int dirfd, intptr_t path, int flags, ...) {
582582
return doOpen(path::parseParent((char*)path, dirfd), flags, mode);
583583
}
584584

585-
int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev) {
585+
int __syscall_mknodat(int dirfd, intptr_t path, mode_t mode, dev_t dev) {
586586
assert(dev == 0); // TODO: support special devices
587587
if (mode & S_IFDIR) {
588588
return -EINVAL;
@@ -598,7 +598,7 @@ int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev) {
598598
}
599599

600600
static int
601-
doMkdir(path::ParsedParent parsed, int mode, backend_t backend = NullBackend) {
601+
doMkdir(path::ParsedParent parsed, mode_t mode, backend_t backend = NullBackend) {
602602
if (auto err = parsed.getError()) {
603603
return err;
604604
}
@@ -655,14 +655,14 @@ doMkdir(path::ParsedParent parsed, int mode, backend_t backend = NullBackend) {
655655

656656
// This function is exposed to users and allows users to specify a particular
657657
// backend that a directory should be created within.
658-
int wasmfs_create_directory(char* path, int mode, backend_t backend) {
658+
int wasmfs_create_directory(char* path, mode_t mode, backend_t backend) {
659659
static_assert(std::is_same_v<decltype(doMkdir(0, 0, 0)), int>,
660660
"unexpected conversion from result of doMkdir to int");
661661
return doMkdir(path::parseParent(path), mode, backend);
662662
}
663663

664664
// TODO: Test this.
665-
int __syscall_mkdirat(int dirfd, intptr_t path, int mode) {
665+
int __syscall_mkdirat(int dirfd, intptr_t path, mode_t mode) {
666666
return doMkdir(path::parseParent((char*)path, dirfd), mode);
667667
}
668668

@@ -1165,7 +1165,7 @@ int __syscall_utimensat(int dirFD, intptr_t path_, intptr_t times_, int flags) {
11651165
}
11661166

11671167
// TODO: Test this with non-AT_FDCWD values.
1168-
int __syscall_fchmodat2(int dirfd, intptr_t path, int mode, int flags) {
1168+
int __syscall_fchmodat2(int dirfd, intptr_t path, mode_t mode, int flags) {
11691169
if (flags & ~AT_SYMLINK_NOFOLLOW) {
11701170
// TODO: Test this case.
11711171
return -EINVAL;
@@ -1181,11 +1181,11 @@ int __syscall_fchmodat2(int dirfd, intptr_t path, int mode, int flags) {
11811181
return 0;
11821182
}
11831183

1184-
int __syscall_chmod(intptr_t path, int mode) {
1184+
int __syscall_chmod(intptr_t path, mode_t mode) {
11851185
return __syscall_fchmodat2(AT_FDCWD, path, mode, 0);
11861186
}
11871187

1188-
int __syscall_fchmod(int fd, int mode) {
1188+
int __syscall_fchmod(int fd, mode_t mode) {
11891189
auto openFile = wasmFS.getFileTable().locked().getEntry(fd);
11901190
if (!openFile) {
11911191
return -EBADF;
@@ -1197,7 +1197,7 @@ int __syscall_fchmod(int fd, int mode) {
11971197
}
11981198

11991199
int __syscall_fchownat(
1200-
int dirfd, intptr_t path, int owner, int group, int flags) {
1200+
int dirfd, intptr_t path, uid_t owner, gid_t group, int flags) {
12011201
// Only accept valid flags.
12021202
if (flags & ~(AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW)) {
12031203
// TODO: Test this case.
@@ -1213,7 +1213,7 @@ int __syscall_fchownat(
12131213
return 0;
12141214
}
12151215

1216-
int __syscall_fchown32(int fd, int owner, int group) {
1216+
int __syscall_fchown32(int fd, uid_t owner, gid_t group) {
12171217
return __syscall_fchownat(fd, (intptr_t) "", owner, group, AT_EMPTY_PATH);
12181218
}
12191219

0 commit comments

Comments
 (0)