3939# include <ucontext.h>
4040#endif
4141
42- #ifndef ZEND_WIN32
42+ #if !defined( ZEND_WIN32 ) && defined( HAVE_MMAP )
4343# include <unistd.h>
4444# include <sys/mman.h>
4545# include <limits.h>
@@ -108,7 +108,9 @@ typedef struct _zend_fiber_vm_state {
108108 zend_execute_data * current_execute_data ;
109109 int error_reporting ;
110110 uint32_t jit_trace_num ;
111+ #ifndef PHP_WASI
111112 JMP_BUF * bailout ;
113+ #endif // PHP_WASI
112114 zend_fiber * active_fiber ;
113115#ifdef ZEND_CHECK_STACK_LIMIT
114116 void * stack_base ;
@@ -125,7 +127,9 @@ static zend_always_inline void zend_fiber_capture_vm_state(zend_fiber_vm_state *
125127 state -> current_execute_data = EG (current_execute_data );
126128 state -> error_reporting = EG (error_reporting );
127129 state -> jit_trace_num = EG (jit_trace_num );
130+ #ifndef PHP_WASI
128131 state -> bailout = EG (bailout );
132+ #endif // PHP_WASI
129133 state -> active_fiber = EG (active_fiber );
130134#ifdef ZEND_CHECK_STACK_LIMIT
131135 state -> stack_base = EG (stack_base );
@@ -142,7 +146,9 @@ static zend_always_inline void zend_fiber_restore_vm_state(zend_fiber_vm_state *
142146 EG (current_execute_data ) = state -> current_execute_data ;
143147 EG (error_reporting ) = state -> error_reporting ;
144148 EG (jit_trace_num ) = state -> jit_trace_num ;
149+ #ifndef PHP_WASI
145150 EG (bailout ) = state -> bailout ;
151+ #endif // PHP_WASI
146152 EG (active_fiber ) = state -> active_fiber ;
147153#ifdef ZEND_CHECK_STACK_LIMIT
148154 EG (stack_base ) = state -> stack_base ;
@@ -236,6 +242,8 @@ static zend_fiber_stack *zend_fiber_stack_allocate(size_t size)
236242 return NULL ;
237243 }
238244# endif
245+ #elif defined(PHP_WASI )
246+ pointer = malloc (alloc_size );
239247#else
240248 pointer = mmap (NULL , alloc_size , PROT_READ | PROT_WRITE , MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK , -1 , 0 );
241249
@@ -302,6 +310,8 @@ static void zend_fiber_stack_free(zend_fiber_stack *stack)
302310
303311#ifdef ZEND_WIN32
304312 VirtualFree (pointer , 0 , MEM_RELEASE );
313+ #elif defined(PHP_WASI )
314+ free (pointer );
305315#else
306316 munmap (pointer , stack -> size + ZEND_FIBER_GUARD_PAGES * page_size );
307317#endif
@@ -394,6 +404,7 @@ ZEND_API bool zend_fiber_switch_blocked(void)
394404 return zend_fiber_switch_blocking ;
395405}
396406
407+ #ifndef PHP_WASI
397408ZEND_API zend_result zend_fiber_init_context (zend_fiber_context * context , void * kind , zend_fiber_coroutine coroutine , size_t stack_size )
398409{
399410 context -> stack = zend_fiber_stack_allocate (stack_size );
@@ -440,6 +451,7 @@ ZEND_API zend_result zend_fiber_init_context(zend_fiber_context *context, void *
440451
441452 return SUCCESS ;
442453}
454+ #endif // PHP_WASI
443455
444456ZEND_API void zend_fiber_destroy_context (zend_fiber_context * context )
445457{
@@ -502,16 +514,18 @@ ZEND_API void zend_fiber_switch_context(zend_fiber_transfer *transfer)
502514
503515 /* Copy transfer struct because it might live on the other fiber's stack that will eventually be destroyed. */
504516 * transfer = * transfer_data ;
505- #else
517+ #elif !defined( PHP_WASI )
506518 boost_context_data data = jump_fcontext (to -> handle , transfer );
507519
508520 /* Copy transfer struct because it might live on the other fiber's stack that will eventually be destroyed. */
509521 * transfer = * data .transfer ;
522+ #else
523+ return ;
510524#endif
511525
512526 to = transfer -> context ;
513527
514- #ifndef ZEND_FIBER_UCONTEXT
528+ #if !defined( ZEND_FIBER_UCONTEXT ) && !defined( PHP_WASI )
515529 /* Get the context that resumed us and update its handle to allow for symmetric coroutines. */
516530 to -> handle = data .handle ;
517531#endif
0 commit comments