Skip to content

Commit

Permalink
lib/vfscore: Solve redefining conflicts
Browse files Browse the repository at this point in the history
There are many functions that are defined
in musl as well as in vfscore. When using
musl you want to use the musl functions.
When we use musl the
`LIBSYSCALL_SHIM_NOWRAPPER` macro is set
, which leads to the setting of
`UK_LIBC_SYSCALLS` to 0. We can use this
to exclude the redefined functions from vfscore.

Signed-off-by: Dragos Iulian Argint <dragosargint21@gmail.com>
  • Loading branch information
dragosargint committed Apr 4, 2022
1 parent 507b1e9 commit 2071df8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
68 changes: 58 additions & 10 deletions lib/vfscore/main.c
Expand Up @@ -289,7 +289,8 @@ UK_TRACEPOINT(trace_vfs_mknod, "\"%s\" 0%0o 0x%x", const char*, mode_t, dev_t);
UK_TRACEPOINT(trace_vfs_mknod_ret, "");
UK_TRACEPOINT(trace_vfs_mknod_err, "%d", int);

int __xmknod(int ver, const char *pathname, mode_t mode, dev_t *dev __unused)
static int __xmknod_helper(int ver, const char *pathname,
mode_t mode, dev_t *dev __unused)
{
UK_ASSERT(ver == 0); // On x86-64 Linux, _MKNOD_VER_LINUX is 0.
struct task *t = main_task;
Expand All @@ -312,9 +313,17 @@ int __xmknod(int ver, const char *pathname, mode_t mode, dev_t *dev __unused)
return -error;
}

#if UK_LIBC_SYSCALLS
int __xmknod(int ver, const char *pathname,
mode_t mode, dev_t *dev __unused)
{
return __xmknod_helper(ver, pathname, mode, dev);
}
#endif // UK_LIBC_SYSCALLS

UK_SYSCALL_R_DEFINE(int, mknod, const char*, pathname, mode_t, mode, dev_t, dev)
{
return __xmknod(0, pathname, mode, &dev);
return __xmknod_helper(0, pathname, mode, &dev);
}

UK_TRACEPOINT(trace_vfs_lseek, "%d 0x%x %d", int, off_t, int);
Expand Down Expand Up @@ -823,7 +832,7 @@ UK_TRACEPOINT(trace_vfs_fstat, "%d %p", int, struct stat*);
UK_TRACEPOINT(trace_vfs_fstat_ret, "");
UK_TRACEPOINT(trace_vfs_fstat_err, "%d", int);

int __fxstat(int ver __unused, int fd, struct stat *st)
static int __fxstat_helper(int ver __unused, int fd, struct stat *st)
{
struct vfscore_file *fp;
int error;
Expand All @@ -848,15 +857,21 @@ int __fxstat(int ver __unused, int fd, struct stat *st)
return -1;
}

#if UK_LIBC_SYSCALLS
int __fxstat(int ver __unused, int fd, struct stat *st)
{
return __fxstat_helper(ver, fd, st);
}
#ifdef __fxstat64
#undef __fxstat64
#endif

LFS64(__fxstat);
#endif //UK_LIBC_SYSCALLS

UK_SYSCALL_DEFINE(int, fstat, int, fd, struct stat *, st)
{
return __fxstat(1, fd, st);
return __fxstat_helper(1, fd, st);
}

#ifdef fstat64
Expand All @@ -865,8 +880,8 @@ UK_SYSCALL_DEFINE(int, fstat, int, fd, struct stat *, st)

LFS64(fstat);

int __fxstatat(int ver __unused, int dirfd, const char *pathname, struct stat *st,
int flags)
static int __fxstatat_helper(int ver __unused, int dirfd, const char *pathname,
struct stat *st,int flags)
{
if (pathname[0] == '/' || dirfd == AT_FDCWD) {
return stat(pathname, st);
Expand Down Expand Up @@ -905,27 +920,42 @@ int __fxstatat(int ver __unused, int dirfd, const char *pathname, struct stat *s
return error;
}

#if UK_LIBC_SYSCALLS
int __fxstatat(int ver __unused, int dirfd, const char *pathname,
struct stat *st, int flags)
{
return __fxstatat_helper(ver, dirfd, pathname, st, flags);
}
#ifdef __fxstatat64
#undef __fxstatat64
#endif

LFS64(__fxstatat);
#endif // UK_LIBC_SYSCALLS

UK_SYSCALL_R_DEFINE(int, fstatat, int, dirfd, const char*, path,
struct stat*, st, int, flags)
{
return __fxstatat_helper(1, dirfd, path, st, flags);
}

#if UK_LIBC_SYSCALLS
int fstatat(int dirfd, const char *path, struct stat *st, int flags)
{
return __fxstatat(1, dirfd, path, st, flags);
return __fxstatat_helper(1, dirfd, path, st, flags);
}

#ifdef fstatat64
#undef fstatat64
#endif

LFS64(fstatat);
#endif // UK_LIBC_SYSCALLS

UK_SYSCALL_R_DEFINE(int, newfstatat, int, dirfd, const char*, path,
struct stat*, st, int, flags)
{
return __fxstatat(1, dirfd, path, st, flags);
return __fxstatat_helper(1, dirfd, path, st, flags);
}

UK_SYSCALL_R_DEFINE(int, flock, int, fd, int, operation)
Expand Down Expand Up @@ -1521,7 +1551,8 @@ UK_TRACEPOINT(trace_vfs_stat, "\"%s\" %p", const char*, struct stat*);
UK_TRACEPOINT(trace_vfs_stat_ret, "");
UK_TRACEPOINT(trace_vfs_stat_err, "%d", int);

int __xstat(int ver __unused, const char *pathname, struct stat *st)
static int __xstat_helper(int ver __unused, const char *pathname,
struct stat *st)
{
struct task *t = main_task;
char path[PATH_MAX];
Expand All @@ -1544,18 +1575,25 @@ int __xstat(int ver __unused, const char *pathname, struct stat *st)
return -error;
}

#if UK_LIBC_SYSCALLS
static int __xstat(int ver __unused, const char *pathname,
struct stat *st)
{
return __xstat_helper(ver, pathname, st);
}
#ifdef __xstat64
#undef __xstat64
#endif

LFS64(__xstat);
#endif // UK_LIBC_SYSCALLS

UK_SYSCALL_R_DEFINE(int, stat, const char*, pathname, struct stat*, st)
{
if (!pathname) {
return -EINVAL;
}
return __xstat(1, pathname, st);
return __xstat_helper(1, pathname, st);
}

#ifdef stat64
Expand All @@ -1569,6 +1607,7 @@ UK_TRACEPOINT(trace_vfs_lstat, "pathname=%s, stat=%p", const char*,
UK_TRACEPOINT(trace_vfs_lstat_ret, "");
UK_TRACEPOINT(trace_vfs_lstat_err, "errno=%d", int);

#if UK_LIBC_SYSCALLS
int __lxstat(int ver __unused, const char *pathname, struct stat *st)
{
struct task *t = main_task;
Expand Down Expand Up @@ -1600,6 +1639,7 @@ int __lxstat(int ver __unused, const char *pathname, struct stat *st)
#endif

LFS64(__lxstat);
#endif // UK_LIBC_SYSCALLS

UK_SYSCALL_R_DEFINE(int, lstat, const char*, pathname, struct stat*, st)
{
Expand Down Expand Up @@ -1704,6 +1744,7 @@ statfs_to_statvfs(struct statvfs *dst, struct statfs *src)
return 0;
}

#if UK_LIBC_SYSCALLS
int
statvfs(const char *pathname, struct statvfs *buf)
{
Expand All @@ -1719,7 +1760,9 @@ statvfs(const char *pathname, struct statvfs *buf)
#endif

LFS64(statvfs);
#endif // UK_LIBC_SYSCALLS

#if UK_LIBC_SYSCALLS
int
fstatvfs(int fd, struct statvfs *buf)
{
Expand All @@ -1735,6 +1778,7 @@ fstatvfs(int fd, struct statvfs *buf)
#endif

LFS64(fstatvfs);
#endif // UK_LIBC_SYSCALLS


UK_TRACEPOINT(trace_vfs_getcwd, "%p %d", char*, size_t);
Expand Down Expand Up @@ -2320,6 +2364,7 @@ UK_SYSCALL_R_DEFINE(int, utimensat, int, dirfd, const char*, pathname, const str
return 0;
}

#if UK_LIBC_SYSCALLS
UK_TRACEPOINT(trace_vfs_futimens, "%d", int);
UK_TRACEPOINT(trace_vfs_futimens_ret, "");
UK_TRACEPOINT(trace_vfs_futimens_err, "%d", int);
Expand All @@ -2338,6 +2383,7 @@ int futimens(int fd, const struct timespec *times)
trace_vfs_futimens_ret();
return 0;
}
#endif // UK_LIBC_SYSCALLS

static int do_utimes(const char *pathname, const struct timeval *times, int flags)
{
Expand Down Expand Up @@ -2542,6 +2588,7 @@ ssize_t sendfile(int out_fd, int in_fd, off_t *_offset, size_t count)
LFS64(sendfile);
#endif

#if UK_LIBC_SYSCALLS
int posix_fadvise(int fd __unused, off_t offset __unused, off_t len __unused,
int advice)
{
Expand All @@ -2563,6 +2610,7 @@ int posix_fadvise(int fd __unused, off_t offset __unused, off_t len __unused,
#endif

LFS64(posix_fadvise);
#endif // UK_LIBC_SYSCALLS

UK_SYSCALL_R_DEFINE(mode_t, umask, mode_t, newmask)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/vfscore/mount.c
Expand Up @@ -308,11 +308,13 @@ UK_SYSCALL_R_DEFINE(int, umount2, const char*, path, int, flags)
return error;
}

#if UK_LIBC_SYSCALLS
int
umount(const char *path)
{
return umount2(path, 0);
}
#endif // UK_LIBC_SYSCALLS

#if 0
int
Expand Down
2 changes: 2 additions & 0 deletions lib/vfscore/pipe.c
Expand Up @@ -604,10 +604,12 @@ UK_SYSCALL_R_DEFINE(int, pipe2, int*, pipefd, int, flags)
return 0;
}

#if UK_LIBC_SYSCALLS
/* TODO maybe find a better place for this when it will be implemented */
int mkfifo(const char *path __unused, mode_t mode __unused)
{
UK_WARN_STUBBED();
errno = ENOTSUP;
return -1;
}
#endif // UK_LIBC_SYSCALLS

0 comments on commit 2071df8

Please sign in to comment.