Ignore:
Timestamp:
2013-11-06T19:24:29+01:00 (19 months ago)
Author:
moo
Message:

relocate WIP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/processor/head.m4

    r1443 r1444  
    1111
    1212EXPORT(`#include "xcache.h"')
    13 #include "xcache.h"
    1413EXPORT(`#include "mod_cacher/xc_cache.h"')
    15 #include "mod_cacher/xc_cache.h"
    1614EXPORT(`#include "xcache/xc_shm.h"')
    17 #include "xcache/xc_shm.h"
    1815EXPORT(`#include "xcache/xc_allocator.h"')
    19 #include "xcache/xc_allocator.h"
     16#include "xc_processor.h"
    2017#include "xcache/xc_const_string.h"
    2118#include "xcache/xc_utils.h"
    2219#include "util/xc_align.h"
    23 #include "xc_processor.h"
    2420#include "xcache_globals.h"
    2521
     
    8783dnl }}}
    8884dnl {{{ _xc_processor_t
    89 EXPORT(`typedef struct _xc_processor_t xc_processor_t;')
    90 struct _xc_processor_t {
     85typedef struct _xc_processor_t {
    9186    char *p;
    9287    size_t size;
     
    114109    zend_bool readonly_protection; /* wheather it's present */
    115110IFAUTOCHECK(xc_stack_t allocsizes;)
    116 };
     111} xc_processor_t;
    117112dnl }}}
    118 EXPORT(`typedef struct _xc_relocate_t { ptrdiff_t src; ptrdiff_t dst; ptrdiff_t ptrdiff; } xc_relocate_t;')
     113typedef struct _xc_relocate_t { /* {{{ */
     114    ptrdiff_t dst;
     115    char *old_start;
     116    char *new_start;
     117} xc_relocate_t;
     118/* }}} */
    119119EXPORT(`typedef struct _xc_dasm_t { const zend_op_array *active_op_array_src; } xc_dasm_t;')
    120120/* {{{ memsetptr */
     
    394394')
    395395/* }}} */
    396 dnl ================ export API
    397 define(`DEFINE_STORE_API', `
    398 EXPORTED(`$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC)') dnl {{{
    399 {
    400     $1 *dst;
    401     xc_processor_t processor;
    402 
    403     memset(&processor, 0, sizeof(processor));
    404     processor.reference = 1;
    405     processor.shm = shm;
    406     processor.allocator = allocator;
    407 
    408     IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);')
    409 
    410     /* calc size */ {
    411         zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
    412         if (processor.reference) {
    413             zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    414         }
    415 
    416         processor.size = 0;
    417         /* allocate */
    418         processor.size = ALIGN(processor.size + sizeof(src[0]));
    419 
    420         xc_calc_$1(&processor, src TSRMLS_CC);
    421         if (processor.reference) {
    422             zend_hash_destroy(&processor.zvalptrs);
    423         }
    424         zend_hash_destroy(&processor.strings);
    425     }
    426     ifelse(
    427         `$1', `xc_entry_data_php_t', `SRC(`size')',
    428         `', `', SRC(`entry.size')) = processor.size;
    429     ifelse(
    430         `$1', `xc_entry_var_t', `SRC(`have_references') = processor.have_references;',
    431         `$1', `xc_entry_data_php_t', `SRC(`have_references') = processor.have_references;'
    432     )
    433 
    434     IFAUTOCHECK(`xc_stack_reverse(&processor.allocsizes);')
    435     /* store {{{ */
    436     {
    437         IFAUTOCHECK(`char *oldp;')
    438         zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
    439         if (processor.reference) {
    440             zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    441         }
    442 
    443         /* allocator :) */
    444         processor.p = (char *) processor.allocator->vtable->malloc(processor.allocator, processor.size);
    445         if (processor.p == NULL) {
    446             dst = NULL;
    447             goto err_alloc;
    448         }
    449         IFAUTOCHECK(`oldp = processor.p;')
    450         assert(processor.p == (char *) ALIGN(processor.p));
    451 
    452         /* allocate */
    453         dst = ($1 *) processor.p;
    454         processor.p = (char *) ALIGN(processor.p + sizeof(dst[0]));
    455 
    456         xc_store_$1(&processor, dst, src TSRMLS_CC);
    457         IFAUTOCHECK(` {
    458             size_t unexpected = processor.p - oldp;
    459             size_t expected = processor.size;
    460             if (unexpected != processor.size) {
    461                 fprintf(stderr, "unexpected:%lu - expected:%lu = %ld != 0\n", (unsigned long) unexpected, (unsigned long) expected, (long) unexpected - expected);
    462                 abort();
    463             }
    464         }')
    465 err_alloc:
    466         if (processor.reference) {
    467             zend_hash_destroy(&processor.zvalptrs);
    468         }
    469         zend_hash_destroy(&processor.strings);
    470     }
    471     /* }}} */
    472 
    473     IFAUTOCHECK(`xc_stack_destroy(&processor.allocsizes);')
    474 
    475     return dst;
    476 }
    477 dnl }}}
    478 ')
    479 DEFINE_STORE_API(`xc_entry_var_t')
    480 DEFINE_STORE_API(`xc_entry_php_t')
    481 DEFINE_STORE_API(`xc_entry_data_php_t')
    482 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 {{{
    483 {
    484     xc_processor_t processor;
    485 
    486     memset(&processor, 0, sizeof(processor));
    487     xc_restore_xc_entry_php_t(&processor, dst, src TSRMLS_CC);
    488 
    489     return dst;
    490 }
    491 dnl }}}
    492 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 {{{
    493 {
    494     xc_processor_t processor;
    495 
    496     memset(&processor, 0, sizeof(processor));
    497     processor.readonly_protection = readonly_protection;
    498     /* this function is used for php data only */
    499     if (SRC(`have_references')) {
    500         processor.reference = 1;
    501     }
    502     processor.entry_php_src = entry_php;
    503 
    504     if (processor.reference) {
    505         zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    506     }
    507     xc_restore_xc_entry_data_php_t(&processor, dst, src TSRMLS_CC);
    508     if (processor.reference) {
    509         zend_hash_destroy(&processor.zvalptrs);
    510     }
    511     return dst;
    512 }
    513 dnl }}}
    514 EXPORTED(`zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC)') dnl {{{
    515 {
    516     xc_processor_t processor;
    517 
    518     memset(&processor, 0, sizeof(processor));
    519     processor.reference = have_references;
    520 
    521     if (processor.reference) {
    522         zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    523         dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
    524         zend_hash_add(&processor.zvalptrs, (char *)src, sizeof(src), (void*)&dst, sizeof(dst), NULL);
    525     }
    526     xc_restore_zval(&processor, dst, src TSRMLS_CC);
    527     if (processor.reference) {
    528         zend_hash_destroy(&processor.zvalptrs);
    529     }
    530 
    531     return dst;
    532 }
    533 dnl }}}
    534 define(`DEFINE_RELOCATE_API', `
    535 EXPORTED(`void xc_processor_relocate_$1(int a TSRMLS_DC)') dnl {{{
    536 {
    537 }
    538 dnl }}}
    539 ')
    540 DEFINE_RELOCATE_API(`xc_entry_var_t')
    541 DEFINE_RELOCATE_API(`xc_entry_php_t')
    542 DEFINE_RELOCATE_API(`xc_entry_data_php_t')
    543 #ifdef HAVE_XCACHE_DPRINT
    544 EXPORTED(`void xc_dprint(xc_entry_php_t *src, int indent TSRMLS_DC)') dnl {{{
    545 {
    546     IFDPRINT(`INDENT()`'fprintf(stderr, "xc_entry_php_t:src");')
    547     xc_dprint_xc_entry_php_t(src, indent TSRMLS_CC);
    548 }
    549 #endif
    550 dnl }}}
Note: See TracChangeset for help on using the changeset viewer.