Skip to content

Commit 4acbd74

Browse files
committed
Define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS in compiler-rt
In defining this I noticed that musl will also choose to use these canonical syscalls when the alternative is not defined. This allows us to remove a bunch of duplicate syscalls and their implementation.
1 parent a82c8c8 commit 4acbd74

File tree

8 files changed

+16
-49
lines changed

8 files changed

+16
-49
lines changed

src/library_syscall.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,6 @@ var SyscallsLibrary = {
300300
return 0;
301301
},
302302

303-
__syscall_open: function(path, flags, varargs) {
304-
var pathname = SYSCALLS.getStr(path);
305-
var mode = varargs ? SYSCALLS.get() : 0;
306-
var stream = FS.open(pathname, flags, mode);
307-
return stream.fd;
308-
},
309-
__syscall_unlink: function(path) {
310-
path = SYSCALLS.getStr(path);
311-
FS.unlink(path);
312-
return 0;
313-
},
314303
__syscall_chdir: function(path) {
315304
path = SYSCALLS.getStr(path);
316305
FS.chdir(path);
@@ -329,12 +318,6 @@ var SyscallsLibrary = {
329318
path = SYSCALLS.getStr(path);
330319
return SYSCALLS.doAccess(path, amode);
331320
},
332-
__syscall_rename: function(old_path, new_path) {
333-
old_path = SYSCALLS.getStr(old_path);
334-
new_path = SYSCALLS.getStr(new_path);
335-
FS.rename(old_path, new_path);
336-
return 0;
337-
},
338321
__syscall_mkdir: function(path, mode) {
339322
path = SYSCALLS.getStr(path);
340323
return SYSCALLS.doMkdir(path, mode);
@@ -429,10 +412,6 @@ var SyscallsLibrary = {
429412
FS.symlink(target, linkpath);
430413
return 0;
431414
},
432-
__syscall_readlink: function(path, buf, bufsize) {
433-
path = SYSCALLS.getStr(path);
434-
return SYSCALLS.doReadlink(path, buf, bufsize);
435-
},
436415
__syscall_munmap__deps: ['$syscallMunmap'],
437416
__syscall_munmap: function(addr, len) {
438417
return syscallMunmap(addr, len);
@@ -982,9 +961,6 @@ var SyscallsLibrary = {
982961
return 0; // your advice is important to us (but we can't use it)
983962
},
984963
__syscall_openat: function(dirfd, path, flags, varargs) {
985-
#if SYSCALL_DEBUG
986-
err('warning: untested syscall');
987-
#endif
988964
path = SYSCALLS.getStr(path);
989965
path = SYSCALLS.calculateAt(dirfd, path);
990966
var mode = varargs ? SYSCALLS.get() : 0;
@@ -1018,7 +994,7 @@ var SyscallsLibrary = {
1018994
FS.chown(path, owner, group);
1019995
return 0;
1020996
},
1021-
__syscall_fstatat64: function(dirfd, path, buf, flags) {
997+
__syscall_newfstatat: function(dirfd, path, buf, flags) {
1022998
path = SYSCALLS.getStr(path);
1023999
var nofollow = flags & {{{ cDefine('AT_SYMLINK_NOFOLLOW') }}};
10241000
var allowEmpty = flags & {{{ cDefine('AT_EMPTY_PATH') }}};
@@ -1042,9 +1018,6 @@ var SyscallsLibrary = {
10421018
return 0;
10431019
},
10441020
__syscall_renameat: function(olddirfd, oldpath, newdirfd, newpath) {
1045-
#if SYSCALL_DEBUG
1046-
err('warning: untested syscall');
1047-
#endif
10481021
oldpath = SYSCALLS.getStr(oldpath);
10491022
newpath = SYSCALLS.getStr(newpath);
10501023
oldpath = SYSCALLS.calculateAt(olddirfd, oldpath);
@@ -1066,9 +1039,6 @@ var SyscallsLibrary = {
10661039
return 0;
10671040
},
10681041
__syscall_readlinkat: function(dirfd, path, buf, bufsize) {
1069-
#if SYSCALL_DEBUG
1070-
err('warning: untested syscall');
1071-
#endif
10721042
path = SYSCALLS.getStr(path);
10731043
path = SYSCALLS.calculateAt(dirfd, path);
10741044
return SYSCALLS.doReadlink(path, buf, bufsize);

system/lib/compiler-rt/lib/sanitizer_common/sanitizer_platform.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@
286286
#define SANITIZER_SIGN_EXTENDED_ADDRESSES 0
287287
#endif
288288

289+
// Emscripten emulates the canonical linux syscall set.
290+
#if !defined SANITIZER_USES_CANONICAL_LINUX_SYSCALLS && SANITIZER_EMSCRIPTEN
291+
# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
292+
#endif
293+
289294
// The AArch64 and RISC-V linux ports use the canonical syscall set as
290295
// mandated by the upstream linux community for all new ports. Other ports
291296
// may still use legacy syscalls.

system/lib/fetch/asmfs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ long __syscall_link(long oldpath, long newpath)
12061206
RETURN_ERRNO(ENOTSUP, "TODO: link() is a stub and not yet implemented in ASMFS");
12071207
}
12081208

1209-
long __syscall_unlink(long path)
1209+
long __syscall_unlinkat(long path, long flags)
12101210
{
12111211
const char* pathname = (const char *)path;
12121212
#ifdef ASMFS_DEBUG

system/lib/libc/musl/arch/emscripten/bits/syscall.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#define SYS_open __syscall_open
21
#define SYS_link __syscall_link
3-
#define SYS_unlink __syscall_unlink
42
#define SYS_chdir __syscall_chdir
53
#define SYS_mknod __syscall_mknod
64
#define SYS_chmod __syscall_chmod
@@ -9,7 +7,6 @@
97
#define SYS_access __syscall_access
108
#define SYS_nice __syscall_nice
119
#define SYS_sync __syscall_sync
12-
#define SYS_rename __syscall_rename
1310
#define SYS_mkdir __syscall_mkdir
1411
#define SYS_rmdir __syscall_rmdir
1512
#define SYS_dup __syscall_dup
@@ -24,7 +21,6 @@
2421
#define SYS_setrlimit __syscall_setrlimit
2522
#define SYS_getrusage __syscall_getrusage
2623
#define SYS_symlink __syscall_symlink
27-
#define SYS_readlink __syscall_readlink
2824
#define SYS_munmap __syscall_munmap
2925
#define SYS_fchmod __syscall_fchmod
3026
#define SYS_getpriority __syscall_getpriority
@@ -76,7 +72,7 @@
7672
#define SYS_mkdirat __syscall_mkdirat
7773
#define SYS_mknodat __syscall_mknodat
7874
#define SYS_fchownat __syscall_fchownat
79-
#define SYS_fstatat64 __syscall_fstatat64
75+
#define SYS_newfstatat __syscall_newfstatat
8076
#define SYS_unlinkat __syscall_unlinkat
8177
#define SYS_renameat __syscall_renameat
8278
#define SYS_linkat __syscall_linkat

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
extern "C" {
1212
#endif
1313

14-
long __syscall_open(long path, long flags, ...); // mode is optional
1514
long __syscall_link(long oldpath, long newpath);
16-
long __syscall_unlink(long path);
1715
long __syscall_chdir(long path);
1816
long __syscall_mknod(long path, long mode, long dev);
1917
long __syscall_chmod(long path, long mode);
@@ -22,7 +20,6 @@ long __syscall_pause(void);
2220
long __syscall_access(long path, long amode);
2321
long __syscall_nice(long inc);
2422
long __syscall_sync(void);
25-
long __syscall_rename(long old_path, long new_path);
2623
long __syscall_mkdir(long path, long mode);
2724
long __syscall_rmdir(long path);
2825
long __syscall_dup(long fd);
@@ -38,7 +35,6 @@ long __syscall_setsid(void);
3835
long __syscall_setrlimit(long resource, long limit);
3936
long __syscall_getrusage(long who, long usage);
4037
long __syscall_symlink(long target, long linkpath);
41-
long __syscall_readlink(long path, long buf, long bufsize);
4238
long __syscall_munmap(long addr, long len);
4339
long __syscall_fchmod(long fd, long mode);
4440
long __syscall_getpriority(long which, long who);
@@ -93,11 +89,11 @@ long __syscall_fcntl64(long fd, long cmd, ...);
9389
long __syscall_statfs64(long path, long size, long buf);
9490
long __syscall_fstatfs64(long fd, long size, long buf);
9591
long __syscall_fadvise64_64(long fd, long low, long high, long low2, long high2, long advice);
96-
long __syscall_openat(long dirfd, long path, long flags, ...);
92+
long __syscall_openat(long dirfd, long path, long flags, ...); // mode is optional
9793
long __syscall_mkdirat(long dirfd, long path, long mode);
9894
long __syscall_mknodat(long dirfd, long path, long mode, long dev);
9995
long __syscall_fchownat(long dirfd, long path, long owner, long group, long flags);
100-
long __syscall_fstatat64(long dirfd, long path, long buf, long flags);
96+
long __syscall_newfstatat(long dirfd, long path, long buf, long flags);
10197
long __syscall_unlinkat(long dirfd, long path, long flags);
10298
long __syscall_renameat(long olddirfd, long oldpath, long newdirfd, long newpath);
10399
long __syscall_linkat(long olddirfd, long oldpath, long newdirfd, long newpath, long flags);

system/lib/libc/musl/src/internal/syscall.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ long __syscall_ret(unsigned long),
257257
#define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo)
258258
#endif
259259
#else // __EMSCRIPTEN__
260-
#define __sys_open2(x,pn,fl) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE))
261-
#define __sys_open3(x,pn,fl,mo) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
262-
#define __sys_open_cp2(x,pn,fl) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE))
263-
#define __sys_open_cp3(x,pn,fl,mo) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
260+
#define __sys_open2(x,pn,fl) __syscall_openat(__scc(AT_FDCWD), __scc(pn), __scc((fl)|O_LARGEFILE))
261+
#define __sys_open3(x,pn,fl,mo) __syscall_openat(__scc(AT_FDCWD), __scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
262+
#define __sys_open_cp2(x,pn,fl) __syscall_openat(__scc(AT_FDCWD), __scc(pn), __scc((fl)|O_LARGEFILE))
263+
#define __sys_open_cp3(x,pn,fl,mo) __syscall_openat(__scc(AT_FDCWD), __scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
264264
#endif
265265
#define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__)
266266
#define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__))

system/lib/standalone/standalone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ long __syscall_mmap2(long addr, long len, long prot, long flags, long fd, long o
7070
// corner case error checking; everything else is not permitted.
7171
// TODO: full file support for WASI, or an option for it
7272
// open()
73-
long __syscall_open(const char* path, long flags, ...) {
73+
long __syscall_openat(const char* path, long flags, ...) {
7474
if (!strcmp(path, "/dev/stdin")) return STDIN_FILENO;
7575
if (!strcmp(path, "/dev/stdout")) return STDOUT_FILENO;
7676
if (!strcmp(path, "/dev/stderr")) return STDERR_FILENO;

system/lib/wasmfs/syscalls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ long __syscall_fstat64(long fd, long buf) {
282282
return __WASI_ERRNO_SUCCESS;
283283
}
284284

285-
__wasi_fd_t __syscall_open(long pathname, long flags, long mode) {
285+
__wasi_fd_t __syscall_openat(int dirfd, long pathname, long flags, long mode) {
286286
int accessMode = (flags & O_ACCMODE);
287287
bool canWrite = false;
288288

0 commit comments

Comments
 (0)