]> granicus.if.org Git - php/commitdiff
Turn system_id into a true global
authorChristoph M. Becker <cmbecker69@gmx.de>
Mon, 17 Jun 2019 16:43:05 +0000 (18:43 +0200)
committerJoe Watkins <krakjoe@php.net>
Tue, 18 Jun 2019 08:27:35 +0000 (10:27 +0200)
The system_id is identical for all threads and can be computed during
module startup, so there is no need to calculate and store it for each
thread.

ext/opcache/ZendAccelerator.c
ext/opcache/ZendAccelerator.h
ext/opcache/shared_alloc_win32.c
ext/opcache/zend_file_cache.c

index 9fa178dd1151355222af53fc4d654c428ca0034a..e75ae03234910f66ffcf4c43f5e752f2720e8df2 100644 (file)
@@ -109,6 +109,7 @@ ZEND_TSRMLS_CACHE_DEFINE()
 zend_accel_shared_globals *accel_shared_globals = NULL;
 
 /* true globals, no need for thread safety */
+char accel_system_id[32];
 zend_bool accel_startup_ok = 0;
 static char *zps_failure_reason = NULL;
 char *zps_api_failure_reason = NULL;
@@ -2584,9 +2585,6 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
        ZEND_TSRMLS_CACHE_UPDATE();
 #endif
        memset(accel_globals, 0, sizeof(zend_accel_globals));
-
-       /* TODO refactor to init this just once. */
-       accel_gen_system_id();
 }
 
 #define ZEND_BIN_ID "BIN_" ZEND_TOSTR(SIZEOF_INT) ZEND_TOSTR(SIZEOF_LONG) ZEND_TOSTR(SIZEOF_SIZE_T) ZEND_TOSTR(SIZEOF_ZEND_LONG) ZEND_TOSTR(ZEND_MM_ALIGNMENT)
@@ -2595,7 +2593,7 @@ static void accel_gen_system_id(void)
 {
        PHP_MD5_CTX context;
        unsigned char digest[16], c;
-       char *md5str = ZCG(system_id);
+       char *md5str = accel_system_id;
        int i;
 
        PHP_MD5Init(&context);
@@ -2795,14 +2793,14 @@ static int accel_startup(zend_extension *extension)
 # endif
 #endif
 
+       accel_gen_system_id();
+
        if (start_accel_module() == FAILURE) {
                accel_startup_ok = 0;
                zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME ": module registration failed!");
                return FAILURE;
        }
 
-       accel_gen_system_id();
-
 #ifdef HAVE_HUGE_CODE_PAGES
        if (ZCG(accel_directives).huge_code_pages &&
            (strcmp(sapi_module.name, "cli") == 0 ||
index 3830df7b42c50892f66419f4b21d561244337f7b..a0df1c148a2e6a8c26cf382061c1427c52cfe659 100644 (file)
@@ -206,7 +206,6 @@ typedef struct _zend_accel_globals {
        int                     auto_globals_mask;
        time_t                  request_time;
        time_t                  last_restart_time; /* used to synchronize SHM and in-process caches */
-       char                    system_id[32];
        HashTable               xlat_table;
 #ifndef ZEND_WIN32
        zend_ulong              root_hash;
@@ -270,6 +269,7 @@ typedef struct _zend_accel_shared_globals {
        zend_string_table interned_strings;
 } zend_accel_shared_globals;
 
+extern char accel_system_id[32];
 extern zend_bool accel_startup_ok;
 extern zend_bool file_cache_only;
 #if ENABLE_FILE_CACHE_FALLBACK
index 2755f394865bb025b44e5675dc0a34cb2003e7ac..2d0cea1e970603fcfe961e9048c82e7f150ebd81 100644 (file)
@@ -74,7 +74,7 @@ static char *create_name_with_username(char *name)
        if (!uname) {
                return NULL;
        }
-       snprintf(newname, sizeof(newname) - 1, "%s@%s@%.32s", name, uname, ZCG(system_id));
+       snprintf(newname, sizeof(newname) - 1, "%s@%s@%.32s", name, uname, accel_system_id);
 
        free(uname);
 
@@ -96,7 +96,7 @@ static char *get_mmap_base_file(void)
        if ('\\' == windir[l-1]) {
                l--;
        }
-       snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%s@%.32s", ACCEL_FILEMAP_BASE, uname, ZCG(system_id));
+       snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%s@%.32s", ACCEL_FILEMAP_BASE, uname, accel_system_id);
 
        free(uname);
 
index 816acf15d99eed380e9de51f24be1a76f7ec2898..231affedf328ef2f96884bb5739a5530c24529c6 100644 (file)
@@ -798,7 +798,7 @@ static void zend_file_cache_serialize(zend_persistent_script   *script,
        zend_persistent_script *new_script;
 
        memcpy(info->magic, "OPCACHE", 8);
-       memcpy(info->system_id, ZCG(system_id), 32);
+       memcpy(info->system_id, accel_system_id, 32);
        info->mem_size = script->size;
        info->str_size = 0;
        info->script_offset = (char*)script - (char*)script->mem;
@@ -827,7 +827,7 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
        filename = emalloc(len + 33 + ZSTR_LEN(script_path) + sizeof(SUFFIX));
        memcpy(filename, ZCG(accel_directives).file_cache, len);
        filename[len] = '/';
-       memcpy(filename + len + 1, ZCG(system_id), 32);
+       memcpy(filename + len + 1, accel_system_id, 32);
        memcpy(filename + len + 33, ZSTR_VAL(script_path), ZSTR_LEN(script_path));
        memcpy(filename + len + 33 + ZSTR_LEN(script_path), SUFFIX, sizeof(SUFFIX));
 #else
@@ -859,7 +859,7 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
        len += 32;
        filename[len] = '\\';
 
-       memcpy(filename + len + 1, ZCG(system_id), 32);
+       memcpy(filename + len + 1, accel_system_id, 32);
 
        if (ZSTR_LEN(script_path) >= 7 && ':' == ZSTR_VAL(script_path)[4] && '/' == ZSTR_VAL(script_path)[5]  && '/' == ZSTR_VAL(script_path)[6]) {
                /* phar:// or file:// */
@@ -1550,7 +1550,7 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
                efree(filename);
                return NULL;
        }
-       if (memcmp(info.system_id, ZCG(system_id), 32) != 0) {
+       if (memcmp(info.system_id, accel_system_id, 32) != 0) {
                zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot read from file '%s' (wrong \"system_id\")\n", filename);
                zend_file_cache_flock(fd, LOCK_UN);
                close(fd);