Skip to content

Commit

Permalink
Modified system id handling. Removed debug print.
Browse files Browse the repository at this point in the history
  • Loading branch information
nanosonde committed May 22, 2018
1 parent cad9766 commit b511c38
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 36 deletions.
32 changes: 12 additions & 20 deletions ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "zend_ini.h"
#include "zend_virtual_cwd.h"
#include "zend_accelerator_util_funcs.h"
#include "ext/standard/md5.h"

#include "zend_file_cache.h"

Expand Down Expand Up @@ -92,7 +91,6 @@ static zend_op_array *(*accelerator_orig_compile_file)(zend_file_handle *file_ha

static void accel_gen_system_id(void);

static void accel_gen_system_id(void);
static int accel_post_startup(void);

static inline int is_stream_path(const char *filename)
Expand Down Expand Up @@ -512,28 +510,22 @@ static void accel_globals_dtor(zend_accel_globals *accel_globals)
}
}

#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 void accel_gen_system_id(void)
{
PHP_MD5_CTX context;
unsigned char digest[16], c;
char *md5str = ZCG(system_id);
unsigned char *sysid = ZCG(system_id);
int i;

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);
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;
}
memset(sysid, 0, sizeof(ZCG(system_id)));

sysid[0] = PHP_MAJOR_VERSION;
sysid[1] = PHP_MINOR_VERSION;
sysid[2] = PHP_RELEASE_VERSION;
sysid[3] = sizeof(char);
sysid[4] = sizeof(int);
sysid[5] = sizeof(long);
sysid[6] = sizeof(size_t);
sysid[7] = sizeof(zend_long);
sysid[8] = ZEND_MM_ALIGNMENT;
}

#ifdef HAVE_HUGE_CODE_PAGES
Expand Down
2 changes: 1 addition & 1 deletion ZendAccelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ typedef struct _zend_accel_globals {
HashTable bind_hash; /* prototype and zval lookup table */
zend_accel_directives accel_directives;
int auto_globals_mask;
char system_id[32];
unsigned char system_id[32];
char *outfilename;
HashTable xlat_table;
/* preallocated memory block to save current script */
Expand Down
68 changes: 68 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */

/* Whether to build bcgen as dynamic module */
#define COMPILE_DL_BCGEN 1

/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1

/* Define to enable copying PHP CODE pages into HUGE PAGES (experimental) */
#define HAVE_HUGE_CODE_PAGES 1

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the <sys/uio.h> header file. */
#define HAVE_SYS_UIO_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define to the sub-directory where libtool stores uninstalled libraries. */
#define LT_OBJDIR ".libs/"

/* Define to 1 if your C compiler doesn't accept -c and -o together. */
/* #undef NO_MINUS_C_MINUS_O */

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""

/* Define to the full name of this package. */
#define PACKAGE_NAME ""

/* Define to the full name and version of this package. */
#define PACKAGE_STRING ""

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME ""

/* Define to the home page for this package. */
#define PACKAGE_URL ""

/* Define to the version of this package. */
#define PACKAGE_VERSION ""

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
1 change: 0 additions & 1 deletion zend_accelerator_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ static ZEND_FUNCTION(bcgen_compile_file)
ZCG(outfilename) = emalloc(outscript_name_len + 1);
memcpy(ZCG(outfilename), outscript_name, outscript_name_len);
ZCG(outfilename)[outscript_name_len] = '\0';
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " len is %d, %d, %s", outscript_name_len, strlen (ZCG(outfilename)), ZCG(outfilename));

handle.filename = script_name;
handle.free_filename = 0;
Expand Down
22 changes: 8 additions & 14 deletions zend_file_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include "zend_interfaces.h"

#include "php.h"
#ifdef ZEND_WIN32
#include "ext/standard/md5.h"
#endif

#include "ZendAccelerator.h"
#include "zend_file_cache.h"
Expand Down Expand Up @@ -102,12 +99,12 @@ static const uint32_t uninitialized_bucket[-HT_MIN_MASK] =
{HT_INVALID_IDX, HT_INVALID_IDX};

typedef struct _zend_file_cache_metainfo {
char magic[8];
char system_id[32];
size_t mem_size;
size_t str_size;
size_t script_offset;
uint32_t checksum;
char magic[8];
unsigned char system_id[32];
size_t mem_size;
size_t str_size;
size_t script_offset;
uint32_t checksum;
} zend_file_cache_metainfo;

typedef void (*serialize_callback_t)(zval *zv,
Expand Down Expand Up @@ -653,7 +650,6 @@ int zend_file_cache_script_store(zend_persistent_script *script)
#endif
void *mem, *buf;

zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " len is %d, %s", strlen (ZCG(outfilename)), ZCG(outfilename));
zend_accel_error(ACCEL_LOG_WARNING, "writing to file '%s'\n", ZCG(outfilename));

#ifndef ZEND_WIN32
Expand Down Expand Up @@ -1211,10 +1207,8 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
return NULL;
}
if (memcmp(info.system_id, ZCG(system_id), 32) != 0) {
zend_accel_error(ACCEL_LOG_DEBUG, "bcgen '%s' is not a bcgen file (wrong \"system_id\")\n", filename);
close(fd);
efree(filename);
return NULL;
zend_accel_error(ACCEL_LOG_WARNING , "bcgen: '%s' was compiled with different system id\n"
"Things might run unstable...\n", filename);
}

checkpoint = zend_arena_checkpoint(CG(arena));
Expand Down

0 comments on commit b511c38

Please sign in to comment.