Skip to content

Commit

Permalink
Get VFS jart#76 to build
Browse files Browse the repository at this point in the history
  • Loading branch information
jart authored and trungnt2910 committed Mar 8, 2023
1 parent d78a7d1 commit dc49c0f
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 216 deletions.
29 changes: 7 additions & 22 deletions blink/hostfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/errno.h>
#include <string.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
Expand Down Expand Up @@ -176,15 +177,13 @@ int HostfsCreateInfo(struct HostfsInfo **output) {
}

int HostfsGetHostPath(struct VfsInfo *info, char **output) {
struct HostfsInfo *hostfsinfo;
struct HostfsDevice *hostfsdevice;
char *path, *hostpath;
size_t pathlen, sourcelen;
if (info == NULL) {
efault();
return -1;
}
hostfsinfo = (struct HostfsInfo *)info->data;
hostfsdevice = (struct HostfsDevice *)info->device->data;
if (VfsPathBuild(info, info->device->root, &path) == -1) {
return -1;
Expand All @@ -210,9 +209,7 @@ int HostfsGetHostPath(struct VfsInfo *info, char **output) {

int HostfsGetDirFd(struct VfsInfo *dir) {
struct HostfsInfo *dirinfo;
struct HostfsDevice *hostfsdevice;
char *path, *hostpath;
size_t pathlen, sourcelen;
char *hostpath;
int ret = -1;
if (dir == NULL) {
efault();
Expand All @@ -223,7 +220,6 @@ int HostfsGetDirFd(struct VfsInfo *dir) {
return -1;
}
dirinfo = (struct HostfsInfo *)dir->data;
hostfsdevice = (struct HostfsDevice *)dir->device->data;
if (dirinfo->filefd != -1) {
return dup(dirinfo->filefd);
} else {
Expand Down Expand Up @@ -556,7 +552,6 @@ int HostfsUnlink(struct VfsInfo *parent, const char *name, int flags) {

ssize_t HostfsRead(struct VfsInfo *info, void *buf, size_t size) {
struct HostfsInfo *hostinfo;
ssize_t rc;
VFS_LOGF("HostfsRead(%p, %p, %ld)", info, buf, size);
if (info == NULL || buf == NULL) {
return efault();
Expand All @@ -567,7 +562,6 @@ ssize_t HostfsRead(struct VfsInfo *info, void *buf, size_t size) {

ssize_t HostfsWrite(struct VfsInfo *info, const void *buf, size_t size) {
struct HostfsInfo *hostinfo;
ssize_t rc;
VFS_LOGF("HostfsWrite(%p, %p, %ld)", info, buf, size);
if (info == NULL || buf == NULL) {
return efault();
Expand All @@ -579,7 +573,6 @@ ssize_t HostfsWrite(struct VfsInfo *info, const void *buf, size_t size) {
ssize_t HostfsPread(struct VfsInfo *info, void *buf, size_t size,
off_t offset) {
struct HostfsInfo *hostinfo;
ssize_t rc;
VFS_LOGF("HostfsPread(%p, %p, %ld, %ld)", info, buf, size, offset);
if (info == NULL || buf == NULL) {
return efault();
Expand All @@ -591,7 +584,6 @@ ssize_t HostfsPread(struct VfsInfo *info, void *buf, size_t size,
ssize_t HostfsPwrite(struct VfsInfo *info, const void *buf, size_t size,
off_t offset) {
struct HostfsInfo *hostinfo;
ssize_t rc;
VFS_LOGF("HostfsPwrite(%p, %p, %ld, %ld)", info, buf, size, offset);
if (info == NULL || buf == NULL) {
return efault();
Expand All @@ -602,7 +594,6 @@ ssize_t HostfsPwrite(struct VfsInfo *info, const void *buf, size_t size,

ssize_t HostfsReadv(struct VfsInfo *info, const struct iovec *iov, int iovcnt) {
struct HostfsInfo *hostinfo;
ssize_t rc;
VFS_LOGF("HostfsReadv(%p, %p, %d)", info, iov, iovcnt);
if (info == NULL || iov == NULL) {
return efault();
Expand All @@ -614,7 +605,6 @@ ssize_t HostfsReadv(struct VfsInfo *info, const struct iovec *iov, int iovcnt) {
ssize_t HostfsWritev(struct VfsInfo *info, const struct iovec *iov,
int iovcnt) {
struct HostfsInfo *hostinfo;
ssize_t rc;
VFS_LOGF("HostfsWritev(%p, %p, %d)", info, iov, iovcnt);
if (info == NULL || iov == NULL) {
return efault();
Expand All @@ -626,7 +616,6 @@ ssize_t HostfsWritev(struct VfsInfo *info, const struct iovec *iov,
ssize_t HostfsPreadv(struct VfsInfo *info, const struct iovec *iov, int iovcnt,
off_t offset) {
struct HostfsInfo *hostinfo;
ssize_t rc;
VFS_LOGF("HostfsPreadv(%p, %p, %d, %ld)", info, iov, iovcnt, offset);
if (info == NULL || iov == NULL) {
return efault();
Expand All @@ -638,7 +627,6 @@ ssize_t HostfsPreadv(struct VfsInfo *info, const struct iovec *iov, int iovcnt,
ssize_t HostfsPwritev(struct VfsInfo *info, const struct iovec *iov, int iovcnt,
off_t offset) {
struct HostfsInfo *hostinfo;
ssize_t rc;
VFS_LOGF("HostfsPwritev(%p, %p, %d, %ld)", info, iov, iovcnt, offset);
if (info == NULL || iov == NULL) {
return efault();
Expand Down Expand Up @@ -779,7 +767,6 @@ int HostfsIoctl(struct VfsInfo *info, unsigned long request, const void *arg) {

int HostfsDup(struct VfsInfo *info, struct VfsInfo **newinfo) {
struct HostfsInfo *hostinfo, *newhostinfo;
int rc;
VFS_LOGF("HostfsDup(%p, %p)", info, newinfo);
if (info == NULL || newinfo == NULL) {
return efault();
Expand Down Expand Up @@ -837,7 +824,6 @@ int HostfsDup(struct VfsInfo *info, struct VfsInfo **newinfo) {
#ifdef HAVE_DUP3
int HostfsDup3(struct VfsInfo *info, struct VfsInfo **newinfo, int flags) {
struct HostfsInfo *hostinfo, *newhostinfo;
int rc;
VFS_LOGF("HostfsDup3(%p, %p, %i)", info, newinfo, flags);
if (info == NULL || newinfo == NULL) {
return efault();
Expand Down Expand Up @@ -1046,7 +1032,7 @@ int HostfsConnect(struct VfsInfo *info, const struct sockaddr *addr,

int HostfsConnectUnix(struct VfsInfo *sock, struct VfsInfo *info,
const struct sockaddr_un *addr, socklen_t addrlen) {
struct HostfsInfo *hostinfo, *sockinfo;
struct HostfsInfo *hostinfo;
struct sockaddr_un *hostun;
socklen_t hostlen;
char *hostpath;
Expand Down Expand Up @@ -1163,7 +1149,7 @@ ssize_t HostfsSendmsg(struct VfsInfo *info, const struct msghdr *msg,

ssize_t HostfsRecvmsgUnix(struct VfsInfo *sock, struct VfsInfo *info,
struct msghdr *msg, int flags) {
struct HostfsInfo *hostinfo, *sockinfo;
struct HostfsInfo *hostinfo;
struct sockaddr_un *hostun, *oldun;
socklen_t hostlen, oldlen;
char *hostpath;
Expand Down Expand Up @@ -1200,7 +1186,7 @@ ssize_t HostfsRecvmsgUnix(struct VfsInfo *sock, struct VfsInfo *info,

ssize_t HostfsSendmsgUnix(struct VfsInfo *sock, struct VfsInfo *info,
const struct msghdr *msg, int flags) {
struct HostfsInfo *hostinfo, *sockinfo;
struct HostfsInfo *hostinfo;
struct msghdr newmsg;
struct sockaddr_un *hostun;
socklen_t hostlen;
Expand Down Expand Up @@ -1262,7 +1248,6 @@ int HostfsGetsockname(struct VfsInfo *info, struct sockaddr *addr,
struct HostfsInfo *hostinfo;
struct sockaddr_un *un;
char *path;
socklen_t len;
VFS_LOGF("HostfsGetsockname(%p, %p, %p)", info, addr, addrlen);
if (info == NULL || addr == NULL || addrlen == NULL) {
return efault();
Expand Down Expand Up @@ -1296,7 +1281,7 @@ int HostfsGetpeername(struct VfsInfo *info, struct sockaddr *addr,
socklen_t *addrlen) {
struct HostfsInfo *hostinfo;
struct sockaddr_un *hostun;
socklen_t hostlen = sizeof(hostun);
socklen_t hostlen = sizeof(*hostun);
char *s;
VFS_LOGF("HostfsGetpeername(%p, %p, %p)", info, addr, addrlen);
if (info == NULL || addr == NULL || addrlen == NULL) {
Expand Down
41 changes: 21 additions & 20 deletions blink/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,7 @@ static i64 SysSendfile(struct Machine *m, i32 out_fd, i32 in_fd, i64 offsetaddr,
return eoverflow();
}
}
for (toto = 0; toto < count; ) {
for (toto = 0; toto < count;) {
chunk = MIN(count - toto, maxchunk);
if (offsetp) {
got = VfsPread(in_fd, buf, chunk, offset + toto);
Expand Down Expand Up @@ -2781,7 +2781,7 @@ static int XlatFaccessatFlags(int x) {
static int SysFaccessat2(struct Machine *m, i32 dirfd, i64 path, i32 mode,
i32 flags) {
return VfsAccess(GetDirFildes(dirfd), LoadStr(m, path), XlatAccess(mode),
XlatFaccessatFlags(flags));
XlatFaccessatFlags(flags));
}

static int SysFaccessat(struct Machine *m, i32 dirfd, i64 path, i32 mode) {
Expand Down Expand Up @@ -2844,8 +2844,8 @@ static int SysFstatat(struct Machine *m, i32 dirfd, i64 pathaddr, i64 staddr,
}
#endif
#endif
if ((rc = VfsStat(GetDirFildes(dirfd), path, &st,
XlatFstatatFlags(flags))) != -1) {
if ((rc = VfsStat(GetDirFildes(dirfd), path, &st, XlatFstatatFlags(flags))) !=
-1) {
XlatStatToLinux(&gst, &st);
if (CopyToUserWrite(m, staddr, &gst, sizeof(gst)) == -1) rc = -1;
}
Expand Down Expand Up @@ -2899,7 +2899,7 @@ static int SysFchownat(struct Machine *m, i32 dirfd, i64 pathaddr, u32 uid,
#endif
#endif
return VfsChown(GetDirFildes(dirfd), path, uid, gid,
XlatFchownatFlags(flags));
XlatFchownatFlags(flags));
}

static int SysChown(struct Machine *m, i64 pathaddr, u32 uid, u32 gid) {
Expand Down Expand Up @@ -2967,9 +2967,9 @@ static int CheckSyncable(int fildes) {
// question though is if FreeBSD actually does something here.
struct stat st;
if (!VfsFstat(fildes, &st) && //
(S_ISCHR(st.st_mode) || //
S_ISFIFO(st.st_mode) || //
S_ISLNK(st.st_mode) || //
(S_ISCHR(st.st_mode) || //
S_ISFIFO(st.st_mode) || //
S_ISLNK(st.st_mode) || //
S_ISSOCK(st.st_mode))) {
return einval();
}
Expand Down Expand Up @@ -3300,8 +3300,8 @@ static ssize_t SysReadlinkat(struct Machine *m, int dirfd, i64 path,
// implementations (e.g. Musl) consider it to be posixly incorrect.
if (bufsiz <= 0) return einval();
if (!(buf = (char *)AddToFreeList(m, malloc(bufsiz)))) return -1;
if ((rc = VfsReadlink(GetDirFildes(dirfd), LoadStr(m, path), buf,
bufsiz)) != -1) {
if ((rc = VfsReadlink(GetDirFildes(dirfd), LoadStr(m, path), buf, bufsiz)) !=
-1) {
if (CopyToUserWrite(m, bufaddr, buf, rc) == -1) rc = -1;
}
return rc;
Expand All @@ -3327,7 +3327,7 @@ static int SysTruncate(struct Machine *m, i64 pathaddr, i64 length) {
static int SysSymlinkat(struct Machine *m, i64 targetpath, i32 newdirfd,
i64 linkpath) {
return VfsSymlink(LoadStr(m, targetpath), GetDirFildes(newdirfd),
LoadStr(m, linkpath));
LoadStr(m, linkpath));
}

static int SysSymlink(struct Machine *m, i64 targetpath, i64 linkpath) {
Expand Down Expand Up @@ -3443,7 +3443,7 @@ static int SysRenameat2(struct Machine *m, int srcdirfd, i64 srcpath,
return -1;
}
return VfsRename(GetDirFildes(srcdirfd), LoadStr(m, srcpath),
GetDirFildes(dstdirfd), dstpath);
GetDirFildes(dstdirfd), dstpath);
}

static int SysRenameat(struct Machine *m, int srcdirfd, i64 srcpath,
Expand Down Expand Up @@ -3478,8 +3478,8 @@ static i32 SysLinkat(struct Machine *m, //
i64 newpath, //
i32 flags) {
return VfsLink(GetDirFildes(olddirfd), LoadStr(m, oldpath),
GetDirFildes(newdirfd), LoadStr(m, newpath),
XlatLinkatFlags(flags));
GetDirFildes(newdirfd), LoadStr(m, newpath),
XlatLinkatFlags(flags));
}

static int SysLink(struct Machine *m, i64 existingpath, i64 newpath) {
Expand Down Expand Up @@ -4398,11 +4398,10 @@ static i32 Select(struct Machine *m, //
int fildes, rc;
i32 setsize;
u64 oldmask_guest = 0;
sigset_t block, oldmask;
fd_set readfds, writefds, exceptfds, readyreadfds, readywritefds,
readyexceptfds;
struct pollfd hfds[1];
struct timespec *tp, now, wait, remain, deadline = {0};
struct timespec now, wait, remain, deadline = {0};
struct Fd *fd;
int (*poll_impl)(struct pollfd *, nfds_t, int);
if (timeoutp) {
Expand Down Expand Up @@ -4469,8 +4468,8 @@ static i32 Select(struct Machine *m, //
if (fd) {
hfds[0].fd = fildes;
hfds[0].events = ((FD_ISSET(fildes, &readfds) ? POLLIN : 0) |
(FD_ISSET(fildes, &writefds) ? POLLOUT : 0) |
(FD_ISSET(fildes, &exceptfds) ? POLLPRI : 0));
(FD_ISSET(fildes, &writefds) ? POLLOUT : 0) |
(FD_ISSET(fildes, &exceptfds) ? POLLPRI : 0));
switch (poll_impl(hfds, 1, 0)) {
case 0:
break;
Expand Down Expand Up @@ -4521,8 +4520,10 @@ static i32 Select(struct Machine *m, //
SIG_LOGF("sigmask pop %" PRIx64, m->sigmask);
}
if (rc != -1) {
if ((readfds_addr && SaveFdSet(m, nfds, &readyreadfds, readfds_addr) == -1) ||
(writefds_addr && SaveFdSet(m, nfds, &readywritefds, writefds_addr) == -1) ||
if ((readfds_addr &&
SaveFdSet(m, nfds, &readyreadfds, readfds_addr) == -1) ||
(writefds_addr &&
SaveFdSet(m, nfds, &readywritefds, writefds_addr) == -1) ||
(exceptfds_addr &&
SaveFdSet(m, nfds, &readyexceptfds, exceptfds_addr) == -1)) {
return -1;
Expand Down
Loading

0 comments on commit dc49c0f

Please sign in to comment.