Skip to content

Commit 1a0b77c

Browse files
authored
Define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS in compiler-rt (#15411)
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 80e3010 commit 1a0b77c

File tree

7 files changed

+14
-59
lines changed

7 files changed

+14
-59
lines changed

src/library_syscall.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,6 @@ var SyscallsLibrary = {
261261
#endif
262262
},
263263

264-
__syscall_open: function(path, flags, varargs) {
265-
var pathname = SYSCALLS.getStr(path);
266-
var mode = varargs ? SYSCALLS.get() : 0;
267-
var stream = FS.open(pathname, flags, mode);
268-
return stream.fd;
269-
},
270-
__syscall_unlink: function(path) {
271-
path = SYSCALLS.getStr(path);
272-
FS.unlink(path);
273-
return 0;
274-
},
275264
__syscall_chdir: function(path) {
276265
path = SYSCALLS.getStr(path);
277266
FS.chdir(path);
@@ -381,10 +370,6 @@ var SyscallsLibrary = {
381370
FS.symlink(target, linkpath);
382371
return 0;
383372
},
384-
__syscall_readlink: function(path, buf, bufsize) {
385-
path = SYSCALLS.getStr(path);
386-
return SYSCALLS.doReadlink(path, buf, bufsize);
387-
},
388373
__syscall_fchmod: function(fd, mode) {
389374
FS.fchmod(fd, mode);
390375
return 0;
@@ -929,9 +914,6 @@ var SyscallsLibrary = {
929914
return 0; // your advice is important to us (but we can't use it)
930915
},
931916
__syscall_openat: function(dirfd, path, flags, varargs) {
932-
#if SYSCALL_DEBUG
933-
err('warning: untested syscall');
934-
#endif
935917
path = SYSCALLS.getStr(path);
936918
path = SYSCALLS.calculateAt(dirfd, path);
937919
var mode = varargs ? SYSCALLS.get() : 0;
@@ -965,7 +947,7 @@ var SyscallsLibrary = {
965947
FS.chown(path, owner, group);
966948
return 0;
967949
},
968-
__syscall_fstatat64: function(dirfd, path, buf, flags) {
950+
__syscall_newfstatat: function(dirfd, path, buf, flags) {
969951
path = SYSCALLS.getStr(path);
970952
var nofollow = flags & {{{ cDefine('AT_SYMLINK_NOFOLLOW') }}};
971953
var allowEmpty = flags & {{{ cDefine('AT_EMPTY_PATH') }}};
@@ -989,9 +971,6 @@ var SyscallsLibrary = {
989971
return 0;
990972
},
991973
__syscall_renameat: function(olddirfd, oldpath, newdirfd, newpath) {
992-
#if SYSCALL_DEBUG
993-
err('warning: untested syscall');
994-
#endif
995974
oldpath = SYSCALLS.getStr(oldpath);
996975
newpath = SYSCALLS.getStr(newpath);
997976
oldpath = SYSCALLS.calculateAt(olddirfd, oldpath);
@@ -1013,9 +992,6 @@ var SyscallsLibrary = {
1013992
return 0;
1014993
},
1015994
__syscall_readlinkat: function(dirfd, path, buf, bufsize) {
1016-
#if SYSCALL_DEBUG
1017-
err('warning: untested syscall');
1018-
#endif
1019995
path = SYSCALLS.getStr(path);
1020996
path = SYSCALLS.calculateAt(dirfd, path);
1021997
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
@@ -283,6 +283,11 @@
283283
#define SANITIZER_SIGN_EXTENDED_ADDRESSES 0
284284
#endif
285285

286+
// Emscripten emulates the canonical linux syscall set.
287+
#if !defined SANITIZER_USES_CANONICAL_LINUX_SYSCALLS && SANITIZER_EMSCRIPTEN
288+
# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
289+
#endif
290+
286291
// The AArch64 and RISC-V linux ports use the canonical syscall set as
287292
// mandated by the upstream linux community for all new ports. Other ports
288293
// may still use legacy syscalls.

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
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
75
#define SYS_getpid __syscall_getpid
86
#define SYS_pause __syscall_pause
97
#define SYS_nice __syscall_nice
108
#define SYS_sync __syscall_sync
11-
#define SYS_rename __syscall_rename
129
#define SYS_mkdir __syscall_mkdir
1310
#define SYS_rmdir __syscall_rmdir
1411
#define SYS_dup __syscall_dup
@@ -22,7 +19,6 @@
2219
#define SYS_setrlimit __syscall_setrlimit
2320
#define SYS_getrusage __syscall_getrusage
2421
#define SYS_symlink __syscall_symlink
25-
#define SYS_readlink __syscall_readlink
2622
#define SYS_munmap __syscall_munmap
2723
#define SYS_fchmod __syscall_fchmod
2824
#define SYS_getpriority __syscall_getpriority
@@ -74,7 +70,7 @@
7470
#define SYS_mkdirat __syscall_mkdirat
7571
#define SYS_mknodat __syscall_mknodat
7672
#define SYS_fchownat __syscall_fchownat
77-
#define SYS_fstatat64 __syscall_fstatat64
73+
#define SYS_newfstatat __syscall_newfstatat
7874
#define SYS_unlinkat __syscall_unlinkat
7975
#define SYS_renameat __syscall_renameat
8076
#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);
@@ -37,7 +34,6 @@ long __syscall_setsid(void);
3734
long __syscall_setrlimit(long resource, long limit);
3835
long __syscall_getrusage(long who, long usage);
3936
long __syscall_symlink(long target, long linkpath);
40-
long __syscall_readlink(long path, long buf, long bufsize);
4137
long __syscall_munmap(long addr, long len);
4238
long __syscall_fchmod(long fd, long mode);
4339
long __syscall_getpriority(long which, long who);
@@ -92,11 +88,11 @@ long __syscall_fcntl64(long fd, long cmd, ...);
9288
long __syscall_statfs64(long path, long size, long buf);
9389
long __syscall_fstatfs64(long fd, long size, long buf);
9490
long __syscall_fadvise64_64(long fd, long low, long high, long low2, long high2, long advice);
95-
long __syscall_openat(long dirfd, long path, long flags, ...);
91+
long __syscall_openat(long dirfd, long path, long flags, ...); // mode is optional
9692
long __syscall_mkdirat(long dirfd, long path, long mode);
9793
long __syscall_mknodat(long dirfd, long path, long mode, long dev);
9894
long __syscall_fchownat(long dirfd, long path, long owner, long group, long flags);
99-
long __syscall_fstatat64(long dirfd, long path, long buf, long flags);
95+
long __syscall_newfstatat(long dirfd, long path, long buf, long flags);
10096
long __syscall_unlinkat(long dirfd, long path, long flags);
10197
long __syscall_renameat(long olddirfd, long oldpath, long newdirfd, long newpath);
10298
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
@@ -417,10 +417,10 @@ static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, l
417417
#define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo)
418418
#endif
419419
#else // __EMSCRIPTEN__
420-
#define __sys_open2(x,pn,fl) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE))
421-
#define __sys_open3(x,pn,fl,mo) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
422-
#define __sys_open_cp2(x,pn,fl) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE))
423-
#define __sys_open_cp3(x,pn,fl,mo) __syscall_open(__scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
420+
#define __sys_open2(x,pn,fl) __syscall_openat(__scc(AT_FDCWD), __scc(pn), __scc((fl)|O_LARGEFILE))
421+
#define __sys_open3(x,pn,fl,mo) __syscall_openat(__scc(AT_FDCWD), __scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
422+
#define __sys_open_cp2(x,pn,fl) __syscall_openat(__scc(AT_FDCWD), __scc(pn), __scc((fl)|O_LARGEFILE))
423+
#define __sys_open_cp3(x,pn,fl,mo) __syscall_openat(__scc(AT_FDCWD), __scc(pn), __scc((fl)|O_LARGEFILE), __scc(mo))
424424
#endif
425425

426426
#define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__)

system/lib/standalone/standalone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ long _munmap_js(long addr, long length, long prot, long flags, long fd, long off
8383
// Mark this as weak so that wasmfs does not collide with it. That is, if wasmfs
8484
// is in use, we want to use that and not this.
8585
__attribute__((__weak__))
86-
long __syscall_open(const char* path, long flags, ...) {
86+
long __syscall_openat(int dirfd, const char* path, long flags, ...) {
8787
if (!strcmp(path, "/dev/stdin")) return STDIN_FILENO;
8888
if (!strcmp(path, "/dev/stdout")) return STDOUT_FILENO;
8989
if (!strcmp(path, "/dev/stderr")) return STDERR_FILENO;

system/lib/wasmfs/syscalls.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,6 @@ int wasmfs_create_file(char* pathname, mode_t mode, backend_t backend) {
464464
return doOpen(path::parseParent((char*)pathname), O_CREAT, mode, backend);
465465
}
466466

467-
long __syscall_open(long path, long flags, ...) {
468-
mode_t mode = 0;
469-
va_list v1;
470-
va_start(v1, flags);
471-
mode = va_arg(v1, int);
472-
va_end(v1);
473-
474-
return doOpen(path::parseParent((char*)path), flags, mode);
475-
}
476-
477467
// TODO: Test this with non-AT_FDCWD values.
478468
long __syscall_openat(long dirfd, long path, long flags, ...) {
479469
mode_t mode = 0;
@@ -747,10 +737,6 @@ long __syscall_rmdir(long path) {
747737
return __syscall_unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
748738
}
749739

750-
long __syscall_unlink(long path) {
751-
return __syscall_unlinkat(AT_FDCWD, path, 0);
752-
}
753-
754740
long __syscall_getdents64(long fd, long dirp, long count) {
755741
dirent* result = (dirent*)dirp;
756742

@@ -984,10 +970,6 @@ long __syscall_readlinkat(long dirfd, long path, long buf, long bufsize) {
984970
return bytes;
985971
}
986972

987-
long __syscall_readlink(long path, long buf, size_t bufSize) {
988-
return __syscall_readlinkat(AT_FDCWD, path, buf, bufSize);
989-
}
990-
991973
// TODO: Test this with non-AT_FDCWD values.
992974
long __syscall_utimensat(int dirFD,
993975
char* path,

0 commit comments

Comments
 (0)