Skip to content

Commit 73d5b2b

Browse files
committed
fix(wasi): update wasi stubs
Signed-off-by: Bailey Hayes <[email protected]>
1 parent 482a974 commit 73d5b2b

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

absl/base/internal/low_level_alloc.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,48 @@ ABSL_NAMESPACE_END
659659
} // namespace absl
660660

661661
#endif // ABSL_LOW_LEVEL_ALLOC_MISSING
662+
663+
// WASI stubs: WASI doesn't have mmap, so use malloc/free instead
664+
#if defined(__wasi__)
665+
666+
namespace absl {
667+
ABSL_NAMESPACE_BEGIN
668+
namespace base_internal {
669+
670+
void *LowLevelAlloc::Alloc(size_t request) {
671+
return malloc(request);
672+
}
673+
674+
void LowLevelAlloc::Free(void *v) {
675+
free(v);
676+
}
677+
678+
void *LowLevelAlloc::AllocWithArena(size_t request, Arena* /*arena*/) {
679+
// Ignore arena parameter and use malloc
680+
return malloc(request);
681+
}
682+
683+
LowLevelAlloc::Arena *LowLevelAlloc::DefaultArena() {
684+
return nullptr;
685+
}
686+
687+
LowLevelAlloc::Arena *LowLevelAlloc::NewArena(uint32_t /*flags*/) {
688+
return nullptr;
689+
}
690+
691+
bool LowLevelAlloc::DeleteArena(Arena* /*arena*/) {
692+
return true;
693+
}
694+
695+
LowLevelAlloc::Arena *SigSafeArena() {
696+
// Return nullptr - arenas are ignored in WASI's AllocWithArena
697+
return nullptr;
698+
}
699+
700+
void InitSigSafeArena() {}
701+
702+
} // namespace base_internal
703+
ABSL_NAMESPACE_END
704+
} // namespace absl
705+
706+
#endif // __wasi__

absl/base/internal/low_level_alloc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
// LowLevelAlloc.
3737
#ifdef ABSL_LOW_LEVEL_ALLOC_MISSING
3838
#error ABSL_LOW_LEVEL_ALLOC_MISSING cannot be directly set
39+
#elif defined(__wasi__)
40+
#define ABSL_LOW_LEVEL_ALLOC_MISSING 1
3941
#elif !defined(ABSL_HAVE_MMAP) && !defined(_WIN32)
4042
#define ABSL_LOW_LEVEL_ALLOC_MISSING 1
4143
#endif

absl/synchronization/internal/create_thread_identity.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,24 @@ ABSL_NAMESPACE_END
150150
} // namespace absl
151151

152152
#endif // ABSL_LOW_LEVEL_ALLOC_MISSING
153+
154+
// WASI stubs: WASI is single-threaded, use a static identity
155+
#if defined(__wasi__)
156+
157+
#include "absl/base/internal/thread_identity.h"
158+
159+
namespace absl {
160+
ABSL_NAMESPACE_BEGIN
161+
namespace synchronization_internal {
162+
163+
static base_internal::ThreadIdentity g_wasi_thread_identity = {};
164+
165+
base_internal::ThreadIdentity* CreateThreadIdentity() {
166+
return &g_wasi_thread_identity;
167+
}
168+
169+
} // namespace synchronization_internal
170+
ABSL_NAMESPACE_END
171+
} // namespace absl
172+
173+
#endif // __wasi__

absl/synchronization/internal/per_thread_sem.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,29 @@ ABSL_ATTRIBUTE_WEAK bool ABSL_INTERNAL_C_SYMBOL(AbslInternalPerThreadSemWait)(
104104
} // extern "C"
105105

106106
#endif // ABSL_LOW_LEVEL_ALLOC_MISSING
107+
108+
// WASI stubs: WASI is single-threaded, so these are no-ops
109+
#if defined(__wasi__)
110+
111+
#include "absl/base/attributes.h"
112+
#include "absl/synchronization/internal/per_thread_sem.h"
113+
114+
extern "C" {
115+
116+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalPerThreadSemInit)(
117+
absl::base_internal::ThreadIdentity* /*identity*/) {}
118+
119+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalPerThreadSemPost)(
120+
absl::base_internal::ThreadIdentity* /*identity*/) {}
121+
122+
void ABSL_INTERNAL_C_SYMBOL(AbslInternalPerThreadSemPoke)(
123+
absl::base_internal::ThreadIdentity* /*identity*/) {}
124+
125+
bool ABSL_INTERNAL_C_SYMBOL(AbslInternalPerThreadSemWait)(
126+
absl::synchronization_internal::KernelTimeout /*t*/) {
127+
return true;
128+
}
129+
130+
} // extern "C"
131+
132+
#endif // __wasi__

0 commit comments

Comments
 (0)