From: Anatol Belski Date: Fri, 11 Dec 2015 16:39:57 +0000 (+0100) Subject: backported 7c981192eb26fbb93be767cd6b2dc765d370bbab from 7.0 X-Git-Tag: php-7.0.2RC1~30^2^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=157d0372e01e600535a9ec9a62c19b8bc41ae6e8;p=php backported 7c981192eb26fbb93be767cd6b2dc765d370bbab from 7.0 the way it doesn't hurt BC --- diff --git a/ext/opcache/shared_alloc_win32.c b/ext/opcache/shared_alloc_win32.c index fd5d334269..171bd0d25c 100644 --- a/ext/opcache/shared_alloc_win32.c +++ b/ext/opcache/shared_alloc_win32.c @@ -26,6 +26,9 @@ #include #include +#include "main/php.h" +#include "ext/standard/md5.h" + #define ACCEL_FILEMAP_NAME "ZendOPcache.SharedMemoryArea" #define ACCEL_MUTEX_NAME "ZendOPcache.SharedMemoryMutex" #define ACCEL_FILEMAP_BASE_DEFAULT 0x01000000 @@ -74,20 +77,59 @@ static void zend_win_error_message(int type, char *msg, int err) zend_accel_error(type, msg); } +/* Backported from 7.0, the way no globals are touched which means win32 + only where it's essentially needed. */ +#define ZEND_BIN_ID "BIN_" ZEND_TOSTR(SIZEOF_CHAR) ZEND_TOSTR(SIZEOF_INT) ZEND_TOSTR(SIZEOF_LONG) ZEND_TOSTR(SIZEOF_SIZE_T) ZEND_TOSTR(SIZEOF_ZEND_LONG) ZEND_TOSTR(ZEND_MM_ALIGNMENT) +static char *accel_gen_system_id(void) +{ + PHP_MD5_CTX context; + unsigned char digest[16], c; + int i; + static char md5str[32]; + static zend_bool done = 0; + + if (done) { + return md5str; + } + + PHP_MD5Init(&context); + PHP_MD5Update(&context, PHP_VERSION, sizeof(PHP_VERSION)-1); + PHP_MD5Update(&context, ZEND_EXTENSION_BUILD_ID, sizeof(ZEND_EXTENSION_BUILD_ID)-1); + PHP_MD5Update(&context, ZEND_BIN_ID, sizeof(ZEND_BIN_ID)-1); + if (strstr(PHP_VERSION, "-dev") != 0) { + /* Development versions may be changed from build to build */ + PHP_MD5Update(&context, __DATE__, sizeof(__DATE__)-1); + PHP_MD5Update(&context, __TIME__, sizeof(__TIME__)-1); + } + PHP_MD5Final(digest, &context); + for (i = 0; i < 16; i++) { + c = digest[i] >> 4; + c = (c <= 9) ? c + '0' : c - 10 + 'a'; + md5str[i * 2] = c; + c = digest[i] & 0x0f; + c = (c <= 9) ? c + '0' : c - 10 + 'a'; + md5str[(i * 2) + 1] = c; + } + + done = 1; + + return md5str; +} + static char *create_name_with_username(char *name) { - static char newname[MAXPATHLEN + UNLEN + 4]; + static char newname[MAXPATHLEN + UNLEN + 4 + 1 + 32]; char uname[UNLEN + 1]; DWORD unsize = UNLEN; GetUserName(uname, &unsize); - snprintf(newname, sizeof(newname) - 1, "%s@%s", name, uname); + snprintf(newname, sizeof(newname) - 1, "%s@%s@%.32s", name, uname, accel_gen_system_id()); return newname; } static char *get_mmap_base_file(void) { - static char windir[MAXPATHLEN+UNLEN + 3 + sizeof("\\\\@")]; + static char windir[MAXPATHLEN+UNLEN + 3 + sizeof("\\\\@") + 1 + 32]; char uname[UNLEN + 1]; DWORD unsize = UNLEN; int l; @@ -95,7 +137,7 @@ static char *get_mmap_base_file(void) GetTempPath(MAXPATHLEN, windir); GetUserName(uname, &unsize); l = strlen(windir); - snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%s", ACCEL_FILEMAP_BASE, uname); + snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%s@%.32s", ACCEL_FILEMAP_BASE, uname, accel_gen_system_id()); return windir; }