Skip to content

Instantly share code, notes, and snippets.

@nono303
Created November 20, 2025 07:04
Show Gist options
  • Select an option

  • Save nono303/be0f9b3f04da2ee921b938a0ab8f1e74 to your computer and use it in GitHub Desktop.

Select an option

Save nono303/be0f9b3f04da2ee921b938a0ab8f1e74 to your computer and use it in GitHub Desktop.
php-8.5_win7.patch
diff --git "a/Zend/zend_call_stack.c" "b/Zend/zend_call_stack.c"
index ed86ecc74a2..ed3c58a471e 100644
--- "a/Zend/zend_call_stack.c"
+++ "b/Zend/zend_call_stack.c"
@@ -415,7 +415,12 @@ static bool zend_call_stack_get_win32(zend_call_stack *stack)
* v Lower addresses v
*/
- GetCurrentThreadStackLimits(&low_limit, &high_limit);
+ 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;
+ }
result_size = VirtualQuery((void*)low_limit,
&uncommitted_region, sizeof(uncommitted_region));
diff --git a/win32/ioutil.c b/win32/ioutil.c
index c9464c94744..e39a1c26ab8 100644
--- a/win32/ioutil.c
+++ b/win32/ioutil.c
@@ -67,6 +67,10 @@
#include <winnls.h>
*/
+typedef HRESULT (__stdcall *MyPathCchCanonicalizeEx)(wchar_t *pszPathOut, size_t cchPathOut, const wchar_t *pszPathIn, unsigned long dwFlags);
+
+static MyPathCchCanonicalizeEx canonicalize_path_w = NULL;
+
PW32IO BOOL php_win32_ioutil_posix_to_open_opts(int flags, mode_t mode, php_ioutil_open_opts *opts)
{/*{{{*/
int current_umask;
@@ -637,7 +641,7 @@ PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(w
}
}
- if (S_OK != PathCchCanonicalizeEx(canonicalw, MAXPATHLEN, _tmp, PATHCCH_ALLOW_LONG_PATHS)) {
+ if (S_OK != canonicalize_path_w(canonicalw, MAXPATHLEN, _tmp, PATHCCH_ALLOW_LONG_PATHS)) {
/* Length unchanged. */
*new_len = len;
return PHP_WIN32_IOUTIL_NORM_PARTIAL;
@@ -661,6 +665,27 @@ PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(w
return PHP_WIN32_IOUTIL_NORM_OK;
}/*}}}*/
+static HRESULT __stdcall MyPathCchCanonicalizeExFallback(wchar_t *pszPathOut, size_t cchPathOut, const wchar_t *pszPathIn, unsigned long dwFlags)
+{/*{{{*/
+ return -42;
+}/*}}}*/
+
+BOOL php_win32_ioutil_init(void)
+{/*{{{*/
+ HMODULE hMod = GetModuleHandle("api-ms-win-core-path-l1-1-0");
+
+ if (hMod) {
+ canonicalize_path_w = (MyPathCchCanonicalizeEx)GetProcAddress(hMod, "PathCchCanonicalizeEx");
+ if (!canonicalize_path_w) {
+ canonicalize_path_w = (MyPathCchCanonicalizeEx)MyPathCchCanonicalizeExFallback;
+ }
+ } else {
+ canonicalize_path_w = (MyPathCchCanonicalizeEx)MyPathCchCanonicalizeExFallback;
+ }
+
+ return TRUE;
+}/*}}}*/
+
PW32IO int php_win32_ioutil_access_w(const wchar_t *path, mode_t mode)
{/*{{{*/
DWORD attr;
diff --git a/win32/ioutil.h b/win32/ioutil.h
index affe7607455..8da82a7f4cc 100644
--- a/win32/ioutil.h
+++ b/win32/ioutil.h
@@ -169,6 +169,11 @@ typedef enum {
} while (0);
PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(wchar_t **buf, size_t len, size_t *new_len);
+#ifdef PHP_EXPORTS
+/* This symbols are needed only for the DllMain, but should not be exported
+ or be available when used with PHP binaries. */
+BOOL php_win32_ioutil_init(void);
+#endif
/* Keep these functions aliased for case some additional handling
is needed later. */
diff --git a/win32/time.c b/win32/time.c
index ac1abbc9e9c..f0575ce886e 100644
--- a/win32/time.c
+++ b/win32/time.c
@@ -29,7 +29,7 @@ static zend_always_inline void getfilesystemtime(struct timeval *tv)
unsigned __int64 ff = 0;
ULARGE_INTEGER fft;
- GetSystemTimePreciseAsFileTime(&ft);
+ GetSystemTimeAsFileTime(&ft);
/*
* Do not cast a pointer to a FILETIME structure to either a
@nono303
Copy link
Copy Markdown
Author

nono303 commented Nov 20, 2025

php-8 5_win7

@nono303
Copy link
Copy Markdown
Author

nono303 commented Nov 20, 2025

original thread (locked) php/php-src#12762

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