Skip to content

Commit b27e45d

Browse files
committed
Use dedicated pointer types in internal syscall layer. NFC
1 parent d4ac893 commit b27e45d

File tree

8 files changed

+291
-304
lines changed

8 files changed

+291
-304
lines changed

system/lib/libc/emscripten_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ int _mmap_js(size_t length,
7676
int* allocated,
7777
void** addr);
7878
int _munmap_js(
79-
intptr_t addr, size_t length, int prot, int flags, int fd, off_t offset);
79+
void *addr, size_t length, int prot, int flags, int fd, off_t offset);
8080
int _msync_js(
81-
intptr_t addr, size_t length, int prot, int flags, int fd, off_t offset);
81+
void *addr, size_t length, int prot, int flags, int fd, off_t offset);
8282

8383
struct dso;
8484

system/lib/libc/emscripten_mmap.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ struct map {
3535
static volatile int lock[1];
3636
static struct map* mappings;
3737

38-
static struct map* find_mapping(intptr_t addr, struct map** prev) {
38+
static struct map* find_mapping(void *addr, struct map** prev) {
3939
struct map* map = mappings;
4040
while (map) {
41-
if (map->addr == (void*)addr) {
41+
if (map->addr == addr) {
4242
return map;
4343
}
4444
if (prev) {
@@ -49,7 +49,7 @@ static struct map* find_mapping(intptr_t addr, struct map** prev) {
4949
return map;
5050
}
5151

52-
int __syscall_munmap(intptr_t addr, size_t length) {
52+
int __syscall_munmap(void *addr, size_t length) {
5353
LOCK(lock);
5454
struct map* prev = NULL;
5555
struct map* map = find_mapping(addr, &prev);
@@ -89,7 +89,7 @@ int __syscall_munmap(intptr_t addr, size_t length) {
8989
return 0;
9090
}
9191

92-
int __syscall_msync(intptr_t addr, size_t len, int flags) {
92+
int __syscall_msync(void *addr, size_t len, int flags) {
9393
LOCK(lock);
9494
struct map* map = find_mapping(addr, NULL);
9595
UNLOCK(lock);
@@ -102,7 +102,7 @@ int __syscall_msync(intptr_t addr, size_t len, int flags) {
102102
return _msync_js(addr, len, map->prot, map->flags, map->fd, map->offset);
103103
}
104104

105-
intptr_t __syscall_mmap2(intptr_t addr, size_t len, int prot, int flags, int fd, off_t offset) {
105+
void *__syscall_mmap2(void *addr, size_t len, int prot, int flags, int fd, off_t offset) {
106106
if (addr != 0) {
107107
// We don't currently support location hints for the address of the mapping
108108
return -EINVAL;
@@ -147,5 +147,5 @@ intptr_t __syscall_mmap2(intptr_t addr, size_t len, int prot, int flags, int fd,
147147
mappings = new_map;
148148
UNLOCK(lock);
149149

150-
return (long)new_map->addr;
150+
return new_map->addr;
151151
}

system/lib/libc/emscripten_syscall_stubs.c

Lines changed: 44 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,10 @@
1111
* 3. Return ENOSYS and warn at runtime if called.
1212
*/
1313

14+
#define _GNU_SOURCE // for struct mmsghdr
1415
#include <errno.h>
15-
#include <stdio.h>
16-
#include <sys/types.h>
17-
#include <unistd.h>
18-
#include <syscall_arch.h>
1916
#include <string.h>
20-
#include <sys/resource.h>
21-
#include <sys/stat.h>
22-
#include <time.h>
23-
#include <sys/utsname.h>
17+
#include <syscall_arch.h>
2418
#include <emscripten/console.h>
2519
#include <emscripten/version.h>
2620
#include <emscripten/stack.h>
@@ -47,24 +41,22 @@ static mode_t g_umask = S_IWGRP | S_IWOTH;
4741
#define STRINGIFY(s) #s
4842
#define STR(s) STRINGIFY(s)
4943

50-
weak int __syscall_uname(intptr_t buf) {
44+
weak int __syscall_uname(struct utsname *buf) {
5145
if (!buf) {
5246
return -EFAULT;
5347
}
5448
const char* full_version = STR(__EMSCRIPTEN_major__) "." \
5549
STR(__EMSCRIPTEN_minor__) "." \
5650
STR(__EMSCRIPTEN_tiny__);
5751

58-
struct utsname *utsname = (struct utsname *)buf;
59-
60-
strcpy(utsname->sysname, "Emscripten");
61-
strcpy(utsname->nodename, "emscripten");
62-
strcpy(utsname->release, full_version);
63-
strcpy(utsname->version, "#1");
52+
strcpy(buf->sysname, "Emscripten");
53+
strcpy(buf->nodename, "emscripten");
54+
strcpy(buf->release, full_version);
55+
strcpy(buf->version, "#1");
6456
#ifdef __wasm64__
65-
strcpy(utsname->machine, "wasm64");
57+
strcpy(buf->machine, "wasm64");
6658
#else
67-
strcpy(utsname->machine, "wasm32");
59+
strcpy(buf->machine, "wasm32");
6860
#endif
6961
return 0;
7062
}
@@ -105,15 +97,15 @@ weak pid_t __syscall_getppid() {
10597
return g_ppid;
10698
}
10799

108-
weak int __syscall_linkat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath, int flags) {
100+
weak int __syscall_linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags) {
109101
return -EMLINK; // no hardlinks for us
110102
}
111103

112-
weak int __syscall_getgroups32(int count, intptr_t list) {
104+
weak int __syscall_getgroups32(int count, gid_t list[]) {
113105
if (count < 1) {
114106
return -EINVAL;
115107
}
116-
((gid_t*)list)[0] = 0;
108+
list[0] = 0;
117109
return 1;
118110
}
119111

@@ -134,7 +126,7 @@ struct kusage {
134126
long stime_tv_usec;
135127
};
136128

137-
weak int __syscall_getrusage(int who, intptr_t usage) {
129+
weak int __syscall_getrusage(int who, void *usage) {
138130
REPORT(getrusage);
139131
struct kusage *u = (struct kusage*)usage;
140132
u->utime_tv_sec = 1;
@@ -152,7 +144,7 @@ weak int __syscall_setpriority(int which, id_t who, int prio) {
152144
return -EPERM;
153145
}
154146

155-
weak int __syscall_setdomainname(intptr_t name, size_t size) {
147+
weak int __syscall_setdomainname(const char *name, size_t len) {
156148
return -EPERM;
157149
}
158150

@@ -172,18 +164,18 @@ weak gid_t __syscall_getegid32(void) {
172164
return 0;
173165
}
174166

175-
weak int __syscall_getresuid32(intptr_t ruid, intptr_t euid, intptr_t suid) {
176-
*((uid_t *)ruid) = 0;
177-
*((uid_t *)euid) = 0;
178-
*((uid_t *)suid) = 0;
167+
weak int __syscall_getresuid32(uid_t *ruid, uid_t *euid, uid_t *suid) {
168+
*ruid = 0;
169+
*euid = 0;
170+
*suid = 0;
179171
return 0;
180172
}
181173

182-
weak int __syscall_getresgid32(intptr_t ruid, intptr_t euid, intptr_t suid) {
174+
weak int __syscall_getresgid32(gid_t *rgid, gid_t *egid, gid_t *sgid) {
183175
REPORT(getresgid32);
184-
*((uid_t *)ruid) = 0;
185-
*((uid_t *)euid) = 0;
186-
*((uid_t *)suid) = 0;
176+
*rgid = 0;
177+
*egid = 0;
178+
*sgid = 0;
187179
return 0;
188180
}
189181

@@ -192,28 +184,28 @@ weak int __syscall_pause() {
192184
return -EINTR; // we can't pause
193185
}
194186

195-
weak int __syscall_madvise(intptr_t addr, size_t length, int advice) {
187+
weak int __syscall_madvise(void *addr, size_t length, int advice) {
196188
REPORT(madvise);
197189
// advice is welcome, but ignored
198190
return 0;
199191
}
200192

201-
weak int __syscall_mlock(intptr_t addr, size_t len) {
193+
weak int __syscall_mlock(const void *addr, size_t len) {
202194
REPORT(mlock);
203195
return 0;
204196
}
205197

206-
weak int __syscall_munlock(intptr_t addr, size_t len) {
198+
weak int __syscall_munlock(const void *addr, size_t len) {
207199
REPORT(munlock);
208200
return 0;
209201
}
210202

211-
weak int __syscall_mprotect(size_t addr, size_t len, int prot) {
203+
weak int __syscall_mprotect(size_t start, size_t len, int prot) {
212204
REPORT(mprotect);
213205
return 0; // let's not and say we did
214206
}
215207

216-
weak int __syscall_mremap(intptr_t old_addr, size_t old_size, size_t new_size, int flags, intptr_t new_addr) {
208+
weak int __syscall_mremap(void *old_addr, size_t old_size, size_t new_size, int flags, void *new_addr) {
217209
REPORT(mremap);
218210
return -ENOMEM; // never succeed
219211
}
@@ -228,48 +220,47 @@ weak int __syscall_munlockall() {
228220
return 0;
229221
}
230222

231-
weak int __syscall_prlimit64(pid_t pid, int resource, intptr_t new_limit, intptr_t old_limit) {
223+
weak int __syscall_prlimit64(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit) {
232224
REPORT(prlimit64);
233-
struct rlimit *old = (struct rlimit *)old_limit;
234225
if (new_limit) {
235226
return -EPERM;
236227
}
237-
if (old) {
228+
if (old_limit) {
238229
if (resource == RLIMIT_NOFILE) {
239230
// See FS.MAX_OPEN_FDS in src/lib/libfs.js
240-
old->rlim_cur = 4096;
241-
old->rlim_max = 4096;
231+
old_limit->rlim_cur = 4096;
232+
old_limit->rlim_max = 4096;
242233
} else if (resource == RLIMIT_STACK) {
243234
uintptr_t end = emscripten_stack_get_end();
244235
uintptr_t base = emscripten_stack_get_base();
245236

246-
old->rlim_cur = base - end;
237+
old_limit->rlim_cur = base - end;
247238
// we can not change the stack size, so the maximum is the same as the current
248-
old->rlim_max = base - end;
239+
old_limit->rlim_max = base - end;
249240
} else {
250241
// Just report no limits
251-
old->rlim_cur = RLIM_INFINITY;
252-
old->rlim_max = RLIM_INFINITY;
242+
old_limit->rlim_cur = RLIM_INFINITY;
243+
old_limit->rlim_max = RLIM_INFINITY;
253244
}
254245
}
255246
return 0;
256247
}
257248

258-
weak int __syscall_setsockopt(int sockfd, int level, int optname, intptr_t optval, socklen_t optlen, ...) {
249+
weak int __syscall_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen, ...) {
259250
REPORT(setsockopt);
260251
return -ENOPROTOOPT; // The option is unknown at the level indicated.
261252
}
262253

263-
weak pid_t __syscall_wait4(pid_t pid, intptr_t wstatus, int options, int rusage) {
254+
weak pid_t __syscall_wait4(pid_t pid, int *wstatus, int options, struct rusage *rusage) {
264255
REPORT(wait4);
265256
return (pid_t)-1;
266257
}
267258

268-
UNIMPLEMENTED(acct, (intptr_t filename))
269-
UNIMPLEMENTED(mincore, (intptr_t addr, size_t length, intptr_t vec))
270-
UNIMPLEMENTED(pipe2, (intptr_t fds, int flags))
271-
UNIMPLEMENTED(pselect6, (int nfds, intptr_t readfds, intptr_t writefds, intptr_t exceptfds, intptr_t timeout, intptr_t sigmaks))
272-
UNIMPLEMENTED(recvmmsg, (int sockfd, intptr_t msgvec, unsigned int vlen, unsigned int flags, intptr_t timeout))
273-
UNIMPLEMENTED(sendmmsg, (int sockfd, intptr_t msgvec, unsigned int vlen, unsigned int flags))
259+
UNIMPLEMENTED(acct, (const char *filename))
260+
UNIMPLEMENTED(mincore, (void *addr, size_t length, unsigned char *vec))
261+
UNIMPLEMENTED(pipe2, (int pipefd[2], int flags))
262+
UNIMPLEMENTED(pselect6, (int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, const struct timespec *ts, const void *mask))
263+
UNIMPLEMENTED(recvmmsg, (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags, struct timespec *timeout))
264+
UNIMPLEMENTED(sendmmsg, (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags))
274265
UNIMPLEMENTED(shutdown, (int sockfd, int how, ...))
275-
UNIMPLEMENTED(socketpair, (int domain, int type, int protocol, intptr_t fds, ...))
266+
UNIMPLEMENTED(socketpair, (int domain, int type, int protocol, int fd[2], ...))

0 commit comments

Comments
 (0)