1
0
Fork 0

relocate: update proto to like memcpy/store/restore, update test code

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1455 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
master
Xuefer 2013-11-08 09:30:06 +00:00
parent 02c070d109
commit ffe43cb799
2 changed files with 27 additions and 15 deletions

View File

@ -181,13 +181,25 @@ static xc_entry_data_php_t *xc_php_store_unlocked(xc_cache_t *cache, xc_entry_da
xc_entry_data_php_t *p = malloc(stored_php->size);
xc_entry_data_php_t *backup = malloc(stored_php->size);
fprintf(stderr, "%lu\n", stored_php->size);
memcpy(p, stored_php, stored_php->size);
memcpy(backup, stored_php, stored_php->size);
xc_processor_relocate_xc_entry_data_php_t(stored_php, stored_php, p, 0 TSRMLS_CC);
assert(memcmp(stored_php, backup, stored_php->size) == 0);
memcpy(stored_php, p, p->size);
xc_processor_relocate_xc_entry_data_php_t(p, 0, stored_php, stored_php TSRMLS_CC);
{
memcpy(p, stored_php, stored_php->size);
xc_processor_relocate_xc_entry_data_php_t(p, p , stored_php, stored_php TSRMLS_CC);
assert(memcmp(stored_php, backup, stored_php->size) == 0);
memcpy(stored_php, p, p->size);
xc_processor_relocate_xc_entry_data_php_t(stored_php, stored_php, p, p TSRMLS_CC);
}
{
memcpy(p, stored_php, stored_php->size);
xc_processor_relocate_xc_entry_data_php_t(p, 0, stored_php, stored_php TSRMLS_CC);
assert(memcmp(stored_php, backup, stored_php->size) == 0);
memcpy(stored_php, p, p->size);
xc_processor_relocate_xc_entry_data_php_t(stored_php, stored_php, p, 0 TSRMLS_CC);
}
}
#endif
if (stored_php) {

View File

@ -136,22 +136,22 @@ EXPORTED_FUNCTION(`zval *xc_processor_restore_zval(zval *dst, const zval *src, z
}
dnl }}}
define(`DEFINE_RELOCATE_API', `
/* old_src = readable element, before memcpy if any
* new_src = writable element, after memcpy if any
* virtual_old_src = brother pointers relatived to this address, before relocation
* virtual_new_src = brother pointers relatived to this address, after relocation
/* src = readable element, before memcpy if any
* dst = writable element, after memcpy if any
* virtual_src = brother pointers relatived to this address, before relocation
* virtual_dst = brother pointers relatived to this address, after relocation
*/
EXPORTED_FUNCTION(`void xc_processor_relocate_$1($1 *old_src, $1 *virtual_old_src, $1 *new_src, $1 *virtual_new_src TSRMLS_DC)') dnl {{{
EXPORTED_FUNCTION(`void xc_processor_relocate_$1($1 *dst, $1 *virtual_dst, $1 *src, $1 *virtual_src TSRMLS_DC)') dnl {{{
{
char *old_address = 0; /* unkown X used later */
ptrdiff_t offset = ptrsub(old_address, (ptrdiff_t) virtual_old_src);
ptrdiff_t offset = ptrsub(old_address, (ptrdiff_t) virtual_src);
/* diff to new_ptr */
ptrdiff_t ptrdiff = ptrsub(new_src, old_src);
ptrdiff_t relocatediff = (ptrdiff_t) ptradd($1 *, virtual_new_src, offset);
assert(ptradd($1 *, old_src, ptrdiff) == new_src);
ptrdiff_t ptrdiff = ptrsub(dst, src);
ptrdiff_t relocatediff = (ptrdiff_t) ptradd($1 *, virtual_dst, offset);
assert(ptradd($1 *, src, ptrdiff) == dst);
xc_relocate_$1(new_src, ptrdiff, relocatediff TSRMLS_CC);
xc_relocate_$1(dst, ptrdiff, relocatediff TSRMLS_CC);
}
dnl }}}
')