1
0
Fork 0

clean up shm handlers

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1468 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
master
Xuefer 10 years ago
parent 548985cdb7
commit d19d64546d

@ -175,7 +175,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);
stored_php = xc_processor_store_xc_entry_data_php_t(cache->shm->readonlydiff, cache->allocator, php TSRMLS_CC);
#if 0
{
xc_entry_data_php_t *p = malloc(stored_php->size);
@ -312,8 +312,8 @@ static xc_entry_t *xc_entry_store_unlocked(xc_entry_type_t type, xc_cache_t *cac
entry->ctime = XG(request_time);
entry->atime = XG(request_time);
stored_entry = type == XC_TYPE_PHP
? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache->shm, cache->allocator, (xc_entry_php_t *) entry TSRMLS_CC)
: (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache->shm, cache->allocator, (xc_entry_var_t *) entry TSRMLS_CC);
? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache->shm->readonlydiff, cache->allocator, (xc_entry_php_t *) entry TSRMLS_CC)
: (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache->shm->readonlydiff, cache->allocator, (xc_entry_var_t *) entry TSRMLS_CC);
if (stored_entry) {
xc_entry_add_unlocked(cache->cached, entryslotid, stored_entry);
++cache->cached->updates;
@ -2240,7 +2240,7 @@ zend_bool xc_is_rw(const void *p) /* {{{ */
if (xc_php_caches) {
for (i = 0; i < xc_php_hcache.size; i ++) {
shm = xc_php_caches[i].shm;
if (shm->handlers->is_readwrite(shm, p)) {
if (shm->vtable->is_readwrite(shm, p)) {
return 1;
}
}
@ -2249,7 +2249,7 @@ zend_bool xc_is_rw(const void *p) /* {{{ */
if (xc_var_caches) {
for (i = 0; i < xc_var_hcache.size; i ++) {
shm = xc_var_caches[i].shm;
if (shm->handlers->is_readwrite(shm, p)) {
if (shm->vtable->is_readwrite(shm, p)) {
return 1;
}
}
@ -2265,7 +2265,7 @@ zend_bool xc_is_ro(const void *p) /* {{{ */
if (xc_php_caches) {
for (i = 0; i < xc_php_hcache.size; i ++) {
shm = xc_php_caches[i].shm;
if (shm->handlers->is_readonly(shm, p)) {
if (shm->vtable->is_readonly(shm, p)) {
return 1;
}
}
@ -2274,7 +2274,7 @@ zend_bool xc_is_ro(const void *p) /* {{{ */
if (xc_var_caches) {
for (i = 0; i < xc_var_hcache.size; i ++) {
shm = xc_var_caches[i].shm;
if (shm->handlers->is_readonly(shm, p)) {
if (shm->vtable->is_readonly(shm, p)) {
return 1;
}
}
@ -2637,7 +2637,7 @@ static xc_shm_t *xc_cache_destroy(xc_cache_t *caches, xc_hash_t *hcache) /* {{{
}
shm = cache->shm;
if (shm) {
cache->shm->handlers->memdestroy(cache->allocator);
cache->shm->vtable->memdestroy(cache->allocator);
}
}
}
@ -2670,7 +2670,7 @@ static xc_cache_t *xc_cache_init(xc_shm_t *shm, const char *allocator_name, xc_h
for (i = 0; i < hcache->size; i ++) {
xc_cache_t *cache = &caches[i];
CHECK(allocator = shm->handlers->meminit(shm, memsize), "Failed init shm");
CHECK(allocator = shm->vtable->meminit(shm, memsize), "Failed init shm");
if (!(allocator->vtable = xc_allocator_find(allocator_name))) {
zend_error(E_ERROR, "Allocator %s not found", allocator_name);
goto err;
@ -2745,7 +2745,7 @@ static int xc_init() /* {{{ */
if (xc_php_size || xc_var_size) {
CHECK(shm = xc_shm_init(xc_shm_scheme, shmsize, xc_readonly_protection, xc_mmap_path, NULL), "Cannot create shm");
if (!shm->handlers->can_readonly(shm)) {
if (!xc_shm_can_readonly(shm)) {
xc_readonly_protection = 0;
}
@ -3469,7 +3469,7 @@ static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{
value += (inc == 1 ? count : - count);
RETVAL_LONG(value);
zv = (zval *) cache->shm->handlers->to_readwrite(cache->shm, (char *) stored_entry_var->value);
zv = (zval *) xc_shm_to_readwrite(cache->shm, (char *) stored_entry_var->value);
Z_LVAL_P(zv) = value;
++cache->cached->updates;
break; /* leave lock */

@ -1,19 +1,18 @@
define(`DEFINE_STORE_API', `
EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC)') dnl {{{
EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(ptrdiff_t relocatediff, 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;
processor.handle_reference = 1;
processor.relocatediff = relocatediff;
IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);')
/* calc size */ {
zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
if (processor.reference) {
if (processor.handle_reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
}
@ -22,7 +21,7 @@ EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allo
processor.size = ALIGN(processor.size + sizeof(src[0]));
xc_calc_$1(&processor, src TSRMLS_CC);
if (processor.reference) {
if (processor.handle_reference) {
zend_hash_destroy(&processor.zvalptrs);
}
zend_hash_destroy(&processor.strings);
@ -40,12 +39,12 @@ EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allo
{
IFAUTOCHECK(`char *oldp;')
zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
if (processor.reference) {
if (processor.handle_reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
}
/* allocator :) */
processor.p = (char *) processor.allocator->vtable->malloc(processor.allocator, processor.size);
processor.p = (char *) allocator->vtable->malloc(allocator, processor.size);
if (processor.p == NULL) {
dst = NULL;
goto err_alloc;
@ -67,7 +66,7 @@ EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allo
}
}')
err_alloc:
if (processor.reference) {
if (processor.handle_reference) {
zend_hash_destroy(&processor.zvalptrs);
}
zend_hash_destroy(&processor.strings);
@ -101,15 +100,15 @@ EXPORTED_FUNCTION(`xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t
processor.readonly_protection = readonly_protection;
/* this function is used for php data only */
if (SRC(`have_references')) {
processor.reference = 1;
processor.handle_reference = 1;
}
processor.entry_php_src = entry_php;
if (processor.reference) {
if (processor.handle_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) {
if (processor.handle_reference) {
zend_hash_destroy(&processor.zvalptrs);
}
return dst;
@ -120,15 +119,15 @@ EXPORTED_FUNCTION(`zval *xc_processor_restore_zval(zval *dst, const zval *src, z
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
processor.reference = have_references;
processor.handle_reference = have_references;
if (processor.reference) {
if (processor.handle_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) {
if (processor.handle_reference) {
zend_hash_destroy(&processor.zvalptrs);
}

@ -100,14 +100,14 @@ typedef struct _xc_processor_t {
size_t size;
HashTable strings;
HashTable zvalptrs;
zend_bool reference; /* enable if to deal with reference */
zend_bool handle_reference; /* enable if to deal with reference */
zend_bool have_references;
ptrdiff_t relocatediff;
const xc_entry_php_t *entry_php_src;
const xc_entry_php_t *entry_php_dst;
const xc_entry_data_php_t *php_src;
const xc_entry_data_php_t *php_dst;
xc_shm_t *shm;
xc_allocator_t *allocator;
const zend_class_entry *cache_ce;
zend_ulong cache_class_index;

@ -259,7 +259,7 @@ 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);')
pushdef(`FIXPOINTER_EX', `$2 = ptradd($1 *, notnullable($2), processor->relocatediff);')
REDEF(`PROCESSOR_TYPE', `store') include(srcdir`/processor/processor.m4')
popdef(`FIXPOINTER_EX')
@ -280,6 +280,8 @@ REDEF(`PROCESSOR_TYPE', `dprint') include(srcdir`/processor/processor.m4')
REDEF(`PROCESSOR_TYPE', `dasm') include(srcdir`/processor/processor.m4')
#endif /* HAVE_XCACHE_DISASSEMBLER */
undefine(`PROCESSOR_TYPE')
include(srcdir`/processor/foot.m4')
ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')

@ -169,7 +169,7 @@ DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
', `
do {
IFCALCCOPY(`
if (processor->reference) {
if (processor->handle_reference) {
zval_ptr *ppzv;
if (zend_hash_find(&processor->zvalptrs, (char *) &SRC()[0], sizeof(SRC()[0]), (void **) &ppzv) == SUCCESS) {
IFCOPY(`
@ -187,7 +187,7 @@ DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
ALLOC(DST()[0], zval)
IFCALCCOPY(`
if (processor->reference) {
if (processor->handle_reference) {
IFCALC(`
/* make dummy */
zval_ptr pzv = (zval_ptr)-1;

@ -1,5 +1,7 @@
#define XC_SHM_IMPL _xc_malloc_shm_t
typedef struct xc_malloc_shm_t xc_shm_t;
#define XC_SHM_T_DEFINED
#define _xc_allocator_t _xc_allocator_malloc_t
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -18,11 +20,11 @@ struct _xc_allocator_malloc_t {
xc_memsize_t avail; /* total free */
};
/* {{{ _xc_malloc_shm_t */
struct _xc_malloc_shm_t {
xc_shm_handlers_t *handlers;
xc_shmsize_t size;
xc_shmsize_t memoffset;
/* {{{ xc_malloc_shm_t */
struct xc_malloc_shm_t {
xc_shm_vtable_t *vtable;
xc_shmsize_t size;
xc_shmsize_t memoffset;
#ifndef TEST
HashTable blocks;
#endif
@ -138,25 +140,45 @@ static XC_ALLOCATOR_DESTROY(xc_allocator_malloc_destroy) /* {{{ */
}
/* }}} */
static XC_SHM_CAN_READONLY(xc_malloc_can_readonly) /* {{{ */
static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */
{
return 0;
#ifndef TEST
zend_hash_destroy(&shm->blocks);
#endif
free(shm);
return;
}
/* }}} */
static XC_SHM_INIT(xc_malloc_init) /* {{{ */
{
xc_shm_t *shm;
CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM");
shm->size = size;
#ifndef TEST
zend_hash_init(&shm->blocks, 64, NULL, NULL, 1);
#endif
return shm;
err:
return NULL;
}
/* }}} */
static XC_SHM_IS_READWRITE(xc_malloc_is_readwrite) /* {{{ */
{
#ifndef TEST
HashPosition pos;
size_t *psize;
char **ptr;
HashTable *blocks = &((xc_shm_t *) shm)->blocks;
zend_hash_internal_pointer_reset_ex(&shm->blocks, &pos);
while (zend_hash_get_current_data_ex(&shm->blocks, (void **) &psize, &pos) == SUCCESS) {
zend_hash_get_current_key_ex(&shm->blocks, (void *) &ptr, NULL, NULL, 0, &pos);
zend_hash_internal_pointer_reset_ex(blocks, &pos);
while (zend_hash_get_current_data_ex(blocks, (void **) &psize, &pos) == SUCCESS) {
zend_hash_get_current_key_ex(blocks, (void *) &ptr, NULL, NULL, 0, &pos);
if ((char *) p >= *ptr && (char *) p < *ptr + *psize) {
return 1;
}
zend_hash_move_forward_ex(&shm->blocks, &pos);
zend_hash_move_forward_ex(blocks, &pos);
}
#endif
@ -168,40 +190,6 @@ static XC_SHM_IS_READONLY(xc_malloc_is_readonly) /* {{{ */
return 0;
}
/* }}} */
static XC_SHM_TO_READWRITE(xc_malloc_to_readwrite) /* {{{ */
{
return p;
}
/* }}} */
static XC_SHM_TO_READONLY(xc_malloc_to_readonly) /* {{{ */
{
return p;
}
/* }}} */
static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */
{
#ifndef TEST
zend_hash_destroy(&shm->blocks);
#endif
free(shm);
return;
}
/* }}} */
static XC_SHM_INIT(xc_malloc_init) /* {{{ */
{
xc_shm_t *shm;
CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM");
shm->size = size;
#ifndef TEST
zend_hash_init(&shm->blocks, 64, NULL, NULL, 1);
#endif
return shm;
err:
return NULL;
}
/* }}} */
static XC_SHM_MEMINIT(xc_malloc_meminit) /* {{{ */
{
@ -227,7 +215,7 @@ static XC_SHM_MEMDESTROY(xc_malloc_memdestroy) /* {{{ */
static xc_allocator_vtable_t xc_allocator_malloc_vtable = XC_ALLOCATOR_VTABLE(allocator_malloc);
#ifndef TEST
static xc_shm_handlers_t xc_shm_malloc_handlers = XC_SHM_HANDLERS(malloc);
static xc_shm_vtable_t xc_shm_malloc_vtable = XC_SHM_VTABLE(malloc);
#endif
void xc_allocator_malloc_register() /* {{{ */
{
@ -242,7 +230,7 @@ void xc_allocator_malloc_register() /* {{{ */
#ifndef TEST
void xc_shm_malloc_register() /* {{{ */
{
if (xc_shm_scheme_register("malloc", &xc_shm_malloc_handlers) == 0) {
if (xc_shm_scheme_register("malloc", &xc_shm_malloc_vtable) == 0) {
zend_error(E_ERROR, "XCache: failed to register malloc shm_scheme");
}
}

@ -14,8 +14,8 @@
#include <string.h>
struct _xc_shm_scheme_t {
const char *name;
const xc_shm_handlers_t *handlers;
const char *name;
const xc_shm_vtable_t *vtable;
};
static xc_shm_scheme_t xc_shm_schemes[10];
@ -35,25 +35,25 @@ void xc_shm_init_modules() /* {{{ */
xc_shm_mmap_register();
}
/* }}} */
int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers) /* {{{ */
int xc_shm_scheme_register(const char *name, const xc_shm_vtable_t *vtable) /* {{{ */
{
int i;
for (i = 0; i < 10; i ++) {
if (!xc_shm_schemes[i].name) {
xc_shm_schemes[i].name = name;
xc_shm_schemes[i].handlers = handlers;
xc_shm_schemes[i].vtable = vtable;
return 1;
}
}
return 0;
}
/* }}} */
const xc_shm_handlers_t *xc_shm_scheme_find(const char *name) /* {{{ */
const xc_shm_vtable_t *xc_shm_scheme_find(const char *name) /* {{{ */
{
int i;
for (i = 0; i < 10 && xc_shm_schemes[i].name; i ++) {
if (strcmp(xc_shm_schemes[i].name, name) == 0) {
return xc_shm_schemes[i].handlers;
return xc_shm_schemes[i].vtable;
}
}
return NULL;
@ -78,12 +78,12 @@ const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme) /* {{{ */
/* }}} */
xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) /* {{{ */
{
const xc_shm_handlers_t *handlers = xc_shm_scheme_find(type);
const xc_shm_vtable_t *vtable = xc_shm_scheme_find(type);
if (handlers) {
xc_shm_t *shm = handlers->init(size, readonly_protection, arg1, arg2);
if (vtable) {
xc_shm_t *shm = vtable->init(size, readonly_protection, arg1, arg2);
if (shm) {
shm->handlers = handlers;
shm->vtable = vtable;
}
return shm;
}
@ -93,6 +93,36 @@ xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protecti
/* }}} */
void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
{
shm->handlers->destroy(shm);
shm->vtable->destroy(shm);
}
/* }}} */
int xc_shm_can_readonly(const xc_shm_t *shm) /* {{{ */
{
return ((xc_shm_base_t *)shm)->readonlydiff != 0;
}
/* }}} */
void *xc_shm_to_readwrite(const xc_shm_t *shm_, void *p) /* {{{ */
{
const xc_shm_base_t *shm = (const xc_shm_base_t *) shm_;
if (shm->readonlydiff) {
assert(shm->vtable->is_readonly(shm_, p));
p = ((char *) p) - shm->readonlydiff;
}
assert(shm->vtable->is_readwrite(shm_, p));
return p;
}
/* }}} */
void *xc_shm_to_readonly(const xc_shm_t *shm_, void *p) /* {{{ */
{
const xc_shm_base_t *shm = (const xc_shm_base_t *) shm_;
assert(shm->vtable->is_readwrite(shm_, p));
if (shm->readonlydiff) {
p = ((char *) p) + shm->readonlydiff;
assert(shm->vtable->is_readonly(shm_, p));
}
return p;
}
/* }}} */

@ -2,25 +2,26 @@
#define XC_SHM_H
#include <stdlib.h>
#include <stddef.h>
#include <assert.h>
typedef struct _xc_shm_handlers_t xc_shm_handlers_t;
#ifndef XC_SHM_IMPL
struct _xc_shm_t {
const xc_shm_handlers_t *handlers;
};
#define XC_SHM_IMPL _xc_shm_t
#ifndef XC_SHM_T_DEFINED
typedef struct _xc_shm_base_t xc_shm_t;
#define XC_SHM_T_DEFINED
#endif
typedef struct XC_SHM_IMPL xc_shm_t;
typedef struct _xc_shm_vtable_t xc_shm_vtable_t;
typedef struct _xc_shm_base_t {
const xc_shm_vtable_t *vtable;
ptrdiff_t readonlydiff;
} xc_shm_base_t;
typedef size_t xc_shmsize_t;
/* shm */
#define XC_SHM_CAN_READONLY(func) int func(xc_shm_t *shm)
#define XC_SHM_IS_READWRITE(func) int func(xc_shm_t *shm, const void *p)
#define XC_SHM_IS_READONLY(func) int func(xc_shm_t *shm, const void *p)
#define XC_SHM_TO_READWRITE(func) void *func(xc_shm_t *shm, void *p)
#define XC_SHM_TO_READONLY(func) void *func(xc_shm_t *shm, void *p)
#define XC_SHM_IS_READWRITE(func) int func(const xc_shm_t *shm, const void *p)
#define XC_SHM_IS_READONLY(func) int func(const xc_shm_t *shm, const void *p)
#define XC_SHM_INIT(func) xc_shm_t *func(xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2)
#define XC_SHM_DESTROY(func) void func(xc_shm_t *shm)
@ -28,28 +29,22 @@ typedef size_t xc_shmsize_t;
#define XC_SHM_MEMINIT(func) void *func(xc_shm_t *shm, xc_shmsize_t size)
#define XC_SHM_MEMDESTROY(func) void func(void *mem)
#define XC_SHM_HANDLERS(name) { \
xc_##name##_can_readonly \
#define XC_SHM_VTABLE(name) { \
xc_##name##_init \
, xc_##name##_destroy \
, xc_##name##_is_readwrite \
, xc_##name##_is_readonly \
, xc_##name##_to_readwrite \
, xc_##name##_to_readonly \
\
, xc_##name##_init \
, xc_##name##_destroy \
\
, xc_##name##_meminit \
, xc_##name##_memdestroy \
}
struct _xc_shm_handlers_t {
XC_SHM_CAN_READONLY((*can_readonly));
XC_SHM_IS_READWRITE((*is_readwrite));
XC_SHM_IS_READONLY((*is_readonly));
XC_SHM_TO_READWRITE((*to_readwrite));
XC_SHM_TO_READONLY((*to_readonly));
struct _xc_shm_vtable_t {
XC_SHM_INIT((*init));
XC_SHM_DESTROY((*destroy));
XC_SHM_IS_READWRITE((*is_readwrite));
XC_SHM_IS_READONLY((*is_readonly));
XC_SHM_MEMINIT((*meminit));
XC_SHM_MEMDESTROY((*memdestroy));
@ -58,12 +53,17 @@ struct _xc_shm_handlers_t {
typedef struct _xc_shm_scheme_t xc_shm_scheme_t;
void xc_shm_init_modules();
int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers);
const xc_shm_handlers_t *xc_shm_scheme_find(const char *name);
int xc_shm_scheme_register(const char *name, const xc_shm_vtable_t *vtable);
const xc_shm_vtable_t *xc_shm_scheme_find(const char *name);
xc_shm_scheme_t *xc_shm_scheme_first();
xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme);
const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme);
xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2);
void xc_shm_destroy(xc_shm_t *shm);
int xc_shm_can_readonly(const xc_shm_t *shm);
void *xc_shm_to_readwrite(const xc_shm_t *shm_, void *p);
void *xc_shm_to_readonly(const xc_shm_t *shm_, void *p);
#endif

@ -29,7 +29,9 @@
#endif
#include "php.h"
#define XC_SHM_IMPL _xc_mmap_shm_t
typedef struct xc_mmap_shm_t xc_shm_t;
#define XC_SHM_T_DEFINED
#include "xc_shm.h"
#include "xc_utils.h"
@ -38,12 +40,10 @@
#endif
/* {{{ xc_shm_t */
struct _xc_mmap_shm_t {
xc_shm_handlers_t *handlers;
zend_bool disabled;
struct xc_mmap_shm_t {
xc_shm_base_t base;
void *ptr;
void *ptr_ro;
long diff;
xc_shmsize_t size;
xc_shmsize_t memoffset;
char *name;
@ -60,11 +60,6 @@ struct _xc_mmap_shm_t {
#define PTR_ADD(ptr, v) (((char *) (ptr)) + (v))
#define PTR_SUB(ptr, v) (((char *) (ptr)) - (v))
static XC_SHM_CAN_READONLY(xc_mmap_can_readonly) /* {{{ */
{
return shm->ptr_ro != NULL;
}
/* }}} */
static XC_SHM_IS_READWRITE(xc_mmap_is_readwrite) /* {{{ */
{
return p >= shm->ptr && (char *)p < (char *)shm->ptr + shm->size;
@ -72,27 +67,7 @@ static XC_SHM_IS_READWRITE(xc_mmap_is_readwrite) /* {{{ */
/* }}} */
static XC_SHM_IS_READONLY(xc_mmap_is_readonly) /* {{{ */
{
return xc_mmap_can_readonly(shm) && p >= shm->ptr_ro && (char *)p < (char *)shm->ptr_ro + shm->size;
}
/* }}} */
static XC_SHM_TO_READWRITE(xc_mmap_to_readwrite) /* {{{ */
{
if (shm->diff) {
assert(xc_mmap_is_readonly(shm, p));
p = PTR_SUB(p, shm->diff);
}
assert(xc_mmap_is_readwrite(shm, p));
return p;
}
/* }}} */
static XC_SHM_TO_READONLY(xc_mmap_to_readonly) /* {{{ */
{
assert(xc_mmap_is_readwrite(shm, p));
if (shm->diff) {
p = PTR_ADD(p, shm->diff);
assert(xc_mmap_is_readonly(shm, p));
}
return p;
return xc_shm_can_readonly(shm) && p >= shm->ptr_ro && (char *)p < (char *)shm->ptr_ro + shm->size;
}
/* }}} */
@ -132,7 +107,7 @@ static XC_SHM_DESTROY(xc_mmap_destroy) /* {{{ */
}
/*
shm->size = NULL;
shm->diff = 0;
shm->base.readonlydiff = 0;
*/
free(shm);
@ -242,9 +217,9 @@ static XC_SHM_INIT(xc_mmap_init) /* {{{ */
} while (0);
if (ro_ok) {
shm->diff = PTR_SUB(shm->ptr_ro, (char *) shm->ptr);
shm->base.readonlydiff = PTR_SUB(shm->ptr_ro, (char *) shm->ptr);
/* no overlap */
assert((xc_shmsize_t) abs(shm->diff) >= size);
assert((xc_shmsize_t) abs(shm->base.readonlydiff) >= size);
}
else {
if (shm->ptr_ro) {
@ -256,7 +231,7 @@ static XC_SHM_INIT(xc_mmap_init) /* {{{ */
}
#endif
shm->ptr_ro = NULL;
shm->diff = 0;
shm->base.readonlydiff = 0;
}
}
@ -308,10 +283,10 @@ static XC_SHM_MEMDESTROY(xc_mmap_memdestroy) /* {{{ */
}
/* }}} */
static xc_shm_handlers_t xc_shm_mmap_handlers = XC_SHM_HANDLERS(mmap);
static xc_shm_vtable_t xc_shm_mmap_vtable = XC_SHM_VTABLE(mmap);
void xc_shm_mmap_register() /* {{{ */
{
if (xc_shm_scheme_register("mmap", &xc_shm_mmap_handlers) == 0) {
if (xc_shm_scheme_register("mmap", &xc_shm_mmap_vtable) == 0) {
zend_error(E_ERROR, "XCache: failed to register mmap shm_scheme");
}
return;

Loading…
Cancel
Save