Skip to content

Commit 4edbf37

Browse files
committed
Basic working under PHP 8.5
Most notably we need to adapt to the phpng TLS model, but also need to make some minor changes. We also disable SEH support for now, since inline asm is no longer supported by MSVC.
1 parent a68882e commit 4edbf37

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

sapi/isapi/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (PHP_ISAPI == "yes") {
77
if (PHP_ZTS == "no") {
88
WARNING("ISAPI module requires an --enable-zts build of PHP");
99
} else {
10-
SAPI('isapi', 'php7isapi.c', 'php' + PHP_VERSION + 'isapi.dll', '/D PHP7ISAPI_EXPORTS');
10+
SAPI('isapi', 'php7isapi.c', 'php' + PHP_VERSION + 'isapi.dll', '/D PHP7ISAPI_EXPORTS /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
1111
ADD_FLAG('LDFLAGS_ISAPI', '/DEF:sapi\\isapi\\php7isapi.def');
1212
}
1313
}

sapi/isapi/php7isapi.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#endif
4646

4747
#ifdef PHP_WIN32
48-
#define PHP_ENABLE_SEH
48+
// #define PHP_ENABLE_SEH
4949
#endif
5050

5151
/*
@@ -143,6 +143,9 @@ static char *isapi_secure_server_variable_names[] = {
143143
NULL
144144
};
145145

146+
#if defined(PHP_WIN32) && defined(ZTS)
147+
ZEND_TSRMLS_CACHE_DEFINE()
148+
#endif
146149

147150
static void php_info_isapi(ZEND_MODULE_INFO_FUNC_ARGS)
148151
{
@@ -202,7 +205,7 @@ static zend_module_entry php_isapi_module = {
202205
};
203206

204207

205-
static int sapi_isapi_ub_write(const char *str, uint str_length)
208+
static size_t sapi_isapi_ub_write(const char *str, size_t str_length)
206209
{
207210
DWORD num_bytes = str_length;
208211
LPEXTENSION_CONTROL_BLOCK ecb;
@@ -222,7 +225,7 @@ static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_heade
222225

223226

224227

225-
static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length)
228+
static void accumulate_header_length(sapi_header_struct *sapi_header, unsigned int *total_length)
226229
{
227230
*total_length += sapi_header->header_len+2;
228231
}
@@ -241,7 +244,7 @@ static void concat_header(sapi_header_struct *sapi_header, char **combined_heade
241244

242245
static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers)
243246
{
244-
uint total_length = 2; /* account for the trailing \r\n */
247+
unsigned int total_length = 2; /* account for the trailing \r\n */
245248
char *combined_headers, *combined_headers_ptr;
246249
LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
247250
HSE_SEND_HEADER_EX_INFO header_info;
@@ -315,7 +318,7 @@ static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers)
315318

316319
static int php_isapi_startup(sapi_module_struct *sapi_module)
317320
{
318-
if (php_module_startup(sapi_module, &php_isapi_module, 1)==FAILURE) {
321+
if (php_module_startup(sapi_module, &php_isapi_module)==FAILURE) {
319322
return FAILURE;
320323
} else {
321324
bTerminateThreadsOnError = (zend_bool) INI_INT("isapi.terminate_threads_on_error");
@@ -324,7 +327,7 @@ static int php_isapi_startup(sapi_module_struct *sapi_module)
324327
}
325328

326329

327-
static int sapi_isapi_read_post(char *buffer, uint count_bytes)
330+
static size_t sapi_isapi_read_post(char *buffer, size_t count_bytes)
328331
{
329332
LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
330333
DWORD read_from_buf=0;
@@ -372,7 +375,7 @@ static char *sapi_isapi_read_cookies(void)
372375
efree(tmp_variable_buf);
373376
}
374377
}
375-
return STR_EMPTY_ALLOC();
378+
return NULL;
376379
}
377380

378381

@@ -836,6 +839,13 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
836839
int retval = FAILURE;
837840
#ifdef PHP_ENABLE_SEH
838841
LPEXCEPTION_POINTERS e;
842+
#endif
843+
#ifdef ZTS
844+
/* initial resource fetch */
845+
(void)ts_resource(0);
846+
# ifdef PHP_WIN32
847+
ZEND_TSRMLS_CACHE_UPDATE();
848+
# endif
839849
#endif
840850

841851
zend_first_try {
@@ -844,13 +854,11 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
844854
#endif
845855
init_request_info(lpECB);
846856
SG(server_context) = lpECB;
847-
848857
php_request_startup();
849858

850-
file_handle.filename = SG(request_info).path_translated;
851-
file_handle.free_filename = 0;
852-
file_handle.type = ZEND_HANDLE_FILENAME;
853-
file_handle.opened_path = NULL;
859+
// FIXME: we're leaking the file_handle.filename
860+
zend_stream_init_filename(&file_handle, (char *) SG(request_info).path_translated);
861+
file_handle.primary_script = 1;
854862

855863
/* open the script here so we can 404 if it fails */
856864
if (file_handle.filename)
@@ -862,12 +870,14 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
862870
} else {
863871
php_execute_script(&file_handle);
864872
}
873+
zend_destroy_file_handle(&file_handle);
865874

866875
if (SG(request_info).cookie_data) {
867876
efree(SG(request_info).cookie_data);
868877
}
869-
if (SG(request_info).path_translated)
878+
if (SG(request_info).path_translated) {
870879
efree(SG(request_info).path_translated);
880+
}
871881
#ifdef PHP_ENABLE_SEH
872882
} __except(exceptionhandler(&e, GetExceptionInformation())) {
873883
char buf[1024];
@@ -880,7 +890,7 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
880890
GetSystemInfo(&si);
881891

882892
/* Get page ESP is pointing to */
883-
_asm mov lpPage, esp;
893+
// _asm mov lpPage, esp;
884894

885895
/* Get stack allocation base */
886896
VirtualQuery(lpPage, &mi, sizeof(mi));
@@ -937,11 +947,10 @@ __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, L
937947
{
938948
switch (fdwReason) {
939949
case DLL_PROCESS_ATTACH:
940-
#ifdef WITH_ZEUS
941-
tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "TSRM.log");
942-
#else
943-
tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "C:\\TSRM.log");
944-
#endif
950+
php_tsrm_startup_ex(128);
951+
# ifdef PHP_WIN32
952+
ZEND_TSRMLS_CACHE_UPDATE();
953+
# endif
945954
sapi_startup(&isapi_sapi_module);
946955
if (isapi_sapi_module.startup) {
947956
isapi_sapi_module.startup(&sapi_module);

0 commit comments

Comments
 (0)