Add Cosmopolitan Libc Platform (#2598)
This PR adds the Cosmopolitan Libc platform enabling compatibility with multiple x86_64 operating systems with the same binary. The platform is similar to the Linux platform, but for now only x86_64 with interpreter modes are supported. The only major change to the core is `posix.c/convert_errno()` was rewritten to use a switch statement. With Cosmopolitan errno values depend on the currently running operating system, and so they are non-constant and cannot be used in array designators. However, the `cosmocc` compiler allows non-constant case labels in switch statements, enabling the new version. And updated wamr-test-suites script to add `-j <platform>` option. The spec tests can be ran via `CC=cosmocc ./test_wamr.sh -j cosmopolitan -t classic-interp` or `CC=cosmocc ./test_wamr.sh -j cosmopolitan -t fast-interp`.
This commit is contained in:
@ -60,98 +60,99 @@ static_assert(sizeof(struct iovec) == sizeof(__wasi_ciovec_t),
|
||||
static __wasi_errno_t
|
||||
convert_errno(int error)
|
||||
{
|
||||
static const __wasi_errno_t errors[] = {
|
||||
#define X(v) [v] = __WASI_##v
|
||||
X(E2BIG),
|
||||
X(EACCES),
|
||||
X(EADDRINUSE),
|
||||
X(EADDRNOTAVAIL),
|
||||
X(EAFNOSUPPORT),
|
||||
X(EAGAIN),
|
||||
X(EALREADY),
|
||||
X(EBADF),
|
||||
X(EBADMSG),
|
||||
X(EBUSY),
|
||||
X(ECANCELED),
|
||||
X(ECHILD),
|
||||
X(ECONNABORTED),
|
||||
X(ECONNREFUSED),
|
||||
X(ECONNRESET),
|
||||
X(EDEADLK),
|
||||
X(EDESTADDRREQ),
|
||||
X(EDOM),
|
||||
X(EDQUOT),
|
||||
X(EEXIST),
|
||||
X(EFAULT),
|
||||
X(EFBIG),
|
||||
X(EHOSTUNREACH),
|
||||
X(EIDRM),
|
||||
X(EILSEQ),
|
||||
X(EINPROGRESS),
|
||||
X(EINTR),
|
||||
X(EINVAL),
|
||||
X(EIO),
|
||||
X(EISCONN),
|
||||
X(EISDIR),
|
||||
X(ELOOP),
|
||||
X(EMFILE),
|
||||
X(EMLINK),
|
||||
X(EMSGSIZE),
|
||||
X(EMULTIHOP),
|
||||
X(ENAMETOOLONG),
|
||||
X(ENETDOWN),
|
||||
X(ENETRESET),
|
||||
X(ENETUNREACH),
|
||||
X(ENFILE),
|
||||
X(ENOBUFS),
|
||||
X(ENODEV),
|
||||
X(ENOENT),
|
||||
X(ENOEXEC),
|
||||
X(ENOLCK),
|
||||
X(ENOLINK),
|
||||
X(ENOMEM),
|
||||
X(ENOMSG),
|
||||
X(ENOPROTOOPT),
|
||||
X(ENOSPC),
|
||||
X(ENOSYS),
|
||||
__wasi_errno_t code = __WASI_ENOSYS;
|
||||
#define X(v) \
|
||||
case v: \
|
||||
code = __WASI_##v; \
|
||||
break;
|
||||
switch (error) {
|
||||
X(E2BIG)
|
||||
X(EACCES)
|
||||
X(EADDRINUSE)
|
||||
X(EADDRNOTAVAIL)
|
||||
X(EAFNOSUPPORT)
|
||||
X(EAGAIN)
|
||||
X(EALREADY)
|
||||
X(EBADF)
|
||||
X(EBADMSG)
|
||||
X(EBUSY)
|
||||
X(ECANCELED)
|
||||
X(ECHILD)
|
||||
X(ECONNABORTED)
|
||||
X(ECONNREFUSED)
|
||||
X(ECONNRESET)
|
||||
X(EDEADLK)
|
||||
X(EDESTADDRREQ)
|
||||
X(EDOM)
|
||||
X(EDQUOT)
|
||||
X(EEXIST)
|
||||
X(EFAULT)
|
||||
X(EFBIG)
|
||||
X(EHOSTUNREACH)
|
||||
X(EIDRM)
|
||||
X(EILSEQ)
|
||||
X(EINPROGRESS)
|
||||
X(EINTR)
|
||||
X(EINVAL)
|
||||
X(EIO)
|
||||
X(EISCONN)
|
||||
X(EISDIR)
|
||||
X(ELOOP)
|
||||
X(EMFILE)
|
||||
X(EMLINK)
|
||||
X(EMSGSIZE)
|
||||
X(EMULTIHOP)
|
||||
X(ENAMETOOLONG)
|
||||
X(ENETDOWN)
|
||||
X(ENETRESET)
|
||||
X(ENETUNREACH)
|
||||
X(ENFILE)
|
||||
X(ENOBUFS)
|
||||
X(ENODEV)
|
||||
X(ENOENT)
|
||||
X(ENOEXEC)
|
||||
X(ENOLCK)
|
||||
X(ENOLINK)
|
||||
X(ENOMEM)
|
||||
X(ENOMSG)
|
||||
X(ENOPROTOOPT)
|
||||
X(ENOSPC)
|
||||
X(ENOSYS)
|
||||
#ifdef ENOTCAPABLE
|
||||
X(ENOTCAPABLE),
|
||||
X(ENOTCAPABLE)
|
||||
#endif
|
||||
X(ENOTCONN),
|
||||
X(ENOTDIR),
|
||||
X(ENOTEMPTY),
|
||||
X(ENOTRECOVERABLE),
|
||||
X(ENOTSOCK),
|
||||
X(ENOTSUP),
|
||||
X(ENOTTY),
|
||||
X(ENXIO),
|
||||
X(EOVERFLOW),
|
||||
X(EOWNERDEAD),
|
||||
X(EPERM),
|
||||
X(EPIPE),
|
||||
X(EPROTO),
|
||||
X(EPROTONOSUPPORT),
|
||||
X(EPROTOTYPE),
|
||||
X(ERANGE),
|
||||
X(EROFS),
|
||||
X(ESPIPE),
|
||||
X(ESRCH),
|
||||
X(ESTALE),
|
||||
X(ETIMEDOUT),
|
||||
X(ETXTBSY),
|
||||
X(EXDEV),
|
||||
X(ENOTCONN)
|
||||
X(ENOTDIR)
|
||||
X(ENOTEMPTY)
|
||||
X(ENOTRECOVERABLE)
|
||||
X(ENOTSOCK)
|
||||
X(ENOTSUP)
|
||||
X(ENOTTY)
|
||||
X(ENXIO)
|
||||
X(EOVERFLOW)
|
||||
X(EOWNERDEAD)
|
||||
X(EPERM)
|
||||
X(EPIPE)
|
||||
X(EPROTO)
|
||||
X(EPROTONOSUPPORT)
|
||||
X(EPROTOTYPE)
|
||||
X(ERANGE)
|
||||
X(EROFS)
|
||||
X(ESPIPE)
|
||||
X(ESRCH)
|
||||
X(ESTALE)
|
||||
X(ETIMEDOUT)
|
||||
X(ETXTBSY)
|
||||
X(EXDEV)
|
||||
default:
|
||||
if (error == EOPNOTSUPP)
|
||||
code = __WASI_ENOTSUP;
|
||||
else if (code == EWOULDBLOCK)
|
||||
code = __WASI_EAGAIN;
|
||||
break;
|
||||
}
|
||||
#undef X
|
||||
#if EOPNOTSUPP != ENOTSUP
|
||||
[EOPNOTSUPP] = __WASI_ENOTSUP,
|
||||
#endif
|
||||
#if EWOULDBLOCK != EAGAIN
|
||||
[EWOULDBLOCK] = __WASI_EAGAIN,
|
||||
#endif
|
||||
};
|
||||
if (error < 0 || (size_t)error >= sizeof(errors) / sizeof(errors[0])
|
||||
|| errors[error] == 0)
|
||||
return __WASI_ENOSYS;
|
||||
return errors[error];
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
||||
@ -65,7 +65,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && !defined(ESP_PLATFORM)
|
||||
#if !defined(__APPLE__) && !defined(ESP_PLATFORM) && !defined(__COSMOPOLITAN__)
|
||||
#define CONFIG_HAS_POSIX_FALLOCATE 1
|
||||
#else
|
||||
#define CONFIG_HAS_POSIX_FALLOCATE 0
|
||||
@ -83,7 +83,8 @@
|
||||
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 0
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX)
|
||||
#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) \
|
||||
&& !defined(__COSMOPOLITAN__)
|
||||
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 1
|
||||
#else
|
||||
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 0
|
||||
|
||||
Reference in New Issue
Block a user