Skip to content
Merged
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
1 change: 1 addition & 0 deletions druntime/src/core/demangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,7 @@ CXX_DEMANGLER getCXXDemangler() nothrow @trusted
version (Darwin) import core.sys.darwin.dlfcn : RTLD_DEFAULT;
version (Solaris) import core.sys.solaris.dlfcn : RTLD_DEFAULT;
version (Hurd) import core.sys.hurd.dlfcn : RTLD_DEFAULT;
version (CRuntime_WASI) import core.sys.posix.dlfcn : RTLD_DEFAULT;

if (auto found = cast(CXX_DEMANGLER) dlsym(RTLD_DEFAULT, "__cxa_demangle"))
atomicStore(__cxa_demangle, found);
Expand Down
88 changes: 0 additions & 88 deletions druntime/src/core/internal/abort.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,94 +41,6 @@ void abort(scope string msg, scope string filename = __FILE__, size_t line = __L
}
}
}
else version (WASIp1) {
// currently depends on wasi-libc being linked in to provide these "syscalls"
// TODO: detach this from wasi-libc
alias ushort __wasi_errno_t;
alias int __wasi_fd_t;
alias size_t __wasi_size_t;

extern(C) struct __wasi_ciovec_t {
const(ubyte)* buf;
__wasi_size_t buf_len;
}

pragma(mangle, "__wasi_fd_write")
extern(C) static __wasi_errno_t
__wasi_fd_write(__wasi_fd_t fd,
const __wasi_ciovec_t *iovs,
size_t iovs_len, __wasi_size_t *retptr0) @nogc nothrow;

static void writeStr(scope const(char)[][] m...) @nogc nothrow @trusted
{
foreach (s; m) {
__wasi_ciovec_t iovec;
__wasi_size_t ret;
iovec.buf = cast(const(ubyte)*)s.ptr;
iovec.buf_len = s.length;
cast(void)__wasi_fd_write(2, &iovec, 1, &ret);
}
}
} else version (WASIp2) {
// currently depends on wasi-libc being linked in to provide these "syscalls"
// TODO: detach this from wasi-libc
extern(C) struct wasip2_list_u8_t {
ubyte* ptr;
size_t len;
}
extern(C) struct streams_own_output_stream_t {
int __handle;
}
extern(C) struct streams_borrow_output_stream_t {
int __handle;
}
alias streams_own_output_stream_t stderr_own_output_stream_t;
extern(C) struct io_error_own_error_t {
int __handle;
}
alias io_error_own_error_t streams_own_error_t;

extern(C) struct streams_stream_error_t {
ubyte tag;

union Val {
streams_own_error_t last_operation_failed;
}
Val val;
}

pragma(mangle, "streams_output_stream_drop_own")
extern(C) static void streams_output_stream_drop_own(streams_own_output_stream_t handle) @nogc nothrow;
pragma(mangle, "streams_borrow_output_stream")
extern(C) static streams_borrow_output_stream_t streams_borrow_output_stream(streams_own_output_stream_t handle) @nogc nothrow;
pragma(mangle, "stderr_get_stderr")
extern(C) static stderr_own_output_stream_t stderr_get_stderr() @nogc nothrow;
pragma(mangle, "io_error_error_drop_own")
extern(C) static void io_error_error_drop_own(io_error_own_error_t handle) @nogc nothrow;
pragma(mangle, "streams_stream_error_free")
extern(C) static void streams_stream_error_free(streams_stream_error_t *ptr) @nogc nothrow;
pragma(mangle, "streams_method_output_stream_blocking_write_and_flush")
extern(C) static bool streams_method_output_stream_blocking_write_and_flush(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err) @nogc nothrow;

static void writeStr(scope const(char)[][] m...) @nogc nothrow @trusted
{
auto stderr_own = stderr_get_stderr();
scope(exit) streams_output_stream_drop_own(stderr_own);

auto stderr = streams_borrow_output_stream(stderr_own);

foreach (s; m) {
wasip2_list_u8_t contents;
contents.ptr = cast(ubyte*)s.ptr;
contents.len = s.length;
streams_stream_error_t err;
bool success = streams_method_output_stream_blocking_write_and_flush(stderr, &contents, &err);
if (!success) {
streams_stream_error_free(&err);
}
}
}
}
else
static assert(0, "Unsupported OS");

Expand Down
3 changes: 3 additions & 0 deletions druntime/src/core/internal/backtrace/dwarf.d
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ module core.internal.backtrace.dwarf;

version (Posix):

version (WASI) {}
else:

import core.internal.string;

version (OSX)
Expand Down
3 changes: 3 additions & 0 deletions druntime/src/core/internal/elf/io.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module core.internal.elf.io;

version (Posix):

version (WASI) {}
else:

import core.lifetime : move;
import core.memory : pageSize;
import core.stdc.stdlib : free, malloc;
Expand Down
12 changes: 8 additions & 4 deletions druntime/src/core/internal/gc/impl/conservative/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ module core.internal.gc.impl.conservative.gc;

/***************************************************/
version (WASI) {} // WASI is single-threaded
else version = COLLECT_PARALLEL; // parallel scanning
else
{
version = COLLECT_PARALLEL; // parallel scanning

version (Posix)
version = COLLECT_FORK;
version (Posix)
version = COLLECT_FORK;
}

import core.internal.gc.bits;
import core.internal.gc.os;
Expand Down Expand Up @@ -1786,7 +1789,8 @@ struct Gcx
usedSmallPages = usedLargePages = 0;
mappedPages = 0;
//printf("gcx = %p, self = %x\n", &this, self);
version (Posix)
version (WASI) {}
else version (Posix)
{
import core.sys.posix.pthread : pthread_atfork;
instance = &this;
Expand Down
4 changes: 4 additions & 0 deletions druntime/src/core/internal/gc/os.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ version (Windows)

//version = GC_Use_Alloc_Win32;
}
else version (WASI)
{
import core.stdc.stdlib : free, malloc;
}
else version (Posix)
{
version (OSX)
Expand Down
3 changes: 2 additions & 1 deletion druntime/src/core/runtime.d
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ void defaultTraceDeallocator(Throwable.TraceInfo info) nothrow
}

/// Default implementation for most POSIX systems
version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo
version (WASI) {}
else version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo
{
import core.demangle;
import core.stdc.stdlib : free;
Expand Down
31 changes: 0 additions & 31 deletions druntime/src/core/stdc/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -182,37 +182,6 @@ else version (Posix)
alias cpp_ulonglong = ulong;
}
}
else version (WASI)
{
static if ( (void*).sizeof > int.sizeof )
{
enum __c_longlong : long;
enum __c_ulonglong : ulong;

alias c_long = long;
alias c_ulong = ulong;

alias cpp_long = long;
alias cpp_ulong = ulong;

alias cpp_longlong = __c_longlong;
alias cpp_ulonglong = __c_ulonglong;
}
else
{
enum __c_long : int;
enum __c_ulong : uint;

alias c_long = int;
alias c_ulong = uint;

alias cpp_long = __c_long;
alias cpp_ulong = __c_ulong;

alias cpp_longlong = long;
alias cpp_ulonglong = ulong;
}
}

version (GNU)
alias c_long_double = real;
Expand Down
2 changes: 1 addition & 1 deletion druntime/src/core/stdc/limits.d
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ else version (CRuntime_WASI)
///
enum PATH_MAX = 256;
///
enum PIPE_BUF = 512;
enum PIPE_BUF = 4096;
}
else
static assert(0, "unsupported OS");
32 changes: 17 additions & 15 deletions druntime/src/core/stdc/signal.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ nothrow:

// this should be volatile
///
version (CRuntime_WASI) {
version (CRuntime_WASI)
{
import core.stdc.config : c_long;
alias c_long sig_atomic_t;
} else {
Expand All @@ -29,14 +30,18 @@ version (CRuntime_WASI) {

private alias sigfn_t = void function(int);

version (Posix)

version (CRuntime_WASI)
{
extern(C) void __SIG_ERR(int);
extern(C) void __SIG_IGN(int);

///
enum SIG_ERR = cast(sigfn_t) -1;
enum SIG_ERR = cast(sigfn_t)&__SIG_ERR;
///
enum SIG_DFL = cast(sigfn_t) 0;
enum SIG_DFL = cast(sigfn_t)0;
///
enum SIG_IGN = cast(sigfn_t) 1;
enum SIG_IGN = cast(sigfn_t)&__SIG_IGN;

// standard C signals
///
Expand All @@ -52,7 +57,7 @@ version (Posix)
///
enum SIGTERM = 15; // Termination
}
else version (Windows)
version (Posix)
{
///
enum SIG_ERR = cast(sigfn_t) -1;
Expand All @@ -63,7 +68,7 @@ else version (Windows)

// standard C signals
///
enum SIGABRT = 22; // Abnormal termination
enum SIGABRT = 6; // Abnormal termination
///
enum SIGFPE = 8; // Floating-point error
///
Expand All @@ -75,21 +80,18 @@ else version (Windows)
///
enum SIGTERM = 15; // Termination
}
else version (CRuntime_WASI)
else version (Windows)
{
extern(C) void __SIG_ERR(int);
extern(C) void __SIG_IGN(int);

///
enum SIG_ERR = cast(sigfn_t)&__SIG_ERR;
enum SIG_ERR = cast(sigfn_t) -1;
///
enum SIG_DFL = cast(sigfn_t)0;
enum SIG_DFL = cast(sigfn_t) 0;
///
enum SIG_IGN = cast(sigfn_t)&__SIG_IGN;
enum SIG_IGN = cast(sigfn_t) 1;

// standard C signals
///
enum SIGABRT = 6; // Abnormal termination
enum SIGABRT = 22; // Abnormal termination
///
enum SIGFPE = 8; // Floating-point error
///
Expand Down
5 changes: 0 additions & 5 deletions druntime/src/core/stdc/stddef.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,3 @@ else version (Posix)
///
alias wchar_t = dchar;
}
else version (WASI)
{
///
alias wchar_t = dchar;
}
16 changes: 8 additions & 8 deletions druntime/src/core/stdc/stdint.d
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ else version (WASI)
alias int_least64_t = long; ///
alias uint_least64_t = ulong; ///

alias int_fast8_t = byte; ///
alias uint_fast8_t = ubyte; ///
alias int_fast16_t = ptrdiff_t; ///
alias uint_fast16_t = size_t; ///
alias int_fast32_t = ptrdiff_t; ///
alias uint_fast32_t = size_t; ///
alias int_fast8_t = byte; ///
alias uint_fast8_t = ubyte; ///
alias int_fast16_t = short; ///
alias uint_fast16_t = ushort; ///
alias int_fast32_t = int; ///
alias uint_fast32_t = uint; ///

alias int_fast64_t = long; ///
alias uint_fast64_t = ulong; ///
alias int_fast64_t = long; ///
alias uint_fast64_t = ulong; ///

alias intptr_t = ptrdiff_t; ///
alias uintptr_t = size_t; ///
Expand Down
4 changes: 1 addition & 3 deletions druntime/src/core/stdc/time.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ version (Posix)
public import core.sys.posix.stdc.time;
else version (Windows)
public import core.sys.windows.stdc.time;
else version (WASI) {
public import core.sys.wasi.posix.stdc.time;
} else
else
static assert(0, "unsupported system");

import core.stdc.config;
Expand Down
12 changes: 12 additions & 0 deletions druntime/src/core/stdc/wchar_.d
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ else version (Windows)
///
alias mbstate_t = __mbstate_t;
}
else version (CRuntime_WASI)
{
///
struct __mbstate_t
{
uint __opaque1;
uint __opaque2;
}

///
alias mbstate_t = __mbstate_t;
}
else
{
///
Expand Down
Loading
Loading