1
0
Fork 0

relocate WIP

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1444 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
master
Xuefer 10 years ago
parent b5f6974ff9
commit 41b20da882

@ -1,25 +1,25 @@
$(XCACHE_INCLUDES_I) includes.lo $(builddir)/includes.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h
mod_assembler/xc_assembler.lo $(builddir)/mod_assembler/xc_assembler.lo:
mod_cacher/xc_cacher.lo $(builddir)/mod_cacher/xc_cacher.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(XCACHE_PROC_H)
mod_coverager/xc_coverager.lo $(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h
mod_cacher/xc_cacher.lo $(builddir)/mod_cacher/xc_cacher.lo: $(XCACHE_PROC_H) $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
mod_coverager/xc_coverager.lo $(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
mod_decoder/xc_decoder.lo $(builddir)/mod_decoder/xc_decoder.lo:
mod_disassembler/xc_disassembler.lo $(builddir)/mod_disassembler/xc_disassembler.lo: $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(XCACHE_PROC_H)
mod_disassembler/xc_disassembler.lo $(builddir)/mod_disassembler/xc_disassembler.lo: $(XCACHE_PROC_H) $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h
mod_encoder/xc_encoder.lo $(builddir)/mod_encoder/xc_encoder.lo:
mod_optimizer/xc_optimizer.lo $(builddir)/mod_optimizer/xc_optimizer.lo: $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(XCACHE_PROC_H)
mod_optimizer/xc_optimizer.lo $(builddir)/mod_optimizer/xc_optimizer.lo: $(XCACHE_PROC_H) $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
util/xc_stack.lo $(builddir)/util/xc_stack.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h
util/xc_trace.lo $(builddir)/util/xc_trace.lo: $(srcdir)/util/xc_trace.h
xcache.lo $(builddir)/xcache.lo: $(srcdir)/util/xc_foreachcoresig.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(XCACHE_PROC_H)
xcache.lo $(builddir)/xcache.lo: $(XCACHE_PROC_H) $(srcdir)/util/xc_foreachcoresig.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
xcache/xc_allocator.lo $(builddir)/xcache/xc_allocator.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_allocator_bestfit.lo $(builddir)/xcache/xc_allocator_bestfit.lo: $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h
xcache/xc_allocator.lo $(builddir)/xcache/xc_allocator.lo: $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h
xcache/xc_compatibility.lo $(builddir)/xcache/xc_compatibility.lo: $(srcdir)/xcache/xc_compatibility.h
xcache/xc_const_string.lo $(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php4.x.h $(srcdir)/xcache/xc_const_string_opcodes_php5.0.h $(srcdir)/xcache/xc_const_string_opcodes_php5.1.h $(srcdir)/xcache/xc_const_string_opcodes_php5.2.h $(srcdir)/xcache/xc_const_string_opcodes_php5.3.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h $(srcdir)/xcache/xc_const_string_opcodes_php5.5.h $(srcdir)/xcache/xc_const_string_opcodes_php6.x.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_extension.lo $(builddir)/xcache/xc_extension.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_ini.lo $(builddir)/xcache/xc_ini.lo: $(srcdir)/xcache/xc_ini.h
xcache/xc_malloc.lo $(builddir)/xcache/xc_malloc.lo: $(srcdir)/util/xc_align.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_mutex.lo $(builddir)/xcache/xc_mutex.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_opcode_spec.lo $(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec_def.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h
xcache/xc_opcode_spec.lo $(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_opcode_spec_def.h $(srcdir)/xcache/xc_shm.h
xcache/xc_processor.lo $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C)
xcache/xc_sandbox.lo $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/util/xc_stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h
xcache/xc_shm.lo $(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache/xc_shm.h
xcache/xc_sandbox.lo $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/util/xc_stack.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
xcache/xc_shm.lo $(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_shm_mmap.lo $(builddir)/xcache/xc_shm_mmap.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h
xcache/xc_utils.lo $(builddir)/xcache/xc_utils.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h
xcache/xc_utils.lo $(builddir)/xcache/xc_utils.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h

@ -176,6 +176,16 @@ static xc_entry_data_php_t *xc_php_store_unlocked(xc_cache_t *cache, xc_entry_da
php->hits = 0;
php->refcount = 0;
stored_php = xc_processor_store_xc_entry_data_php_t(cache->shm, cache->allocator, php TSRMLS_CC);
#if 1
{
char *p = malloc(stored_php->size);
fprintf(stderr, "%d\n", stored_php->size);
memcpy(p, stored_php, stored_php->size);
/*
xc_processor_relocate_xc_entry_data_php_t(p, p, 0, stored_php TSRMLS_CC);
*/
}
#endif
if (stored_php) {
xc_php_add_unlocked(cache->cached, stored_php);
return stored_php;

@ -0,0 +1,159 @@
define(`DEFINE_STORE_API', `
EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC)') dnl {{{
{
$1 *dst;
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
processor.reference = 1;
processor.shm = shm;
processor.allocator = allocator;
IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);')
/* calc size */ {
zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
}
processor.size = 0;
/* allocate */
processor.size = ALIGN(processor.size + sizeof(src[0]));
xc_calc_$1(&processor, src TSRMLS_CC);
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
zend_hash_destroy(&processor.strings);
}
ifelse(
`$1', `xc_entry_data_php_t', `SRC(`size')',
`', `', SRC(`entry.size')) = processor.size;
ifelse(
`$1', `xc_entry_var_t', `SRC(`have_references') = processor.have_references;',
`$1', `xc_entry_data_php_t', `SRC(`have_references') = processor.have_references;'
)
IFAUTOCHECK(`xc_stack_reverse(&processor.allocsizes);')
/* store {{{ */
{
IFAUTOCHECK(`char *oldp;')
zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
}
/* allocator :) */
processor.p = (char *) processor.allocator->vtable->malloc(processor.allocator, processor.size);
if (processor.p == NULL) {
dst = NULL;
goto err_alloc;
}
IFAUTOCHECK(`oldp = processor.p;')
assert(processor.p == (char *) ALIGN(processor.p));
/* allocate */
dst = ($1 *) processor.p;
processor.p = (char *) ALIGN(processor.p + sizeof(dst[0]));
xc_store_$1(&processor, dst, src TSRMLS_CC);
IFAUTOCHECK(` {
size_t unexpected = processor.p - oldp;
size_t expected = processor.size;
if (unexpected != processor.size) {
fprintf(stderr, "unexpected:%lu - expected:%lu = %ld != 0\n", (unsigned long) unexpected, (unsigned long) expected, (long) unexpected - expected);
abort();
}
}')
err_alloc:
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
zend_hash_destroy(&processor.strings);
}
/* }}} */
IFAUTOCHECK(`xc_stack_destroy(&processor.allocsizes);')
return dst;
}
dnl }}}
')
DEFINE_STORE_API(`xc_entry_var_t')
DEFINE_STORE_API(`xc_entry_php_t')
DEFINE_STORE_API(`xc_entry_data_php_t')
EXPORTED_FUNCTION(`xc_entry_php_t *xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC)') dnl {{{
{
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
xc_restore_xc_entry_php_t(&processor, dst, src TSRMLS_CC);
return dst;
}
dnl }}}
EXPORTED_FUNCTION(`xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_php_t *entry_php, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC)') dnl {{{
{
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
processor.readonly_protection = readonly_protection;
/* this function is used for php data only */
if (SRC(`have_references')) {
processor.reference = 1;
}
processor.entry_php_src = entry_php;
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
}
xc_restore_xc_entry_data_php_t(&processor, dst, src TSRMLS_CC);
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
return dst;
}
dnl }}}
EXPORTED_FUNCTION(`zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC)') dnl {{{
{
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
processor.reference = have_references;
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
zend_hash_add(&processor.zvalptrs, (char *)src, sizeof(src), (void*)&dst, sizeof(dst), NULL);
}
xc_restore_zval(&processor, dst, src TSRMLS_CC);
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
return dst;
}
dnl }}}
define(`DEFINE_RELOCATE_API', `
EXPORTED_FUNCTION(`void xc_processor_relocate_$1($1 *dst, char *old_start, char *new_start TSRMLS_DC)') dnl {{{
{
xc_relocate_t relocate;
relocate.dst = dst;
relocate.old_start = old_start;
relocate.new_start = new_start;
xc_relocate_$1(&relocate, dst TSRMLS_CC);
}
dnl }}}
')
DEFINE_RELOCATE_API(`xc_entry_var_t')
DEFINE_RELOCATE_API(`xc_entry_php_t')
DEFINE_RELOCATE_API(`xc_entry_data_php_t')
EXPORTED(`#ifdef HAVE_XCACHE_DPRINT')
EXPORTED_FUNCTION(`void xc_dprint(xc_entry_php_t *src, int indent TSRMLS_DC)') dnl {{{
{
IFDPRINT(`INDENT()`'fprintf(stderr, "xc_entry_php_t:src");')
xc_dprint_xc_entry_php_t(src, indent TSRMLS_CC);
}
dnl }}}
EXPORTED(`#endif')

@ -72,8 +72,7 @@ define(`DEF_HASH_TABLE_FUNC', `
CALLOC(`DST(`arBuckets')', Bucket*, SRC(`nTableSize'))
DONE(arBuckets)
DISABLECHECK(`
for (srcBucket = SRCPTR(`Bucket', `pListHead'); srcBucket != NULL; srcBucket = SRCPTR_EX(`Bucket', `srcBucket->pListNext')) {
IFPTRMOVE(`Bucket *dstBucket = srcBucket;')
for (srcBucket = SRCPTR_EX(`Bucket', SRC(`pListHead')); srcBucket != NULL; srcBucket = SRCPTR_EX(`Bucket', `srcBucket->pListNext')) {
IFCALCCOPY(`bucketsize = BUCKET_SIZE(srcBucket);')
ALLOC(dstBucket, char, bucketsize, , Bucket)
IFCOPY(`
@ -107,7 +106,7 @@ define(`DEF_HASH_TABLE_FUNC', `
IFCOPY(`dstBucket->pData = &dstBucket->pDataPtr;')
dnl $6 = `' to skip alloc
STRUCT_P_EX(`$2', dstBucket->pData, (($2*)srcBucket->pData), `', `$3', ` ')
FIXPOINTER_EX(`$2', dstBucket->pData, srcBucket->pData)
FIXPOINTER_EX(`$2', dstBucket->pData)
}
else {
STRUCT_P_EX(`$2', dstBucket->pData, (($2*)srcBucket->pData), `', `$3')
@ -128,7 +127,7 @@ define(`DEF_HASH_TABLE_FUNC', `
}
prev = dstBucket;
')
FIXPOINTER_EX(`Bucket', `dstBucket', `srcBucket')
FIXPOINTER_EX(`Bucket', `dstBucket')
IFCOPY(`
DST(`arBuckets[n]') = dstBucket;
')

@ -10,17 +10,13 @@ divert(0)
#include "zend_ini.h"
EXPORT(`#include "xcache.h"')
#include "xcache.h"
EXPORT(`#include "mod_cacher/xc_cache.h"')
#include "mod_cacher/xc_cache.h"
EXPORT(`#include "xcache/xc_shm.h"')
#include "xcache/xc_shm.h"
EXPORT(`#include "xcache/xc_allocator.h"')
#include "xcache/xc_allocator.h"
#include "xc_processor.h"
#include "xcache/xc_const_string.h"
#include "xcache/xc_utils.h"
#include "util/xc_align.h"
#include "xc_processor.h"
#include "xcache_globals.h"
#if defined(HARDENING_PATCH_HASH_PROTECT) && HARDENING_PATCH_HASH_PROTECT
@ -86,8 +82,7 @@ typedef char zstr_char;
#define MAX_DUP_STR_LEN 256
dnl }}}
dnl {{{ _xc_processor_t
EXPORT(`typedef struct _xc_processor_t xc_processor_t;')
struct _xc_processor_t {
typedef struct _xc_processor_t {
char *p;
size_t size;
HashTable strings;
@ -113,9 +108,14 @@ struct _xc_processor_t {
zend_bool readonly_protection; /* wheather it's present */
IFAUTOCHECK(xc_stack_t allocsizes;)
};
} xc_processor_t;
dnl }}}
EXPORT(`typedef struct _xc_relocate_t { ptrdiff_t src; ptrdiff_t dst; ptrdiff_t ptrdiff; } xc_relocate_t;')
typedef struct _xc_relocate_t { /* {{{ */
ptrdiff_t dst;
char *old_start;
char *new_start;
} xc_relocate_t;
/* }}} */
EXPORT(`typedef struct _xc_dasm_t { const zend_op_array *active_op_array_src; } xc_dasm_t;')
/* {{{ memsetptr */
IFAUTOCHECK(`dnl
@ -393,158 +393,3 @@ static int xc_check_names(const char *file, int line, const char *functionName,
}
')
/* }}} */
dnl ================ export API
define(`DEFINE_STORE_API', `
EXPORTED(`$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC)') dnl {{{
{
$1 *dst;
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
processor.reference = 1;
processor.shm = shm;
processor.allocator = allocator;
IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);')
/* calc size */ {
zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
}
processor.size = 0;
/* allocate */
processor.size = ALIGN(processor.size + sizeof(src[0]));
xc_calc_$1(&processor, src TSRMLS_CC);
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
zend_hash_destroy(&processor.strings);
}
ifelse(
`$1', `xc_entry_data_php_t', `SRC(`size')',
`', `', SRC(`entry.size')) = processor.size;
ifelse(
`$1', `xc_entry_var_t', `SRC(`have_references') = processor.have_references;',
`$1', `xc_entry_data_php_t', `SRC(`have_references') = processor.have_references;'
)
IFAUTOCHECK(`xc_stack_reverse(&processor.allocsizes);')
/* store {{{ */
{
IFAUTOCHECK(`char *oldp;')
zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
}
/* allocator :) */
processor.p = (char *) processor.allocator->vtable->malloc(processor.allocator, processor.size);
if (processor.p == NULL) {
dst = NULL;
goto err_alloc;
}
IFAUTOCHECK(`oldp = processor.p;')
assert(processor.p == (char *) ALIGN(processor.p));
/* allocate */
dst = ($1 *) processor.p;
processor.p = (char *) ALIGN(processor.p + sizeof(dst[0]));
xc_store_$1(&processor, dst, src TSRMLS_CC);
IFAUTOCHECK(` {
size_t unexpected = processor.p - oldp;
size_t expected = processor.size;
if (unexpected != processor.size) {
fprintf(stderr, "unexpected:%lu - expected:%lu = %ld != 0\n", (unsigned long) unexpected, (unsigned long) expected, (long) unexpected - expected);
abort();
}
}')
err_alloc:
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
zend_hash_destroy(&processor.strings);
}
/* }}} */
IFAUTOCHECK(`xc_stack_destroy(&processor.allocsizes);')
return dst;
}
dnl }}}
')
DEFINE_STORE_API(`xc_entry_var_t')
DEFINE_STORE_API(`xc_entry_php_t')
DEFINE_STORE_API(`xc_entry_data_php_t')
EXPORTED(`xc_entry_php_t *xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC)') dnl {{{
{
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
xc_restore_xc_entry_php_t(&processor, dst, src TSRMLS_CC);
return dst;
}
dnl }}}
EXPORTED(`xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_php_t *entry_php, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC)') dnl {{{
{
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
processor.readonly_protection = readonly_protection;
/* this function is used for php data only */
if (SRC(`have_references')) {
processor.reference = 1;
}
processor.entry_php_src = entry_php;
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
}
xc_restore_xc_entry_data_php_t(&processor, dst, src TSRMLS_CC);
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
return dst;
}
dnl }}}
EXPORTED(`zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC)') dnl {{{
{
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
processor.reference = have_references;
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
zend_hash_add(&processor.zvalptrs, (char *)src, sizeof(src), (void*)&dst, sizeof(dst), NULL);
}
xc_restore_zval(&processor, dst, src TSRMLS_CC);
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
return dst;
}
dnl }}}
define(`DEFINE_RELOCATE_API', `
EXPORTED(`void xc_processor_relocate_$1(int a TSRMLS_DC)') dnl {{{
{
}
dnl }}}
')
DEFINE_RELOCATE_API(`xc_entry_var_t')
DEFINE_RELOCATE_API(`xc_entry_php_t')
DEFINE_RELOCATE_API(`xc_entry_data_php_t')
#ifdef HAVE_XCACHE_DPRINT
EXPORTED(`void xc_dprint(xc_entry_php_t *src, int indent TSRMLS_DC)') dnl {{{
{
IFDPRINT(`INDENT()`'fprintf(stderr, "xc_entry_php_t:src");')
xc_dprint_xc_entry_php_t(src, indent TSRMLS_CC);
}
#endif
dnl }}}

@ -24,13 +24,8 @@ define(`SRC', `src->$1')
dnl ============
define(`INDENT', `xc_dprint_indent(indent);')
dnl }}}
dnl {{{ SRCPTR(1:type, 2:elm)
define(`SRCPTR', `SRCPTR_EX(`$1', `SRC(`$2')')')
define(`SRCPTR_EX', `IFPTRMOVE(`(($1 *) (((char *) $2) + relocate->src))', `$2')')
dnl }}}
dnl {{{ DSTPTR(1:type, 2:elm)
define(`DSTPTR', `DSTPTR_EX(`$1', `DST(`$2')')')
define(`DSTPTR_EX', `IFPTRMOVE(`(($1 *) (((char *) $2) + relocate->dst))', `$2')')
dnl {{{ SRCPTR_EX(1:type, 2:elm)
define(`SRCPTR_EX', `IFRELOCATE(`(($1 *) (((char *) $2) + 1))', `$2')')
dnl }}}
dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:realtype=$2)
define(`ALLOC', `
@ -129,19 +124,21 @@ define(`DBG', `ifdef(`XCACHE_ENABLE_TEST', `
dnl }}}
dnl {{{ EXPORT(1:code)
define(`EXPORT', `/* export: $1 :export */')
define(`EXPORTED', `EXPORT(`$1;')
define(`EXPORTED', `EXPORT(`$1')
$1')
define(`EXPORTED_FUNCTION', `EXPORT(`$1;')
$1')
dnl }}}
dnl {{{ EXPORT_PROCESSOR(1:type, 2:processor)
define(`EXPORT_PROCESSOR', `define(`EXPORT_$1_$2', 1)')
dnl }}}
dnl {{{ FIXPOINTER(1:type, 2:ele)
define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `DST(`$2')', `SRCPTR(`$1', `$2')')')
define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `DST(`$2')')')
dnl }}}
dnl {{{ FIXPOINTER_EX(1:type, 2:dst, 3:src)
dnl {{{ FIXPOINTER_EX(1:type, 2:dst)
define(`FIXPOINTER_EX', `
IFSTORE(`$2 = ($1 *) processor->shm->handlers->to_readonly(processor->shm, (void *)$2);')
IFPTRMOVE(`$2 = ($1 *) (((char *) $3) + relocate->ptrdiff);')
IFRELOCATE(`patsubst($2, `dst', `src') = ($1 *) (((char *) patsubst($2, `dst', `src')) + 1);')
')
dnl }}}
dnl {{{ IFNOTMEMCPY
@ -241,7 +238,7 @@ define(`IFCALC', `ifelse(PROCESSOR_TYPE, `calc', `$1', `$2')')
define(`IFSTORE', `ifelse(PROCESSOR_TYPE, `store', `$1', `$2')')
define(`IFCALCSTORE', `IFSTORE(`$1', `IFCALC(`$1', `$2')')')
define(`IFRESTORE', `ifelse(PROCESSOR_TYPE, `restore', `$1', `$2')')
define(`IFPTRMOVE', `ifelse(PROCESSOR_TYPE, `relocate', `$1', `$2')')
define(`IFRELOCATE', `ifelse(PROCESSOR_TYPE, `relocate', `$1', `$2')')
define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')')
define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')')
define(`IFDPRINT', `ifelse(PROCESSOR_TYPE, `dprint', `$1', `$2')')
@ -252,18 +249,18 @@ EXPORT_PROCESSOR(`dasm', `zend_op_array')
EXPORT_PROCESSOR(`dasm', `zend_function')
EXPORT_PROCESSOR(`dasm', `zend_class_entry')
EXPORT_PROCESSOR(`calc', `xc_entry_data_php_t')
EXPORT_PROCESSOR(`calc', `xc_entry_php_t')
EXPORT_PROCESSOR(`calc', `xc_entry_var_t')
EXPORT_PROCESSOR(`store', `xc_entry_data_php_t')
EXPORT_PROCESSOR(`store', `xc_entry_php_t')
EXPORT_PROCESSOR(`store', `xc_entry_var_t')
EXPORT_PROCESSOR(`restore', `xc_entry_data_php_t')
EXPORT_PROCESSOR(`restore', `xc_entry_php_t')
EXPORT_PROCESSOR(`dasm', `xc_entry_data_php_t')
EXPORT_PROCESSOR(`dprint', `xc_entry_php_t')
dnl EXPORT_PROCESSOR(`calc', `xc_entry_data_php_t')
dnl EXPORT_PROCESSOR(`calc', `xc_entry_php_t')
dnl EXPORT_PROCESSOR(`calc', `xc_entry_var_t')
dnl EXPORT_PROCESSOR(`store', `xc_entry_data_php_t')
dnl EXPORT_PROCESSOR(`store', `xc_entry_php_t')
dnl EXPORT_PROCESSOR(`store', `xc_entry_var_t')
dnl EXPORT_PROCESSOR(`restore', `xc_entry_data_php_t')
dnl EXPORT_PROCESSOR(`restore', `xc_entry_php_t')
dnl EXPORT_PROCESSOR(`dasm', `xc_entry_data_php_t')
dnl EXPORT_PROCESSOR(`dprint', `xc_entry_php_t')
EXPORT_PROCESSOR(`restore', `zval')
dnl EXPORT_PROCESSOR(`restore', `zval')
EXPORT_PROCESSOR(`dprint', `zval')
include(srcdir`/processor/hashtable.m4')
@ -284,4 +281,6 @@ REDEF(`PROCESSOR_TYPE', `dprint') include(srcdir`/processor/processor.m4')
REDEF(`PROCESSOR_TYPE', `dasm') include(srcdir`/processor/processor.m4')
#endif /* HAVE_XCACHE_DISASSEMBLER */
include(srcdir`/processor/foot.m4')
ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')

@ -193,10 +193,9 @@ DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
zval_ptr pzv = (zval_ptr)-1;
', `
zval_ptr pzv = dst[0];
FIXPOINTER_EX(zval, pzv, dst[0])
FIXPOINTER_EX(zval, pzv)
')
if (zend_hash_add(&processor->zvalptrs, (char *) &src[0], sizeof(src[0]), (void *) &pzv, sizeof(pzv), NULL) == SUCCESS) {
/* first add, go on */
if (zend_hash_add(&processor->zvalptrs, (char *) &src[0], sizeof(src[0]), (void *) &pzv, sizeof(pzv), NULL) == SUCCESS) { /* first add, go on */
dnl fprintf(stderr, "mark[%p] = %p\n", src[0], pzv);
}
else {
@ -209,7 +208,7 @@ DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
')
IFDPRINT(`INDENT()`'fprintf(stderr, "[%p] ", (void *) src[0]);')
STRUCT_P_EX(zval, dst[0], src[0], `[0]', `', ` ')
FIXPOINTER_EX(zval, dst[0], src[0])
FIXPOINTER_EX(zval, dst[0])
} while (0);
')
DONE_SIZE(sizeof(zval_ptr))
@ -335,7 +334,7 @@ DEF_STRUCT_P_FUNC(`zend_trait_alias_ptr', , `dnl {{{
', `
ALLOC(dst[0], zend_trait_alias)
STRUCT_P_EX(zend_trait_alias, dst[0], src[0], `[0]', `', ` ')
FIXPOINTER_EX(zend_trait_alias, dst[0], src[0])
FIXPOINTER_EX(zend_trait_alias, dst[0])
')
DONE_SIZE(sizeof(zend_trait_alias))
')
@ -348,7 +347,7 @@ DEF_STRUCT_P_FUNC(`zend_trait_precedence_ptr', , `dnl {{{
', `
ALLOC(dst[0], zend_trait_precedence)
STRUCT_P_EX(zend_trait_precedence, dst[0], src[0], `[0]', `', ` ')
FIXPOINTER_EX(zend_trait_precedence, dst[0], src[0])
FIXPOINTER_EX(zend_trait_precedence, dst[0])
')
DONE_SIZE(sizeof(zend_trait_precedence))
')
@ -673,7 +672,7 @@ DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{
Z_OP(DST(`op1')).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(SRC(`op1')).jmp_addr - processor->active_op_array_src->opcodes);
assert(Z_OP(DST(`op1')).jmp_addr >= processor->active_op_array_dst->opcodes);
assert(Z_OP(DST(`op1')).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
FIXPOINTER_EX(zend_op, `Z_OP(DST(`op1')).jmp_addr', `Z_OP(SRC(`op1')).jmp_addr')
FIXPOINTER_EX(zend_op, `Z_OP(DST(`op1')).jmp_addr')
break;
case ZEND_JMPZ:
@ -691,7 +690,7 @@ DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{
Z_OP(DST(`op2')).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(SRC(`op2')).jmp_addr - processor->active_op_array_src->opcodes);
assert(Z_OP(DST(`op2')).jmp_addr >= processor->active_op_array_dst->opcodes);
assert(Z_OP(DST(`op2')).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
FIXPOINTER_EX(zend_op, `Z_OP(DST(`op2')).jmp_addr', `Z_OP(SRC(`op2')).jmp_addr')
FIXPOINTER_EX(zend_op, `Z_OP(DST(`op2')).jmp_addr')
break;
default:

@ -63,7 +63,7 @@ define(`PROC_STRING_N_EX', `
IFRESTORE(`
DSTPTR = ifdef(`REALPTRTYPE', `(REALPTRTYPE() *)') STRDUP() (SRCPTR, ($3) - 1);
')
FIXPOINTER_EX(ifdef(`REALPTRTYPE', `REALPTRTYPE()', `PTRTYPE'), DSTPTR, SRCPTR)
FIXPOINTER_EX(ifdef(`REALPTRTYPE', `REALPTRTYPE()', `PTRTYPE'), DSTPTR)
IFDASM(`
ifelse(STRTYPE,zstr_uchar, `
add_assoc_unicodel_ex(dst, XCACHE_STRS("$4"), ZSTR_U($2), $3-1, 1);

@ -14,8 +14,8 @@ define(`DECL_STRUCT_P_FUNC', `translit(
IFCALC( `xc_processor_t *processor, const $1 * const src')
IFSTORE( `xc_processor_t *processor, $1 *dst, const $1 * const src')
IFRESTORE(`xc_processor_t *processor, $1 *dst, const $1 * const src')
IFPTRMOVE(`const xc_relocate_t *relocate, $1 * const dst, const $1 * const src')
IFDASM( `xc_dasm_t *dasm, zval *dst, const $1 * const src')
IFRELOCATE(`const xc_relocate_t *relocate, $1 *const src')
IFDASM(`xc_dasm_t *dasm, zval *dst, const $1 * const src')
TSRMLS_DC
)ifelse(`$3', `', `;')
popdef(`FUNC_NAME')dnl
@ -147,12 +147,11 @@ ifdef(`DASM_STRUCT_DIRECT', `', `
IFCALC( `processor, $6 $3')
IFSTORE( `processor, $6 $2, $6 $3')
IFRESTORE(`processor, $6 $2, $6 $3')
IFPTRMOVE(`
IFRELOCATE(`
relocate
, ifelse(`$6', `', `DSTPTR_EX(`$1', `$2')', `$6 $2')
, ifelse(`$6', `', `SRCPTR_EX(`$1', `$3')', `$6 $3')
')
IFDASM( `dasm, ifdef(`DASM_STRUCT_DIRECT', `dst', `zv'), $6 $3')
IFDASM(`dasm, ifdef(`DASM_STRUCT_DIRECT', `dst', `zv'), $6 $3')
TSRMLS_CC
);
ifdef(`DASM_STRUCT_DIRECT', `', `
@ -162,7 +161,7 @@ ifdef(`DASM_STRUCT_DIRECT', `', `
')
')
popdef(`FUNC_NAME')
ifelse(`$6', , `FIXPOINTER_EX(`$1', `$2', `$3')')
ifelse(`$6', , `FIXPOINTER_EX(`$1', `$2')')
')
dnl }}}
dnl {{{ STRUCT_P(1:type, 2:elm, 3:name=type)

Loading…
Cancel
Save