Fix wasi openat (#191)

* Fix wasi openat

* add / to wasi (as ./)

* tiny cosmetic change
extensions
Giovanni Petrantoni 4 years ago committed by GitHub
parent 6dec21d694
commit 8fbe8d7fc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -68,18 +68,20 @@ typedef struct wasi_iovec_t
__wasi_size_t buf_len;
} wasi_iovec_t;
#define PREOPEN_CNT 4
#define PREOPEN_CNT 5
typedef struct Preopen {
int fd;
const char* path;
const char* real_path;
} Preopen;
Preopen preopen[PREOPEN_CNT] = {
{ 0, "<stdin>" },
{ 1, "<stdout>" },
{ 2, "<stderr>" },
{ -1, "./" },
{ 0, "<stdin>" , "" },
{ 1, "<stdout>", "" },
{ 2, "<stderr>", "" },
{ -1, "./" , "./" },
{ -1, "/" , "./" },
};
static
@ -448,7 +450,7 @@ m3ApiRawFunction(m3_wasi_unstable_path_open)
flags |= O_RDONLY; // no-op because O_RDONLY is 0
}
int mode = 0644;
int host_fd = openat (dirfd, host_path, flags, mode);
int host_fd = openat (preopen[dirfd].fd, host_path, flags, mode);
if (host_fd < 0)
{
@ -680,7 +682,7 @@ M3Result m3_LinkWASI (IM3Module module)
#else
// Preopen dirs
for (int i = 3; i < PREOPEN_CNT; i++) {
preopen[i].fd = open(preopen[i].path, O_RDONLY);
preopen[i].fd = open(preopen[i].real_path, O_RDONLY);
}
#endif

Loading…
Cancel
Save