Browse Source

relocate: fix handling hash table, TODO: fix dst/src stuff

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1460 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
master
Xuefer 8 years ago
parent
commit
d913f3e5fd
  1. 2
      mod_cacher/xc_cacher.c
  2. 77
      processor/hashtable.m4
  3. 4
      processor/head.m4
  4. 28
      processor/main.m4
  5. 4
      processor/struct.m4

2
mod_cacher/xc_cacher.c

@ -176,7 +176,7 @@ 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
#if 0
{
xc_entry_data_php_t *p = malloc(stored_php->size);
xc_entry_data_php_t *backup = malloc(stored_php->size);

77
processor/hashtable.m4

@ -47,11 +47,13 @@ define(`DEF_HASH_TABLE_FUNC', `DEF_STRUCT_P_FUNC(`HashTable', `$1', `
', ` dnl IFDASM else
dnl }}}
Bucket *srcBucket;
IFCOPY(`Bucket *dstBucket = NULL, *prev = NULL;')
zend_bool first = 1;
IFFIXPOINTER(`Bucket *next;')
IFRELOCATE(`Bucket *dstBucket = NULL;')
IFCOPY(`Bucket *dstBucket = NULL, *first = NULL, *last = NULL;')
dnl only used for copy
IFCOPY(`uint n;')
IFCALCCOPY(`size_t bucketsize;')
IFRELOCATE(`uint n;')
IFCALCCOPY(`size_t bucketSize;')
#if defined(HARDENING_PATCH_HASH_PROTECT) && HARDENING_PATCH_HASH_PROTECT
IFRESTORE(`
@ -66,7 +68,6 @@ define(`DEF_HASH_TABLE_FUNC', `DEF_STRUCT_P_FUNC(`HashTable', `$1', `
PROCESS(uint, nNumOfElements)
PROCESS(ulong, nNextFreeElement)
IFCOPY(`DST(`pInternalPointer') = NULL; /* Used for element traversal */') DONE(pInternalPointer)
IFCOPY(`DST(`pListHead') = NULL;') DONE(pListHead)
#ifdef ZEND_ENGINE_2_4
if (SRC(`nTableMask')) {
#endif
@ -74,8 +75,8 @@ define(`DEF_HASH_TABLE_FUNC', `DEF_STRUCT_P_FUNC(`HashTable', `$1', `
DONE(arBuckets)
DISABLECHECK(`
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)
IFCALCCOPY(`bucketSize = BUCKET_SIZE(srcBucket);')
ALLOC(dstBucket, char, bucketSize, , Bucket)
IFCOPY(`
#ifdef ZEND_ENGINE_2_4
memcpy(dstBucket, srcBucket, BUCKET_HEAD_SIZE(Bucket));
@ -87,7 +88,7 @@ define(`DEF_HASH_TABLE_FUNC', `DEF_STRUCT_P_FUNC(`HashTable', `$1', `
dstBucket->arKey = NULL;
}
#else
memcpy(dstBucket, srcBucket, bucketsize);
memcpy(dstBucket, srcBucket, bucketSize);
#endif
n = srcBucket->h & SRC(`nTableMask');
/* dstBucket into hash node chain */
@ -97,6 +98,7 @@ define(`DEF_HASH_TABLE_FUNC', `DEF_STRUCT_P_FUNC(`HashTable', `$1', `
dstBucket->pNext->pLast = dstBucket;
}
')
IFDPRINT(`
INDENT()
fprintf(stderr, "$2:\"");
@ -115,34 +117,69 @@ define(`DEF_HASH_TABLE_FUNC', `DEF_STRUCT_P_FUNC(`HashTable', `$1', `
IFCOPY(`dstBucket->pDataPtr = NULL;')
}
if (first) {
IFCOPY(`DST(`pListHead') = dstBucket;')
first = 0;
}
IFCOPY(`
if (!first) {
first = dstBucket;
}
/* flat link */
dstBucket->pListLast = prev;
dstBucket->pListLast = last;
dstBucket->pListNext = NULL;
if (prev) {
prev->pListNext = dstBucket;
if (last) {
last->pListNext = dstBucket;
}
last = dstBucket;
n = srcBucket->h & SRC(`nTableMask');
/* dstBucket into hash node chain */
dstBucket->pLast = NULL;
dstBucket->pNext = DST(`arBuckets[n]');
if (dstBucket->pNext) {
dstBucket->pNext->pLast = dstBucket;
}
prev = dstBucket;
')
FIXPOINTER_EX(`Bucket', `dstBucket')
IFCOPY(`
DST(`arBuckets[n]') = dstBucket;
')
}
') dnl DISABLECHECK
IFCOPY(`DST(`pListHead') = first;') DONE(pListHead)
IFCOPY(`DST(`pListTail') = dstBucket;') DONE(pListTail)
IFFIXPOINTER(`
for (n = 0; n < SRC(`nTableSize'); ++n) {
if (SRC(`arBuckets[n]')) {
next = DSTPTR_EX(`Bucket', `DST(`arBuckets[n]')');
do {
dstBucket = next;
next = DSTPTR_EX(`Bucket', `next->pNext');
if (dstBucket->pListLast) {
FIXPOINTER_EX(Bucket, dstBucket->pListLast)
}
if (dstBucket->pListNext) {
FIXPOINTER_EX(Bucket, dstBucket->pListNext)
}
if (dstBucket->pNext) {
FIXPOINTER_EX(Bucket, dstBucket->pNext)
}
if (dstBucket->pLast) {
FIXPOINTER_EX(Bucket, dstBucket->pLast)
}
} while (next);
FIXPOINTER(Bucket, arBuckets[n])
}
}
')
FIXPOINTER(Bucket, pListHead)
FIXPOINTER(Bucket, pListTail)
FIXPOINTER(Bucket *, arBuckets)
#ifdef ZEND_ENGINE_2_4
}
else { /* if (SRC(`nTableMask')) */
IFCOPY(`DST(`pListHead') = NULL;') DONE(pListHead)
IFCOPY(`DST(`pListTail') = NULL;') DONE(pListTail)
DONE(arBuckets)
}
#endif
IFCOPY(`DST(`pListTail') = dstBucket;') DONE(pListTail)
IFCOPY(`DST(`pDestructor') = SRC(`pDestructor');') DONE(pDestructor)
PROCESS(zend_bool, persistent)
#ifdef IS_UNICODE

4
processor/head.m4

@ -86,10 +86,10 @@ typedef char zstr_char;
#ifdef NDEBUG
#define notnullable(ptr) (ptr)
#else
static inline void *notnullable(void *ptr)
static inline void *notnullable(const void *ptr)
{
assert(ptr);
return ptr;
return (void *) ptr;
}
#endif
dnl }}}

28
processor/main.m4

@ -25,7 +25,10 @@ dnl ============
define(`INDENT', `xc_dprint_indent(indent);')
dnl }}}
dnl {{{ SRCPTR_EX(1:type, 2:elm)
define(`SRCPTR_EX', `IFRELOCATE(`ptradd($1 *, notnullable($2), ptrdiff)', `$2')')
define(`SRCPTR_EX', `DSTPTR_EX(`$1', `$2')')
dnl }}}
dnl {{{ DSTPTR_EX(1:type, 2:elm)
define(`DSTPTR_EX', `$2')
dnl }}}
dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:realtype=$2)
define(`ALLOC', `
@ -136,14 +139,7 @@ dnl {{{ FIXPOINTER(1:type, 2:ele)
define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `DST(`$2')')')
dnl }}}
dnl {{{ FIXPOINTER_EX(1:type, 2:dst)
define(`FIXPOINTER_EX', `
IFSTORE(`$2 = ($1 *) processor->shm->handlers->to_readonly(processor->shm, (void *)$2);')
IFRELOCATE(`
pushdef(`relocatee', `patsubst($2, `dst', `src')')
relocatee = ($1 *) (((char *) relocatee) + relocatediff);
popdef(`relocatee')
')
')
define(`FIXPOINTER_EX', `')
dnl }}}
dnl {{{ IFNOTMEMCPY
define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
@ -242,9 +238,10 @@ 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(`IFRELOCATE', `ifelse(PROCESSOR_TYPE, `relocate', `$1', `$2')')
define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')')
define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')')
define(`IFRELOCATE', `ifelse(PROCESSOR_TYPE, `relocate', `$1', `$2')')
define(`IFFIXPOINTER', `IFSTORE(`$1', `IFRELOCATE(`$1', `$2')')')
define(`IFDPRINT', `ifelse(PROCESSOR_TYPE, `dprint', `$1', `$2')')
define(`IFDASM', `ifelse(PROCESSOR_TYPE, `dasm', `$1', `$2')')
dnl }}}
@ -261,9 +258,20 @@ include(srcdir`/processor/process.m4')
include(srcdir`/processor/head.m4')
REDEF(`PROCESSOR_TYPE', `calc') include(srcdir`/processor/processor.m4')
pushdef(`FIXPOINTER_EX', `$2 = ($1 *) processor->shm->handlers->to_readonly(processor->shm, (void *)$2);')
REDEF(`PROCESSOR_TYPE', `store') include(srcdir`/processor/processor.m4')
popdef(`FIXPOINTER_EX')
REDEF(`PROCESSOR_TYPE', `restore') include(srcdir`/processor/processor.m4')
define(`DSTPTR_EX', `ptradd($1 *, notnullable($2), ptrdiff)')
pushdef(`FIXPOINTER_EX', `$2 = ptradd($1 *, notnullable($2), relocatediff);')
define(`SRC', `DST(`$1')')
REDEF(`PROCESSOR_TYPE', `relocate') include(srcdir`/processor/processor.m4')
popdef(`SRC')
popdef(`FIXPOINTER_EX')
popdef(`DSTPTR_EX')
#ifdef HAVE_XCACHE_DPRINT
REDEF(`PROCESSOR_TYPE', `dprint') include(srcdir`/processor/processor.m4')

4
processor/struct.m4

@ -14,7 +14,7 @@ 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')
IFRELOCATE(`$1 *const src, ptrdiff_t ptrdiff, ptrdiff_t relocatediff')
IFRELOCATE(`$1 *const dst, ptrdiff_t ptrdiff, ptrdiff_t relocatediff')
IFDASM(`xc_dasm_t *dasm, zval *dst, const $1 * const src')
TSRMLS_DC
)ifelse(`$3', `', `;')
@ -148,7 +148,7 @@ ifdef(`DASM_STRUCT_DIRECT', `', `
IFSTORE( `processor, $6 $2, $6 $3')
IFRESTORE(`processor, $6 $2, $6 $3')
IFRELOCATE(`
ifelse(`$6', `', `SRCPTR_EX(`$1', `$3')', `$6 $3')
ifelse(`$6', `', `DSTPTR_EX(`$1', `$3')', `$6 $3')
, ptrdiff
, relocatediff
')

Loading…
Cancel
Save