Skip to content

Commit b649159

Browse files
committed
Use correct types for syscalls
1 parent dba5b35 commit b649159

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 @@ int __syscall_uname(intptr_t buf) {
6868
return 0;
6969
}
7070

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

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

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

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

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

107107
int __syscall_link(intptr_t oldpath, intptr_t newpath) {
108108
return -EMLINK; // no hardlinks for us
109109
}
110110

111-
int __syscall_getgroups32(int size, intptr_t list) {
112-
if (size < 1) {
111+
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-
int __syscall_setsid() {
119+
pid_t __syscall_setsid() {
120120
return 0; // no-op
121121
}
122122

123-
int __syscall_umask(int mask) {
124-
int old = g_umask;
123+
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 @@ int __syscall_getrusage(int who, intptr_t usage) {
141141
return 0;
142142
}
143143

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

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

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

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

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

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

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

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

228-
int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t old_limit) {
228+
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
@@ -258,4 +258,4 @@ UNIMPLEMENTED(setitimer, (int which, intptr_t new_value, intptr_t old_value))
258258
UNIMPLEMENTED(getitimer, (int which, intptr_t old_value))
259259
UNIMPLEMENTED(shutdown, (int sockfd, int how, int dummy, int dummy2, int dummy3, int dummy4))
260260
UNIMPLEMENTED(socketpair, (int domain, int type, int protocol, intptr_t fds, int dummy, int dummy2))
261-
UNIMPLEMENTED(wait4,(int pid, intptr_t wstatus, int options, int rusage))
261+
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>
@@ -14,9 +15,9 @@ extern "C" {
1415

1516
int __syscall_link(intptr_t oldpath, intptr_t newpath);
1617
int __syscall_chdir(intptr_t path);
17-
int __syscall_mknod(intptr_t path, int mode, int dev);
18-
int __syscall_chmod(intptr_t path, int mode);
19-
int __syscall_getpid(void);
18+
int __syscall_mknod(intptr_t path, mode_t mode, dev_t dev);
19+
int __syscall_chmod(intptr_t path, mode_t mode);
20+
pid_t __syscall_getpid(void);
2021
int __syscall_pause(void);
2122
int __syscall_access(intptr_t path, int amode);
2223
int __syscall_sync(void);
@@ -25,30 +26,30 @@ int __syscall_dup(int fd);
2526
int __syscall_pipe(intptr_t fd);
2627
int __syscall_acct(intptr_t filename);
2728
int __syscall_ioctl(int fd, int request, ...);
28-
int __syscall_setpgid(int pid, int gpid);
29-
int __syscall_umask(int mask);
30-
int __syscall_getppid(void);
31-
int __syscall_getpgrp(void);
32-
int __syscall_setsid(void);
29+
int __syscall_setpgid(pid_t pid, pid_t gpid);
30+
mode_t __syscall_umask(mode_t mask);
31+
pid_t __syscall_getppid(void);
32+
pid_t __syscall_getpgrp(void);
33+
pid_t __syscall_setsid(void);
3334
int __syscall_setrlimit(int resource, intptr_t limit);
3435
int __syscall_getrusage(int who, intptr_t usage);
3536
int __syscall_symlink(intptr_t target, intptr_t linkpath);
3637
int __syscall_munmap(intptr_t addr, size_t len);
37-
int __syscall_fchmod(int fd, int mode);
38-
int __syscall_getpriority(int which, int who);
39-
int __syscall_setpriority(int which, int who, int prio);
38+
int __syscall_fchmod(int fd, mode_t mode);
39+
int __syscall_getpriority(int which, id_t who);
40+
int __syscall_setpriority(int which, id_t who, int prio);
4041
int __syscall_socketcall(int call, intptr_t args);
4142
int __syscall_setitimer(int which, intptr_t new_value, intptr_t old_value);
4243
int __syscall_getitimer(int which, intptr_t old_value);
43-
int __syscall_wait4(int pid, intptr_t wstatus, int options, int rusage);
44+
pid_t __syscall_wait4(pid_t pid, intptr_t wstatus, int options, int rusage);
4445
int __syscall_setdomainname(intptr_t name, size_t size);
4546
int __syscall_uname(intptr_t buf);
4647
int __syscall_mprotect(size_t addr, size_t len, int prot);
47-
int __syscall_getpgid(int pid);
48+
pid_t __syscall_getpgid(pid_t pid);
4849
int __syscall_fchdir(int fd);
4950
int __syscall__newselect(int nfds, intptr_t readfds, intptr_t writefds, intptr_t exceptfds, intptr_t timeout);
5051
int __syscall_msync(intptr_t addr, size_t len, int flags);
51-
int __syscall_getsid(int pid);
52+
pid_t __syscall_getsid(pid_t pid);
5253
int __syscall_fdatasync(int fd);
5354
int __syscall_mlock(intptr_t addr, size_t len);
5455
int __syscall_munlock(intptr_t addr, size_t len);
@@ -59,51 +60,51 @@ int __syscall_poll(intptr_t fds, int nfds, int timeout);
5960
int __syscall_getcwd(intptr_t buf, size_t size);
6061
int __syscall_ugetrlimit(int resource, intptr_t rlim);
6162
intptr_t __syscall_mmap2(intptr_t addr, size_t len, int prot, int flags, int fd, size_t off);
62-
int __syscall_truncate64(intptr_t path, uint64_t length);
63-
int __syscall_ftruncate64(int fd, uint64_t length);
63+
int __syscall_truncate64(intptr_t path, off_t length);
64+
int __syscall_ftruncate64(int fd, off_t length);
6465
int __syscall_stat64(intptr_t path, intptr_t buf);
6566
int __syscall_lstat64(intptr_t path, intptr_t buf);
6667
int __syscall_fstat64(int fd, intptr_t buf);
67-
int __syscall_getuid32(void);
68-
int __syscall_getgid32(void);
69-
int __syscall_geteuid32(void);
70-
int __syscall_getegid32(void);
71-
int __syscall_setreuid32(int ruid, int euid);
72-
int __syscall_setregid32(int rgid, int egid);
73-
int __syscall_getgroups32(int size, intptr_t list);
74-
int __syscall_fchown32(int fd, int owner, int group);
75-
int __syscall_setresuid32(int ruid, int euid, int suid);
68+
uid_t __syscall_getuid32(void);
69+
gid_t __syscall_getgid32(void);
70+
uid_t __syscall_geteuid32(void);
71+
gid_t __syscall_getegid32(void);
72+
int __syscall_setreuid32(uid_t ruid, uid_t euid);
73+
int __syscall_setregid32(gid_t rgid, gid_t egid);
74+
int __syscall_getgroups32(int count, intptr_t list);
75+
int __syscall_fchown32(int fd, uid_t owner, gid_t group);
76+
int __syscall_setresuid32(int ruid, uid_t euid, uid_t suid);
7677
int __syscall_getresuid32(intptr_t ruid, intptr_t euid, intptr_t suid);
77-
int __syscall_setresgid32(int rgid, int egid, int sgid);
78+
int __syscall_setresgid32(int rgid, uid_t egid, uid_t sgid);
7879
int __syscall_getresgid32(intptr_t rgid, intptr_t egid, intptr_t sgid);
79-
int __syscall_setuid32(int uid);
80-
int __syscall_setgid32(int uid);
80+
int __syscall_setuid32(uid_t uid);
81+
int __syscall_setgid32(gid_t gid);
8182
int __syscall_mincore(intptr_t addr, size_t length, intptr_t vec);
8283
int __syscall_madvise(intptr_t addr, size_t length, int advice);
8384
int __syscall_getdents64(int fd, intptr_t dirp, size_t count);
8485
int __syscall_fcntl64(int fd, int cmd, ...);
8586
int __syscall_statfs64(intptr_t path, size_t size, intptr_t buf);
8687
int __syscall_fstatfs64(int fd, size_t size, intptr_t buf);
87-
int __syscall_fadvise64(int fd, uint64_t offset, uint64_t length, int advice);
88+
int __syscall_fadvise64(int fd, off_t offset, off_t length, int advice);
8889
int __syscall_openat(int dirfd, intptr_t path, int flags, ...); // mode is optional
89-
int __syscall_mkdirat(int dirfd, intptr_t path, int mode);
90-
int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev);
91-
int __syscall_fchownat(int dirfd, intptr_t path, int owner, int group, int flags);
90+
int __syscall_mkdirat(int dirfd, intptr_t path, mode_t mode);
91+
int __syscall_mknodat(int dirfd, intptr_t path, mode_t mode, dev_t dev);
92+
int __syscall_fchownat(int dirfd, intptr_t path, uid_t owner, gid_t group, int flags);
9293
int __syscall_newfstatat(int dirfd, intptr_t path, intptr_t buf, int flags);
9394
int __syscall_unlinkat(int dirfd, intptr_t path, int flags);
9495
int __syscall_renameat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath);
9596
int __syscall_linkat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath, int flags);
9697
int __syscall_symlinkat(intptr_t target, int newdirfd, intptr_t linkpath);
9798
int __syscall_readlinkat(int dirfd, intptr_t path, intptr_t buf, size_t bufsize);
98-
int __syscall_fchmodat(int dirfd, intptr_t path, int mode, ...);
99+
int __syscall_fchmodat(int dirfd, intptr_t path, mode_t mode, ...);
99100
int __syscall_faccessat(int dirfd, intptr_t path, int amode, int flags);
100101
int __syscall_pselect6(int nfds, intptr_t readfds, intptr_t writefds, intptr_t exceptfds, intptr_t timeout, intptr_t sigmaks);
101102
int __syscall_utimensat(int dirfd, intptr_t path, intptr_t times, int flags);
102-
int __syscall_fallocate(int fd, int mode, uint64_t off, uint64_t len);
103+
int __syscall_fallocate(int fd, int mode, off_t off, off_t len);
103104
int __syscall_dup3(int fd, int suggestfd, int flags);
104105
int __syscall_pipe2(intptr_t fds, int flags);
105106
int __syscall_recvmmsg(int sockfd, intptr_t msgvec, size_t vlen, int flags, ...);
106-
int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t old_limit);
107+
int __syscall_prlimit64(pid_t pid, int resource, intptr_t new_limit, intptr_t old_limit);
107108
int __syscall_sendmmsg(int sockfd, intptr_t msgvec, size_t vlen, int flags, ...);
108109
int __syscall_socket(int domain, int type, int protocol, int dummy1, int dummy2, int dummy3);
109110
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
@@ -94,7 +94,7 @@ int _wasmfs_write_file(char* pathname, char* data, size_t data_size) {
9494
return data_size;
9595
}
9696

97-
int _wasmfs_mkdir(char* path, int mode) {
97+
int _wasmfs_mkdir(char* path, mode_t mode) {
9898
return __syscall_mkdirat(AT_FDCWD, (intptr_t)path, mode);
9999
}
100100

system/lib/wasmfs/syscalls.cpp

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

534-
int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev) {
534+
int __syscall_mknodat(int dirfd, intptr_t path, mode_t mode, dev_t dev) {
535535
assert(dev == 0); // TODO: support special devices
536536
if (mode & S_IFDIR) {
537537
return -EINVAL;
@@ -547,7 +547,7 @@ int __syscall_mknodat(int dirfd, intptr_t path, int mode, int dev) {
547547
}
548548

549549
static int
550-
doMkdir(path::ParsedParent parsed, int mode, backend_t backend = NullBackend) {
550+
doMkdir(path::ParsedParent parsed, mode_t mode, backend_t backend = NullBackend) {
551551
if (auto err = parsed.getError()) {
552552
return err;
553553
}
@@ -596,14 +596,14 @@ doMkdir(path::ParsedParent parsed, int mode, backend_t backend = NullBackend) {
596596

597597
// This function is exposed to users and allows users to specify a particular
598598
// backend that a directory should be created within.
599-
int wasmfs_create_directory(char* path, int mode, backend_t backend) {
599+
int wasmfs_create_directory(char* path, mode_t mode, backend_t backend) {
600600
static_assert(std::is_same_v<decltype(doMkdir(0, 0, 0)), int>,
601601
"unexpected conversion from result of doMkdir to int");
602602
return doMkdir(path::parseParent(path), mode, backend);
603603
}
604604

605605
// TODO: Test this.
606-
int __syscall_mkdirat(int dirfd, intptr_t path, int mode) {
606+
int __syscall_mkdirat(int dirfd, intptr_t path, mode_t mode) {
607607
return doMkdir(path::parseParent((char*)path, dirfd), mode);
608608
}
609609

@@ -1064,7 +1064,7 @@ int __syscall_utimensat(int dirFD, intptr_t path_, intptr_t times_, int flags) {
10641064
}
10651065

10661066
// TODO: Test this with non-AT_FDCWD values.
1067-
int __syscall_fchmodat(int dirfd, intptr_t path, int mode, ...) {
1067+
int __syscall_fchmodat(int dirfd, intptr_t path, mode_t mode, ...) {
10681068
int flags = 0;
10691069
va_list v1;
10701070
va_start(v1, mode);
@@ -1087,11 +1087,11 @@ int __syscall_fchmodat(int dirfd, intptr_t path, int mode, ...) {
10871087
return 0;
10881088
}
10891089

1090-
int __syscall_chmod(intptr_t path, int mode) {
1090+
int __syscall_chmod(intptr_t path, mode_t mode) {
10911091
return __syscall_fchmodat(AT_FDCWD, path, mode, 0);
10921092
}
10931093

1094-
int __syscall_fchmod(int fd, int mode) {
1094+
int __syscall_fchmod(int fd, mode_t mode) {
10951095
auto openFile = wasmFS.getFileTable().locked().getEntry(fd);
10961096
if (!openFile) {
10971097
return -EBADF;
@@ -1103,7 +1103,7 @@ int __syscall_fchmod(int fd, int mode) {
11031103
}
11041104

11051105
int __syscall_fchownat(
1106-
int dirfd, intptr_t path, int owner, int group, int flags) {
1106+
int dirfd, intptr_t path, uid_t owner, gid_t group, int flags) {
11071107
// Only accept valid flags.
11081108
if (flags & ~(AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW)) {
11091109
// TODO: Test this case.
@@ -1119,7 +1119,7 @@ int __syscall_fchownat(
11191119
return 0;
11201120
}
11211121

1122-
int __syscall_fchown32(int fd, int owner, int group) {
1122+
int __syscall_fchown32(int fd, uid_t owner, gid_t group) {
11231123
return __syscall_fchownat(fd, (intptr_t) "", owner, group, AT_EMPTY_PATH);
11241124
}
11251125

@@ -1180,15 +1180,15 @@ static int doTruncate(std::shared_ptr<File>& file, off_t size) {
11801180
return 0;
11811181
}
11821182

1183-
int __syscall_truncate64(intptr_t path, uint64_t size) {
1183+
int __syscall_truncate64(intptr_t path, off_t size) {
11841184
auto parsed = path::parseFile((char*)path);
11851185
if (auto err = parsed.getError()) {
11861186
return err;
11871187
}
11881188
return doTruncate(parsed.getFile(), size);
11891189
}
11901190

1191-
int __syscall_ftruncate64(int fd, uint64_t size) {
1191+
int __syscall_ftruncate64(int fd, off_t size) {
11921192
auto openFile = wasmFS.getFileTable().locked().getEntry(fd);
11931193
if (!openFile) {
11941194
return -EBADF;
@@ -1315,7 +1315,7 @@ int __syscall_poll(intptr_t fds_, int nfds, int timeout) {
13151315
return nonzero;
13161316
}
13171317

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

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

0 commit comments

Comments
 (0)