1
0
Fork 0

make it build on windows vc compiler

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@11 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
1.1
Xuefer 2006-05-24 07:52:48 +00:00
parent aab6656cd2
commit da19436031
15 changed files with 337 additions and 119 deletions

View File

@ -7,19 +7,22 @@ XCACHE_INCLUDES_I=$(builddir)/includes.i
XCACHE_STRUCT_OUT=$(builddir)/structinfo.m4
$(XCACHE_INCLUDES_I): $(XCACHE_INCLUDES_SRC) $(srcdir)/xcache.h
$(CC) -I. -I$(srcdir) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) -E $(XCACHE_INCLUDES_SRC) -o $(XCACHE_INCLUDES_I)
$(CC) -I. -I$(srcdir) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) -E $(XCACHE_INCLUDES_SRC) -o $(XCACHE_INCLUDES_I)
$(XCACHE_STRUCT_OUT): $(XCACHE_INCLUDES_I) $(srcdir)/mkstructinfo.awk
$(AWK) -f $(srcdir)/mkstructinfo.awk < $(XCACHE_INCLUDES_I) > $(XCACHE_STRUCT_OUT)
$(XCACHE_PROC_OUT): $(XCACHE_PROC_SRC) $(XCACHE_STRUCT_OUT) $(XCACHE_PROC_SOURCES)
m4 -D srcdir="$(srcdir)/" -D builddir="$(builddir)" $(XCACHE_ENABLE_TEST) -E $(XCACHE_PROC_SRC) > $(XCACHE_PROC_OUT).tmp && mv -f $(XCACHE_PROC_OUT).tmp $(XCACHE_PROC_OUT)
$(M4) -D srcdir="$(srcdir)" -D builddir="$(builddir)" $(XCACHE_ENABLE_TEST) -E $(XCACHE_PROC_SRC) > $(XCACHE_PROC_OUT).tmp
mv -f $(XCACHE_PROC_OUT).tmp $(XCACHE_PROC_OUT)
$(XCACHE_PROC_H): $(XCACHE_PROC_OUT)
grep -F 'export: ' $(XCACHE_PROC_OUT) | sed -r 's/.*export:(.*):export.*/\1/g' | $(XCACHE_INDENT) > $(XCACHE_PROC_H).tmp && mv -f $(XCACHE_PROC_H).tmp $(XCACHE_PROC_H)
$(GREP) -F 'export: ' $(XCACHE_PROC_OUT) | $(SED) -r 's/.*export:(.*):export.*/\1/g' | $(XCACHE_INDENT) > $(XCACHE_PROC_H).tmp
mv -f $(XCACHE_PROC_H).tmp $(XCACHE_PROC_H)
$(XCACHE_PROC_C): $(XCACHE_PROC_OUT) $(XCACHE_PROC_H)
cat $(XCACHE_PROC_OUT) | $(XCACHE_INDENT) > $(XCACHE_PROC_C).tmp && mv -f $(XCACHE_PROC_C).tmp $(XCACHE_PROC_C)
$(XCACHE_INDENT) < $(XCACHE_PROC_OUT) > $(XCACHE_PROC_C).tmp
mv -f $(XCACHE_PROC_C).tmp $(XCACHE_PROC_C)
$(builddir)/processor.lo: $(XCACHE_PROC_C) $(XCACHE_PROC_H) $(srcdir)/processor.c

View File

@ -1,21 +1,19 @@
dnl
dnl $Id:$
dnl vim:ts=2:sw=2:expandtab
AC_DEFUN([XCACHE_OPTION], [
PHP_ARG_ENABLE(xcache-$1, for XCACHE $1,
[ --enable-xcache-$2 XCACHE: $4], no, no)
if test "$PHP_$3" = "yes"; then
PHP_ARG_ENABLE(xcache-$1, for XCache $1,
[ --enable-xcache-$2 XCache: $4], no, no)
if test "$PHP_$3" != "no"; then
xcache_sources="$xcache_sources $1.c"
HAVE_$3=1
AC_DEFINE([HAVE_$3], 1, [Define for XCACHE: $4])
AC_DEFINE([HAVE_$3], 1, [Define for XCache: $4])
else
HAVE_$3=
fi
])dnl
PHP_ARG_ENABLE(xcache, for XCACHE support,
[ --enable-xcache Include XCACHE support.])
PHP_ARG_ENABLE(xcache, for XCache support,
[ --enable-xcache Include XCache support.])
if test "$PHP_XCACHE" != "no"; then
xcache_sources="processor.c \
@ -38,17 +36,22 @@ if test "$PHP_XCACHE" != "no"; then
PHP_NEW_EXTENSION(xcache, $xcache_sources, $ext_shared)
PHP_ADD_MAKEFILE_FRAGMENT()
PHP_ARG_ENABLE(xcache-test, for XCACHE self test,
[ --enable-xcache-test XCACHE: Enable self test - FOR DEVELOPERS ONLY!!], no, no)
if test "$PHP_XCACHE_TEST" = "yes"; then
PHP_ARG_ENABLE(xcache-test, for XCache self test,
[ --enable-xcache-test XCache: Enable self test - FOR DEVELOPERS ONLY!!], no, no)
if test "$PHP_XCACHE_TEST" != "no"; then
XCACHE_ENABLE_TEST=-DXCACHE_ENABLE_TEST
AC_DEFINE([HAVE_XCACHE_TEST], 1, [Define to enable XCACHE self test])
AC_DEFINE([HAVE_XCACHE_TEST], 1, [Define to enable XCache self test])
else
XCACHE_ENABLE_TEST=
fi
PHP_SUBST([XCACHE_ENABLE_TEST])
AC_PATH_PROGS(INDENT, [indent cat])
AC_PATH_PROGS([AWK], [gawk awk])
AC_PATH_PROGS([M4], [m4])
AC_PATH_PROGS([GREP], [grep])
AC_PATH_PROGS([SED], [sed])
AC_PATH_PROGS([INDENT], [indent cat])
case $INDENT in
*/indent[)]
XCACHE_INDENT="$INDENT -kr --use-tabs --tab-size 4 -sob -nce"
@ -63,9 +66,9 @@ if test "$PHP_XCACHE" != "no"; then
XCACHE_PROC_SOURCES=`ls $ac_srcdir/processor/*.m4`
PHP_SUBST([XCACHE_PROC_SOURCES])
AC_MSG_CHECKING(if you have opcode_spec_def.h for xcache)
AC_MSG_CHECKING(if you have opcode_spec_def.h for XCache)
if test -e "$ac_srcdir/opcode_spec_def.h" ; then
AC_DEFINE([HAVE_XCACHE_OPCODE_SPEC_DEF], 1, [Define if you have opcode_spec_def.h for xcache])
AC_DEFINE([HAVE_XCACHE_OPCODE_SPEC_DEF], 1, [Define if you have opcode_spec_def.h for XCache])
AC_MSG_RESULT(yes)
else
dnl check for features depend on opcode_spec_def.h
@ -73,7 +76,7 @@ if test "$PHP_XCACHE" != "no"; then
define([ERROR], [
AC_MSG_ERROR([cannot build with $1, $ac_srcdir/opcode_spec_def.h required])
])
if test "$HAVE_XCACHE_DISASSEMBLER" = "1" ; then
if test "$PHP_XCACHE_DISASSEMBLER" != "no" ; then
ERROR(disassembler)
fi
undefine([ERROR])

131
config.w32 Normal file
View File

@ -0,0 +1,131 @@
// vim:ft=javascript
ARG_ENABLE("xcache", "Include XCache support", "yes,shared");
if (PHP_XCACHE != "no") {
var xcache_sources = "processor.c \
xcache.c \
mmap.c \
mem.c \
const_string.c \
opcode_spec.c \
stack.c \
utils.c \
lock.c \
";
// {{{ add sources on enabled
ARG_ENABLE("xcache-optimizer", "(N/A)", "no");
ARG_ENABLE("xcache-coverage", "Enable code coverage dumper, NOT for production server", "no");
ARG_ENABLE("xcache-assembler", "(N/A)", "no");
ARG_ENABLE("xcache-disassembler", "Enable opcode to php variable dumper, NOT for production server", "no");
ARG_ENABLE("xcache-encoder", "(N/A)", "no");
ARG_ENABLE("xcache-decoder", "(N/A)", "no");
var options = ["optimizer",
"coverage",
"assembler", "disassembler",
"encoder", "decoder"];
for (var i in options) {
var name = options[i];
var uname = name.toUpperCase();
var withval = eval("PHP_XCACHE_" + uname);
if (withval != "no") {
xcache_sources += " " + name + ".c";
STDOUT.WriteLine("Enabling XCache Module: " + name);
AC_DEFINE("HAVE_XCACHE_" + uname, 1, "Define for XCache: " + name)
}
}
// }}}
// {{{ check for programs needed
var apps = ["m4", "grep", "sed"];
for (var i in apps) {
if (!PATH_PROG(apps[i])) {
ERROR(apps[i] + " is currently required to build XCache");
}
}
PATH_PROG("gawk", null, "AWK") || PATH_PROG("awk", null, "AWK");
// the cygwin indent is known broken on our output
var indent = false; // PATH_PROG("indent");
if (indent) {
indent += " -kr --use-tabs --tab-size 4 -sob -nce";
}
else {
indent = PATH_PROG("cat");
if (!indent) {
indent = '';
}
}
DEFINE("XCACHE_INDENT", indent);
// }}}
// {{{ create extension
EXTENSION("xcache", xcache_sources);
var srcdir = configure_module_dirname;
// it's a bit harder to get builddir
var mfofile = "Makefile.objects";
MFO.Close();
var mfo = file_get_contents(mfofile);
mfo.match(/(.*\\xcache)\\xcache.obj/);
var builddir = RegExp.$1;
mfo.match(/(.*\$\(CC\).* )\/c.*\\xcache\\xcache.c.*/i);
var ccrule = RegExp.$1;
MFO = FSO.OpenTextFile(mfofile, 8);
mfo = null;
// }}}
// {{{ add make fragments
var file = srcdir + "\\Makefile.frag";
STDOUT.WriteLine("Adding Makefile.frag: " + file);
var frag = file_get_contents(file);
frag = frag.replace(/\$\(srcdir\)\//g, srcdir + '\\');
frag = frag.replace(/\$\(srcdir\)/g, srcdir);
frag = frag.replace(/\$\(builddir\)\//g, builddir + '\\');
frag = frag.replace(/\$\(builddir\)/g, builddir);
frag = frag.replace(/processor\//g, "processor\\");
frag = frag.replace(/\.lo:/g, ".obj:");
frag = frag.replace(/.*\$\(CC\).* -E (.*) -o (.*)/, ccrule + " /E $1 > $2");
frag = frag.replace(/ -o /g, " /Fo");
frag = frag.replace(/ -E /g, " /E ");
frag = frag.replace(/mv -f /g, "move ");
if (indent == '') {
frag = frag.replace(/\| +\$\(XCACHE_INDENT\)/, '');
frag = frag.replace(/\$\(XCACHE_INDENT\) < /, 'type ');
}
MFO.WriteLine(frag);
ADD_FLAG("CFLAGS_XCACHE", "/I " + builddir);
/// }}}
// {{{ check for xcache-test
ARG_ENABLE("xcache-test", "XCache: Enable self test - FOR DEVELOPERS ONLY!!", "no");
if (PHP_XCACHE_TEST != "no") {
ADD_FLAG("XCACHE_ENABLE_TEST", "-DXCACHE_ENABLE_TEST");
AC_DEFINE("HAVE_XCACHE_TEST", 1, "Define to enable XCache self test");
}
else {
ADD_FLAG("XCACHE_ENABLE_TEST", "");
}
XCACHE_PROC_SOURCES=glob(srcdir + "\\processor\\*.m4").join(' ');
ADD_FLAG("XCACHE_PROC_SOURCES", XCACHE_PROC_SOURCES);
// }}}
// {{{ check for opcode_spec_def.h
STDOUT.Write("Checking if you have opcode_spec_def.h for XCache ... ");
var file = srcdir + "\\opcode_spec_def.h";
if (FSO.FileExists(file)) {
STDOUT.WriteLine("yes");
AC_DEFINE("HAVE_XCACHE_OPCODE_SPEC_DEF", 1, "Define if you have opcode_spec_def.h for XCache");
}
else {
STDOUT.WriteLine("no");
// check for features depend on opcode_spec_def.h
var xcache_require_opcode_spec_def = function(withval, name) {
if (withval != "no") {
ERROR(file + " is required to enable XCache " + name);
}
}
xcache_require_opcode_spec_def(PHP_XCACHE_DISASSEMBLER, "disassembler");
}
// }}}
}

View File

@ -4,6 +4,10 @@
#ifdef HAVE_SYS_FILE_H
# include <sys/file.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "stack.h"
#include "xcache_globals.h"
#include "coverage.h"
@ -304,15 +308,15 @@ static int xc_coverage_init_op_array(zend_op_array *op_array TSRMLS_DC) /* {{{ *
{
zend_uint size;
coverage_t cov;
int i;
zend_uint i;
if (op_array->type != ZEND_USER_FUNCTION) {
return 0;
}
size = xc_coverage_get_op_array_size_no_tail(op_array);
cov = xc_coverage_get(op_array->filename);
for (i = 0; i < size; i++) {
cov = xc_coverage_get(op_array->filename TSRMLS_CC);
for (i = 0; i < size; i ++) {
switch (op_array->opcodes[i].opcode) {
case ZEND_EXT_STMT:
#if 0
@ -350,12 +354,13 @@ static zend_op_array *xc_compile_file_for_coverage(zend_file_handle *h, int type
/* hits */
void xc_coverage_handle_ext_stmt(zend_op_array *op_array, zend_uchar op) /* {{{ */
{
TSRMLS_FETCH();
if (XG(coveragedumper) && XG(coverages)) {
TSRMLS_FETCH();
int size = xc_coverage_get_op_array_size_no_tail(op_array);
int oplineno = (*EG(opline_ptr)) - op_array->opcodes;
if (oplineno < size) {
xc_coverage_add_hits(xc_coverage_get(op_array->filename), (*EG(opline_ptr))->lineno, 1 TSRMLS_CC);
xc_coverage_add_hits(xc_coverage_get(op_array->filename TSRMLS_CC), (*EG(opline_ptr))->lineno, 1 TSRMLS_CC);
}
}
}

34
lock.c
View File

@ -5,6 +5,7 @@
#include <php.h>
#ifndef ZEND_WIN32
typedef int HANDLE;
# define CloseHandle(h) close(h)
#endif
#include "lock.h"
@ -17,6 +18,10 @@ struct _xc_lock_t {
# include <unistd.h>
# include <fcntl.h>
# include <errno.h>
# define LCK_WR F_WRLCK
# define LCK_RD F_RDLCK
# define LCK_UN F_UNLCK
# define LCK_NB 0
static inline int dolock(xc_lock_t *lck, int type) /* {{{ */
{
int ret;
@ -34,10 +39,6 @@ static inline int dolock(xc_lock_t *lck, int type) /* {{{ */
return ret;
}
/* }}} */
#define LCK_WR F_WRLCK
#define LCK_RD F_RDLCK
#define LCK_UN F_UNLCK
#define LCK_NB 0
#else
# include <win32/flock.h>
@ -45,37 +46,40 @@ static inline int dolock(xc_lock_t *lck, int type) /* {{{ */
# include <fcntl.h>
# include <sys/types.h>
# include <sys/stat.h>
# define errno GetLastError()
# ifndef errno
# define errno GetLastError()
# endif
# define getuid() 0
# define LCK_WR LOCKFILE_EXCLUSIVE_LOCK
# define LCK_RD 0
# define LCK_UN 0
# define LCK_NB LOCKFILE_FAIL_IMMEDIATELY
static inline int dolock(xc_lock_t *lck, int type) /* {{{ */
{
static OVERLAPPED offset = {0, 0, 0, 0, NULL};
if (type == LCK_UN) {
return UnlockFileEx((HANDLE)fd, 0, 1, 0, &offset);
return UnlockFileEx((HANDLE)lck->fd, 0, 1, 0, &offset);
}
else {
return LockFileEx((HANDLE)fd, type, 0, 1, 0, &offset);
return LockFileEx((HANDLE)lck->fd, type, 0, 1, 0, &offset);
}
}
/* }}} */
#define LCK_WR LOCKFILE_EXCLUSIVE_LOCK
#define LCK_RD 0
#define LCK_UN 0
#define LCK_NB LOCKFILE_FAIL_IMMEDIATELY
#endif
xc_lock_t *xc_fcntl_init(const char *pathname) /* {{{ */
{
HANDLE fd;
char myname[sizeof("/tmp/.xcache.lock") - 1 + 20];
char myname[sizeof("/tmp/.xcache.lock") - 1 + 100];
if (pathname == NULL) {
static int i = 0;
snprintf(myname, sizeof(myname) - 1, "/tmp/.xcache.%d.%d.lock", (int) getuid(), i ++);
snprintf(myname, sizeof(myname) - 1, "/tmp/.xcache.%d.%d.%d.lock", (int) getuid(), i ++, rand());
pathname = myname;
}
fd = open(pathname, O_RDWR|O_CREAT, 0666);
fd = (HANDLE) open(pathname, O_RDWR|O_CREAT, 0666);
if (fd > 0) {
xc_lock_t *lck = malloc(sizeof(lck[0]));
@ -98,7 +102,7 @@ xc_lock_t *xc_fcntl_init(const char *pathname) /* {{{ */
/* }}} */
void xc_fcntl_destroy(xc_lock_t *lck) /* {{{ */
{
close(lck->fd);
CloseHandle(lck->fd);
#ifdef __CYGWIN__
unlink(lck->pathname);
#endif

100
mmap.c
View File

@ -6,12 +6,27 @@
#include <limits.h>
#include <string.h>
#include <stdlib.h>
/* mmap */
#include <unistd.h>
#ifdef ZEND_WIN32
# define ftruncate chsize
# define getuid() 0
# define XcacheCreateFileMapping(size, perm, name) \
CreateFileMapping(INVALID_HANDLE_VALUE, NULL, perm, (sizeof(xc_shmsize_t) > 4) ? size >> 32 : 0, size & 0xffffffff, name)
# define XCACHE_MAP_FAILED NULL
# define munmap(p, s) UnmapViewOfFile(p)
#else
# include <unistd.h>
# define XCACHE_MAP_FAILED MAP_FAILED
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifndef ZEND_WIN32
#include <sys/mman.h>
#endif
#include "php.h"
#include "myshm.h"
@ -26,10 +41,15 @@ struct _xc_shm_t {
void *ptr_ro;
long diff;
xc_shmsize_t size;
char *name;
#ifdef ZEND_WIN32
HANDLE hmap;
HANDLE hmap_ro;
#endif
};
#undef NDEBUG
#ifdef ALLOC_DEBUG
# undef NDEBUG
# define inline
#else
# define NDEBUG
@ -37,6 +57,8 @@ struct _xc_shm_t {
#include <assert.h>
/* }}} */
#define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0)
#define PTR_ADD(ptr, v) (((char *) (ptr)) + (v))
#define PTR_SUB(ptr, v) (((char *) (ptr)) - (v))
int xc_shm_can_readonly(xc_shm_t *shm) /* {{{ */
{
@ -57,7 +79,7 @@ void *xc_shm_to_readwrite(xc_shm_t *shm, void *p) /* {{{ */
{
if (shm->diff) {
assert(xc_shm_is_readonly(p));
p = p - shm->diff;
p = PTR_SUB(p, -shm->diff);
}
assert(xc_shm_is_readwrite(p));
return p;
@ -67,7 +89,7 @@ void *xc_shm_to_readonly(xc_shm_t *shm, void *p) /* {{{ */
{
assert(xc_shm_is_readwrite(p));
if (shm->diff) {
p = p + shm->diff;
p = PTR_ADD(p, shm->diff);
assert(xc_shm_is_readonly(p));
}
return p;
@ -89,6 +111,21 @@ void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
shm->ptr = NULL;
*/
}
#ifdef ZEND_WIN32
if (shm->hmap) {
CloseHandle(shm->hmap);
}
if (shm->hmap_ro) {
CloseHandle(shm->hmap_ro);
}
#endif
if (shm->name) {
#ifdef __CYGWIN__
unlink(shm->name);
#endif
free(shm->name);
}
/*
shm->size = NULL;
shm->diff = 0;
@ -101,47 +138,59 @@ void xc_shm_destroy(xc_shm_t *shm) /* {{{ */
xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_protection) /* {{{ */
{
xc_shm_t *shm = NULL;
int fd;
int fd = -1;
int ro_ok;
volatile void *romem;
int created = 0;
char tmpname[sizeof("/tmp/xcache") - 1 + 100];
CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM");
shm->size = size;
if (path == NULL || !path[0]) {
path = "/tmp/xcache";
static int inc = 0;
snprintf(tmpname, sizeof(tmpname) - 1, "/tmp/xcache.%d.%d.%d", (int) getuid(), inc ++, rand());
path = tmpname;
}
fd = open(path, O_RDWR, S_IRUSR | S_IWUSR);
shm->name = strdup(path);
#ifndef ZEND_WIN32
# define XCACHE_MMAP_PERMISSION (S_IRUSR | S_IWUSR)
fd = open(shm->name, O_RDWR, XCACHE_MMAP_PERMISSION);
if (fd == -1) {
created = 1;
fd = open(path, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
fd = open(shm->name, O_CREAT | O_RDWR, XCACHE_MMAP_PERMISSION);
if (fd == -1) {
if (created) {
unlink(path);
}
goto err;
}
}
ftruncate(fd, size);
#endif
#ifdef ZEND_WIN32
shm->hmap = XcacheCreateFileMapping(size, PAGE_READWRITE, shm->name);
shm->ptr = (LPSTR) MapViewOfFile(shm->hmap, FILE_MAP_WRITE, 0, 0, 0);
#else
shm->ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (shm->ptr == MAP_FAILED) {
#endif
if (shm->ptr == XCACHE_MAP_FAILED) {
shm->ptr = NULL;
close(fd);
if (created) {
unlink(path);
}
goto err;
}
ro_ok = 0;
if (readonly_protection) {
#ifdef ZEND_WIN32
shm->hmap_ro = XcacheCreateFileMapping(size, PAGE_READONLY, shm->name);
shm->ptr_ro = (LPSTR) MapViewOfFile(shm->hmap_ro, FILE_MAP_READ, 0, 0, 0);
#else
shm->ptr_ro = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
#endif
romem = shm->ptr_ro;
/* {{{ check if ptr_ro works */
do {
if (shm->ptr_ro == MAP_FAILED || shm->ptr_ro == shm->ptr) {
if (shm->ptr_ro == XCACHE_MAP_FAILED || shm->ptr_ro == shm->ptr) {
break;
}
*(char *)shm->ptr = 1;
@ -157,11 +206,11 @@ xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_pr
}
if (ro_ok) {
shm->diff = shm->ptr_ro - shm->ptr;
shm->diff = PTR_SUB(shm->ptr_ro, (char *) shm->ptr);
assert(abs(shm->diff) >= size);
}
else {
if (shm->ptr_ro != MAP_FAILED) {
if (shm->ptr_ro != XCACHE_MAP_FAILED) {
munmap(shm->ptr_ro, size);
}
shm->ptr_ro = NULL;
@ -170,13 +219,16 @@ xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_pr
/* }}} */
close(fd);
if (created) {
unlink(path);
}
#ifndef __CYGWIN__
unlink(shm->name);
#endif
return shm;
err:
if (fd != -1) {
close(fd);
}
if (shm) {
xc_shm_destroy(shm);
}

View File

@ -1,5 +1,5 @@
typedef struct _xc_shm_t xc_shm_t;
typedef unsigned int xc_shmsize_t;
typedef size_t xc_shmsize_t;
int xc_shm_can_readonly(xc_shm_t *shm);
int xc_shm_is_readwrite(xc_shm_t *shm, const void *p);

View File

@ -14,7 +14,6 @@ dnl ============
define(`INDENT', `xc_dprint_indent(indent);')
dnl }}}
dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:forcetype=$2)
dnl don't use typeof(dst) as we need the compiler warning
define(`ALLOC', `
pushdef(`COUNT', `ifelse(`$3', `', `1', `$3')')
pushdef(`SIZE', `sizeof($2)ifelse(`$3', `', `', ` * $3')')

View File

@ -364,15 +364,18 @@ dnl }}}
DEF_STRUCT_P_FUNC(`znode', , `dnl {{{
DISPATCH(int, op_type)
#ifdef IS_CV
# define XCACHE_IS_CV IS_CV
#else
/* compatible with zend optimizer */
# define XCACHE_IS_CV 16
#endif
assert(src->op_type == IS_CONST ||
src->op_type == IS_VAR ||
#ifdef IS_CV
src->op_type == IS_CV ||
#else
src->op_type == 16 || /* zend optimizer */
#endif
src->op_type == XCACHE_IS_CV ||
src->op_type == IS_TMP_VAR ||
src->op_type == IS_UNUSED);
#undef XCACHE_IS_CV
dnl dirty dispatch
DISABLECHECK(`
switch (src->op_type) {
@ -462,6 +465,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
')
do {
dnl RESTORE is done above!
zend_uint ii;
int i;
/* Common elements */
@ -480,7 +484,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
DISPATCH(zend_uint, fn_flags)
/* useless */
COPY(prototype)
STRUCT_ARRAY(num_args, zend_arg_info, arg_info)
STRUCT_ARRAY_I(num_args, zend_arg_info, arg_info)
DISPATCH(zend_uint, num_args)
DISPATCH(zend_uint, required_num_args)
DISPATCH(zend_bool, pass_rest_by_reference)
@ -489,6 +493,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
ALLOC(dst->arg_types, zend_uchar, src->arg_types[0] + 1)
IFCOPY(`memcpy(dst->arg_types, src->arg_types, sizeof(src->arg_types[0]) * (src->arg_types[0]+1));')
IFDASM(`do {
zend_uint ii;
int i;
zval *zv;
ALLOC_INIT_ZVAL(zv);
@ -527,7 +532,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
processor->active_opcodes_dst = dst->opcodes;
processor->active_opcodes_src = src->opcodes;
')')
STRUCT_ARRAY(last, zend_op, opcodes)
STRUCT_ARRAY_I(last, zend_op, opcodes)
popdef(`AFTER_ALLOC')
DISPATCH(zend_uint, last)
IFCOPY(`dst->size = src->last;DONE(size)', `DISPATCH(zend_uint, size)')
@ -545,7 +550,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
DISPATCH(zend_uint, T)
STRUCT_ARRAY(last_brk_cont, zend_brk_cont_element, brk_cont_array)
STRUCT_ARRAY_I(last_brk_cont, zend_brk_cont_element, brk_cont_array)
DISPATCH(zend_uint, last_brk_cont)
DISPATCH(zend_uint, current_brk_cont)
#ifndef ZEND_ENGINE_2

View File

@ -35,12 +35,12 @@ define(`PROC_STRING_N_EX', `
')
')
IFCALC(`xc_calc_string_n(processor, ISTYPE, (void *) $2, `$3' IFASSERT(`, __LINE__'));')
IFSTORE(`$1 = (typeof($1)) xc_store_string_n(processor, ISTYPE, (char *) $2, `$3' IFASSERT(`, __LINE__'));')
IFSTORE(`$1 = (STRTYPE *) xc_store_string_n(processor, ISTYPE, (char *) $2, `$3' IFASSERT(`, __LINE__'));')
IFRESTORE(`
ALLOC(`$1', `typeof($1[0])', `sizeof(STRTYPE) * ($3)')
ALLOC(`$1', `STRTYPE', `sizeof(STRTYPE) * ($3)')
memcpy($1, $2, sizeof(STRTYPE) * ($3));
')
FIXPOINTER_EX(`typeof($1[0])', `$1')
FIXPOINTER_EX(`STRTYPE', `$1')
IFDASM(`
ifelse(STRTYPE,UChar, `
add_assoc_unicodel_ex(dst, ZEND_STRS("$4"), $2, $3-1, 1);

View File

@ -38,10 +38,12 @@ DECL_STRUCT_P_FUNC(`$1', `$2', 1)
/* }}} */
IFRESTORE(`assert(xc_is_shm(src));')
IFCALCSTORE(`assert(!xc_is_shm(src));')
do {
')
ifdef(`USEMEMCPY', `IFCOPY(`
memcpy(dst, src, sizeof($1));
do {
')')
IFDPRINT(`
@ -83,7 +85,11 @@ DECL_STRUCT_P_FUNC(`$1', `$2', 1)
')
/* }}} */
')')
ifdef(`USEMEMCPY', `IFCOPY(`
} while (0);
')')
IFASSERT(`
} while (0);
undefine(`ELEMENTS_DONE')
')
}
@ -143,6 +149,13 @@ define(`STRUCT', `
DONE(`$2')
')
dnl }}}
dnl {{{ STRUCT_ARRAY_I(1:count, 2:type, 3:elm, 4:name=type)
define(`STRUCT_ARRAY_I', `
pushdef(`i', `ii')
STRUCT_ARRAY(`$1', `$2', `$3', `$4')
popdef(`i')
')
dnl }}}
dnl {{{ STRUCT_ARRAY(1:count, 2:type, 3:elm, 4:name=type)
define(`STRUCT_ARRAY', `
if (src->$3) {

View File

@ -50,7 +50,7 @@ int xc_stack_size(S stack)
void xc_stack_reverse(S stack)
{
typeof(stack->cnt) i, j;
int i, j;
void *tmp;
assert(stack != NULL);

View File

@ -233,7 +233,7 @@ static void xc_fix_opcode_ex_znode(int tofix, xc_op_spec_t spec, znode *znode, i
static void xc_fix_opcode_ex(zend_op_array *op_array, int tofix TSRMLS_DC) /* {{{ */
{
zend_op *opline;
int i;
zend_uint i;
opline = op_array->opcodes;
for (i = 0; i < op_array->last; i ++, opline ++) {
@ -281,8 +281,8 @@ void xc_install_function(char *filename, zend_function *func, zend_uchar type, c
/* }}} */
ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, zend_uchar type, void *key, uint len TSRMLS_DC) /* {{{ */
{
ZESW(void *stored_ce_ptr, );
zend_class_entry *cep = CestToCePtr(*cest);
ZESW(void *stored_ce_ptr, );
if (zend_u_hash_add(CG(class_table), type, key, len,
cest, sizeof(xc_cest_t),

View File

@ -26,8 +26,8 @@
#include "const_string.h"
#include "opcode_spec.h"
#undef NDEBUG
#ifdef DEBUG
# undef NDEBUG
# undef inline
# define inline
#else
@ -339,7 +339,7 @@ static void xc_filllist_dmz(xc_cache_t *cache, zval *return_value TSRMLS_DC) /*
for (i = 0, c = cache->hentry->size; i < c; i ++) {
for (e = cache->entries[i]; e; e = e->next) {
xc_fillentry_dmz(e, 0, list);
xc_fillentry_dmz(e, 0, list TSRMLS_CC);
}
}
add_assoc_zval(return_value, "cache_list", list);
@ -347,7 +347,7 @@ static void xc_filllist_dmz(xc_cache_t *cache, zval *return_value TSRMLS_DC) /*
ALLOC_INIT_ZVAL(list);
array_init(list);
for (e = cache->deletes; e; e = e->next) {
xc_fillentry_dmz(e, 1, list);
xc_fillentry_dmz(e, 1, list TSRMLS_CC);
}
add_assoc_zval(return_value, "deleted_list", list);
}
@ -401,13 +401,14 @@ static void xc_entry_gc_real(xc_cache_t **caches, int size TSRMLS_DC) /* {{{ */
time_t t = XG(request_time);
int i;
xc_cache_t *cache;
typeof(cache->deletes) p, *last;
typedef xc_entry_t *xc_delete_t;
xc_delete_t p, *last;
for (i = 0; i < size; i ++) {
cache = caches[i];
ENTER_LOCK(cache) {
if (cache->deletes) {
last = (typeof(last)) &cache->deletes;
last = (xc_delete_t *) &cache->deletes;
for (p = *last; p; p = p->next) {
if (t - p->dtime > 3600) {
p->refcount = 0;
@ -432,7 +433,7 @@ static void xc_entry_gc(TSRMLS_D) /* {{{ */
xc_entry_gc_real(xc_var_caches, xc_var_hcache.size TSRMLS_CC);
}
/* }}} */
static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t **caches, int cachecount) /* {{{ */
static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t **caches, int cachecount TSRMLS_DC) /* {{{ */
{
int i;
xc_stack_t *s;
@ -456,11 +457,11 @@ static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t **caches,
/* }}} */
static void xc_entry_unholds(TSRMLS_D) /* {{{ */
{
xc_entry_unholds_real(XG(php_holds), xc_php_caches, xc_php_hcache.size);
xc_entry_unholds_real(XG(var_holds), xc_var_caches, xc_var_hcache.size);
xc_entry_unholds_real(XG(php_holds), xc_php_caches, xc_php_hcache.size TSRMLS_CC);
xc_entry_unholds_real(XG(var_holds), xc_var_caches, xc_var_hcache.size TSRMLS_CC);
}
/* }}} */
static int xc_stat(const char *filename, const char *include_path, struct stat *pbuf) /* {{{ */
static int xc_stat(const char *filename, const char *include_path, struct stat *pbuf TSRMLS_DC) /* {{{ */
{
char filepath[1024];
char *paths, *path;
@ -471,7 +472,7 @@ static int xc_stat(const char *filename, const char *include_path, struct stat *
paths = (char *)do_alloca(size);
memcpy(paths, include_path, size);
for (path = strtok_r(paths, tokens, &tokbuf); path; path = strtok_r(NULL, tokens, &tokbuf)) {
for (path = php_strtok_r(paths, tokens, &tokbuf); path; path = php_strtok_r(NULL, tokens, &tokbuf)) {
if (strlen(path) + strlen(filename) + 1 > 1024) {
continue;
}
@ -535,7 +536,7 @@ static int xc_entry_init_key_php(xc_entry_t *xce, char *filename TSRMLS_DC) /* {
}
}
else {
if (xc_stat(filename, PG(include_path), pbuf) != 0) {
if (xc_stat(filename, PG(include_path), pbuf TSRMLS_CC) != 0) {
return 0;
}
}
@ -824,18 +825,19 @@ int xc_is_shm(const void *p) /* {{{ */
/* module helper function */
static int xc_init_constant(int module_number TSRMLS_DC) /* {{{ */
{
struct {
typedef struct {
const char *prefix;
int (*getsize)();
const char *(*get)(zend_uchar i);
} nameinfos[] = {
} xc_meminfo_t;
xc_meminfo_t nameinfos[] = {
{ "", xc_get_op_type_count, xc_get_op_type },
{ "", xc_get_data_type_count, xc_get_data_type },
{ "", xc_get_opcode_count, xc_get_opcode },
{ "OPSPEC_", xc_get_op_spec_count, xc_get_op_spec },
{ NULL, NULL, NULL }
};
typeof(nameinfos[0])* p;
xc_meminfo_t* p;
int i;
char const_name[96];
int const_name_len;
@ -860,7 +862,7 @@ static int xc_init_constant(int module_number TSRMLS_DC) /* {{{ */
return 0;
}
/* }}} */
static xc_shm_t *xc_cache_destroy(xc_cache_t **caches, xc_hash_t *hcache TSRMLS_DC) /* {{{ */
static xc_shm_t *xc_cache_destroy(xc_cache_t **caches, xc_hash_t *hcache) /* {{{ */
{
int i;
xc_cache_t *cache;
@ -890,11 +892,12 @@ static xc_shm_t *xc_cache_destroy(xc_cache_t **caches, xc_hash_t *hcache TSRMLS_
return shm;
}
/* }}} */
static xc_cache_t **xc_cache_init(xc_shm_t *shm, char *ptr, xc_hash_t *hcache, xc_hash_t *hentry, xc_shmsize_t shmsize TSRMLS_DC) /* {{{ */
static xc_cache_t **xc_cache_init(xc_shm_t *shm, char *ptr, xc_hash_t *hcache, xc_hash_t *hentry, xc_shmsize_t shmsize) /* {{{ */
{
xc_cache_t **caches = NULL, *cache;
xc_mem_t *mem;
int i;
xc_memsize_t memsize = shmsize / hcache->size;
CHECK(caches = calloc(hcache->size, sizeof(xc_cache_t *)), "caches OOM");
@ -947,10 +950,11 @@ static void xc_destroy() /* {{{ */
/* }}} */
static int xc_init(int module_number TSRMLS_DC) /* {{{ */
{
xc_php_caches = xc_var_caches = NULL;
xc_shm_t *shm;
char *ptr;
xc_php_caches = xc_var_caches = NULL;
if (xc_php_size || xc_var_size) {
CHECK(shm = xc_shm_init(xc_mmap_path, ALIGN(xc_php_size) + ALIGN(xc_var_size), xc_readonly_protection), "Cannot create shm");
if (!xc_shm_can_readonly(shm)) {
@ -1056,24 +1060,21 @@ static void xc_shutdown_globals(zend_xcache_globals* xc_globals TSRMLS_DC) /* {{
}
/* }}} */
#define NEED_INITIZED() do { \
if (!xc_initized) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "XCache is not initized"); \
RETURN_FALSE; \
} \
} while (0)
/* user functions */
/* {{{ xcache_op */
typedef enum { XC_OP_COUNT, XC_OP_INFO, XC_OP_LIST, XC_OP_CLEAR } xcache_op_type;
static void xcache_op(xcache_op_type optype, INTERNAL_FUNCTION_PARAMETERS)
{
NEED_INITIZED();
long type;
int size;
xc_cache_t **caches, *cache;
long id = 0;
if (!xc_initized) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "XCache is not initized");
RETURN_FALSE;
}
if (optype == XC_OP_COUNT) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type) == FAILURE) {
return;
@ -1238,7 +1239,7 @@ PHP_FUNCTION(xcache_get)
break;
}
else {
xc_entry_remove_dmz(stored_xce);
xc_entry_remove_dmz(stored_xce TSRMLS_CC);
}
}
@ -1265,11 +1266,11 @@ PHP_FUNCTION(xcache_set)
ENTER_LOCK(xce.cache) {
stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
if (stored_xce) {
xc_entry_remove_dmz(stored_xce);
xc_entry_remove_dmz(stored_xce TSRMLS_CC);
}
var.value = value;
var.etime = ttl ? XG(request_time) + ttl : TIME_MAX;
RETVAL_BOOL(xc_entry_store_dmz(&xce) != NULL ? 1 : 0);
RETVAL_BOOL(xc_entry_store_dmz(&xce TSRMLS_CC) != NULL ? 1 : 0);
} LEAVE_LOCK(xce.cache);
}
/* }}} */
@ -1296,7 +1297,7 @@ PHP_FUNCTION(xcache_isset)
break;
}
else {
xc_entry_remove_dmz(stored_xce);
xc_entry_remove_dmz(stored_xce TSRMLS_CC);
}
}
@ -1321,7 +1322,7 @@ PHP_FUNCTION(xcache_unset)
ENTER_LOCK(xce.cache) {
stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
if (stored_xce) {
xc_entry_remove_dmz(stored_xce);
xc_entry_remove_dmz(stored_xce TSRMLS_CC);
RETVAL_TRUE;
}
else {
@ -1358,7 +1359,7 @@ static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{
#ifdef DEBUG
fprintf(stderr, "incdec: expired\n");
#endif
xc_entry_remove_dmz(stored_xce);
xc_entry_remove_dmz(stored_xce TSRMLS_CC);
stored_xce = NULL;
}
else {
@ -1398,9 +1399,9 @@ static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{
xce.atime = stored_xce->atime;
xce.ctime = stored_xce->ctime;
xce.hits = stored_xce->hits;
xc_entry_remove_dmz(stored_xce);
xc_entry_remove_dmz(stored_xce TSRMLS_CC);
}
xc_entry_store_dmz(&xce);
xc_entry_store_dmz(&xce TSRMLS_CC);
} LEAVE_LOCK(xce.cache);
}
@ -1491,7 +1492,7 @@ static void xc_call_getter(xc_name_getter_t getter, int count, INTERNAL_FUNCTION
return;
}
if (spec >= 0 && spec < count) {
name = getter(spec);
name = getter((zend_uchar) spec);
if (name) {
/* RETURN_STRING */
int len = strlen(name);
@ -1539,7 +1540,7 @@ PHP_FUNCTION(xcache_get_opcode_spec)
return;
}
if (spec <= xc_get_opcode_spec_count()) {
opspec = xc_get_opcode_spec(spec);
opspec = xc_get_opcode_spec((zend_uchar) spec);
if (opspec) {
array_init(return_value);
add_assoc_long_ex(return_value, ZEND_STRS("ext"), opspec->ext);
@ -1885,6 +1886,8 @@ static PHP_RSHUTDOWN_FUNCTION(xcache)
static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xcache)
#endif
{
TSRMLS_FETCH();
xc_request_shutdown(TSRMLS_C);
return SUCCESS;
}

View File

@ -51,9 +51,9 @@
#define BUCKET_UKEY(b) (UNISW((b)->arKey, (b)->key.u.unicode))
#define BUCKET_KEY_TYPE(b) (UNISW(0, (b)->key.type))
#ifdef IS_UNICODE
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(typeof(b[0]), key)
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key)
#else
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(typeof(b[0]), arKey)
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
#endif
#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
@ -116,11 +116,11 @@ typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRML
/* {{{ xc_cache_t */
typedef struct _xc_entry_t xc_entry_t;
typedef volatile struct {
typedef struct {
int cacheid;
xc_hash_t *hcache; /* hash to cacheid */
zend_bool compiling;
time_t compiling;
zend_ulong misses;
zend_ulong hits;
zend_ulong clogs;