Skip to content

PHP 8.3 not working on Windows 7 #12762

Description

@nono303

Description

Hi,
Just trying to run PHP 8.3.0 on Windows 7 (after successfully compiling it on Win11 vs17 x64) and it's failed with message

image

According to https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentthreadstacklimits it's normal as requirements are:

  • Minimum supported client Windows 8 [desktop apps | UWP apps]
  • Minimum supported server Windows Server 2012 [desktop apps | UWP apps]

It had also been clearly mentioned on #9104 (comment)
Looking to the source code, I found GetCurrentThreadStackLimits used in Zend/zend_call_stack.c

Based on https://stackoverflow.com/a/52404641 I dirtily applied the patch and now PHP 8.3.0 run fine on windows 7

diff --git "a/Zend/zend_call_stack.c" "b/Zend/zend_call_stack.c"
index 06ee521911..9fc2b570bc 100644
--- "a/Zend/zend_call_stack.c"
+++ "b/Zend/zend_call_stack.c"
@@ -376,7 +376,22 @@ static bool zend_call_stack_get_win32(zend_call_stack *stack)
 	 *                v  Lower addresses   v
 	 */
 
-	GetCurrentThreadStackLimits(&low_limit, &high_limit);
+	static void (WINAPI* GetCurrentThreadStackLimits)(PULONG_PTR , PULONG_PTR);
+	if (!GetCurrentThreadStackLimits) {
+		*(void**)&GetCurrentThreadStackLimits = GetProcAddress(GetModuleHandle(L"kernel32"), "GetCurrentThreadStackLimits");
+		if (!GetCurrentThreadStackLimits) {
+			NT_TIB* tib = (NT_TIB*)NtCurrentTeb();
+			high_limit = (ULONG_PTR)tib->StackBase;
+			MEMORY_BASIC_INFORMATION mbi;
+			if (VirtualQuery(tib->StackLimit, &mbi, sizeof(mbi))) {
+				low_limit = (ULONG_PTR)mbi.AllocationBase;
+			}
+		} else {
+			GetCurrentThreadStackLimits(&low_limit, &high_limit);
+		}
+	} else {
+		GetCurrentThreadStackLimits(&low_limit, &high_limit);
+	}
 
 	result_size = VirtualQuery((void*)low_limit,
 			&uncommitted_region, sizeof(uncommitted_region));

image

So... Does this patch (or a corrected one as I don't really master all the elements) would make sense to ensure PHP a long life on old Windows OS ?

PHP Version

PHP 8.3.0

Operating System

Windows 7 x64

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions