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:
Wenyong Huang
2024-10-14 09:52:25 +08:00
committed by GitHub
parent 36d438051e
commit b16b6044ee
8 changed files with 96 additions and 28 deletions

View File

@ -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 */
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 */
if (os_mprotect(sections, code_size,
MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC)

View File

@ -132,6 +132,35 @@ refcount_release(struct refcount *r)
#error "Reference counter isn't implemented"
#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 */
#error "Reference counter isn't implemented"
#endif /* end of CONFIG_HAS_STD_ATOMIC */

View File

@ -70,9 +70,11 @@
#endif
#if !defined(BH_PLATFORM_LINUX_SGX)
/* Clang's __GNUC_PREREQ macro has a different meaning than GCC one,
so we have to handle this case specially */
#if defined(__clang__)
/* Clang provides stdatomic.h since 3.6.0
See https://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html */
#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
#define CONFIG_HAS_STD_ATOMIC 0
#endif
#elif defined(__GNUC_PREREQ)
/* Even though older versions of GCC support C11, atomics were
not implemented until 4.9. See
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) */
#define CONFIG_HAS_STD_ATOMIC 0
#endif /* end of __GNUC_PREREQ(4, 9) */
#else /* else of defined(__GNUC_PREREQ) */
#define CONFIG_HAS_STD_ATOMIC 1
#endif /* end of defined(__GNUC_PREREQ) */
#else /* else of !defined(BH_PLATFORM_LINUX_SGX) */
#elif defined(_MSC_VER)
#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
#endif /* end of SSP_CONFIG_H */