Changeset 1468 in svn


Ignore:
Timestamp:
2013-11-12T10:46:04+01:00 (20 months ago)
Author:
Xuefer
Message:

clean up shm handlers

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/mod_cacher/xc_cacher.c

    r1460 r1468  
    176176    php->hits     = 0;
    177177    php->refcount = 0;
    178     stored_php = xc_processor_store_xc_entry_data_php_t(cache->shm, cache->allocator, php TSRMLS_CC);
     178    stored_php = xc_processor_store_xc_entry_data_php_t(cache->shm->readonlydiff, cache->allocator, php TSRMLS_CC);
    179179#if 0
    180180    {
     
    313313    entry->atime = XG(request_time);
    314314    stored_entry = type == XC_TYPE_PHP
    315         ? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache->shm, cache->allocator, (xc_entry_php_t *) entry TSRMLS_CC)
    316         : (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache->shm, cache->allocator, (xc_entry_var_t *) entry TSRMLS_CC);
     315        ? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache->shm->readonlydiff, cache->allocator, (xc_entry_php_t *) entry TSRMLS_CC)
     316        : (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache->shm->readonlydiff, cache->allocator, (xc_entry_var_t *) entry TSRMLS_CC);
    317317    if (stored_entry) {
    318318        xc_entry_add_unlocked(cache->cached, entryslotid, stored_entry);
     
    22412241        for (i = 0; i < xc_php_hcache.size; i ++) {
    22422242            shm = xc_php_caches[i].shm;
    2243             if (shm->handlers->is_readwrite(shm, p)) {
     2243            if (shm->vtable->is_readwrite(shm, p)) {
    22442244                return 1;
    22452245            }
     
    22502250        for (i = 0; i < xc_var_hcache.size; i ++) {
    22512251            shm = xc_var_caches[i].shm;
    2252             if (shm->handlers->is_readwrite(shm, p)) {
     2252            if (shm->vtable->is_readwrite(shm, p)) {
    22532253                return 1;
    22542254            }
     
    22662266        for (i = 0; i < xc_php_hcache.size; i ++) {
    22672267            shm = xc_php_caches[i].shm;
    2268             if (shm->handlers->is_readonly(shm, p)) {
     2268            if (shm->vtable->is_readonly(shm, p)) {
    22692269                return 1;
    22702270            }
     
    22752275        for (i = 0; i < xc_var_hcache.size; i ++) {
    22762276            shm = xc_var_caches[i].shm;
    2277             if (shm->handlers->is_readonly(shm, p)) {
     2277            if (shm->vtable->is_readonly(shm, p)) {
    22782278                return 1;
    22792279            }
     
    26382638            shm = cache->shm;
    26392639            if (shm) {
    2640                 cache->shm->handlers->memdestroy(cache->allocator);
     2640                cache->shm->vtable->memdestroy(cache->allocator);
    26412641            }
    26422642        }
     
    26712671    for (i = 0; i < hcache->size; i ++) {
    26722672        xc_cache_t *cache = &caches[i];
    2673         CHECK(allocator = shm->handlers->meminit(shm, memsize), "Failed init shm");
     2673        CHECK(allocator = shm->vtable->meminit(shm, memsize), "Failed init shm");
    26742674        if (!(allocator->vtable = xc_allocator_find(allocator_name))) {
    26752675            zend_error(E_ERROR, "Allocator %s not found", allocator_name);
     
    27462746    if (xc_php_size || xc_var_size) {
    27472747        CHECK(shm = xc_shm_init(xc_shm_scheme, shmsize, xc_readonly_protection, xc_mmap_path, NULL), "Cannot create shm");
    2748         if (!shm->handlers->can_readonly(shm)) {
     2748        if (!xc_shm_can_readonly(shm)) {
    27492749            xc_readonly_protection = 0;
    27502750        }
     
    34703470                RETVAL_LONG(value);
    34713471
    3472                 zv = (zval *) cache->shm->handlers->to_readwrite(cache->shm, (char *) stored_entry_var->value);
     3472                zv = (zval *) xc_shm_to_readwrite(cache->shm, (char *) stored_entry_var->value);
    34733473                Z_LVAL_P(zv) = value;
    34743474                ++cache->cached->updates;
  • trunk/processor/foot.m4

    r1456 r1468  
    11define(`DEFINE_STORE_API', `
    2 EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC)') dnl {{{
     2EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(ptrdiff_t relocatediff, xc_allocator_t *allocator, $1 *src TSRMLS_DC)') dnl {{{
    33{
    44    $1 *dst;
     
    66
    77    memset(&processor, 0, sizeof(processor));
    8     processor.reference = 1;
    9     processor.shm = shm;
    10     processor.allocator = allocator;
     8    processor.handle_reference = 1;
     9    processor.relocatediff = relocatediff;
    1110
    1211    IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);')
     
    1413    /* calc size */ {
    1514        zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
    16         if (processor.reference) {
     15        if (processor.handle_reference) {
    1716            zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    1817        }
     
    2322
    2423        xc_calc_$1(&processor, src TSRMLS_CC);
    25         if (processor.reference) {
     24        if (processor.handle_reference) {
    2625            zend_hash_destroy(&processor.zvalptrs);
    2726        }
     
    4140        IFAUTOCHECK(`char *oldp;')
    4241        zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
    43         if (processor.reference) {
     42        if (processor.handle_reference) {
    4443            zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    4544        }
    4645
    4746        /* allocator :) */
    48         processor.p = (char *) processor.allocator->vtable->malloc(processor.allocator, processor.size);
     47        processor.p = (char *) allocator->vtable->malloc(allocator, processor.size);
    4948        if (processor.p == NULL) {
    5049            dst = NULL;
     
    6867        }')
    6968err_alloc:
    70         if (processor.reference) {
     69        if (processor.handle_reference) {
    7170            zend_hash_destroy(&processor.zvalptrs);
    7271        }
     
    102101    /* this function is used for php data only */
    103102    if (SRC(`have_references')) {
    104         processor.reference = 1;
     103        processor.handle_reference = 1;
    105104    }
    106105    processor.entry_php_src = entry_php;
    107106
    108     if (processor.reference) {
     107    if (processor.handle_reference) {
    109108        zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    110109    }
    111110    xc_restore_xc_entry_data_php_t(&processor, dst, src TSRMLS_CC);
    112     if (processor.reference) {
     111    if (processor.handle_reference) {
    113112        zend_hash_destroy(&processor.zvalptrs);
    114113    }
     
    121120
    122121    memset(&processor, 0, sizeof(processor));
    123     processor.reference = have_references;
     122    processor.handle_reference = have_references;
    124123
    125     if (processor.reference) {
     124    if (processor.handle_reference) {
    126125        zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    127126        dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
     
    129128    }
    130129    xc_restore_zval(&processor, dst, src TSRMLS_CC);
    131     if (processor.reference) {
     130    if (processor.handle_reference) {
    132131        zend_hash_destroy(&processor.zvalptrs);
    133132    }
  • trunk/processor/head.m4

    r1466 r1468  
    101101    HashTable strings;
    102102    HashTable zvalptrs;
    103     zend_bool reference; /* enable if to deal with reference */
     103    zend_bool handle_reference; /* enable if to deal with reference */
    104104    zend_bool have_references;
     105    ptrdiff_t relocatediff;
     106
    105107    const xc_entry_php_t *entry_php_src;
    106108    const xc_entry_php_t *entry_php_dst;
    107109    const xc_entry_data_php_t *php_src;
    108110    const xc_entry_data_php_t *php_dst;
    109     xc_shm_t                  *shm;
    110     xc_allocator_t            *allocator;
    111111    const zend_class_entry *cache_ce;
    112112    zend_ulong cache_class_index;
  • trunk/processor/main.m4

    r1461 r1468  
    260260REDEF(`PROCESSOR_TYPE', `calc') include(srcdir`/processor/processor.m4')
    261261
    262 pushdef(`FIXPOINTER_EX', `$2 = ($1 *) processor->shm->handlers->to_readonly(processor->shm, (void *)$2);')
     262pushdef(`FIXPOINTER_EX', `$2 = ptradd($1 *, notnullable($2), processor->relocatediff);')
    263263REDEF(`PROCESSOR_TYPE', `store') include(srcdir`/processor/processor.m4')
    264264popdef(`FIXPOINTER_EX')
     
    281281#endif /* HAVE_XCACHE_DISASSEMBLER */
    282282
     283undefine(`PROCESSOR_TYPE')
     284
    283285include(srcdir`/processor/foot.m4')
    284286
  • trunk/processor/processor.m4

    r1461 r1468  
    170170        do {
    171171            IFCALCCOPY(`
    172                 if (processor->reference) {
     172                if (processor->handle_reference) {
    173173                    zval_ptr *ppzv;
    174174                    if (zend_hash_find(&processor->zvalptrs, (char *) &SRC()[0], sizeof(SRC()[0]), (void **) &ppzv) == SUCCESS) {
     
    188188            ALLOC(DST()[0], zval)
    189189            IFCALCCOPY(`
    190                 if (processor->reference) {
     190                if (processor->handle_reference) {
    191191                    IFCALC(`
    192192                        /* make dummy */
  • trunk/xcache/xc_malloc.c

    r1392 r1468  
    1 #define XC_SHM_IMPL _xc_malloc_shm_t
     1typedef struct xc_malloc_shm_t xc_shm_t;
     2#define XC_SHM_T_DEFINED
    23#define _xc_allocator_t _xc_allocator_malloc_t
     4
    35#include <stdlib.h>
    46#include <stdio.h>
     
    1921};
    2022
    21 /* {{{ _xc_malloc_shm_t */
    22 struct _xc_malloc_shm_t {
    23     xc_shm_handlers_t *handlers;
    24     xc_shmsize_t       size;
    25     xc_shmsize_t       memoffset;
     23/* {{{ xc_malloc_shm_t */
     24struct xc_malloc_shm_t {
     25    xc_shm_vtable_t *vtable;
     26    xc_shmsize_t     size;
     27    xc_shmsize_t     memoffset;
    2628#ifndef TEST
    2729    HashTable blocks;
     
    139141/* }}} */
    140142
    141 static XC_SHM_CAN_READONLY(xc_malloc_can_readonly) /* {{{ */
    142 {
    143     return 0;
    144 }
    145 /* }}} */
     143static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */
     144{
     145#ifndef TEST
     146    zend_hash_destroy(&shm->blocks);
     147#endif
     148    free(shm);
     149    return;
     150}
     151/* }}} */
     152static XC_SHM_INIT(xc_malloc_init) /* {{{ */
     153{
     154    xc_shm_t *shm;
     155    CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM");
     156    shm->size = size;
     157
     158#ifndef TEST
     159    zend_hash_init(&shm->blocks, 64, NULL, NULL, 1);
     160#endif
     161    return shm;
     162err:
     163    return NULL;
     164}
     165/* }}} */
     166
    146167static XC_SHM_IS_READWRITE(xc_malloc_is_readwrite) /* {{{ */
    147168{
     
    150171    size_t *psize;
    151172    char **ptr;
    152 
    153     zend_hash_internal_pointer_reset_ex(&shm->blocks, &pos);
    154     while (zend_hash_get_current_data_ex(&shm->blocks, (void **) &psize, &pos) == SUCCESS) {
    155         zend_hash_get_current_key_ex(&shm->blocks, (void *) &ptr, NULL, NULL, 0, &pos);
     173    HashTable *blocks = &((xc_shm_t *) shm)->blocks;
     174
     175    zend_hash_internal_pointer_reset_ex(blocks, &pos);
     176    while (zend_hash_get_current_data_ex(blocks, (void **) &psize, &pos) == SUCCESS) {
     177        zend_hash_get_current_key_ex(blocks, (void *) &ptr, NULL, NULL, 0, &pos);
    156178        if ((char *) p >= *ptr && (char *) p < *ptr + *psize) {
    157179            return 1;
    158180        }
    159         zend_hash_move_forward_ex(&shm->blocks, &pos);
     181        zend_hash_move_forward_ex(blocks, &pos);
    160182    }
    161183#endif
     
    167189{
    168190    return 0;
    169 }
    170 /* }}} */
    171 static XC_SHM_TO_READWRITE(xc_malloc_to_readwrite) /* {{{ */
    172 {
    173     return p;
    174 }
    175 /* }}} */
    176 static XC_SHM_TO_READONLY(xc_malloc_to_readonly) /* {{{ */
    177 {
    178     return p;
    179 }
    180 /* }}} */
    181 
    182 static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */
    183 {
    184 #ifndef TEST
    185     zend_hash_destroy(&shm->blocks);
    186 #endif
    187     free(shm);
    188     return;
    189 }
    190 /* }}} */
    191 static XC_SHM_INIT(xc_malloc_init) /* {{{ */
    192 {
    193     xc_shm_t *shm;
    194     CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM");
    195     shm->size = size;
    196 
    197 #ifndef TEST
    198     zend_hash_init(&shm->blocks, 64, NULL, NULL, 1);
    199 #endif
    200     return shm;
    201 err:
    202     return NULL;
    203191}
    204192/* }}} */
     
    228216static xc_allocator_vtable_t xc_allocator_malloc_vtable = XC_ALLOCATOR_VTABLE(allocator_malloc);
    229217#ifndef TEST
    230 static xc_shm_handlers_t xc_shm_malloc_handlers = XC_SHM_HANDLERS(malloc);
     218static xc_shm_vtable_t xc_shm_malloc_vtable = XC_SHM_VTABLE(malloc);
    231219#endif
    232220void xc_allocator_malloc_register() /* {{{ */
     
    243231void xc_shm_malloc_register() /* {{{ */
    244232{
    245     if (xc_shm_scheme_register("malloc", &xc_shm_malloc_handlers) == 0) {
     233    if (xc_shm_scheme_register("malloc", &xc_shm_malloc_vtable) == 0) {
    246234        zend_error(E_ERROR, "XCache: failed to register malloc shm_scheme");
    247235    }
  • trunk/xcache/xc_shm.c

    r1378 r1468  
    1515
    1616struct _xc_shm_scheme_t {
    17     const char              *name;
    18     const xc_shm_handlers_t *handlers;
     17    const char            *name;
     18    const xc_shm_vtable_t *vtable;
    1919};
    2020static xc_shm_scheme_t xc_shm_schemes[10];
     
    3636}
    3737/* }}} */
    38 int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers) /* {{{ */
     38int xc_shm_scheme_register(const char *name, const xc_shm_vtable_t *vtable) /* {{{ */
    3939{
    4040    int i;
     
    4242        if (!xc_shm_schemes[i].name) {
    4343            xc_shm_schemes[i].name = name;
    44             xc_shm_schemes[i].handlers = handlers;
     44            xc_shm_schemes[i].vtable = vtable;
    4545            return 1;
    4646        }
     
    4949}
    5050/* }}} */
    51 const xc_shm_handlers_t *xc_shm_scheme_find(const char *name) /* {{{ */
     51const xc_shm_vtable_t *xc_shm_scheme_find(const char *name) /* {{{ */
    5252{
    5353    int i;
    5454    for (i = 0; i < 10 && xc_shm_schemes[i].name; i ++) {
    5555        if (strcmp(xc_shm_schemes[i].name, name) == 0) {
    56             return xc_shm_schemes[i].handlers;
     56            return xc_shm_schemes[i].vtable;
    5757        }
    5858    }
     
    7979xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */
    8080{
    81     const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type);
     81    const xc_shm_vtable_t *vtable = xc_shm_scheme_find(type);
    8282
    83     if (handlers) {
    84         xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2);
     83    if (vtable) {
     84        xc_shm_t *shm = vtable->init(size, readonly_protection, arg1, arg2);
    8585        if (shm) {
    86             shm->handlers = handlers;
     86            shm->vtable = vtable;
    8787        }
    8888        return shm;
     
    9494void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
    9595{
    96     shm->handlers->destroy(shm);
     96    shm->vtable->destroy(shm);
    9797}
    9898/* }}} */
     99
     100int xc_shm_can_readonly(const xc_shm_t *shm) /* {{{ */
     101{
     102    return ((xc_shm_base_t *)shm)->readonlydiff != 0;
     103}
     104/* }}} */
     105void *xc_shm_to_readwrite(const xc_shm_t *shm_, void *p) /* {{{ */
     106{
     107    const xc_shm_base_t *shm = (const xc_shm_base_t *) shm_;
     108
     109    if (shm->readonlydiff) {
     110        assert(shm->vtable->is_readonly(shm_, p));
     111        p = ((char *) p) - shm->readonlydiff;
     112    }
     113    assert(shm->vtable->is_readwrite(shm_, p));
     114    return p;
     115}
     116/* }}} */
     117void *xc_shm_to_readonly(const xc_shm_t *shm_, void *p) /* {{{ */
     118{
     119    const xc_shm_base_t *shm = (const xc_shm_base_t *) shm_;
     120
     121    assert(shm->vtable->is_readwrite(shm_, p));
     122    if (shm->readonlydiff) {
     123        p = ((char *) p) + shm->readonlydiff;
     124        assert(shm->vtable->is_readonly(shm_, p));
     125    }
     126    return p;
     127}
     128/* }}} */
  • trunk/xcache/xc_shm.h

    r1135 r1468  
    33
    44#include <stdlib.h>
     5#include <stddef.h>
     6#include <assert.h>
    57
    6 typedef struct _xc_shm_handlers_t xc_shm_handlers_t;
    7 
    8 #ifndef XC_SHM_IMPL
    9 struct _xc_shm_t {
    10     const xc_shm_handlers_t *handlers;
    11 };
    12 #define XC_SHM_IMPL _xc_shm_t
     8#ifndef XC_SHM_T_DEFINED
     9typedef struct _xc_shm_base_t xc_shm_t;
     10#define XC_SHM_T_DEFINED
    1311#endif
    1412
    15 typedef struct XC_SHM_IMPL xc_shm_t;
     13typedef struct _xc_shm_vtable_t xc_shm_vtable_t;
     14
     15typedef struct _xc_shm_base_t {
     16    const xc_shm_vtable_t *vtable;
     17    ptrdiff_t readonlydiff;
     18} xc_shm_base_t;
     19
    1620typedef size_t xc_shmsize_t;
    1721
    1822/* shm */
    19 #define XC_SHM_CAN_READONLY(func) int   func(xc_shm_t *shm)
    20 #define XC_SHM_IS_READWRITE(func) int   func(xc_shm_t *shm, const void *p)
    21 #define XC_SHM_IS_READONLY(func)  int   func(xc_shm_t *shm, const void *p)
    22 #define XC_SHM_TO_READWRITE(func) void *func(xc_shm_t *shm, void *p)
    23 #define XC_SHM_TO_READONLY(func)  void *func(xc_shm_t *shm, void *p)
     23#define XC_SHM_IS_READWRITE(func) int   func(const xc_shm_t *shm, const void *p)
     24#define XC_SHM_IS_READONLY(func)  int   func(const xc_shm_t *shm, const void *p)
    2425
    2526#define XC_SHM_INIT(func)         xc_shm_t *func(xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2)
     
    2930#define XC_SHM_MEMDESTROY(func)   void func(void *mem)
    3031
    31 #define XC_SHM_HANDLERS(name)    { \
    32     xc_##name##_can_readonly       \
     32#define XC_SHM_VTABLE(name)      { \
     33      xc_##name##_init             \
     34    , xc_##name##_destroy          \
    3335    , xc_##name##_is_readwrite     \
    3436    , xc_##name##_is_readonly      \
    35     , xc_##name##_to_readwrite     \
    36     , xc_##name##_to_readonly      \
    3737\
    38     , xc_##name##_init             \
    39     , xc_##name##_destroy          \
    4038\
    4139    , xc_##name##_meminit          \
     
    4341}
    4442
    45 struct _xc_shm_handlers_t {
    46     XC_SHM_CAN_READONLY((*can_readonly));
     43struct _xc_shm_vtable_t {
     44    XC_SHM_INIT((*init));
     45    XC_SHM_DESTROY((*destroy));
    4746    XC_SHM_IS_READWRITE((*is_readwrite));
    4847    XC_SHM_IS_READONLY((*is_readonly));
    49     XC_SHM_TO_READWRITE((*to_readwrite));
    50     XC_SHM_TO_READONLY((*to_readonly));
    51     XC_SHM_INIT((*init));
    52     XC_SHM_DESTROY((*destroy));
    5348
    5449    XC_SHM_MEMINIT((*meminit));
     
    5954
    6055void xc_shm_init_modules();
    61 int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers);
    62 const xc_shm_handlers_t *xc_shm_scheme_find(const char *name);
     56int xc_shm_scheme_register(const char *name, const xc_shm_vtable_t *vtable);
     57const xc_shm_vtable_t *xc_shm_scheme_find(const char *name);
    6358xc_shm_scheme_t *xc_shm_scheme_first();
    6459xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme);
     
    6762xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2);
    6863void xc_shm_destroy(xc_shm_t *shm);
     64
     65int xc_shm_can_readonly(const xc_shm_t *shm);
     66void *xc_shm_to_readwrite(const xc_shm_t *shm_, void *p);
     67void *xc_shm_to_readonly(const xc_shm_t *shm_, void *p);
     68
    6969#endif
  • trunk/xcache/xc_shm_mmap.c

    r1154 r1468  
    3030
    3131#include "php.h"
    32 #define XC_SHM_IMPL _xc_mmap_shm_t
     32
     33typedef struct xc_mmap_shm_t xc_shm_t;
     34#define XC_SHM_T_DEFINED
    3335#include "xc_shm.h"
    3436#include "xc_utils.h"
     
    3941
    4042/* {{{ xc_shm_t */
    41 struct _xc_mmap_shm_t {
    42     xc_shm_handlers_t *handlers;
    43     zend_bool disabled;
     43struct xc_mmap_shm_t {
     44    xc_shm_base_t base;
    4445    void *ptr;
    4546    void *ptr_ro;
    46     long  diff;
    4747    xc_shmsize_t size;
    4848    xc_shmsize_t memoffset;
     
    6161#define PTR_SUB(ptr, v) (((char *) (ptr)) - (v))
    6262
    63 static XC_SHM_CAN_READONLY(xc_mmap_can_readonly) /* {{{ */
    64 {
    65     return shm->ptr_ro != NULL;
    66 }
    67 /* }}} */
    6863static XC_SHM_IS_READWRITE(xc_mmap_is_readwrite) /* {{{ */
    6964{
     
    7368static XC_SHM_IS_READONLY(xc_mmap_is_readonly) /* {{{ */
    7469{
    75     return xc_mmap_can_readonly(shm) && p >= shm->ptr_ro && (char *)p < (char *)shm->ptr_ro + shm->size;
    76 }
    77 /* }}} */
    78 static XC_SHM_TO_READWRITE(xc_mmap_to_readwrite) /* {{{ */
    79 {
    80     if (shm->diff) {
    81         assert(xc_mmap_is_readonly(shm, p));
    82         p = PTR_SUB(p, shm->diff);
    83     }
    84     assert(xc_mmap_is_readwrite(shm, p));
    85     return p;
    86 }
    87 /* }}} */
    88 static XC_SHM_TO_READONLY(xc_mmap_to_readonly) /* {{{ */
    89 {
    90     assert(xc_mmap_is_readwrite(shm, p));
    91     if (shm->diff) {
    92         p = PTR_ADD(p, shm->diff);
    93         assert(xc_mmap_is_readonly(shm, p));
    94     }
    95     return p;
     70    return xc_shm_can_readonly(shm) && p >= shm->ptr_ro && (char *)p < (char *)shm->ptr_ro + shm->size;
    9671}
    9772/* }}} */
     
    133108    /*
    134109    shm->size = NULL;
    135     shm->diff = 0;
     110    shm->base.readonlydiff = 0;
    136111    */
    137112
     
    243218
    244219        if (ro_ok) {
    245             shm->diff = PTR_SUB(shm->ptr_ro, (char *) shm->ptr);
     220            shm->base.readonlydiff = PTR_SUB(shm->ptr_ro, (char *) shm->ptr);
    246221            /* no overlap */
    247             assert((xc_shmsize_t) abs(shm->diff) >= size);
     222            assert((xc_shmsize_t) abs(shm->base.readonlydiff) >= size);
    248223        }
    249224        else {
     
    257232#endif
    258233            shm->ptr_ro = NULL;
    259             shm->diff = 0;
     234            shm->base.readonlydiff = 0;
    260235        }
    261236    }
     
    309284/* }}} */
    310285
    311 static xc_shm_handlers_t xc_shm_mmap_handlers = XC_SHM_HANDLERS(mmap);
     286static xc_shm_vtable_t xc_shm_mmap_vtable = XC_SHM_VTABLE(mmap);
    312287void xc_shm_mmap_register() /* {{{ */
    313288{
    314     if (xc_shm_scheme_register("mmap", &xc_shm_mmap_handlers) == 0) {
     289    if (xc_shm_scheme_register("mmap", &xc_shm_mmap_vtable) == 0) {
    315290        zend_error(E_ERROR, "XCache: failed to register mmap shm_scheme");
    316291    }
Note: See TracChangeset for help on using the changeset viewer.