summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2019-08-06 11:53:41 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2019-08-07 11:31:12 +0200
commit886be260cb5236cdef69bb3a1125d5e6860ffe1e (patch)
tree4a7b45a8cb84a849b237937a34ea0797df6fd6cc /win32
parent968ed124b22eeb49d721e4f65df0dc4049baefd5 (diff)
downloadphp-git-886be260cb5236cdef69bb3a1125d5e6860ffe1e.tar.gz
Make extension compatibility check more liberal
Checking for the exact linker version appears to be too restrictive; it should be fine if the tens match. We also refactor to avoid repeating ourselves.
Diffstat (limited to 'win32')
-rw-r--r--win32/winutil.c45
1 files changed, 13 insertions, 32 deletions
diff --git a/win32/winutil.c b/win32/winutil.c
index 5484c6d667..5f4821b2ef 100644
--- a/win32/winutil.c
+++ b/win32/winutil.c
@@ -438,7 +438,7 @@ PHP_WINUTIL_API char *php_win32_get_username(void)
return uname;
}/*}}}*/
-PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *name, const char *path, char **err)
+static zend_always_inline BOOL is_compatible(const char *name, BOOL is_smaller, char *format, char **err)
{/*{{{*/
PLOADED_IMAGE img = ImageLoad(name, NULL);
@@ -457,55 +457,36 @@ PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *name, const char *pa
/* VS 2015, 2017 and 2019 are binary compatible, but only forward compatible.
It should be fine, if we load a module linked with an older one into
the core linked with the newer one, but not the otherway round.
+ Analogously, it should be fine, if a PHP build linked with an older version
+ is used with a newer CRT, but not the other way round.
Otherwise, if the linker major version is not same, it is an error, as
per the current knowledge.
This check is to be extended as new VS versions come out. */
- if (14 == major && PHP_LINKER_MINOR < minor || PHP_LINKER_MAJOR != major)
+ DWORD core_minor = (DWORD)(PHP_LINKER_MINOR/10);
+ DWORD comp_minor = (DWORD)(minor/10);
+ if (14 == major && (is_smaller ? core_minor < comp_minor : core_minor > comp_minor) || PHP_LINKER_MAJOR != major)
#else
if (PHP_LINKER_MAJOR != major)
#endif
{
- spprintf(err, 0, "Can't load module '%s' as it's linked with %u.%u, but the core is linked with %d.%d", name, major, minor, PHP_LINKER_MAJOR, PHP_LINKER_MINOR);
+ spprintf(err, 0, format, name, major, minor, PHP_LINKER_MAJOR, PHP_LINKER_MINOR);
ImageUnload(img);
return FALSE;
}
-
ImageUnload(img);
return TRUE;
}/*}}}*/
+PHP_WINUTIL_API BOOL php_win32_image_compatible(const char *name, char **err)
+{/*{{{*/
+ return is_compatible(name, TRUE, "Can't load module '%s' as it's linked with %u.%u, but the core is linked with %d.%d", err);
+}/*}}}*/
+
/* Expect a CRT name DLL. */
PHP_WINUTIL_API BOOL php_win32_crt_compatible(const char *name, char **err)
{/*{{{*/
- PLOADED_IMAGE img = ImageLoad(name, NULL);
-
- if (!img) {
- DWORD _err = GetLastError();
- char *err_txt = php_win32_error_to_msg(_err);
- spprintf(err, 0, "Failed to load %s, %s", name, err_txt);
- free(err_txt);
- return FALSE;
- }
-
- DWORD major = img->FileHeader->OptionalHeader.MajorLinkerVersion;
- DWORD minor = img->FileHeader->OptionalHeader.MinorLinkerVersion;
-
-#if PHP_LINKER_MAJOR == 14
- DWORD core_minor = (DWORD)(PHP_LINKER_MINOR/10);
- DWORD comp_minor = (DWORD)(minor/10);
- if (14 == major && core_minor > comp_minor || PHP_LINKER_MAJOR != major)
-#else
- if (PHP_LINKER_MAJOR != major)
-#endif
- {
- spprintf(err, 0, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", name, major, minor, PHP_LINKER_MAJOR, PHP_LINKER_MINOR);
- ImageUnload(img);
- return FALSE;
- }
- ImageUnload(img);
-
- return TRUE;
+ return is_compatible(name, FALSE, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", err);
}/*}}}*/