Repository navigation
Expand file tree
/
Copy pathphp8.5.patch
More file actions
1057 lines (962 loc) · 36.8 KB
/
Copy pathphp8.5.patch
File metadata and controls
1057 lines (962 loc) · 36.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/third_party/php8.5-src/Zend/zend_API.c b/third_party/php8.5-src/Zend/zend_API.c
index b5c8b7a..58aae9f 100644
--- a/third_party/php8.5-src/Zend/zend_API.c
+++ b/third_party/php8.5-src/Zend/zend_API.c
@@ -3707,6 +3707,70 @@ ZEND_API void zend_disable_functions(const char *function_list) /* {{{ */
}
/* }}} */
+static ZEND_COLD zend_object *display_disabled_class(zend_class_entry *class_type) /* {{{ */
+{
+ zend_object *intern;
+
+ intern = zend_objects_new(class_type);
+
+ /* Initialize default properties */
+ if (EXPECTED(class_type->default_properties_count != 0)) {
+ zval *p = intern->properties_table;
+ zval *end = p + class_type->default_properties_count;
+ do {
+ ZVAL_UNDEF(p);
+ p++;
+ } while (p != end);
+ }
+
+ zend_error(E_WARNING, "%s() has been disabled for security reasons", ZSTR_VAL(class_type->name));
+ return intern;
+}
+
+static const zend_function_entry disabled_class_new[] = {
+ ZEND_FE_END
+};
+
+ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_name_length) /* {{{ */
+{
+ zend_class_entry *disabled_class;
+ zend_string *key;
+ zend_function *fn;
+ zend_property_info *prop;
+
+ key = zend_string_alloc(class_name_length, 0);
+ zend_str_tolower_copy(ZSTR_VAL(key), class_name, class_name_length);
+ disabled_class = zend_hash_find_ptr(CG(class_table), key);
+ zend_string_release_ex(key, 0);
+ if (!disabled_class) {
+ return FAILURE;
+ }
+
+ /* Will be reset by INIT_CLASS_ENTRY. */
+ free(disabled_class->interfaces);
+
+ INIT_CLASS_ENTRY_INIT_METHODS((*disabled_class), disabled_class_new);
+ disabled_class->create_object = display_disabled_class;
+
+ ZEND_HASH_MAP_FOREACH_PTR(&disabled_class->function_table, fn) {
+ if ((fn->common.fn_flags & (ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_HAS_TYPE_HINTS)) &&
+ fn->common.scope == disabled_class) {
+ zend_free_internal_arg_info(&fn->internal_function);
+ }
+ } ZEND_HASH_FOREACH_END();
+ zend_hash_clean(&disabled_class->function_table);
+ ZEND_HASH_MAP_FOREACH_PTR(&disabled_class->properties_info, prop) {
+ if (prop->ce == disabled_class) {
+ zend_string_release(prop->name);
+ zend_type_release(prop->type, /* persistent */ 1);
+ free(prop);
+ }
+ } ZEND_HASH_FOREACH_END();
+ zend_hash_clean(&disabled_class->properties_info);
+ return SUCCESS;
+}
+/* }}} */
+
static zend_always_inline zend_class_entry *get_scope(zend_execute_data *frame)
{
return frame && frame->func ? frame->func->common.scope : NULL;
diff --git a/third_party/php8.5-src/Zend/zend_API.h b/third_party/php8.5-src/Zend/zend_API.h
index 8cde831..f06c07a 100644
--- a/third_party/php8.5-src/Zend/zend_API.h
+++ b/third_party/php8.5-src/Zend/zend_API.h
@@ -405,6 +405,7 @@ static zend_always_inline zend_result zend_register_class_alias(const char *name
zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)
ZEND_API void zend_disable_functions(const char *function_list);
+ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_name_length);
ZEND_API ZEND_COLD void zend_wrong_param_count(void);
ZEND_API ZEND_COLD void zend_wrong_property_read(zval *object, zval *property);
diff --git a/third_party/php8.5-src/Zend/zend_fibers.c b/third_party/php8.5-src/Zend/zend_fibers.c
index d571a62..3857a5c 100644
--- a/third_party/php8.5-src/Zend/zend_fibers.c
+++ b/third_party/php8.5-src/Zend/zend_fibers.c
@@ -34,11 +34,17 @@
#include "zend_fibers.h"
#include "zend_fibers_arginfo.h"
+#ifdef __EMSCRIPTEN__
+# include <emscripten/fiber.h>
+# define ZEND_FIBER_EMSCRIPTEN 1
+# define EMS_FIBER_ASYNCIFY_STACK_SIZE (128 * 1024)
+#endif
+
#ifdef HAVE_VALGRIND
# include <valgrind/valgrind.h>
#endif
-#ifdef ZEND_FIBER_UCONTEXT
+#if defined(ZEND_FIBER_UCONTEXT) && !defined(ZEND_FIBER_EMSCRIPTEN)
# include <ucontext.h>
#endif
@@ -93,7 +99,12 @@ struct _zend_fiber_stack {
size_t asan_size;
#endif
-#ifdef ZEND_FIBER_UCONTEXT
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ /* Embedded Emscripten context and Zend-owned Asyncify stack. */
+ emscripten_fiber_t fiber;
+ void *pointer_asyncify;
+ size_t size_asyncify;
+#elif defined(ZEND_FIBER_UCONTEXT)
/* Embedded ucontext to avoid unnecessary memory allocations. */
ucontext_t ucontext;
#elif BOOST_CONTEXT_SHADOW_STACK
@@ -154,7 +165,7 @@ static zend_always_inline void zend_fiber_restore_vm_state(zend_fiber_vm_state *
#endif
}
-#ifdef ZEND_FIBER_UCONTEXT
+#if defined(ZEND_FIBER_EMSCRIPTEN) || defined(ZEND_FIBER_UCONTEXT)
ZEND_TLS zend_fiber_transfer *transfer_data;
#else
/* boost_context_data is our customized definition of struct transfer_t as
@@ -207,12 +218,16 @@ static zend_fiber_stack *zend_fiber_stack_allocate(size_t size)
{
void *pointer;
const size_t page_size = zend_fiber_get_page_size();
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ const size_t minimum_stack_size = page_size;
+#else
const size_t minimum_stack_size = page_size + ZEND_FIBER_GUARD_PAGES * page_size
#ifdef __SANITIZE_ADDRESS__
// necessary correction due to ASAN redzones
* 6
#endif
;
+#endif
if (size < minimum_stack_size) {
zend_throw_exception_ex(NULL, 0, "Fiber stack size is too small, it needs to be at least %zu bytes", minimum_stack_size);
@@ -220,6 +235,25 @@ static zend_fiber_stack *zend_fiber_stack_allocate(size_t size)
}
const size_t stack_size = (size + page_size - 1) / page_size * page_size;
+
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ pointer = aligned_alloc(16, stack_size);
+
+ if (!pointer) {
+ zend_throw_exception_ex(NULL, 0, "Fiber stack allocate failed: aligned_alloc failed: %s (%d)", strerror(errno), errno);
+ return NULL;
+ }
+
+ ZEND_ASSERT(((uintptr_t) pointer & 0xf) == 0 && "Emscripten fiber stacks must be 16-byte aligned");
+
+ void *pointer_asyncify = malloc(EMS_FIBER_ASYNCIFY_STACK_SIZE);
+
+ if (!pointer_asyncify) {
+ zend_throw_exception_ex(NULL, 0, "Fiber Asyncify stack allocate failed: malloc failed: %s (%d)", strerror(errno), errno);
+ free(pointer);
+ return NULL;
+ }
+#else
const size_t alloc_size = stack_size + ZEND_FIBER_GUARD_PAGES * page_size;
#ifdef ZEND_WIN32
@@ -269,13 +303,25 @@ static zend_fiber_stack *zend_fiber_stack_allocate(size_t size)
}
# endif
#endif
+#endif
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ zend_fiber_stack *stack = ecalloc(1, sizeof(zend_fiber_stack));
+#else
zend_fiber_stack *stack = emalloc(sizeof(zend_fiber_stack));
+#endif
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ stack->pointer = pointer;
+ stack->size = stack_size;
+ stack->pointer_asyncify = pointer_asyncify;
+ stack->size_asyncify = EMS_FIBER_ASYNCIFY_STACK_SIZE;
+#else
stack->pointer = (void *) ((uintptr_t) pointer + ZEND_FIBER_GUARD_PAGES * page_size);
stack->size = stack_size;
+#endif
-#if !defined(ZEND_FIBER_UCONTEXT) && BOOST_CONTEXT_SHADOW_STACK
+#if !defined(ZEND_FIBER_EMSCRIPTEN) && !defined(ZEND_FIBER_UCONTEXT) && BOOST_CONTEXT_SHADOW_STACK
/* shadow stack saves ret address only, need less space */
stack->ss_size= stack_size >> 5;
@@ -311,6 +357,10 @@ static void zend_fiber_stack_free(zend_fiber_stack *stack)
VALGRIND_STACK_DEREGISTER(stack->valgrind_stack_id);
#endif
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ free(stack->pointer_asyncify);
+ free(stack->pointer);
+#else
const size_t page_size = zend_fiber_get_page_size();
void *pointer = (void *) ((uintptr_t) stack->pointer - ZEND_FIBER_GUARD_PAGES * page_size);
@@ -326,8 +376,9 @@ static void zend_fiber_stack_free(zend_fiber_stack *stack)
#else
munmap(pointer, stack->size + ZEND_FIBER_GUARD_PAGES * page_size);
#endif
+#endif
-#if !defined(ZEND_FIBER_UCONTEXT) && BOOST_CONTEXT_SHADOW_STACK
+#if !defined(ZEND_FIBER_EMSCRIPTEN) && !defined(ZEND_FIBER_UCONTEXT) && BOOST_CONTEXT_SHADOW_STACK
munmap(stack->ss_base, stack->ss_size);
#endif
@@ -358,14 +409,19 @@ ZEND_API void* zend_fiber_stack_base(zend_fiber_stack *stack)
}
#endif
-#ifdef ZEND_FIBER_UCONTEXT
+#ifdef ZEND_FIBER_EMSCRIPTEN
+static void zend_fiber_trampoline(void *argument)
+#elif defined(ZEND_FIBER_UCONTEXT)
static ZEND_NORETURN void zend_fiber_trampoline(void)
#else
static ZEND_NORETURN void zend_fiber_trampoline(boost_context_data data)
#endif
{
/* Initialize transfer struct with a copy of passed data. */
-#ifdef ZEND_FIBER_UCONTEXT
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ (void) argument;
+ zend_fiber_transfer transfer = *transfer_data;
+#elif defined(ZEND_FIBER_UCONTEXT)
zend_fiber_transfer transfer = *transfer_data;
#else
zend_fiber_transfer transfer = *data.transfer;
@@ -377,7 +433,7 @@ static ZEND_NORETURN void zend_fiber_trampoline(boost_context_data data)
__sanitizer_finish_switch_fiber(NULL, &from->stack->asan_pointer, &from->stack->asan_size);
#endif
-#ifndef ZEND_FIBER_UCONTEXT
+#if !defined(ZEND_FIBER_EMSCRIPTEN) && !defined(ZEND_FIBER_UCONTEXT)
/* Get the context that resumed us and update its handle to allow for symmetric coroutines. */
from->handle = data.handle;
#endif
@@ -395,8 +451,13 @@ static ZEND_NORETURN void zend_fiber_trampoline(boost_context_data data)
/* Final context switch, the fiber must not be resumed afterwards! */
zend_fiber_switch_context(&transfer);
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ /* Allow Asyncify to finish unwinding the completed fiber's callback. */
+ return;
+#else
/* Abort here because we are in an inconsistent program state. */
abort();
+#endif
}
ZEND_API void zend_fiber_switch_block(void)
@@ -423,7 +484,20 @@ ZEND_API zend_result zend_fiber_init_context(zend_fiber_context *context, void *
return FAILURE;
}
-#ifdef ZEND_FIBER_UCONTEXT
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ emscripten_fiber_t *handle = &context->stack->fiber;
+
+ emscripten_fiber_init(
+ handle,
+ (em_arg_callback_func) zend_fiber_trampoline,
+ NULL,
+ context->stack->pointer,
+ context->stack->size,
+ context->stack->pointer_asyncify,
+ context->stack->size_asyncify);
+
+ context->handle = handle;
+#elif defined(ZEND_FIBER_UCONTEXT)
ucontext_t *handle = &context->stack->ucontext;
getcontext(handle);
@@ -516,7 +590,14 @@ ZEND_API void zend_fiber_switch_context(zend_fiber_transfer *transfer)
to->stack->asan_size);
#endif
-#ifdef ZEND_FIBER_UCONTEXT
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ transfer_data = transfer;
+
+ emscripten_fiber_swap(from->handle, to->handle);
+
+ /* Copy transfer struct because it might live on the other fiber's stack that will eventually be destroyed. */
+ *transfer = *transfer_data;
+#elif defined(ZEND_FIBER_UCONTEXT)
transfer_data = transfer;
swapcontext(from->handle, to->handle);
@@ -532,7 +613,7 @@ ZEND_API void zend_fiber_switch_context(zend_fiber_transfer *transfer)
to = transfer->context;
-#ifndef ZEND_FIBER_UCONTEXT
+#if !defined(ZEND_FIBER_EMSCRIPTEN) && !defined(ZEND_FIBER_UCONTEXT)
/* Get the context that resumed us and update its handle to allow for symmetric coroutines. */
to->handle = data.handle;
#endif
@@ -1127,7 +1208,24 @@ void zend_fiber_init(void)
{
zend_fiber_context *context = ecalloc(1, sizeof(zend_fiber_context));
-#if defined(__SANITIZE_ADDRESS__) || defined(ZEND_FIBER_UCONTEXT)
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ context->stack = ecalloc(1, sizeof(zend_fiber_stack));
+ context->stack->pointer_asyncify = malloc(EMS_FIBER_ASYNCIFY_STACK_SIZE);
+
+ if (!context->stack->pointer_asyncify) {
+ efree(context->stack);
+ efree(context);
+ zend_error_noreturn(E_ERROR, "Main fiber Asyncify stack allocation failed");
+ }
+
+ context->stack->size_asyncify = EMS_FIBER_ASYNCIFY_STACK_SIZE;
+ context->handle = &context->stack->fiber;
+
+ emscripten_fiber_init_from_current_context(
+ context->handle,
+ context->stack->pointer_asyncify,
+ context->stack->size_asyncify);
+#elif defined(__SANITIZE_ADDRESS__) || defined(ZEND_FIBER_UCONTEXT)
// Main fiber stack is only needed if ASan or ucontext is enabled.
context->stack = emalloc(sizeof(zend_fiber_stack));
@@ -1147,7 +1245,10 @@ void zend_fiber_init(void)
void zend_fiber_shutdown(void)
{
-#if defined(__SANITIZE_ADDRESS__) || defined(ZEND_FIBER_UCONTEXT)
+#ifdef ZEND_FIBER_EMSCRIPTEN
+ free(EG(main_fiber_context)->stack->pointer_asyncify);
+ efree(EG(main_fiber_context)->stack);
+#elif defined(__SANITIZE_ADDRESS__) || defined(ZEND_FIBER_UCONTEXT)
efree(EG(main_fiber_context)->stack);
#endif
diff --git a/third_party/php8.5-src/ext/libxml/libxml.c b/third_party/php8.5-src/ext/libxml/libxml.c
index 0105106..2eb9f8f 100644
--- a/third_party/php8.5-src/ext/libxml/libxml.c
+++ b/third_party/php8.5-src/ext/libxml/libxml.c
@@ -50,6 +50,25 @@
#include "libxml_arginfo.h"
+#ifdef LIBXML_DYNAMIC_LOAD
+__attribute__((weak)) const char *xmlParserVersion = {0};
+__attribute__((weak)) int xmlLoadExtDtdDefaultValue = 0;
+__attribute__((weak)) int xmlDoValidityCheckingDefaultValue = 0;
+__attribute__((weak)) void (*xmlFree)(void *);
+__attribute__((weak)) void *(*xmlMalloc)(size_t);
+__attribute__((weak)) void *(*xmlMallocAtomic)(size_t);
+__attribute__((weak)) char *(*xmlMemStrdup)(const char *);
+__attribute__((weak)) void *(*xmlRealloc)(void *, size_t);
+__attribute__((weak)) void (*xmlGenericError)(void *, const char *, ...);
+__attribute__((weak)) void (*xmlStructuredError)(void *, xmlErrorPtr);
+#define PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, symbol) do { \
+ __typeof__(symbol) *symbol##_ptr = (__typeof__(symbol) *) dlsym((handle), #symbol); \
+ if (symbol##_ptr) { \
+ symbol = *symbol##_ptr; \
+ } \
+} while (0)
+#endif
+
/* a true global for initialization */
static bool php_libxml_initialized = false;
static bool php_libxml_per_request_initialization = true;
@@ -983,6 +1002,39 @@ PHP_LIBXML_API void php_libxml_switch_context(const zval *context, zval *oldcont
static PHP_MINIT_FUNCTION(libxml)
{
+#ifdef LIBXML_DYNAMIC_LOAD
+ if (xmlParserVersion == NULL) {
+ void *handle = DL_LOAD("libxml2.so");
+ if (handle) {
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlParserVersion);
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlLoadExtDtdDefaultValue);
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlDoValidityCheckingDefaultValue);
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlFree);
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlMalloc);
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlMallocAtomic);
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlMemStrdup);
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlRealloc);
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlGenericError);
+ PHP_LIBXML_RESOLVE_WEAK_SYMBOL(handle, xmlStructuredError);
+ }
+ }
+#endif
+
+ if (xmlParserVersion == NULL) {
+ zend_disable_class("LibXMLError", sizeof("LibXMLError") - 1);
+ zend_disable_functions(
+ "libxml_set_streams_context,"
+ "libxml_use_internal_errors,"
+ "libxml_get_last_error,"
+ "libxml_get_errors,"
+ "libxml_clear_errors,"
+ "libxml_disable_entity_loader,"
+ "libxml_set_external_entity_loader,"
+ "libxml_get_external_entity_loader,"
+ );
+ return SUCCESS;
+ }
+
php_libxml_initialize();
register_libxml_symbols(module_number);
@@ -1020,6 +1072,8 @@ static PHP_MINIT_FUNCTION(libxml)
static PHP_RINIT_FUNCTION(libxml)
{
+ if (xmlParserVersion == NULL) return SUCCESS;
+
if (php_libxml_per_request_initialization) {
/* report errors via handler rather than stderr */
xmlSetGenericErrorFunc(NULL, php_libxml_error_handler);
@@ -1047,6 +1101,8 @@ static PHP_RSHUTDOWN_FUNCTION(libxml)
static PHP_MSHUTDOWN_FUNCTION(libxml)
{
+ if (xmlParserVersion == NULL) return SUCCESS;
+
if (!php_libxml_per_request_initialization) {
xmlSetGenericErrorFunc(NULL, NULL);
@@ -1060,6 +1116,8 @@ static PHP_MSHUTDOWN_FUNCTION(libxml)
static zend_result php_libxml_post_deactivate(void)
{
+ if (xmlParserVersion == NULL) return SUCCESS;
+
/* reset libxml generic error handling */
if (php_libxml_per_request_initialization) {
xmlSetGenericErrorFunc(NULL, NULL);
@@ -1085,6 +1143,13 @@ static zend_result php_libxml_post_deactivate(void)
static PHP_MINFO_FUNCTION(libxml)
{
+ if (xmlParserVersion == NULL) {
+ php_info_print_table_start();
+ php_info_print_table_row(2, "libXML support", "NOT ACTIVE");
+ php_info_print_table_end();
+ return;
+ }
+
php_info_print_table_start();
php_info_print_table_row(2, "libXML support", "active");
php_info_print_table_row(2, "libXML Compiled Version", LIBXML_DOTTED_VERSION);
@@ -1097,6 +1162,8 @@ static PHP_MINFO_FUNCTION(libxml)
/* {{{ Set the streams context for the next libxml document load or write */
PHP_FUNCTION(libxml_set_streams_context)
{
+ if (xmlParserVersion == NULL) return;
+
zval *arg;
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -1120,6 +1187,8 @@ PHP_LIBXML_API bool php_libxml_uses_internal_errors(void)
/* {{{ Disable libxml errors and allow user to fetch error information as needed */
PHP_FUNCTION(libxml_use_internal_errors)
{
+ if (xmlParserVersion == NULL) return;
+
bool use_errors, use_errors_is_null = true;
ZEND_PARSE_PARAMETERS_START(0, 1)
@@ -1173,6 +1242,8 @@ static void php_libxml_create_error_object(zval *return_value, const xmlError *e
/* {{{ Retrieve last error from libxml */
PHP_FUNCTION(libxml_get_last_error)
{
+ if (xmlParserVersion == NULL) return;
+
ZEND_PARSE_PARAMETERS_NONE();
const xmlError *error;
@@ -1194,6 +1265,8 @@ PHP_FUNCTION(libxml_get_last_error)
/* {{{ Retrieve array of errors */
PHP_FUNCTION(libxml_get_errors)
{
+ if (xmlParserVersion == NULL) return;
+
ZEND_PARSE_PARAMETERS_NONE();
if (LIBXML(error_list)) {
@@ -1215,6 +1288,8 @@ PHP_FUNCTION(libxml_get_errors)
/* {{{ Clear last error from libxml */
PHP_FUNCTION(libxml_clear_errors)
{
+ if (xmlParserVersion == NULL) return;
+
ZEND_PARSE_PARAMETERS_NONE();
xmlResetLastError();
@@ -1235,6 +1310,8 @@ PHP_LIBXML_API bool php_libxml_disable_entity_loader(bool disable) /* {{{ */
/* {{{ Disable/Enable ability to load external entities */
PHP_FUNCTION(libxml_disable_entity_loader)
{
+ if (xmlParserVersion == NULL) return;
+
bool disable = true;
ZEND_PARSE_PARAMETERS_START(0, 1)
@@ -1249,6 +1326,8 @@ PHP_FUNCTION(libxml_disable_entity_loader)
/* {{{ Changes the default external entity loader */
PHP_FUNCTION(libxml_set_external_entity_loader)
{
+ if (xmlParserVersion == NULL) return;
+
zend_fcall_info fci;
zend_fcall_info_cache fcc;
@@ -1270,6 +1349,8 @@ PHP_FUNCTION(libxml_set_external_entity_loader)
/* {{{ Get the current external entity loader, or null if the default loader is installer. */
PHP_FUNCTION(libxml_get_external_entity_loader)
{
+ if (xmlParserVersion == NULL) return;
+
ZEND_PARSE_PARAMETERS_NONE();
if (ZEND_FCC_INITIALIZED(LIBXML(entity_loader_callback))) {
diff --git a/third_party/php8.5-src/ext/openssl/openssl.c b/third_party/php8.5-src/ext/openssl/openssl.c
index cb134e9..b1ef0af 100644
--- a/third_party/php8.5-src/ext/openssl/openssl.c
+++ b/third_party/php8.5-src/ext/openssl/openssl.c
@@ -437,8 +437,8 @@ PHP_MINIT_FUNCTION(openssl)
/* override the default tcp socket provider */
php_stream_xport_register("tcp", php_openssl_ssl_socket_factory);
- php_register_url_stream_wrapper("https", &php_stream_http_wrapper);
- php_register_url_stream_wrapper("ftps", &php_stream_ftp_wrapper);
+ // php_register_url_stream_wrapper("https", &php_stream_http_wrapper);
+ // php_register_url_stream_wrapper("ftps", &php_stream_ftp_wrapper);
REGISTER_INI_ENTRIES();
@@ -2304,7 +2304,7 @@ PHP_FUNCTION(openssl_pkey_get_details)
array_init(return_value);
add_assoc_long(return_value, "bits", EVP_PKEY_bits(pkey));
add_assoc_stringl(return_value, "key", pbio, pbio_len);
-
+
zend_long ktype = php_openssl_pkey_get_details(return_value, pkey);
add_assoc_long(return_value, "type", ktype);
diff --git a/third_party/php8.5-src/ext/pdo_sqlite/pdo_sqlite.c b/third_party/php8.5-src/ext/pdo_sqlite/pdo_sqlite.c
index 667948f..96ee360 100644
--- a/third_party/php8.5-src/ext/pdo_sqlite/pdo_sqlite.c
+++ b/third_party/php8.5-src/ext/pdo_sqlite/pdo_sqlite.c
@@ -22,8 +22,8 @@
#include "php_ini.h"
#include "ext/standard/info.h"
#include "SAPI.h"
-#include "ext/pdo/php_pdo.h"
-#include "ext/pdo/php_pdo_driver.h"
+#include "../ext/pdo/php_pdo.h"
+#include "../ext/pdo/php_pdo_driver.h"
#include "php_pdo_sqlite.h"
#include "php_pdo_sqlite_int.h"
#include "zend_exceptions.h"
diff --git a/third_party/php8.5-src/ext/pdo_sqlite/sqlite_driver.c b/third_party/php8.5-src/ext/pdo_sqlite/sqlite_driver.c
index 537aefa..a55cbd5 100644
--- a/third_party/php8.5-src/ext/pdo_sqlite/sqlite_driver.c
+++ b/third_party/php8.5-src/ext/pdo_sqlite/sqlite_driver.c
@@ -21,8 +21,8 @@
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
-#include "ext/pdo/php_pdo.h"
-#include "ext/pdo/php_pdo_driver.h"
+#include "../ext/pdo/php_pdo.h"
+#include "../ext/pdo/php_pdo_driver.h"
#include "php_pdo_sqlite.h"
#include "php_pdo_sqlite_int.h"
#include "zend_exceptions.h"
diff --git a/third_party/php8.5-src/ext/standard/basic_functions.c b/third_party/php8.5-src/ext/standard/basic_functions.c
index 8b72fff..6f8a63c 100644
--- a/third_party/php8.5-src/ext/standard/basic_functions.c
+++ b/third_party/php8.5-src/ext/standard/basic_functions.c
@@ -342,8 +342,8 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */
php_register_url_stream_wrapper("file", &php_plain_files_wrapper);
php_register_url_stream_wrapper("glob", &php_glob_stream_wrapper);
php_register_url_stream_wrapper("data", &php_stream_rfc2397_wrapper);
- php_register_url_stream_wrapper("http", &php_stream_http_wrapper);
- php_register_url_stream_wrapper("ftp", &php_stream_ftp_wrapper);
+ // php_register_url_stream_wrapper("http", &php_stream_http_wrapper);
+ // php_register_url_stream_wrapper("ftp", &php_stream_ftp_wrapper);
return SUCCESS;
}
diff --git a/third_party/php8.5-src/ext/standard/credits.c b/third_party/php8.5-src/ext/standard/credits.c
index 4e8722d..1343330 100644
--- a/third_party/php8.5-src/ext/standard/credits.c
+++ b/third_party/php8.5-src/ext/standard/credits.c
@@ -33,6 +33,11 @@ PHPAPI ZEND_COLD void php_print_credits(int flag) /* {{{ */
PUTS("PHP Credits\n");
}
+ php_info_print_table_start();
+ php_info_print_table_header(1, "php-wasm");
+ php_info_print_table_row(1, "Sean Morris & Oraoto");
+ php_info_print_table_end();
+
if (flag & PHP_CREDITS_GROUP) {
/* Group */
diff --git a/third_party/php8.5-src/ext/standard/credits_ext.h b/third_party/php8.5-src/ext/standard/credits_ext.h
index 509135a..981ea04 100644
--- a/third_party/php8.5-src/ext/standard/credits_ext.h
+++ b/third_party/php8.5-src/ext/standard/credits_ext.h
@@ -44,10 +44,12 @@ CREDIT_LINE("ODBC", "Stig Bakken, Andreas Karajannis, Frank M. Kromann, Daniel R
CREDIT_LINE("Opcache", "Andi Gutmans, Zeev Suraski, Stanislav Malyshev, Dmitry Stogov, Xinchen Hui");
CREDIT_LINE("OpenSSL", "Stig Venaas, Wez Furlong, Sascha Kettler, Scott MacVicar, Eliot Lear");
CREDIT_LINE("pcntl", "Jason Greene, Arnaud Le Blanc");
+CREDIT_LINE("pdo-pglite", "Sean Morris");
CREDIT_LINE("Perl Compatible Regexps", "Andrei Zmievski");
CREDIT_LINE("PHP Archive", "Gregory Beaver, Marcus Boerger");
CREDIT_LINE("PHP Data Objects", "Wez Furlong, Marcus Boerger, Sterling Hughes, George Schlossnagle, Ilia Alshanetsky");
CREDIT_LINE("PHP hash", "Sara Golemon, Rasmus Lerdorf, Stefan Esser, Michael Wallner, Scott MacVicar");
+CREDIT_LINE("pib", "Oraoto, Sean Morris");
CREDIT_LINE("Posix", "Kristian Koehntopp");
CREDIT_LINE("PostgreSQL driver for PDO", "Edin Kadribasic, Ilia Alshanetsky");
CREDIT_LINE("PostgreSQL", "Jouni Ahto, Zeev Suraski, Yasuo Ohgaki, Chris Kings-Lynne");
@@ -70,6 +72,8 @@ CREDIT_LINE("System V Shared Memory", "Christian Cartus");
CREDIT_LINE("tidy", "John Coggeshall, Ilia Alshanetsky");
CREDIT_LINE("tokenizer", "Andrei Zmievski, Johannes Schlueter");
CREDIT_LINE("uri", "Máté Kocsis, Tim Düsterhus, Ignace Nyamagana Butera, Arnaud Le Blanc, Dennis Snell, Niels Dossche, Nicolas Grekas");
+CREDIT_LINE("Vrzno", "Sean Morris");
+CREDIT_LINE("waitline", "Sean Morris");
CREDIT_LINE("XML", "Stig Bakken, Thies C. Arntzen, Sterling Hughes");
CREDIT_LINE("XMLReader", "Rob Richards");
CREDIT_LINE("XMLWriter", "Rob Richards, Pierre-Alain Joye");
diff --git a/third_party/php8.5-src/ext/tokenizer/tokenizer.c b/third_party/php8.5-src/ext/tokenizer/tokenizer.c
index 203a9b9..0d78de1 100644
--- a/third_party/php8.5-src/ext/tokenizer/tokenizer.c
+++ b/third_party/php8.5-src/ext/tokenizer/tokenizer.c
@@ -318,7 +318,7 @@ static void add_token(
zend_hash_next_index_insert_new(return_value_ht, &token);
}
-static bool tokenize(zval *return_value, zend_string *source, zend_class_entry *token_class)
+bool tokenize(zval *return_value, zend_string *source, zend_class_entry *token_class)
{
zval source_zval;
zend_lex_state original_lex_state;
diff --git a/third_party/php8.5-src/main/fastcgi.c b/third_party/php8.5-src/main/fastcgi.c
index 448576a..7209487 100644
--- a/third_party/php8.5-src/main/fastcgi.c
+++ b/third_party/php8.5-src/main/fastcgi.c
@@ -551,6 +551,7 @@ void fcgi_shutdown(void)
{
if (is_initialized) {
zend_hash_destroy(&fcgi_mgmt_vars);
+ is_initialized = 0;
}
is_fastcgi = 0;
if (allowed_clients) {
diff --git a/third_party/php8.5-src/sapi/cgi/Makefile.frag b/third_party/php8.5-src/sapi/cgi/Makefile.frag
index 79e2afe..0956f43 100644
--- a/third_party/php8.5-src/sapi/cgi/Makefile.frag
+++ b/third_party/php8.5-src/sapi/cgi/Makefile.frag
@@ -1,7 +1,7 @@
cgi: $(SAPI_CGI_PATH)
$(SAPI_CGI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_FASTCGI_OBJS) $(PHP_CGI_OBJS)
- $(BUILD_CGI)
+ $(BUILD_CGI) $(WASM_SHARED_LIBS)
install-cgi: $(SAPI_CGI_PATH)
@echo "Installing PHP CGI binary: $(INSTALL_ROOT)$(bindir)/"
diff --git a/third_party/php8.5-src/sapi/cgi/cgi_main.c b/third_party/php8.5-src/sapi/cgi/cgi_main.c
index 6db96a4..77b7547 100644
--- a/third_party/php8.5-src/sapi/cgi/cgi_main.c
+++ b/third_party/php8.5-src/sapi/cgi/cgi_main.c
@@ -19,6 +19,7 @@
+----------------------------------------------------------------------+
*/
+#include <emscripten.h>
#include "php.h"
#include "php_globals.h"
#include "php_variables.h"
@@ -1870,7 +1871,8 @@ int main(int argc, char *argv[])
SG(request_info).path_translated = NULL;
#endif
- cgi_sapi_module.executable_location = argv[0];
+ // cgi_sapi_module.executable_location = argv[0];
+ cgi_sapi_module.executable_location = NULL;
if (!cgi && !fastcgi && !bindpath) {
cgi_sapi_module.additional_functions = additional_functions;
}
@@ -1952,9 +1954,10 @@ consult the installation file that came with this distribution, or visit \n\
}
/* make php call us to get _ENV vars */
- php_php_import_environment_variables = php_import_environment_variables;
- php_import_environment_variables = cgi_php_import_environment_variables;
-
+ if(php_import_environment_variables != cgi_php_import_environment_variables) {
+ php_php_import_environment_variables = php_import_environment_variables;
+ php_import_environment_variables = cgi_php_import_environment_variables;
+ }
if (fastcgi) {
/* How many times to run PHP scripts before dying */
if (getenv("PHP_FCGI_MAX_REQUESTS")) {
@@ -2677,3 +2680,23 @@ consult the installation file that came with this distribution, or visit \n\
return exit_status;
}
/* }}} */
+
+int EMSCRIPTEN_KEEPALIVE wasm_sapi_cgi_main(int argc, char **argv)
+{
+ return main(argc, argv);
+}
+
+void EMSCRIPTEN_KEEPALIVE wasm_sapi_cgi_init(void)
+{
+ putenv("USE_ZEND_ALLOC=0");
+}
+
+char* EMSCRIPTEN_KEEPALIVE wasm_sapi_cgi_getenv(char *name)
+{
+ return getenv(name);
+}
+
+char* EMSCRIPTEN_KEEPALIVE wasm_sapi_cgi_putenv(char *name, char *value)
+{
+ return _sapi_cgi_putenv(name, strlen(name), value);
+}
diff --git a/third_party/php8.5-src/sapi/cli/Makefile.frag b/third_party/php8.5-src/sapi/cli/Makefile.frag
index aa1d642..649533d 100644
--- a/third_party/php8.5-src/sapi/cli/Makefile.frag
+++ b/third_party/php8.5-src/sapi/cli/Makefile.frag
@@ -1,7 +1,7 @@
cli: $(SAPI_CLI_PATH)
$(SAPI_CLI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_CLI_OBJS)
- $(BUILD_CLI)
+ $(BUILD_CLI) $(WASM_SHARED_LIBS)
install-cli: $(SAPI_CLI_PATH)
@echo "Installing PHP CLI binary: $(INSTALL_ROOT)$(bindir)/"
diff --git a/third_party/php8.5-src/sapi/cli/php_cli.c b/third_party/php8.5-src/sapi/cli/php_cli.c
index 460acb6..0ecdd90 100644
--- a/third_party/php8.5-src/sapi/cli/php_cli.c
+++ b/third_party/php8.5-src/sapi/cli/php_cli.c
@@ -18,6 +18,7 @@
+----------------------------------------------------------------------+
*/
+#include <emscripten.h>
#include "php.h"
#include "php_globals.h"
#include "php_variables.h"
@@ -1395,6 +1396,15 @@ int main(int argc, char *argv[])
* exiting.
*/
cleanup_ps_args(argv);
+#ifdef __EMSCRIPTEN__
+ return exit_status;
+#else
exit(exit_status);
+#endif
}
/* }}} */
+
+int EMSCRIPTEN_KEEPALIVE wasm_sapi_cli_main(int argc, char **argv)
+{
+ return main(argc, argv);
+}
diff --git a/third_party/php8.5-src/sapi/embed/php_embed.c b/third_party/php8.5-src/sapi/embed/php_embed.c
index 06cd1fb..5fb7754 100644
--- a/third_party/php8.5-src/sapi/embed/php_embed.c
+++ b/third_party/php8.5-src/sapi/embed/php_embed.c
@@ -241,8 +241,8 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv)
return FAILURE;
}
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
+ SG(headers_sent) = 0;
+ SG(request_info).no_headers = 0;
php_register_variable("PHP_SELF", "-", NULL);
return SUCCESS;
diff --git a/third_party/php8.5-src/sapi/phpdbg/Makefile.frag b/third_party/php8.5-src/sapi/phpdbg/Makefile.frag
index 3b09f6a..263b3ff 100644
--- a/third_party/php8.5-src/sapi/phpdbg/Makefile.frag
+++ b/third_party/php8.5-src/sapi/phpdbg/Makefile.frag
@@ -6,7 +6,7 @@ $(SAPI_PHPDBG_SHARED_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_PHPDBG_O
$(BUILD_PHPDBG_SHARED)
$(SAPI_PHPDBG_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_PHPDBG_OBJS)
- $(BUILD_PHPDBG)
+ $(BUILD_PHPDBG) $(WASM_SHARED_LIBS)
%.c: %.y
%.c: %.l
diff --git a/third_party/php8.5-src/sapi/phpdbg/phpdbg.c b/third_party/php8.5-src/sapi/phpdbg/phpdbg.c
index 4ef83be..0c3aa8c 100644
--- a/third_party/php8.5-src/sapi/phpdbg/phpdbg.c
+++ b/third_party/php8.5-src/sapi/phpdbg/phpdbg.c
@@ -16,6 +16,8 @@
+----------------------------------------------------------------------+
*/
+#include <emscripten.h>
+
#include "phpdbg.h"
#include "phpdbg_prompt.h"
#include "phpdbg_bp.h"
@@ -144,6 +146,34 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
#endif
} /* }}} */
+const char* phpdbg_wasm_current_file = NULL;
+uint32_t phpdbg_wasm_current_line = NULL;
+
+const char** EMSCRIPTEN_KEEPALIVE phpdbg_wasm_get_current_file(void)
+{
+ return &phpdbg_wasm_current_file;
+}
+
+uint32_t* EMSCRIPTEN_KEEPALIVE phpdbg_wasm_get_current_line(void)
+{
+ return &phpdbg_wasm_current_line;
+}
+
+int* EMSCRIPTEN_KEEPALIVE php_wasm_get_bpcount(void)
+{
+ return &PHPDBG_G(bp_count);
+}
+
+bool EMSCRIPTEN_KEEPALIVE php_wasm_is_executing(void)
+{
+ return PHPDBG_G(in_execution) || (PHPDBG_G(flags) & PHPDBG_IS_STOPPING);
+}
+
+bool EMSCRIPTEN_KEEPALIVE php_wasm_is_running(void)
+{
+ return PHPDBG_G(flags) & PHPDBG_IS_RUNNING;
+}
+
static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */
{
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], 8, NULL, php_phpdbg_destroy_bp_file, 0);
@@ -173,6 +203,9 @@ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */
static PHP_MSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
{
+ phpdbg_wasm_current_file = NULL;
+ phpdbg_wasm_current_line = NULL;
+
zend_hash_destroy(&PHPDBG_G(registered));
phpdbg_destroy_watchpoints();
@@ -1111,7 +1144,7 @@ php_stream *phpdbg_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *
return PHPDBG_G(orig_url_wrap_php)->wops->stream_opener(wrapper, path, mode, options, opened_path, context STREAMS_CC);
} /* }}} */
-int main(int argc, char **argv) /* {{{ */
+int EMSCRIPTEN_KEEPALIVE wasm_sapi_phpdbg_main(int argc, char **argv) /* {{{ */
{
sapi_module_struct *phpdbg = &phpdbg_sapi_module;
char *sapi_name;
diff --git a/third_party/php8.5-src/sapi/phpdbg/phpdbg.h b/third_party/php8.5-src/sapi/phpdbg/phpdbg.h
index e5f6413..487a2e6 100644
--- a/third_party/php8.5-src/sapi/phpdbg/phpdbg.h
+++ b/third_party/php8.5-src/sapi/phpdbg/phpdbg.h
@@ -182,7 +182,7 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input);
#ifndef _WIN32
# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET | PHPDBG_IS_COLOURED | PHPDBG_IS_BP_ENABLED | PHPDBG_HAS_PAGINATION)
#else
-# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET | PHPDBG_IS_BP_ENABLED | PHPDBG_HAS_PAGINATION)
+# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET | PHPDBG_IS_BP_ENABLED)
#endif /* }}} */
/* {{{ output descriptors */
@@ -313,4 +313,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
zend_ulong lines; /* max number of lines to display */
ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */
+extern const char* phpdbg_wasm_current_file;
+extern uint32_t phpdbg_wasm_current_line;
+
#endif /* PHPDBG_H */
diff --git a/third_party/php8.5-src/sapi/phpdbg/phpdbg_cmd.c b/third_party/php8.5-src/sapi/phpdbg/phpdbg_cmd.c
index 9877d60..d27a228 100644
--- a/third_party/php8.5-src/sapi/phpdbg/phpdbg_cmd.c
+++ b/third_party/php8.5-src/sapi/phpdbg/phpdbg_cmd.c
@@ -754,7 +754,7 @@ PHPDBG_API char *phpdbg_read_input(const char *buffered) /* {{{ */
ignored if compiled without readline integration. */
if (!isatty(PHPDBG_G(io)[PHPDBG_STDIN].fd)) {
char buf[PHPDBG_MAX_CMD];
- phpdbg_write("%s", phpdbg_get_prompt());
+ // phpdbg_write("%s", phpdbg_get_prompt());
phpdbg_consume_stdin_line(buf);
buffer = estrdup(buf);
} else
diff --git a/third_party/php8.5-src/sapi/phpdbg/phpdbg_info.c b/third_party/php8.5-src/sapi/phpdbg/phpdbg_info.c
index b329bda..4dde04a 100644
--- a/third_party/php8.5-src/sapi/phpdbg/phpdbg_info.c
+++ b/third_party/php8.5-src/sapi/phpdbg/phpdbg_info.c
@@ -159,7 +159,7 @@ PHPDBG_INFO(constants) /* {{{ */
return SUCCESS;
} /* }}} */
-static int phpdbg_arm_auto_global(zval *ptrzv) {
+int phpdbg_arm_auto_global(zval *ptrzv) {
zend_auto_global *auto_global = Z_PTR_P(ptrzv);
if (auto_global->armed) {
diff --git a/third_party/php8.5-src/sapi/phpdbg/phpdbg_io.c b/third_party/php8.5-src/sapi/phpdbg/phpdbg_io.c
index 261a67c..d614628 100644
--- a/third_party/php8.5-src/sapi/phpdbg/phpdbg_io.c
+++ b/third_party/php8.5-src/sapi/phpdbg/phpdbg_io.c
@@ -14,6 +14,8 @@
+----------------------------------------------------------------------+
*/
+#include <emscripten.h>
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -22,52 +24,40 @@
ZEND_EXTERN_MODULE_GLOBALS(phpdbg)
-/* is easy to generalize ... but not needed for now */
-PHPDBG_API int phpdbg_consume_stdin_line(char *buf) {
- int bytes = PHPDBG_G(input_buflen), len = 0;
+EM_ASYNC_JS(int, phpdbg_internal_consume_stdin_line, (char *buf, int max_length), {
+
+ let input;
+
+ Module.triggerStdin();
- if (PHPDBG_G(input_buflen)) {
- memcpy(buf, PHPDBG_G(input_buffer), bytes);
+ if(Module.inputDataQueue.length)
+ {
+ input = String(Module.inputDataQueue.shift());
+ }
+ else
+ {
+ let a, r;
+ const promise = new Promise((accept, reject) => [a, r] = [ accept, reject ]);
+ Module.awaitingInput = a;
+ input = String(await promise);
}
- PHPDBG_G(last_was_newline) = 1;
+ if(input.length >= max_length)
+ {
+ input = input.slice(0, max_length - 1);
+ }
- do {
- int i;
- if (bytes <= 0) {
- continue;
- }
+ stringToUTF8(input, buf, input.length + 1);
- for (i = len; i < len + bytes; i++) {
- if (buf[i] == '\x03') {
- if (i != len + bytes - 1) {
- memmove(buf + i, buf + i + 1, len + bytes - i - 1);
- }
- len--;
- i--;
- continue;
- }
- if (buf[i] == '\n') {
- PHPDBG_G(input_buflen) = len + bytes - 1 - i;
- if (PHPDBG_G(input_buflen)) {
- memcpy(PHPDBG_G(input_buffer), buf + i + 1, PHPDBG_G(input_buflen));
- }
- if (i != PHPDBG_MAX_CMD - 1) {
- buf[i + 1] = 0;
- }