From: Andrei Tatar Date: Tue, 21 Nov 2023 20:11:46 +0000 (+0100) Subject: vfscore: Move fd handling into posix-fdtab X-Git-Tag: RELEASE-0.16.0~188 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=3d731c0a80ec20b509ff5d3473941d4b3841c8e8;p=unikraft%2Funikraft.git vfscore: Move fd handling into posix-fdtab This change moves the file descriptor table out of vfscore, along with the fd-specific syscalls close and dup*. Implementations of vfscore files are also patched to use posix-fdtab. Checkpatch-Ignore: USE_NEGATIVE_ERRNO Checkpatch-Ignore: LINE_SPACING Signed-off-by: Andrei Tatar Reviewed-by: Simon Kuenzer Approved-by: Simon Kuenzer GitHub-Closes: #1168 --- diff --git a/lib/posix-event/epoll.c b/lib/posix-event/epoll.c index ce30175e6..891b317aa 100644 --- a/lib/posix-event/epoll.c +++ b/lib/posix-event/epoll.c @@ -43,6 +43,8 @@ #include #include +#include + #include #include #include @@ -116,13 +118,6 @@ static int do_epoll_create(struct uk_alloc *a, int flags) if (unlikely(flags & ~EPOLL_CLOEXEC)) return -EINVAL; - /* Reserve a file descriptor number */ - vfs_fd = vfscore_alloc_fd(); - if (unlikely(vfs_fd < 0)) { - ret = -ENFILE; - goto ERR_EXIT; - } - /* Allocate file, vfs_file, and vnode */ ep = uk_malloc(a, sizeof(struct eventpoll)); if (unlikely(!ep)) { @@ -155,7 +150,6 @@ static int do_epoll_create(struct uk_alloc *a, int flags) } /* Initialize data structures */ - vfs_file->fd = vfs_fd; vfs_file->f_flags = 0; vfs_file->f_count = 1; vfs_file->f_data = ep; @@ -171,9 +165,11 @@ static int do_epoll_create(struct uk_alloc *a, int flags) eventpoll_init(ep, a); /* Store within the vfs structure */ - ret = vfscore_install_fd(vfs_fd, vfs_file); - if (unlikely(ret)) + vfs_fd = uk_fdtab_legacy_open(vfs_file); + if (unlikely(vfs_fd < 0)) { + ret = vfs_fd; goto ERR_VFS_INSTALL; + } /* Only the dentry should hold a reference; release ours */ vput(vfs_vnode); @@ -189,8 +185,6 @@ ERR_ALLOC_VNODE: ERR_MALLOC_VFS_FILE: uk_free(a, ep); ERR_MALLOC_FILE: - vfscore_put_fd(vfs_fd); -ERR_EXIT: UK_ASSERT(ret < 0); return ret; } @@ -219,13 +213,13 @@ static int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) struct eventpoll *ep; int ret; - epf = vfscore_get_file(epfd); + epf = uk_fdtab_legacy_get(epfd); if (unlikely(!epf)) { ret = -EBADF; goto EXIT; } - fp = vfscore_get_file(fd); + fp = uk_fdtab_legacy_get(fd); if (unlikely(!fp)) { ret = -EBADF; goto ERR_PUT_EPF; @@ -290,7 +284,7 @@ static int do_epoll_pwait(int epfd, struct epoll_event *events, int maxevents, struct eventpoll *ep; int ret; - epf = vfscore_get_file(epfd); + epf = uk_fdtab_legacy_get(epfd); if (unlikely(!epf)) { ret = -EBADF; goto EXIT; diff --git a/lib/posix-event/eventfd.c b/lib/posix-event/eventfd.c index f26051998..4e399e651 100644 --- a/lib/posix-event/eventfd.c +++ b/lib/posix-event/eventfd.c @@ -47,6 +47,8 @@ #include #include +#include + #include #include #include @@ -350,13 +352,6 @@ static int do_eventfd(struct uk_alloc *a, unsigned int initval, int flags) if (unlikely(flags & ~(EFD_CLOEXEC | EFD_SEMAPHORE | EFD_NONBLOCK))) return -EINVAL; - /* Reserve a file descriptor number */ - vfs_fd = vfscore_alloc_fd(); - if (unlikely(vfs_fd < 0)) { - ret = -ENFILE; - goto ERR_EXIT; - } - /* Allocate file, vfs_file, and vnode */ efd = uk_malloc(a, sizeof(struct eventfd)); if (unlikely(!efd)) { @@ -388,7 +383,6 @@ static int do_eventfd(struct uk_alloc *a, unsigned int initval, int flags) } /* Initialize data structures */ - vfs_file->fd = vfs_fd; vfs_file->f_flags = UK_FREAD | UK_FWRITE; vfs_file->f_count = 1; vfs_file->f_data = efd; @@ -405,9 +399,11 @@ static int do_eventfd(struct uk_alloc *a, unsigned int initval, int flags) eventfd_init(efd, initval, flags); /* Store within the vfs structure */ - ret = vfscore_install_fd(vfs_fd, vfs_file); - if (unlikely(ret)) + vfs_fd = uk_fdtab_legacy_open(vfs_file); + if (unlikely(vfs_fd < 0)) { + ret = vfs_fd; goto ERR_VFS_INSTALL; + } /* Only the dentry should hold a reference; release ours */ vput(vfs_vnode); @@ -431,8 +427,6 @@ ERR_ALLOC_VNODE: ERR_MALLOC_VFS_FILE: uk_free(a, efd); ERR_MALLOC_FILE: - vfscore_put_fd(vfs_fd); -ERR_EXIT: UK_ASSERT(ret < 0); return ret; } diff --git a/lib/posix-fdtab/Makefile.uk b/lib/posix-fdtab/Makefile.uk index 80ef19bc9..d3df9db3f 100644 --- a/lib/posix-fdtab/Makefile.uk +++ b/lib/posix-fdtab/Makefile.uk @@ -4,3 +4,8 @@ CINCLUDES-$(CONFIG_LIBPOSIX_FDTAB) += -I$(LIBPOSIX_FDTAB_BASE)/include CXXINCLUDES-$(CONFIG_LIBPOSIX_FDTAB) += -I$(LIBPOSIX_FDTAB_BASE)/include LIBPOSIX_FDTAB_SRCS-y += $(LIBPOSIX_FDTAB_BASE)/fdtab.c + +UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDTAB) += close-1 +UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDTAB) += dup-1 +UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDTAB) += dup3-3 +UK_PROVIDED_SYSCALLS-$(CONFIG_LIBPOSIX_FDTAB) += dup2-2 diff --git a/lib/posix-fdtab/fdtab.c b/lib/posix-fdtab/fdtab.c index 27a3f3fd2..2510556ed 100644 --- a/lib/posix-fdtab/fdtab.c +++ b/lib/posix-fdtab/fdtab.c @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -457,3 +458,25 @@ int uk_sys_dup(int oldfd) { return uk_sys_dup_min(oldfd, 0, 0); } + +/* Userspace Syscalls */ + +UK_SYSCALL_R_DEFINE(int, close, int, fd) +{ + return uk_sys_close(fd); +} + +UK_SYSCALL_R_DEFINE(int, dup, int, oldfd) +{ + return uk_sys_dup(oldfd); +} + +UK_SYSCALL_R_DEFINE(int, dup2, int, oldfd, int, newfd) +{ + return uk_sys_dup2(oldfd, newfd); +} + +UK_SYSCALL_R_DEFINE(int, dup3, int, oldfd, int, newfd, int, flags) +{ + return uk_sys_dup3(oldfd, newfd, flags); +} diff --git a/lib/posix-socket/socket_vnops.c b/lib/posix-socket/socket_vnops.c index 15c43b2a3..b0e713203 100644 --- a/lib/posix-socket/socket_vnops.c +++ b/lib/posix-socket/socket_vnops.c @@ -49,6 +49,8 @@ #include #include +#include + static struct mount posix_socket_mount; static uint64_t s_inode; @@ -58,7 +60,7 @@ posix_socket_file_get(int sock_fd) { struct vfscore_file *fos; - fos = vfscore_get_file(sock_fd); + fos = uk_fdtab_legacy_get(sock_fd); if (unlikely(!fos)) return ERR2PTR(-ENOENT); @@ -82,13 +84,6 @@ posix_socket_alloc_fd(struct posix_socket_driver *d, int type, void *sock_data) struct dentry *vfs_dentry; struct vnode *vfs_vnode; - /* Reserve file descriptor number */ - vfs_fd = vfscore_alloc_fd(); - if (unlikely(vfs_fd < 0)) { - ret = -ENFILE; - goto ERR_EXIT; - } - /* Allocate file, vfs_file, and vnode */ sock = uk_calloc(d->allocator, 1, sizeof(*sock)); if (unlikely(!sock)) { @@ -118,7 +113,6 @@ posix_socket_alloc_fd(struct posix_socket_driver *d, int type, void *sock_data) } /* Put things together, and fill out necessary fields */ - vfs_file->fd = vfs_fd; vfs_file->f_flags = UK_FWRITE | UK_FREAD; vfs_file->f_count = 1; vfs_file->f_data = sock; @@ -137,9 +131,11 @@ posix_socket_alloc_fd(struct posix_socket_driver *d, int type, void *sock_data) sock->type = type; /* Store within the vfs structure */ - ret = vfscore_install_fd(vfs_fd, vfs_file); - if (unlikely(ret)) + vfs_fd = uk_fdtab_legacy_open(vfs_file); + if (unlikely(vfs_fd < 0)) { + ret = vfs_fd; goto ERR_VFS_INSTALL; + } /* Only the dentry should hold a reference; release ours */ vput(vfs_vnode); @@ -159,8 +155,6 @@ ERR_ALLOC_VNODE: ERR_MALLOC_VFS_FILE: uk_free(d->allocator, sock); ERR_MALLOC_FILE: - vfscore_put_fd(vfs_fd); -ERR_EXIT: UK_ASSERT(ret < 0); return ret; } diff --git a/lib/vfscore/Config.uk b/lib/vfscore/Config.uk index 659a66ed8..b703bda6c 100644 --- a/lib/vfscore/Config.uk +++ b/lib/vfscore/Config.uk @@ -5,6 +5,8 @@ menuconfig LIBVFSCORE select LIBUKDEBUG select LIBUKLOCK select LIBPOSIX_TIME + select LIBPOSIX_FDTAB + select LIBPOSIX_FDTAB_LEGACY_SHIM if LIBVFSCORE config LIBVFSCORE_PIPE_SIZE_ORDER diff --git a/lib/vfscore/Makefile.uk b/lib/vfscore/Makefile.uk index 6c9fd54e8..0d1b2be27 100644 --- a/lib/vfscore/Makefile.uk +++ b/lib/vfscore/Makefile.uk @@ -31,7 +31,6 @@ UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += read-3 readv-3 pread64-4 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += fstat-2 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += fcntl-3 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += readlink-3 -UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += close-1 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += lseek-3 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += link-2 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += ftruncate-2 @@ -43,9 +42,6 @@ UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += chdir-1 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += fchdir-1 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += chmod-2 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += fchmod-2 -UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += dup-1 -UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += dup3-3 -UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += dup2-2 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += pwritev-4 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += utime-2 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += utimes-2 diff --git a/lib/vfscore/exportsyms.uk b/lib/vfscore/exportsyms.uk index 5d0f59763..d25c6cc48 100644 --- a/lib/vfscore/exportsyms.uk +++ b/lib/vfscore/exportsyms.uk @@ -26,8 +26,6 @@ write uk_syscall_e_write uk_syscall_r_write close -uk_syscall_e_close -uk_syscall_r_close read uk_syscall_e_read uk_syscall_r_read diff --git a/lib/vfscore/fd.c b/lib/vfscore/fd.c index d4a4ddd38..a83bd3fda 100644 --- a/lib/vfscore/fd.c +++ b/lib/vfscore/fd.c @@ -44,126 +44,14 @@ #include #endif /* CONFIG_LIBPOSIX_PROCESS_CLONE */ -int init_stdio(void); - -struct fdtable { - unsigned long bitmap[UK_BITS_TO_LONGS(FDTABLE_MAX_FILES)]; - uint32_t fd_start; - struct vfscore_file *files[FDTABLE_MAX_FILES]; -}; -struct fdtable fdtable; - -int vfscore_alloc_fd(void) -{ - unsigned long flags; - int ret; - - flags = ukplat_lcpu_save_irqf(); - ret = uk_find_next_zero_bit(fdtable.bitmap, FDTABLE_MAX_FILES, 0); - - if (ret == FDTABLE_MAX_FILES) { - ret = -ENFILE; - goto exit; - } - - uk_bitmap_set(fdtable.bitmap, ret, 1); - -exit: - ukplat_lcpu_restore_irqf(flags); - return ret; -} - -int vfscore_reserve_fd(int fd) -{ - unsigned long flags; - int ret = 0; - - flags = ukplat_lcpu_save_irqf(); - if (uk_test_bit(fd, fdtable.bitmap)) { - ret = -EBUSY; - goto exit; - } - - uk_bitmap_set(fdtable.bitmap, fd, 1); - -exit: - ukplat_lcpu_restore_irqf(flags); - return ret; -} - -int vfscore_put_fd(int fd) -{ - struct vfscore_file *fp; - unsigned long flags; - - UK_ASSERT(fd < (int) FDTABLE_MAX_FILES); - - /* FIXME Currently it is not allowed to free std(in|out|err): - * if (fd <= 2) return -EBUSY; - * - * However, returning -EBUSY in this case breaks dup2 with stdin, out, - * err. Ignoring this should be fine as long as those are not fdrop-ed - * twice, in which case the static fp would be freed, and here be - * dragons. - */ - - flags = ukplat_lcpu_save_irqf(); - uk_bitmap_clear(fdtable.bitmap, fd, 1); - fp = fdtable.files[fd]; - fdtable.files[fd] = NULL; - ukplat_lcpu_restore_irqf(flags); - - /* - * Since we can alloc a fd without assigning a - * vfsfile we must protect against NULL ptr - */ - if (fp) - fdrop(fp); - - return 0; -} - -int vfscore_install_fd(int fd, struct vfscore_file *file) -{ - unsigned long flags; - struct vfscore_file *orig; - - if ((fd >= (int) FDTABLE_MAX_FILES) || (!file)) - return -EBADF; - - fhold(file); - - file->fd = fd; +#include - flags = ukplat_lcpu_save_irqf(); - orig = fdtable.files[fd]; - fdtable.files[fd] = file; - ukplat_lcpu_restore_irqf(flags); - - fdrop(file); - - if (orig) - fdrop(orig); +int init_stdio(void); - return 0; -} struct vfscore_file *vfscore_get_file(int fd) { - unsigned long flags; - struct vfscore_file *ret = NULL; - - UK_ASSERT(fd < (int) FDTABLE_MAX_FILES); - - flags = ukplat_lcpu_save_irqf(); - if (!uk_test_bit(fd, fdtable.bitmap)) - goto exit; - ret = fdtable.files[fd]; - fhold(ret); - -exit: - ukplat_lcpu_restore_irqf(flags); - return ret; + return uk_fdtab_legacy_get(fd); } void vfscore_put_file(struct vfscore_file *file) @@ -173,48 +61,29 @@ void vfscore_put_file(struct vfscore_file *file) int fget(int fd, struct vfscore_file **out_fp) { - int ret = 0; struct vfscore_file *fp = vfscore_get_file(fd); - if (!fp) - ret = EBADF; - else - *out_fp = fp; - - return ret; + return EBADF; + *out_fp = fp; + return 0; } int fdalloc(struct vfscore_file *fp, int *newfd) { - int fd, ret = 0; - - fd = vfscore_alloc_fd(); - if (fd < 0) { - ret = fd; - goto exit; - } - - fhold(fp); - - ret = vfscore_install_fd(fd, fp); - if (ret) - fdrop(fp); - else - *newfd = fd; - -exit: - return ret; + int r = uk_fdtab_legacy_open(fp); + if (r < 0) + return r; + *newfd = r; + return 0; } static int fdtable_init(void) { - memset(&fdtable, 0, sizeof(fdtable)); - return init_stdio(); } -uk_early_initcall_prio(fdtable_init, UK_PRIO_EARLIEST); +uk_early_initcall(fdtable_init); #if CONFIG_LIBPOSIX_PROCESS_CLONE static int uk_posix_clone_files(const struct clone_args *cl_args, diff --git a/lib/vfscore/include/vfscore/file.h b/lib/vfscore/include/vfscore/file.h index 910b37326..35fa6c69d 100644 --- a/lib/vfscore/include/vfscore/file.h +++ b/lib/vfscore/include/vfscore/file.h @@ -66,10 +66,6 @@ struct vfscore_file { #define FD_LOCK(fp) uk_mutex_lock(&(fp->f_lock)) #define FD_UNLOCK(fp) uk_mutex_unlock(&(fp->f_lock)) -int vfscore_alloc_fd(void); -int vfscore_reserve_fd(int fd); -int vfscore_put_fd(int fd); -int vfscore_install_fd(int fd, struct vfscore_file *file); struct vfscore_file *vfscore_get_file(int fd); void vfscore_put_file(struct vfscore_file *file); diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c index e0974feea..086ac5097 100644 --- a/lib/vfscore/main.c +++ b/lib/vfscore/main.c @@ -248,42 +248,6 @@ UK_SYSCALL_DEFINE(int, creat, const char*, pathname, mode_t, mode) LFS64(creat); -UK_TRACEPOINT(trace_vfs_close, "%d", int); -UK_TRACEPOINT(trace_vfs_close_ret, ""); -UK_TRACEPOINT(trace_vfs_close_err, "%d", int); - -int fdclose(int fd) -{ - struct vfscore_file *fp; - int error; - - fp = vfscore_get_file(fd); - if (!fp) - return EBADF; - - error = vfscore_put_fd(fd); - if (!error) - fdrop(fp); - - return error; -} - -UK_SYSCALL_R_DEFINE(int, close, int, fd) -{ - int error; - - trace_vfs_close(fd); - error = fdclose(fd); - if (error) - goto out_error; - - trace_vfs_close_ret(); - return 0; - - out_error: - trace_vfs_close_err(error); - return -error; -} UK_TRACEPOINT(trace_vfs_mknod, "\"%s\" 0%0o %#x", const char*, mode_t, dev_t); UK_TRACEPOINT(trace_vfs_mknod_ret, ""); @@ -2066,110 +2030,6 @@ out_error: return ERR2PTR(-error); } -UK_TRACEPOINT(trace_vfs_dup, "%d", int); -UK_TRACEPOINT(trace_vfs_dup_ret, "\"%s\"", int); -UK_TRACEPOINT(trace_vfs_dup_err, "%d", int); -/* - * Duplicate a file descriptor - */ -UK_SYSCALL_R_DEFINE(int, dup, int, oldfd) -{ - struct vfscore_file *fp; - int newfd; - int error; - - trace_vfs_dup(oldfd); - error = fget(oldfd, &fp); - if (error) - goto out_error; - - error = fdalloc(fp, &newfd); - if (error) - goto out_fdrop; - - fdrop(fp); - trace_vfs_dup_ret(newfd); - return newfd; - - out_fdrop: - fdrop(fp); - - out_error: - trace_vfs_dup_err(error); - if (error > 0) - return -error; - return error; -} - -UK_TRACEPOINT(trace_vfs_dup3, "%d %d %#x", int, int, int); -UK_TRACEPOINT(trace_vfs_dup3_ret, "%d", int); -UK_TRACEPOINT(trace_vfs_dup3_err, "%d", int); -/* - * Duplicate a file descriptor to a particular value. - */ -UK_SYSCALL_R_DEFINE(int, dup3, int, oldfd, int, newfd, int, flags) -{ - struct vfscore_file *fp; - int error; - - trace_vfs_dup3(oldfd, newfd, flags); - /* - * Don't allow any argument but O_CLOEXEC. But we even ignore - * that as we don't support exec() and thus don't care. - */ - if ((flags & ~O_CLOEXEC) != 0) { - error = EINVAL; - goto out_error; - } - - if (oldfd == newfd) { - error = EINVAL; - goto out_error; - } - - error = fget(oldfd, &fp); - if (error) - goto out_error; - - /* BUG: The close and reserve operation must be atomic */ - error = uk_syscall_r_close(newfd); - if (error && error != -EBADF) - goto out_error_drop; - - error = vfscore_reserve_fd(newfd); - if (error) - goto out_error_drop; - - error = vfscore_install_fd(newfd, fp); - if (error) - goto out_error_drop; - - trace_vfs_dup3_ret(newfd); - return newfd; - -out_error_drop: - fdrop(fp); -out_error: - trace_vfs_dup3_err(error); - return (error > 0) ? -error : error; -} - -UK_SYSCALL_R_DEFINE(int, dup2, int, oldfd, int, newfd) -{ - struct vfscore_file *fp; - int error; - - if (unlikely(oldfd == newfd)) { - error = fget(oldfd, &fp); - if (unlikely(error)) - return -error; - - fdrop(fp); - return newfd; - } - - return uk_syscall_r_dup3(oldfd, newfd, 0); -} /* * The file control system call. diff --git a/lib/vfscore/pipe.c b/lib/vfscore/pipe.c index 3b24cb52e..d0cf93e71 100644 --- a/lib/vfscore/pipe.c +++ b/lib/vfscore/pipe.c @@ -49,6 +49,8 @@ #include #include +#include + /* We use the default size in Linux kernel */ #define PIPE_MAX_SIZE (1 << CONFIG_LIBVFSCORE_PIPE_SIZE_ORDER) @@ -590,13 +592,6 @@ static int pipe_fd_alloc(struct pipe_file *pipe_file, int flags) struct dentry *p_dentry; struct vnode *p_vnode; - /* Reserve file descriptor number */ - vfs_fd = vfscore_alloc_fd(); - if (vfs_fd < 0) { - ret = -ENFILE; - goto ERR_EXIT; - } - /* Allocate file, dentry, and vnode */ vfs_file = calloc(1, sizeof(*vfs_file)); if (!vfs_file) { @@ -621,9 +616,8 @@ static int pipe_fd_alloc(struct pipe_file *pipe_file, int flags) } /* Fill out necessary fields. */ - vfs_file->fd = vfs_fd; vfs_file->f_flags = flags; - vfs_file->f_count = 1; + vfs_file->f_count = 0; vfs_file->f_data = pipe_file; vfs_file->f_dentry = p_dentry; vfs_file->f_vfs_flags = UK_VFSCORE_NOPOS; @@ -635,9 +629,11 @@ static int pipe_fd_alloc(struct pipe_file *pipe_file, int flags) p_vnode->v_type = VFIFO; /* Assign the file descriptors to the corresponding vfs_file. */ - ret = vfscore_install_fd(vfs_fd, vfs_file); - if (ret) + vfs_fd = uk_fdtab_legacy_open(vfs_file); + if (vfs_fd < 0) { + ret = vfs_fd; goto ERR_VFS_INSTALL; + } /* Only the dentry should hold a reference; release ours */ vrele(p_vnode); @@ -651,8 +647,6 @@ ERR_ALLOC_DENTRY: ERR_ALLOC_VNODE: free(vfs_file); ERR_MALLOC_VFS_FILE: - vfscore_put_fd(vfs_fd); -ERR_EXIT: UK_ASSERT(ret < 0); return ret; } @@ -685,7 +679,7 @@ UK_SYSCALL_R_DEFINE(int, pipe, int*, pipefd) return ret; ERR_W_FD: - vfscore_put_fd(r_fd); + uk_syscall_r_close(r_fd); ERR_VFS_INSTALL: pipe_file_free(pipe_file); ERR_EXIT: diff --git a/lib/vfscore/stdio.c b/lib/vfscore/stdio.c index 431dd4ffd..ed53f9fb2 100644 --- a/lib/vfscore/stdio.c +++ b/lib/vfscore/stdio.c @@ -46,6 +46,8 @@ #include #include +#include + /* * When the syscall_shim library is not part of the build, there is warning * of implicit declaration of uk_syscall_r_dup2. @@ -233,12 +235,11 @@ int init_stdio(void) { int fd; - fd = vfscore_alloc_fd(); + fd = uk_fdtab_legacy_open(&stdio_file); if (fd != 0) { - uk_pr_crit("failed to allocate fd for stdin (fd=0)\n"); + uk_pr_crit("failed to allocate fd for stdin (fd=%d)\n", fd); return (fd < 0) ? fd : -EBADF; } - vfscore_install_fd(0, &stdio_file); fd = uk_syscall_r_dup3(0, 1, 0); if (fd != 1) {