Skip to content

Add WASI support in CoreFoundation_Prefix.h #2873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2020
Merged
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
16 changes: 11 additions & 5 deletions CoreFoundation/Base.subproj/CoreFoundation_Prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

#include <CoreFoundation/CFAvailability.h>

#if TARGET_OS_WASI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh; do things even build correctly without dispatch, or at least shims? I'm pretty sure we depend on dispatch_* kind of all over the place, which is why __HAS_DISPATCH__ was kept fixed at 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, at least a certain subset (albeit a useful subset) does. That's why there's more #if TARGET_OS_WASI all over the codebase of our fork, more than a 100 files touched, and certain APIs are disabled completely. I'm going to submit those as separate PRs obviously.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is WASI strictly single-threaded?

Copy link
Contributor Author

@MaxDesiatov MaxDesiatov Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, multi-threading support and atomics aren't standardised yet, and will be available in some future (unspecified) browser versions. Only Chrome has a working implementation hidden with experimental flags, as as I remember.

This restriction applies to whole WebAssembly, not just WASI.

#define __HAS_DISPATCH__ 0
#else
#define __HAS_DISPATCH__ 1
#endif

#include <CoreFoundation/CFBase.h>

Expand Down Expand Up @@ -193,7 +197,7 @@ typedef int boolean_t;
#include <sys/stat.h> // mode_t
#endif

#if TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WIN32
#if TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WIN32 || TARGET_OS_WASI
// Implemented in CFPlatform.c
CF_EXPORT bool OSAtomicCompareAndSwapPtr(void *oldp, void *newp, void *volatile *dst);
CF_EXPORT bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst);
Expand Down Expand Up @@ -227,9 +231,9 @@ CF_INLINE uint64_t mach_absolute_time() {
}

#define malloc_default_zone() (void *)0
#endif // TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WIN32
#endif // TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WIN32 || TARGET_OS_WASI

#if TARGET_OS_LINUX || TARGET_OS_WIN32 || defined(__OpenBSD__)
#if TARGET_OS_LINUX || TARGET_OS_WIN32 || defined(__OpenBSD__) || TARGET_OS_WASI
#define strtod_l(a,b,locale) strtod(a,b)
#define strtoul_l(a,b,c,locale) strtoul(a,b,c)
#define strtol_l(a,b,c,locale) strtol(a,b,c)
Expand All @@ -244,17 +248,19 @@ CF_INLINE int flsl( long mask ) {
}
return idx;
}
#endif // TARGET_OS_LINUX || TARGET_OS_WIN32 || defined(__OpenBSD__)
#endif // TARGET_OS_LINUX || TARGET_OS_WIN32 || defined(__OpenBSD__) || TARGET_OS_WASI

#if TARGET_OS_LINUX
#if TARGET_OS_LINUX || TARGET_OS_WASI

#define CF_PRIVATE extern __attribute__((visibility("hidden")))
#define __weak

#define strtoll_l(a,b,c,locale) strtoll(a,b,c)
#define strncasecmp_l(a, b, c, d) strncasecmp(a, b, c)

#if !TARGET_OS_WASI
#include <pthread.h>
#endif

#if TARGET_OS_ANDROID
typedef unsigned long fd_mask;
Expand Down