Skip to content

Commit eb90d7d

Browse files
committed
Add copy_file_range syscall stub
llvm/llvm-project#169405 has this: ```diff --- a/libcxx/src/filesystem/operations.cpp +++ b/libcxx/src/filesystem/operations.cpp @@ -41,17 +41,10 @@ #include <time.h> // since Linux 4.5 and FreeBSD 13, but the Linux libc wrapper is only provided by glibc >= 2.27 and musl -#if defined(__linux__) -# if defined(_LIBCPP_GLIBC_PREREQ) -# if _LIBCPP_GLIBC_PREREQ(2, 27) -# define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE -# endif -# elif _LIBCPP_HAS_MUSL_LIBC -# define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE -# endif -#elif defined(__FreeBSD__) +#if _LIBCPP_GLIBC_PREREQ(2, 27) || _LIBCPP_HAS_MUSL_LIBC || defined(__FreeBSD__) # define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE #endif + #if __has_include(<sys/sendfile.h>) # include <sys/sendfile.h> # define _LIBCPP_FILESYSTEM_USE_SENDFILE ``` Before the PR, because we didn't define `__linux__`, `_LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE` was not defined. But after it `#if defined(__linux__)` check was gone, and because we defined `_LIBCPP_HAS_MUSL_LIBC`, `_LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE` was defined as well. After this PR, we started to have `error: undefined symbol: copy_file_range` error on `core*.test_dylink_exceptions_try_catch_6_*` tests. --- This commit fixes the linker error by wiring up `SYS_copy_file_range` and provides a stub implementation returning `-ENOSYS` for both legacy JS syscalls and WASMFS. This allows `copy_file_range.c` from musl to be compiled into the system library. The libcxx implementation falls back to other mechanisms when receiving `ENOSYS`.
1 parent b119c87 commit eb90d7d

6 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎src/lib/libsigs.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ sigs = {
240240
__syscall_epoll_create1__sig: 'ii',
241241
__syscall_epoll_ctl__sig: 'iiiip',
242242
__syscall_epoll_pwait__sig: 'iipiipp',
243+
__syscall_copy_file_range__sig: 'iipipii',
243244
__syscall_faccessat__sig: 'iipii',
244245
__syscall_fadvise64__sig: 'iijji',
245246
__syscall_fallocate__sig: 'iiijj',

‎src/lib/libsyscall.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ var SyscallsLibrary = {
708708
__syscall_epoll_ctl: (epfd, op, fd, ev) => -{{{ cDefs.ENOSYS }}},
709709
__syscall_epoll_pwait__nothrow: true,
710710
__syscall_epoll_pwait: (epfd, ev, maxevents, timeout, sigmask, sigsetsize) => -{{{ cDefs.ENOSYS }}},
711+
__syscall_copy_file_range__nothrow: true,
712+
__syscall_copy_file_range: (fd_in, off_in, fd_out, off_out, len, flags) => -{{{ cDefs.ENOSYS }}},
711713
__syscall_getcwd__deps: ['$lengthBytesUTF8', '$stringToUTF8'],
712714
__syscall_getcwd: (buf, size) => {
713715
if (size === 0) return -{{{ cDefs.EINVAL }}};

‎system/include/emscripten/syscalls.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ int __syscall_shutdown(int sockfd, int how, int unused1, int unused2, int unused
122122
int __syscall_epoll_create1(int flags);
123123
int __syscall_epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev);
124124
int __syscall_epoll_pwait(int epfd, struct epoll_event *ev, int maxevents, int timeout, const sigset_t *sigmask, size_t sigsetsize);
125+
ssize_t __syscall_copy_file_range(int fd_in, off_t *off_in, int fd_out, off_t *off_out, size_t len, unsigned flags);
125126

126127
#ifdef __cplusplus
127128
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,4 @@
8787
#define SYS_epoll_create1 __syscall_epoll_create1
8888
#define SYS_epoll_ctl __syscall_epoll_ctl
8989
#define SYS_epoll_pwait __syscall_epoll_pwait
90+
#define SYS_copy_file_range __syscall_copy_file_range

‎system/lib/wasmfs/syscalls.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,4 +1887,13 @@ int __syscall_epoll_pwait(int epfd,
18871887
return -ENOSYS;
18881888
}
18891889

1890+
ssize_t __syscall_copy_file_range(int fd_in,
1891+
off_t* off_in,
1892+
int fd_out,
1893+
off_t* off_out,
1894+
size_t len,
1895+
unsigned flags) {
1896+
return -ENOSYS;
1897+
}
1898+
18901899
} // extern "C"

‎tools/system_libs.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ def get_files(self):
13441344

13451345
libc_files += files_in_path(
13461346
path='system/lib/libc/musl/src/linux',
1347-
filenames=['getdents.c', 'gettid.c', 'utimes.c', 'statx.c', 'wait4.c', 'wait3.c', 'epoll.c'])
1347+
filenames=['getdents.c', 'gettid.c', 'utimes.c', 'statx.c', 'wait4.c', 'wait3.c', 'epoll.c', 'copy_file_range.c'])
13481348

13491349
libc_files += files_in_path(
13501350
path='system/lib/libc/musl/src/malloc',

0 commit comments

Comments
 (0)