@@ -224,6 +224,7 @@ struct LowLevelAlloc::Arena {
224224
225225// ---------------------------------------------------------------
226226// An async-signal-safe arena for LowLevelAlloc
227+ #ifndef __wasi__
227228static std::atomic<base_internal::LowLevelAlloc::Arena *> g_sig_safe_arena;
228229
229230base_internal::LowLevelAlloc::Arena *SigSafeArena () {
@@ -247,6 +248,7 @@ void InitSigSafeArena() {
247248 }
248249 }
249250}
251+ #endif // __wasi__
250252
251253namespace {
252254// Static storage space for the lazily-constructed, default global arena
@@ -535,6 +537,7 @@ static void AddToFreelist(void *v, LowLevelAlloc::Arena *arena)
535537
536538// Frees storage allocated by LowLevelAlloc::Alloc().
537539// L < arena->mu
540+ #ifndef __wasi__
538541void LowLevelAlloc::Free (void *v) {
539542 if (v != nullptr ) {
540543 AllocList *f = reinterpret_cast <AllocList *>(reinterpret_cast <char *>(v) -
@@ -547,6 +550,7 @@ void LowLevelAlloc::Free(void *v) {
547550 section.Leave ();
548551 }
549552}
553+ #endif // __wasi__
550554
551555// allocates and returns a block of size bytes, to be freed with Free()
552556// L < arena->mu
@@ -643,6 +647,7 @@ static void *DoAllocWithArena(size_t request, LowLevelAlloc::Arena *arena) {
643647 return result;
644648}
645649
650+ #ifndef __wasi__
646651void *LowLevelAlloc::Alloc (size_t request) {
647652 void *result = DoAllocWithArena (request, DefaultArena ());
648653 return result;
@@ -653,9 +658,49 @@ void *LowLevelAlloc::AllocWithArena(size_t request, Arena *arena) {
653658 void *result = DoAllocWithArena (request, arena);
654659 return result;
655660}
661+ #endif // __wasi__
656662
657663} // namespace base_internal
658664ABSL_NAMESPACE_END
659665} // namespace absl
660666
661667#endif // ABSL_LOW_LEVEL_ALLOC_MISSING
668+
669+ // WASI-specific implementations
670+ // WASI doesn't support mmap, so we use malloc/free for LowLevelAlloc
671+ #ifdef __wasi__
672+
673+ #include " absl/base/internal/low_level_alloc.h"
674+
675+ namespace absl {
676+ ABSL_NAMESPACE_BEGIN
677+ namespace base_internal {
678+
679+ void *LowLevelAlloc::Alloc (size_t request) {
680+ return malloc (request);
681+ }
682+
683+ void LowLevelAlloc::Free (void *v) {
684+ free (v);
685+ }
686+
687+ void *LowLevelAlloc::AllocWithArena (size_t request, Arena* /* arena*/ ) {
688+ // Ignore arena parameter and use malloc
689+ return malloc (request);
690+ }
691+
692+ // Signal-safe arena stubs for WASI
693+ void InitSigSafeArena () {
694+ // No-op: WASI doesn't need arena initialization
695+ }
696+
697+ LowLevelAlloc::Arena *SigSafeArena () {
698+ // Return nullptr - arenas are ignored in WASI's AllocWithArena
699+ return nullptr ;
700+ }
701+
702+ } // namespace base_internal
703+ ABSL_NAMESPACE_END
704+ } // namespace absl
705+
706+ #endif // __wasi__
0 commit comments