39
39
# include <ucontext.h>
40
40
#endif
41
41
42
- #ifndef ZEND_WIN32
42
+ #if !defined( ZEND_WIN32 ) && defined( HAVE_MMAP )
43
43
# include <unistd.h>
44
44
# include <sys/mman.h>
45
45
# include <limits.h>
@@ -108,7 +108,9 @@ typedef struct _zend_fiber_vm_state {
108
108
zend_execute_data * current_execute_data ;
109
109
int error_reporting ;
110
110
uint32_t jit_trace_num ;
111
+ #ifndef __wasi__
111
112
JMP_BUF * bailout ;
113
+ #endif // __wasi__
112
114
zend_fiber * active_fiber ;
113
115
#ifdef ZEND_CHECK_STACK_LIMIT
114
116
void * stack_base ;
@@ -125,7 +127,9 @@ static zend_always_inline void zend_fiber_capture_vm_state(zend_fiber_vm_state *
125
127
state -> current_execute_data = EG (current_execute_data );
126
128
state -> error_reporting = EG (error_reporting );
127
129
state -> jit_trace_num = EG (jit_trace_num );
130
+ #ifndef __wasi__
128
131
state -> bailout = EG (bailout );
132
+ #endif // __wasi__
129
133
state -> active_fiber = EG (active_fiber );
130
134
#ifdef ZEND_CHECK_STACK_LIMIT
131
135
state -> stack_base = EG (stack_base );
@@ -142,7 +146,9 @@ static zend_always_inline void zend_fiber_restore_vm_state(zend_fiber_vm_state *
142
146
EG (current_execute_data ) = state -> current_execute_data ;
143
147
EG (error_reporting ) = state -> error_reporting ;
144
148
EG (jit_trace_num ) = state -> jit_trace_num ;
149
+ #ifndef __wasi__
145
150
EG (bailout ) = state -> bailout ;
151
+ #endif // __wasi__
146
152
EG (active_fiber ) = state -> active_fiber ;
147
153
#ifdef ZEND_CHECK_STACK_LIMIT
148
154
EG (stack_base ) = state -> stack_base ;
@@ -236,6 +242,8 @@ static zend_fiber_stack *zend_fiber_stack_allocate(size_t size)
236
242
return NULL ;
237
243
}
238
244
# endif
245
+ #elif defined(__wasi__ )
246
+ pointer = malloc (alloc_size );
239
247
#else
240
248
pointer = mmap (NULL , alloc_size , PROT_READ | PROT_WRITE , MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK , -1 , 0 );
241
249
@@ -302,6 +310,8 @@ static void zend_fiber_stack_free(zend_fiber_stack *stack)
302
310
303
311
#ifdef ZEND_WIN32
304
312
VirtualFree (pointer , 0 , MEM_RELEASE );
313
+ #elif defined(__wasi__ )
314
+ free (pointer );
305
315
#else
306
316
munmap (pointer , stack -> size + ZEND_FIBER_GUARD_PAGES * page_size );
307
317
#endif
@@ -394,6 +404,7 @@ ZEND_API bool zend_fiber_switch_blocked(void)
394
404
return zend_fiber_switch_blocking ;
395
405
}
396
406
407
+ #ifndef __wasi__
397
408
ZEND_API zend_result zend_fiber_init_context (zend_fiber_context * context , void * kind , zend_fiber_coroutine coroutine , size_t stack_size )
398
409
{
399
410
context -> stack = zend_fiber_stack_allocate (stack_size );
@@ -415,7 +426,6 @@ ZEND_API zend_result zend_fiber_init_context(zend_fiber_context *context, void *
415
426
makecontext (handle , (void (* )(void )) zend_fiber_trampoline , 0 );
416
427
417
428
context -> handle = handle ;
418
- #else
419
429
// Stack grows down, calculate the top of the stack. make_fcontext then shifts pointer to lower 16-byte boundary.
420
430
void * stack = (void * ) ((uintptr_t ) context -> stack -> pointer + context -> stack -> size );
421
431
@@ -440,6 +450,7 @@ ZEND_API zend_result zend_fiber_init_context(zend_fiber_context *context, void *
440
450
441
451
return SUCCESS ;
442
452
}
453
+ #endif // __wasi__
443
454
444
455
ZEND_API void zend_fiber_destroy_context (zend_fiber_context * context )
445
456
{
@@ -502,16 +513,18 @@ ZEND_API void zend_fiber_switch_context(zend_fiber_transfer *transfer)
502
513
503
514
/* Copy transfer struct because it might live on the other fiber's stack that will eventually be destroyed. */
504
515
* transfer = * transfer_data ;
505
- #else
516
+ #elif !defined( __wasi__ )
506
517
boost_context_data data = jump_fcontext (to -> handle , transfer );
507
518
508
519
/* Copy transfer struct because it might live on the other fiber's stack that will eventually be destroyed. */
509
520
* transfer = * data .transfer ;
521
+ #else
522
+ return ;
510
523
#endif
511
524
512
525
to = transfer -> context ;
513
526
514
- #ifndef ZEND_FIBER_UCONTEXT
527
+ #if !defined( ZEND_FIBER_UCONTEXT ) && !defined( __wasi__ )
515
528
/* Get the context that resumed us and update its handle to allow for symmetric coroutines. */
516
529
to -> handle = data .handle ;
517
530
#endif
0 commit comments