Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Plan 9 support #58

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion w2c2/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ wasmCGetReturnType(
/* TODO: add support for multiple result values */
fprintf(stderr, "w2c2: unsupported function with multiple result values\n");
abort();
return NULL;
}
}

Expand Down Expand Up @@ -2575,7 +2576,7 @@ wasmCWriteFunctionCode(
}
case wasmOpcodeMiscPrefix: {
WasmMiscOpcode miscOpcode = 0;
MUST (leb128ReadU32(writer->code, &miscOpcode) > 0)
MUST (leb128ReadU32(writer->code, (U32*)&miscOpcode) > 0)

switch (miscOpcode) {
case wasmMiscOpcodeMemoryInit: {
Expand Down
2 changes: 2 additions & 0 deletions w2c2/opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ wasmOpcodeResultType(
wasmOpcodeDescription(opcode)
);
abort();
return 0;
}
}
}
Expand Down Expand Up @@ -772,6 +773,7 @@ wasmOpcodeParameter1Type(
wasmOpcodeDescription(opcode)
);
abort();
return 0;
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions w2c2/w2c2_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef signed long long int I64;
typedef float F32;
typedef double F64;

#define MUST(_) { if (!(_)) { return false; }; }
#define MUST(x) { if (!(x)) { return false; }; }

#define WASM_LITTLE_ENDIAN 0
#define WASM_BIG_ENDIAN 1
Expand Down Expand Up @@ -117,8 +117,10 @@ typedef double F64;
#define swap64(x) (x)
#endif

#ifdef _MSC_VER
#if defined(_MSC_VER)
#define W2C2_INLINE __inline
#elif defined(PLAN9)
#define W2C2_INLINE inline
#else
#define W2C2_INLINE __inline__
#endif
Expand Down
35 changes: 11 additions & 24 deletions wasi/wasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ wasiFDWrite(
));
}

iovecs[ciovecIndex].iov_base = memory->data + bufferPointer;
iovecs[ciovecIndex].iov_base = (void*)(memory->data + bufferPointer);
iovecs[ciovecIndex].iov_len = length;
}
}
Expand Down Expand Up @@ -804,7 +804,7 @@ wasiFDWrite(
temporaryBuffer[totalLength + i] = bufferStart[-i];
}

iovecs[ciovecIndex].iov_base = temporaryBuffer + totalLength;
iovecs[ciovecIndex].iov_base = (void*)(temporaryBuffer + totalLength);

totalLength += length;
if (wasiFD > 2) {
Expand Down Expand Up @@ -900,9 +900,9 @@ fdReadImpl(
U32 length = i32_load(memory, iovecPointer + 4);

#if WASM_ENDIAN == WASM_LITTLE_ENDIAN
iovecs[iovecIndex].iov_base = memory->data + bufferPointer;
iovecs[iovecIndex].iov_base = (void*)(memory->data + bufferPointer);
#elif WASM_ENDIAN == WASM_BIG_ENDIAN
iovecs[iovecIndex].iov_base = memoryStart - bufferPointer - length;
iovecs[iovecIndex].iov_base = (void*)(memoryStart - bufferPointer - length);
#endif
iovecs[iovecIndex].iov_len = length;
}
Expand All @@ -922,7 +922,7 @@ fdReadImpl(
{
U32 iovecIndex = 0;
for (; iovecIndex < iovecsCount; iovecIndex++) {
U8* base = iovecs[iovecIndex].iov_base;
U8* base = (U8*)iovecs[iovecIndex].iov_base;
U32 length = iovecs[iovecIndex].iov_len;
int i = 0;
for (; i < length / 2; i++) {
Expand Down Expand Up @@ -975,10 +975,8 @@ wasiFDRead(
}

static
W2C2_INLINE
ssize_t
wrapPositional(
ssize_t f(int, const struct iovec*, int),
preadvFallback(
int fd,
const struct iovec* iovecs,
int count,
Expand All @@ -995,7 +993,7 @@ wrapPositional(
return -1;
}

res = f(fd, iovecs, count);
res = readv(fd, iovecs, count);

currentErrno = errno;
if (lseek(fd, origLoc, SEEK_SET) == (off_t)-1) {
Expand All @@ -1009,17 +1007,6 @@ wrapPositional(
return res;
}

static
ssize_t
preadvFallback(
int fd,
const struct iovec* iovecs,
int count,
off_t offset
) {
return wrapPositional(readv, fd, iovecs, count, offset);
}

U32
wasiFDPread(
void* instance,
Expand Down Expand Up @@ -1479,7 +1466,7 @@ wasiFDReaddir(
}
}

#if !defined(_WIN32) && !defined(macintosh)
#if !defined(_WIN32) && !defined(macintosh) && !defined(PLAN9)
if (cookie != WASI_DIRCOOKIE_START) {
seekdir(descriptor.dir, (long)cookie);
}
Expand Down Expand Up @@ -1509,7 +1496,7 @@ wasiFDReaddir(
break;
}

#if !defined(_WIN32) && !defined(macintosh)
#if !defined(_WIN32) && !defined(macintosh) && !defined(PLAN9)
tell = telldir(descriptor.dir);
if (tell < 0) {
WASI_TRACE(("fd_readdir: telldir failed: %s", strerror(errno)));
Expand All @@ -1518,7 +1505,7 @@ wasiFDReaddir(
#endif

next = (U64)tell;
#if (defined(__MWERKS__) && defined(macintosh)) || defined(__MSDOS__)
#if defined(PLAN9) || (defined(__MWERKS__) && defined(macintosh)) || defined(__MSDOS__)
inode = 0;
#else
inode = entry->d_ino;
Expand Down Expand Up @@ -3805,7 +3792,7 @@ wasiRandomGet(
return WASI_ERRNO_SUCCESS;
}
}
#if defined(__MWERKS__) && defined(macintosh)
#if defined(PLAN9) || (defined(__MWERKS__) && defined(macintosh))
/* Fall back to rand */
{
U32 i = 0;
Expand Down
2 changes: 2 additions & 0 deletions wasi/wasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ typedef long ssize_t;
#include <sys/types.h>
#endif

#ifndef PLAN9
#include <limits.h>
#endif

#ifndef PATH_MAX
#define PATH_MAX 1024
Expand Down