Enable libc-wasi for windows msvc build (#3852)
The default iwasm building in Windows MSVC enables libc-uvwasi because libc-wasi isn't supported at the beginning. Since libc-wasi had been refactored and is supported in Windows msys2 building, and libc-wasi supports more functionalities(e.g. sockets) than libc-uvwasi, this PR fixes some issues to enable libc-wasi in windows MSVC buidlings.
This commit is contained in:
@ -2512,6 +2512,15 @@ try_merge_data_and_text(const uint8 **buf, const uint8 **buf_end,
|
|||||||
/* merge failed but may be not critical for some targets */
|
/* merge failed but may be not critical for some targets */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BH_PLATFORM_WINDOWS
|
||||||
|
if (!os_mem_commit(sections, code_size,
|
||||||
|
MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC)) {
|
||||||
|
os_munmap(sections, (uint32)total_size);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* change the code part to be executable */
|
/* change the code part to be executable */
|
||||||
if (os_mprotect(sections, code_size,
|
if (os_mprotect(sections, code_size,
|
||||||
MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC)
|
MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC)
|
||||||
|
|||||||
@ -132,6 +132,35 @@ refcount_release(struct refcount *r)
|
|||||||
#error "Reference counter isn't implemented"
|
#error "Reference counter isn't implemented"
|
||||||
#endif /* end of __GNUC_PREREQ (4.7) */
|
#endif /* end of __GNUC_PREREQ (4.7) */
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
|
||||||
|
/* Simple reference counter. */
|
||||||
|
struct LOCKABLE refcount {
|
||||||
|
LONG count;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Initialize the reference counter. */
|
||||||
|
static inline void
|
||||||
|
refcount_init(struct refcount *r, unsigned int count)
|
||||||
|
{
|
||||||
|
InterlockedExchange(&r->count, (LONG)count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Increment the reference counter. */
|
||||||
|
static inline void
|
||||||
|
refcount_acquire(struct refcount *r)
|
||||||
|
{
|
||||||
|
InterlockedIncrement(&r->count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Decrement the reference counter, returning whether the reference
|
||||||
|
dropped to zero. */
|
||||||
|
static inline bool
|
||||||
|
refcount_release(struct refcount *r)
|
||||||
|
{
|
||||||
|
return InterlockedDecrement(&r->count) == 0 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
#else /* else of CONFIG_HAS_STD_ATOMIC */
|
#else /* else of CONFIG_HAS_STD_ATOMIC */
|
||||||
#error "Reference counter isn't implemented"
|
#error "Reference counter isn't implemented"
|
||||||
#endif /* end of CONFIG_HAS_STD_ATOMIC */
|
#endif /* end of CONFIG_HAS_STD_ATOMIC */
|
||||||
|
|||||||
@ -70,9 +70,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(BH_PLATFORM_LINUX_SGX)
|
#if !defined(BH_PLATFORM_LINUX_SGX)
|
||||||
|
|
||||||
/* Clang's __GNUC_PREREQ macro has a different meaning than GCC one,
|
/* Clang's __GNUC_PREREQ macro has a different meaning than GCC one,
|
||||||
so we have to handle this case specially */
|
so we have to handle this case specially */
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
|
|
||||||
/* Clang provides stdatomic.h since 3.6.0
|
/* Clang provides stdatomic.h since 3.6.0
|
||||||
See https://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html */
|
See https://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html */
|
||||||
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
|
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
|
||||||
@ -80,7 +82,9 @@ See https://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html */
|
|||||||
#else
|
#else
|
||||||
#define CONFIG_HAS_STD_ATOMIC 0
|
#define CONFIG_HAS_STD_ATOMIC 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__GNUC_PREREQ)
|
#elif defined(__GNUC_PREREQ)
|
||||||
|
|
||||||
/* Even though older versions of GCC support C11, atomics were
|
/* Even though older versions of GCC support C11, atomics were
|
||||||
not implemented until 4.9. See
|
not implemented until 4.9. See
|
||||||
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58016 */
|
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58016 */
|
||||||
@ -89,11 +93,21 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58016 */
|
|||||||
#else /* else of __GNUC_PREREQ(4, 9) */
|
#else /* else of __GNUC_PREREQ(4, 9) */
|
||||||
#define CONFIG_HAS_STD_ATOMIC 0
|
#define CONFIG_HAS_STD_ATOMIC 0
|
||||||
#endif /* end of __GNUC_PREREQ(4, 9) */
|
#endif /* end of __GNUC_PREREQ(4, 9) */
|
||||||
#else /* else of defined(__GNUC_PREREQ) */
|
|
||||||
#define CONFIG_HAS_STD_ATOMIC 1
|
#elif defined(_MSC_VER)
|
||||||
#endif /* end of defined(__GNUC_PREREQ) */
|
|
||||||
#else /* else of !defined(BH_PLATFORM_LINUX_SGX) */
|
|
||||||
#define CONFIG_HAS_STD_ATOMIC 0
|
#define CONFIG_HAS_STD_ATOMIC 0
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define CONFIG_HAS_STD_ATOMIC 1
|
||||||
|
|
||||||
|
#endif /* end of defined(__clang__) */
|
||||||
|
|
||||||
|
#else /* else of !defined(BH_PLATFORM_LINUX_SGX) */
|
||||||
|
|
||||||
|
#define CONFIG_HAS_STD_ATOMIC 0
|
||||||
|
|
||||||
#endif /* end of !defined(BH_PLATFORM_LINUX_SGX) */
|
#endif /* end of !defined(BH_PLATFORM_LINUX_SGX) */
|
||||||
|
|
||||||
#endif
|
#endif /* end of SSP_CONFIG_H */
|
||||||
|
|||||||
@ -6,6 +6,12 @@
|
|||||||
#ifndef _PLATFORM_INTERNAL_H
|
#ifndef _PLATFORM_INTERNAL_H
|
||||||
#define _PLATFORM_INTERNAL_H
|
#define _PLATFORM_INTERNAL_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Suppress the noisy warnings:
|
||||||
|
* winbase.h: warning C5105: macro expansion producing 'defined' has
|
||||||
|
* undefined behavior
|
||||||
|
*/
|
||||||
|
#pragma warning(disable : 5105)
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|||||||
@ -10,6 +10,10 @@
|
|||||||
#define NANOSECONDS_PER_SECOND 1000000000ULL
|
#define NANOSECONDS_PER_SECOND 1000000000ULL
|
||||||
#define NANOSECONDS_PER_TICK 100
|
#define NANOSECONDS_PER_TICK 100
|
||||||
|
|
||||||
|
extern NTSTATUS
|
||||||
|
NtQueryTimerResolution(PULONG MinimumResolution, PULONG MaximumResolution,
|
||||||
|
PULONG CurrentResolution);
|
||||||
|
|
||||||
static __wasi_errno_t
|
static __wasi_errno_t
|
||||||
calculate_monotonic_clock_frequency(uint64 *out_frequency)
|
calculate_monotonic_clock_frequency(uint64 *out_frequency)
|
||||||
{
|
{
|
||||||
@ -140,4 +144,4 @@ os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision,
|
|||||||
default:
|
default:
|
||||||
return __WASI_EINVAL;
|
return __WASI_EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,13 @@
|
|||||||
#define _WIN_UTIL_H
|
#define _WIN_UTIL_H
|
||||||
|
|
||||||
#include "platform_wasi_types.h"
|
#include "platform_wasi_types.h"
|
||||||
#include "windows.h"
|
/*
|
||||||
|
* Suppress the noisy warnings:
|
||||||
|
* winbase.h: warning C5105: macro expansion producing 'defined' has
|
||||||
|
* undefined behavior
|
||||||
|
*/
|
||||||
|
#pragma warning(disable : 5105)
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
__wasi_timestamp_t
|
__wasi_timestamp_t
|
||||||
convert_filetime_to_wasi_timestamp(LPFILETIME filetime);
|
convert_filetime_to_wasi_timestamp(LPFILETIME filetime);
|
||||||
@ -23,4 +29,4 @@ convert_windows_error_code(DWORD windows_error_code);
|
|||||||
__wasi_errno_t
|
__wasi_errno_t
|
||||||
convert_winsock_error_code(int error_code);
|
convert_winsock_error_code(int error_code);
|
||||||
|
|
||||||
#endif /* end of _WIN_UTIL_H */
|
#endif /* end of _WIN_UTIL_H */
|
||||||
|
|||||||
@ -52,9 +52,9 @@ if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
|
|||||||
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_LIBC_UVWASI)
|
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
|
||||||
# Enable libc uvwasi support by default
|
# Enable libc wasi support by default
|
||||||
set (WAMR_BUILD_LIBC_UVWASI 1)
|
set (WAMR_BUILD_LIBC_WASI 1)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
||||||
|
|||||||
@ -223,24 +223,14 @@ include_directories (${SHARED_DIR}/include
|
|||||||
|
|
||||||
enable_language (ASM)
|
enable_language (ASM)
|
||||||
|
|
||||||
if (NOT MINGW AND NOT MSVC)
|
if ((NOT DEFINED WAMR_BUILD_LIBC_WASI) AND (NOT DEFINED WAMR_BUILD_LIBC_UVWASI))
|
||||||
if ((NOT DEFINED WAMR_BUILD_LIBC_WASI) AND (NOT DEFINED WAMR_BUILD_LIBC_UVWASI))
|
# Enable WAMR_BUILD_LIBC_WASI if both are not set
|
||||||
set (WAMR_BUILD_LIBC_WASI 1)
|
set (WAMR_BUILD_LIBC_WASI 1)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if ((WAMR_BUILD_LIBC_WASI EQUAL 1) AND (WAMR_BUILD_LIBC_UVWASI EQUAL 1))
|
if ((WAMR_BUILD_LIBC_WASI EQUAL 1) AND (WAMR_BUILD_LIBC_UVWASI EQUAL 1))
|
||||||
message (WARNING "-- pick WAMR_BULID_LIBC_UVWASI when both are enabled")
|
message (WARNING "-- pick WAMR_BULID_LIBC_UVWASI when both are enabled")
|
||||||
set (WAMR_BUILD_LIBC_WASI 0)
|
set (WAMR_BUILD_LIBC_WASI 0)
|
||||||
endif ()
|
|
||||||
else ()
|
|
||||||
if (NOT DEFINED WAMR_BUILD_LIBC_UVWASI)
|
|
||||||
set (WAMR_BUILD_LIBC_UVWASI 1)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
if (WAMR_BUILD_LIBC_WASI EQUAL 1)
|
|
||||||
message (WARNING "-- don't accept WAMR_BUILD_LIBC_WASI=1 on MINGW or MSVC")
|
|
||||||
set (WAMR_BUILD_LIBC_WASI 0)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
|
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
|
||||||
@ -308,6 +298,16 @@ if (WAMR_BUILD_LIBC_WASI EQUAL 1)
|
|||||||
include (${IWASM_DIR}/libraries/libc-wasi/libc_wasi.cmake)
|
include (${IWASM_DIR}/libraries/libc-wasi/libc_wasi.cmake)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (WAMR_BUILD_LIBC_WASI EQUAL 1)
|
||||||
|
# Enable _Static_assert
|
||||||
|
set (CMAKE_C_STANDARD 11)
|
||||||
|
if (MSVC)
|
||||||
|
add_compile_options(/experimental:c11atomics)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set (CMAKE_C_STANDARD 99)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
|
if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
|
||||||
include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake)
|
include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake)
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
Reference in New Issue
Block a user