Skip to content

Commit 60b7d73

Browse files
committed
feat: Add php 8.2.0 with wasmedge and tests
1 parent 81763aa commit 60b7d73

9 files changed

+3450
-0
lines changed

php/php-8.2.0/patches/0001-Initial-port-of-the-php-7.4.32-patch-for-php-8.2.11.patch

Lines changed: 2042 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
From 60d1ba4112181cc071ac3317424da057290d74eb Mon Sep 17 00:00:00 2001
2+
From: Asen Alexandrov <[email protected]>
3+
Date: Tue, 3 Jan 2023 17:02:38 +0200
4+
Subject: [PATCH 2/5] feat: Incapacitate fibers when compiling for WASI
5+
6+
26.2% Zend/
7+
8+
26.2% Zend/
9+
diff --git a/Zend/zend_fibers.c b/Zend/zend_fibers.c
10+
index 0bc4e0c676..772d379dd8 100644
11+
--- a/Zend/zend_fibers.c
12+
+++ b/Zend/zend_fibers.c
13+
@@ -347,12 +347,14 @@ ZEND_API bool zend_fiber_init_context(zend_fiber_context *context, void *kind, z
14+
makecontext(handle, (void (*)(void)) zend_fiber_trampoline, 0);
15+
16+
context->handle = handle;
17+
-#else
18+
+#elif !defined(__wasi__)
19+
// Stack grows down, calculate the top of the stack. make_fcontext then shifts pointer to lower 16-byte boundary.
20+
void *stack = (void *) ((uintptr_t) context->stack->pointer + context->stack->size);
21+
22+
context->handle = make_fcontext(stack, context->stack->size, zend_fiber_trampoline);
23+
ZEND_ASSERT(context->handle != NULL && "make_fcontext() never returns NULL");
24+
+#else
25+
+ return false;
26+
#endif
27+
28+
context->kind = kind;
29+
@@ -427,16 +429,18 @@ ZEND_API void zend_fiber_switch_context(zend_fiber_transfer *transfer)
30+
31+
/* Copy transfer struct because it might live on the other fiber's stack that will eventually be destroyed. */
32+
*transfer = *transfer_data;
33+
-#else
34+
+#elif !defined(__wasi__)
35+
boost_context_data data = jump_fcontext(to->handle, transfer);
36+
37+
/* Copy transfer struct because it might live on the other fiber's stack that will eventually be destroyed. */
38+
*transfer = *data.transfer;
39+
+#else
40+
+ return;
41+
#endif
42+
43+
to = transfer->context;
44+
45+
-#ifndef ZEND_FIBER_UCONTEXT
46+
+#if !defined(ZEND_FIBER_UCONTEXT) && !defined(__wasi__)
47+
/* Get the context that resumed us and update its handle to allow for symmetric coroutines. */
48+
to->handle = data.handle;
49+
#endif
50+
diff --git a/configure.ac b/configure.ac
51+
index 009e8f88e9..f8088c3a94 100644
52+
--- a/configure.ac
53+
+++ b/configure.ac
54+
@@ -197,6 +197,9 @@ label2:
55+
fi
56+
PHP_SUBST(RE2C_FLAGS)
57+
58+
+dnl Check if __wasi__ is defined by the compiler
59+
+AC_CHECK_DECLS([__wasi__])
60+
+
61+
dnl Platform-specific compile settings.
62+
dnl ----------------------------------------------------------------------------
63+
64+
@@ -1300,11 +1303,13 @@ else
65+
if test "$fiber_os" = 'mac'; then
66+
AC_DEFINE([_XOPEN_SOURCE], 1, [ ])
67+
fi
68+
- AC_CHECK_HEADER(ucontext.h, [
69+
- AC_DEFINE([ZEND_FIBER_UCONTEXT], 1, [ ])
70+
- ], [
71+
- AC_MSG_ERROR([fibers not available on this platform])
72+
- ])
73+
+ if test "$ac_cv_have_decl___wasi__" != "yes"; then
74+
+ AC_CHECK_HEADER(ucontext.h, [
75+
+ AC_DEFINE([ZEND_FIBER_UCONTEXT], 1, [ ])
76+
+ ], [
77+
+ AC_MSG_ERROR([fibers not available on this platform])
78+
+ ])
79+
+ fi
80+
fi
81+
82+
LIBZEND_BASIC_CHECKS
83+
--
84+
2.38.1
85+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
From 4110cce86c84bc5df75d23675d6a2398a4baea0a Mon Sep 17 00:00:00 2001
2+
From: "[email protected]" <Wasm Labs Team>
3+
Date: Fri, 6 Jan 2023 11:04:53 +0200
4+
Subject: [PATCH 3/5] fix: Add more ifdefs for php-8.2.0
5+
6+
7+
43.3% ext/standard/
8+
56.6% main/
9+
diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h
10+
index a5b7b9a0dc..adacedd9f8 100644
11+
--- a/ext/standard/basic_functions_arginfo.h
12+
+++ b/ext/standard/basic_functions_arginfo.h
13+
@@ -3634,6 +3634,7 @@ static void register_basic_functions_symbols(int module_number)
14+
REGISTER_LONG_CONSTANT("IMAGETYPE_AVIF", IMAGE_FILETYPE_AVIF, CONST_PERSISTENT);
15+
REGISTER_LONG_CONSTANT("IMAGETYPE_UNKNOWN", IMAGE_FILETYPE_UNKNOWN, CONST_PERSISTENT);
16+
REGISTER_LONG_CONSTANT("IMAGETYPE_COUNT", IMAGE_FILETYPE_COUNT, CONST_PERSISTENT);
17+
+#ifndef __wasi__
18+
REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_PERSISTENT);
19+
REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_PERSISTENT);
20+
REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_PERSISTENT);
21+
@@ -3695,6 +3696,7 @@ static void register_basic_functions_symbols(int module_number)
22+
#if defined(LOG_PERROR)
23+
REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_PERSISTENT);
24+
#endif
25+
+#endif // __wasi__
26+
REGISTER_LONG_CONSTANT("STR_PAD_LEFT", PHP_STR_PAD_LEFT, CONST_PERSISTENT);
27+
REGISTER_LONG_CONSTANT("STR_PAD_RIGHT", PHP_STR_PAD_RIGHT, CONST_PERSISTENT);
28+
REGISTER_LONG_CONSTANT("STR_PAD_BOTH", PHP_STR_PAD_BOTH, CONST_PERSISTENT);
29+
diff --git a/main/network.c b/main/network.c
30+
index 6fb97865cb..683e11d03d 100644
31+
--- a/main/network.c
32+
+++ b/main/network.c
33+
@@ -929,7 +929,9 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short
34+
#ifdef IP_BIND_ADDRESS_NO_PORT
35+
{
36+
int val = 1;
37+
+#ifndef __wasi__
38+
(void) setsockopt(sock, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &val, sizeof(val));
39+
+#endif // !defined(__wasi__)o
40+
}
41+
#endif
42+
if (local_address_len == 0) {
43+
--
44+
2.38.1
45+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
From c11343977c9e0cdc72d48e7f20c2f76801a80d2e Mon Sep 17 00:00:00 2001
2+
From: "[email protected]" <Wasm Labs Team>
3+
Date: Fri, 6 Jan 2023 11:21:03 +0200
4+
Subject: [PATCH 4/5] fix: Fix memory issues and introduce WASM_WASMEDGE.
5+
6+
7+
76.4% Zend/
8+
11.4% ext/posix/
9+
12.1% ext/standard/
10+
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
11+
index 5e67345c76..258766a5d0 100644
12+
--- a/Zend/zend_alloc.c
13+
+++ b/Zend/zend_alloc.c
14+
@@ -465,8 +465,8 @@ static void *zend_mm_mmap(size_t size)
15+
}
16+
return ptr;
17+
#elif ! HAVE_MMAP
18+
- void* ptr = malloc(size);
19+
- memset(ptr, 0, size);
20+
+ void* ptr = malloc(size + ZEND_MMAP_AHEAD);
21+
+ memset(ptr, 0, size + ZEND_MMAP_AHEAD);
22+
return ptr;
23+
#else
24+
void *ptr;
25+
@@ -697,8 +697,8 @@ static zend_always_inline void zend_mm_hugepage(void* ptr, size_t size)
26+
static void *zend_mm_chunk_alloc_int(size_t size, size_t alignment)
27+
{
28+
#if ! HAVE_MMAP
29+
- void* ptr = aligned_alloc(alignment, size);
30+
- memset(ptr, 0, size);
31+
+ void* ptr = aligned_alloc(alignment, size + ZEND_MMAP_AHEAD);
32+
+ memset(ptr, 0, size + ZEND_MMAP_AHEAD);
33+
return ptr;
34+
#else
35+
void *ptr = zend_mm_mmap(size);
36+
diff --git a/ext/posix/posix.c b/ext/posix/posix.c
37+
index 49806f2cb4..c5e5c4a06e 100644
38+
--- a/ext/posix/posix.c
39+
+++ b/ext/posix/posix.c
40+
@@ -536,8 +536,12 @@ PHP_FUNCTION(posix_ttyname)
41+
RETURN_FALSE;
42+
}
43+
#endif
44+
+#else
45+
+ p = emalloc(1);
46+
+ *p = '\0';
47+
#endif // WASM_WASI
48+
RETURN_STRING("");
49+
+ efree(p);
50+
}
51+
/* }}} */
52+
53+
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
54+
index e3e443b48b..d367dd8e42 100755
55+
--- a/ext/standard/basic_functions.c
56+
+++ b/ext/standard/basic_functions.c
57+
@@ -70,6 +70,8 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
58+
#else
59+
#include "win32/inet.h"
60+
#endif
61+
+#elif defined(WASM_WASMEDGE)
62+
+# include <netdb.h>
63+
#endif // WASM_WASI
64+
65+
#ifdef HAVE_ARPA_INET_H
66+
--
67+
2.38.1
68+

0 commit comments

Comments
 (0)