Skip to content

Commit 21329a1

Browse files
QuantumSegfaultthewilsonator
authored andcommitted
druntime: Use WASIp1 directly instead of POSIX emulation
1 parent 24f8e10 commit 21329a1

4 files changed

Lines changed: 1839 additions & 44 deletions

File tree

druntime/src/core/internal/abort.d

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,16 @@ void abort(scope string msg, scope string filename = __FILE__, size_t line = __L
4242
}
4343
}
4444
else version (WASIp1) {
45-
// currently depends on wasi-libc being linked in to provide these "syscalls"
46-
// TODO: detach this from wasi-libc
47-
alias ushort __wasi_errno_t;
48-
alias int __wasi_fd_t;
49-
alias size_t __wasi_size_t;
50-
51-
extern(C) struct __wasi_ciovec_t {
52-
const(ubyte)* buf;
53-
__wasi_size_t buf_len;
54-
}
55-
56-
pragma(mangle, "__wasi_fd_write")
57-
extern(C) static __wasi_errno_t
58-
__wasi_fd_write(__wasi_fd_t fd,
59-
const __wasi_ciovec_t *iovs,
60-
size_t iovs_len, __wasi_size_t *retptr0) @nogc nothrow;
45+
import core.sys.wasi.p1 : CIOVec, fdWrite;
6146

6247
static void writeStr(scope const(char)[][] m...) @nogc nothrow @trusted
6348
{
6449
foreach (s; m) {
65-
__wasi_ciovec_t iovec;
66-
__wasi_size_t ret;
67-
iovec.buf = cast(const(ubyte)*)s.ptr;
68-
iovec.buf_len = s.length;
69-
cast(void)__wasi_fd_write(2, &iovec, 1, &ret);
50+
CIOVec[1] iovecs;
51+
size_t bytesWritten;
52+
iovecs[0].buf = cast(const(ubyte)*)s.ptr;
53+
iovecs[0].bufLen = s.length;
54+
cast(void)fdWrite(2, iovecs[], bytesWritten);
7055
}
7156
}
7257
} else version (WASIp2) {

0 commit comments

Comments
 (0)