summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkrakjoe <joe.watkins@live.co.uk>2014-09-20 20:22:14 +0100
committerkrakjoe <joe.watkins@live.co.uk>2014-09-20 20:22:14 +0100
commitb3aebda9eaf55706af2e21178f229a171725a168 (patch)
tree9aa1794dc4b513d5c0077adcbeb89fa215f181a4
parent763bfb4f3b0e66d5a961f9f367aa86e9f9da262e (diff)
downloadphp-git-b3aebda9eaf55706af2e21178f229a171725a168.tar.gz
native tls initial patch
-rw-r--r--TSRM/TSRM.c138
-rw-r--r--TSRM/TSRM.h84
-rw-r--r--TSRM/configure.in5
-rw-r--r--TSRM/tsrm.m468
-rw-r--r--TSRM/tsrm_win32.c2
-rw-r--r--Zend/zend.c22
-rw-r--r--Zend/zend_API.c2
-rw-r--r--Zend/zend_API.h6
-rw-r--r--Zend/zend_alloc.c4
-rw-r--r--Zend/zend_builtin_functions.c2
-rw-r--r--Zend/zend_compile.c6
-rw-r--r--Zend/zend_gc.c4
-rw-r--r--Zend/zend_gc.h2
-rw-r--r--Zend/zend_globals.h4
-rw-r--r--Zend/zend_globals_macros.h11
-rw-r--r--Zend/zend_ini_parser.y2
-rw-r--r--Zend/zend_ini_scanner.c2
-rw-r--r--Zend/zend_ini_scanner.l2
-rw-r--r--Zend/zend_language_parser.y2
-rw-r--r--Zend/zend_language_scanner.c2
-rw-r--r--Zend/zend_language_scanner.l2
-rw-r--r--Zend/zend_modules.h3
-rw-r--r--Zend/zend_stack.c5
-rw-r--r--Zend/zend_virtual_cwd.c4
-rw-r--r--Zend/zend_virtual_cwd.h2
-rw-r--r--acinclude.m42
-rw-r--r--configure.in1
-rw-r--r--ext/reflection/php_reflection.c2
-rw-r--r--ext/standard/basic_functions.c8
-rw-r--r--ext/standard/basic_functions.h2
-rw-r--r--ext/standard/browscap.c3
-rw-r--r--ext/standard/dir.c4
-rw-r--r--ext/standard/file.c4
-rw-r--r--ext/standard/file.h2
-rw-r--r--ext/standard/info.c4
-rw-r--r--ext/standard/lcg.c4
-rw-r--r--main/SAPI.c4
-rw-r--r--main/SAPI.h2
-rw-r--r--main/main.c9
-rw-r--r--main/output.c2
-rw-r--r--main/php.h2
-rw-r--r--main/php_globals.h2
-rw-r--r--main/php_output.h1
-rw-r--r--sapi/apache/php_apache.c2
-rw-r--r--sapi/apache2handler/php_apache.h2
-rw-r--r--sapi/apache2handler/php_functions.c4
-rw-r--r--sapi/apache2handler/sapi_apache2.c3
-rw-r--r--sapi/apache_hooks/php_apache.c2
-rw-r--r--sapi/cgi/cgi_main.c12
-rw-r--r--sapi/cli/php_cli.c5
-rw-r--r--sapi/cli/php_cli_server.c9
-rw-r--r--sapi/embed/php_embed.c7
-rw-r--r--sapi/embed/php_embed.h6
53 files changed, 319 insertions, 177 deletions
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c
index efdea5c880..32c28993f8 100644
--- a/TSRM/TSRM.c
+++ b/TSRM/TSRM.c
@@ -23,7 +23,7 @@
typedef struct _tsrm_tls_entry tsrm_tls_entry;
struct _tsrm_tls_entry {
- void **storage;
+ void *storage;
int count;
THREAD_T thread_id;
tsrm_tls_entry *next;
@@ -31,6 +31,7 @@ struct _tsrm_tls_entry {
typedef struct {
+ ts_rsrc_offset offset;
size_t size;
ts_allocate_ctor ctor;
ts_allocate_dtor dtor;
@@ -42,7 +43,7 @@ typedef struct {
static tsrm_tls_entry **tsrm_tls_table=NULL;
static int tsrm_tls_table_size;
static ts_rsrc_id id_count;
-
+static size_t rsrcs_size;
/* The resource sizes table */
static tsrm_resource_type *resource_types_table=NULL;
static int resource_types_table_size;
@@ -61,31 +62,62 @@ int tsrm_error(int level, const char *format, ...);
static int tsrm_error_level;
static FILE *tsrm_error_file;
+#ifdef USE___THREAD
+TSRM_API TSRM_TLS void *tsrm_ls_cache = 0;
+#endif
+
+#ifdef PASS_TSRMLS
+# define CALL_TSRMG_CTOR(ctor, globale, storage) (ctor)((globale), (storage))
+# define CALL_TSRMG_DTOR(ctor, globale, storage) (ctor)((globale), (storage))
+# define CALL_NEW_THREAD_BEGIN_HANDLER(thread_id, storage) tsrm_new_thread_begin_handler((thread_id), (storage))
+# define CALL_NEW_THREAD_END_HANDLER(thread_id, storage) tsrm_new_thread_end_handler((thread_id), (storage))
+#else
+# define CALL_TSRMG_CTOR(ctor, globale, storage) (ctor)((globale))
+# define CALL_TSRMG_DTOR(ctor, globale, storage) (ctor)((globale))
+# define CALL_NEW_THREAD_BEGIN_HANDLER(thread_id, storage) tsrm_new_thread_begin_handler((thread_id))
+# define CALL_NEW_THREAD_END_HANDLER(thread_id, storage) tsrm_new_thread_end_handler((thread_id))
+#endif
+
+#ifndef TSRM_MM_ALIGNMENT
+# define TSRM_MM_ALIGNMENT 8
+#elif TSRM_MM_ALIGNMENT < 4
+# undef TSRM_MM_ALIGNMENT
+# define TSRM_MM_ALIGNMENT 8
+#endif
+
+#define TSRMG_PTR(storage, offset) ((void *)((tsrm_uintptr_t)storage + offset))
+
+#ifdef USE___THREAD
+# define TSRM_RETURN_TSRM_LS(array) array
+#else
+# define TSRM_RETURN_TSRM_LS(array) &array
+#endif
+
#if TSRM_DEBUG
#define TSRM_ERROR(args) tsrm_error args
-#define TSRM_SAFE_RETURN_RSRC(array, offset, range) \
+#define TSRM_SAFE_RETURN_RSRC(array, id, range) \
{ \
- int unshuffled_offset = TSRM_UNSHUFFLE_RSRC_ID(offset); \
+ int unshuffled_id = TSRM_UNSHUFFLE_RSRC_ID(id); \
\
- if (offset==0) { \
- return &array; \
- } else if ((unshuffled_offset)>=0 && (unshuffled_offset)<(range)) { \
+ if (id==0) { \
+ return TSRM_RETURN_TSRM_LS(array); \
+ } else if ((unshuffled_id)>=0 && (unshuffled_id)<(range)) { \
TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Successfully fetched resource id %d for thread id %ld - 0x%0.8X", \
- unshuffled_offset, (long) thread_resources->thread_id, array[unshuffled_offset])); \
- return array[unshuffled_offset]; \
+ unshuffled_id, (long) thread_resources->thread_id, TSRMG_PTR(array, resource_types_table[unshuffled_id].offset))); \
+ return TSRMG_PTR(array, resource_types_table[unshuffled_id].offset); \
} else { \
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Resource id %d is out of range (%d..%d)", \
- unshuffled_offset, TSRM_SHUFFLE_RSRC_ID(0), TSRM_SHUFFLE_RSRC_ID(thread_resources->count-1))); \
+ unshuffled_id, TSRM_SHUFFLE_RSRC_ID(0), TSRM_SHUFFLE_RSRC_ID(thread_resources->count-1))); \
return NULL; \
} \
}
#else
#define TSRM_ERROR(args)
-#define TSRM_SAFE_RETURN_RSRC(array, offset, range) \
- if (offset==0) { \
- return &array; \
- } else { \
- return array[TSRM_UNSHUFFLE_RSRC_ID(offset)]; \
+#define TSRM_SAFE_RETURN_RSRC(array, id, range) \
+ if (id==0) { \
+ return TSRM_RETURN_TSRM_LS(array); \
+ } else { \
+ return TSRMG_PTR(array, resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(id)].offset); \
}
#endif
@@ -175,12 +207,9 @@ TSRM_API void tsrm_shutdown(void)
next_p = p->next;
for (j=0; j<p->count; j++) {
- if (p->storage[j]) {
- if (resource_types_table && !resource_types_table[j].done && resource_types_table[j].dtor) {
- resource_types_table[j].dtor(p->storage[j], &p->storage);
- }
- free(p->storage[j]);
- }
+ if (resource_types_table && !resource_types_table[j].done && resource_types_table[j].dtor) {
+ CALL_TSRMG_CTOR(resource_types_table[j].dtor, TSRMG_PTR(p->storage, resource_types_table[j].offset), &p->storage);
+ }
}
free(p->storage);
free(p);
@@ -212,9 +241,10 @@ TSRM_API void tsrm_shutdown(void)
/* allocates a new thread-safe-resource id */
-TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
+TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, ts_rsrc_offset *rsrc_offset, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
{
int i;
+ ts_rsrc_offset offset = 0;
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new resource id, %d bytes", size));
@@ -235,6 +265,17 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate
}
resource_types_table_size = id_count;
}
+
+ if (TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id) > 0) {
+ offset = resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id-1)].offset
+ +resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id-1)].size;
+ }
+ offset = ((TSRM_MM_ALIGNMENT + offset - 1) & ~(TSRM_MM_ALIGNMENT - 1));
+ if (rsrc_offset) {
+ *rsrc_offset = offset;
+ }
+
+ resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].offset = offset;
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].size = size;
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].ctor = ctor;
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].dtor = dtor;
@@ -248,11 +289,13 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate
if (p->count < id_count) {
int j;
- p->storage = (void *) realloc(p->storage, sizeof(void *)*id_count);
+ p->storage = realloc(p->storage, offset + size);
+#ifdef USE___THREAD
+ tsrm_ls_cache = p->storage;
+#endif
for (j=p->count; j<id_count; j++) {
- p->storage[j] = (void *) malloc(resource_types_table[j].size);
if (resource_types_table[j].ctor) {
- resource_types_table[j].ctor(p->storage[j], &p->storage);
+ CALL_TSRMG_CTOR(resource_types_table[j].ctor, TSRMG_PTR(p->storage, resource_types_table[j].offset), &p->storage);
}
}
p->count = id_count;
@@ -260,9 +303,10 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate
p = p->next;
}
}
+ rsrcs_size = offset + size;
tsrm_mutex_unlock(tsmm_mutex);
- TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
+ TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d, offset %u", *rsrc_id, *rsrc_offset));
return *rsrc_id;
}
@@ -273,7 +317,7 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Creating data structures for thread %x", thread_id));
(*thread_resources_ptr) = (tsrm_tls_entry *) malloc(sizeof(tsrm_tls_entry));
- (*thread_resources_ptr)->storage = (void **) malloc(sizeof(void *)*id_count);
+ (*thread_resources_ptr)->storage = malloc(rsrcs_size);
(*thread_resources_ptr)->count = id_count;
(*thread_resources_ptr)->thread_id = thread_id;
(*thread_resources_ptr)->next = NULL;
@@ -281,23 +325,23 @@ static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_
/* Set thread local storage to this new thread resources structure */
tsrm_tls_set(*thread_resources_ptr);
+#ifdef USE___THREAD
+ tsrm_ls_cache = (*thread_resources_ptr)->storage;
+#endif
+
if (tsrm_new_thread_begin_handler) {
- tsrm_new_thread_begin_handler(thread_id, &((*thread_resources_ptr)->storage));
+ CALL_NEW_THREAD_BEGIN_HANDLER(thread_id, &(*thread_resources_ptr)->storage);
}
for (i=0; i<id_count; i++) {
if (resource_types_table[i].done) {
- (*thread_resources_ptr)->storage[i] = NULL;
- } else
- {
- (*thread_resources_ptr)->storage[i] = (void *) malloc(resource_types_table[i].size);
if (resource_types_table[i].ctor) {
- resource_types_table[i].ctor((*thread_resources_ptr)->storage[i], &(*thread_resources_ptr)->storage);
+ CALL_TSRMG_CTOR(resource_types_table[i].ctor, TSRMG_PTR((*thread_resources_ptr)->storage, resource_types_table[i].offset), &(*thread_resources_ptr)->storage);
}
}
}
if (tsrm_new_thread_end_handler) {
- tsrm_new_thread_end_handler(thread_id, &((*thread_resources_ptr)->storage));
+ CALL_NEW_THREAD_END_HANDLER(thread_id, &(*thread_resources_ptr)->storage);
}
tsrm_mutex_unlock(tsmm_mutex);
@@ -390,12 +434,10 @@ void tsrm_free_interpreter_context(void *context)
for (i=0; i<thread_resources->count; i++) {
if (resource_types_table[i].dtor) {
- resource_types_table[i].dtor(thread_resources->storage[i], &thread_resources->storage);
+ CALL_TSRMG_DTOR(resource_types_table[i].dtor, TSRMG_PTR(thread_resources->storage, resource_types_table[i].offset), &thread_resources->storage);
}
}
- for (i=0; i<thread_resources->count; i++) {
- free(thread_resources->storage[i]);
- }
+
free(thread_resources->storage);
free(thread_resources);
thread_resources = next;
@@ -413,6 +455,10 @@ void *tsrm_set_interpreter_context(void *new_ctx)
/* Set thread local storage to this new thread resources structure */
tsrm_tls_set(new_ctx);
+
+#ifdef USE___THREAD
+ tsrm_ls_cache = ((tsrm_tls_entry*)new_ctx)->storage;
+#endif
/* return old context, so caller can restore it when they're done */
return current;
@@ -455,12 +501,9 @@ void ts_free_thread(void)
if (thread_resources->thread_id == thread_id) {
for (i=0; i<thread_resources->count; i++) {
if (resource_types_table[i].dtor) {
- resource_types_table[i].dtor(thread_resources->storage[i], &thread_resources->storage);
+ CALL_TSRMG_DTOR(resource_types_table[i].dtor, TSRMG_PTR(thread_resources->storage, resource_types_table[i].offset), &thread_resources->storage);
}
}
- for (i=0; i<thread_resources->count; i++) {
- free(thread_resources->storage[i]);
- }
free(thread_resources->storage);
if (last) {
last->next = thread_resources->next;
@@ -497,12 +540,9 @@ void ts_free_worker_threads(void)
if (thread_resources->thread_id != thread_id) {
for (i=0; i<thread_resources->count; i++) {
if (resource_types_table[i].dtor) {
- resource_types_table[i].dtor(thread_resources->storage[i], &thread_resources->storage);
+ CALL_TSRMG_DTOR(resource_types_table[i].dtor, TSRMG_PTR(thread_resources->storage, resource_types_table[i].offset), &thread_resources->storage);
}
}
- for (i=0; i<thread_resources->count; i++) {
- free(thread_resources->storage[i]);
- }
free(thread_resources->storage);
if (last) {
last->next = thread_resources->next;
@@ -541,12 +581,10 @@ void ts_free_id(ts_rsrc_id id)
tsrm_tls_entry *p = tsrm_tls_table[i];
while (p) {
- if (p->count > j && p->storage[j]) {
+ if (p->count > j) {
if (resource_types_table && resource_types_table[j].dtor) {
- resource_types_table[j].dtor(p->storage[j], &p->storage);
+ CALL_TSRMG_DTOR(resource_types_table[j].dtor, TSRMG_PTR(p->storage, resource_types_table[j].offset), &p->storage);
}
- free(p->storage[j]);
- p->storage[j] = NULL;
}
p = p->next;
}
diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h
index b232429d4d..f77dcbf035 100644
--- a/TSRM/TSRM.h
+++ b/TSRM/TSRM.h
@@ -61,6 +61,7 @@ typedef unsigned long tsrm_uintptr_t;
#endif
typedef int ts_rsrc_id;
+typedef tsrm_uintptr_t ts_rsrc_offset;
/* Define THREAD_T and MUTEX_T */
#ifdef TSRM_WIN32
@@ -94,21 +95,78 @@ typedef struct {
#include <signal.h>
#endif
-typedef void (*ts_allocate_ctor)(void *, void ***);
-typedef void (*ts_allocate_dtor)(void *, void ***);
-
#define THREAD_HASH_OF(thr,ts) (unsigned long)thr%(unsigned long)ts
#ifdef __cplusplus
extern "C" {
#endif
+#ifdef USE___THREAD
+
+# ifdef TSRM_WIN32
+# define TSRM_TLS __declspec(thread)
+# else
+# define TSRM_TLS __thread
+# endif
+
+TSRM_API extern TSRM_TLS void *tsrm_ls_cache;
+
+#define TSRMG(id, type, element) \
+ ((type)((tsrm_uintptr_t)tsrm_ls_cache + id##_offset))->element
+
+#define TSRMLS_INIT() tsrm_ls_cache = (void *) ts_resource_ex(0, NULL);
+#define TSRMLS_FETCH()
+#define TSRMLS_FETCH_FROM_CTX(ctx)
+#define TSRMLS_SET_CTX(ctx)
+#define TSRMLS_D void
+#define TSRMLS_DC
+#define TSRMLS_C
+#define TSRMLS_CC
+
+#else /* USE___THREAD */
+
+#define TSRMG(id, type, element) \
+ ((type)(*(tsrm_uintptr_t *)tsrm_ls + id##_offset))->element
+
+#define TSRMLS_INIT() TSRMLS_FETCH()
+#define TSRMLS_FETCH() void **tsrm_ls = (void **) ts_resource_ex(0, NULL);
+
+#define TSRMLS_FETCH_FROM_CTX(ctx) void **tsrm_ls = (void **) ctx
+#define TSRMLS_SET_CTX(ctx) ctx = (void **) tsrm_ls
+#define TSRMLS_D void **tsrm_ls
+#define TSRMLS_DC , TSRMLS_D
+#define TSRMLS_C tsrm_ls
+#define TSRMLS_CC , TSRMLS_C
+#define PASS_TSRMLS 1
+
+#endif /* USE___THREAD */
+
+#define TSRMG_DH(type, id) \
+ TSRM_API extern ts_rsrc_id id; \
+ TSRM_API extern ts_rsrc_offset id##_offset;
+
+#define TSRMG_D(type, id) \
+ TSRM_API ts_rsrc_id id; \
+ TSRM_API ts_rsrc_offset id##_offset;
+
+#define TSRMG_ALLOCATE(id, size, ctor, dtor) \
+ TSRMG_ALLOCATE_EX(id, id##_offset, size, ctor, dtor);
+
+#define TSRMG_ALLOCATE_EX(id, offset, size, ctor, dtor) \
+ ts_allocate_id(&(id), &(offset), (size), (ctor), (dtor));
+
+#define TSRM_SHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)+1)
+#define TSRM_UNSHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)-1)
+
+typedef void (*ts_allocate_ctor)(void * TSRMLS_DC);
+typedef void (*ts_allocate_dtor)(void * TSRMLS_DC);
+
/* startup/shutdown */
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename);
TSRM_API void tsrm_shutdown(void);
/* allocates a new thread-safe-resource id */
-TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor);
+TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, ts_rsrc_offset *rsrc_offset, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor);
/* fetches the requested resource for the current thread */
TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id);
@@ -129,9 +187,8 @@ TSRM_API void ts_free_id(ts_rsrc_id id);
#define TSRM_ERROR_LEVEL_CORE 2
#define TSRM_ERROR_LEVEL_INFO 3
-typedef void (*tsrm_thread_begin_func_t)(THREAD_T thread_id, void ***tsrm_ls);
-typedef void (*tsrm_thread_end_func_t)(THREAD_T thread_id, void ***tsrm_ls);
-
+typedef void (*tsrm_thread_begin_func_t)(THREAD_T thread_id TSRMLS_DC);
+typedef void (*tsrm_thread_end_func_t)(THREAD_T thread_id TSRMLS_DC);
TSRM_API int tsrm_error(int level, const char *format, ...);
TSRM_API void tsrm_error_set(int level, char *debug_filename);
@@ -155,24 +212,13 @@ TSRM_API void *tsrm_new_interpreter_context(void);
TSRM_API void *tsrm_set_interpreter_context(void *new_ctx);
TSRM_API void tsrm_free_interpreter_context(void *context);
-#define TSRM_SHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)+1)
-#define TSRM_UNSHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)-1)
-
-#define TSRMLS_FETCH() void ***tsrm_ls = (void ***) ts_resource_ex(0, NULL)
-#define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx
-#define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_ls
-#define TSRMG(id, type, element) (((type) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
-#define TSRMLS_D void ***tsrm_ls
-#define TSRMLS_DC , TSRMLS_D
-#define TSRMLS_C tsrm_ls
-#define TSRMLS_CC , TSRMLS_C
-
#ifdef __cplusplus
}
#endif
#else /* non ZTS */
+#define TSRMLS_INIT()
#define TSRMLS_FETCH()
#define TSRMLS_FETCH_FROM_CTX(ctx)
#define TSRMLS_SET_CTX(ctx)
diff --git a/TSRM/configure.in b/TSRM/configure.in
index 6f10f5ab13..1c79dafc7f 100644
--- a/TSRM/configure.in
+++ b/TSRM/configure.in
@@ -12,10 +12,11 @@ AH_TOP([
])
sinclude(tsrm.m4)
-
+
TSRM_BASIC_CHECKS
TSRM_THREADS_CHECKS
-
+TSRM___THREAD_CHECKS
+
AM_PROG_LIBTOOL
if test "$enable_debug" != "yes"; then
AM_SET_LIBTOOL_VARIABLE([--silent])
diff --git a/TSRM/tsrm.m4 b/TSRM/tsrm.m4
index b53a4bb805..b9690f5d8f 100644
--- a/TSRM/tsrm.m4
+++ b/TSRM/tsrm.m4
@@ -21,6 +21,72 @@ AC_DEFUN([TSRM_CHECK_GCC_ARG],[
fi
])
+AC_DEFUN([TSRM___THREAD_CHECKS],[
+ AC_ARG_WITH(tsrm-native-tls,
+ [ --with-tsrm-native-tls
+ Use native TLS],[
+ USE___THREAD=yes
+ ],[
+ USE___THREAD=no
+])
+
+if test $USE___THREAD = yes; then
+ AC_CACHE_CHECK([for __thread specifier], ac_cv_tsrm_have___thread, [
+ AC_TRY_RUN([
+ __thread int foo = 42;
+ int main() {
+ return foo - 42;
+ }
+ ],[
+ ac_cv_tsrm_have___thread=yes
+ ],[
+ ac_cv_tsrm_have___thread=no
+ ])
+ ])
+ AC_MSG_CHECKING(wether to use native TLS)
+ if test $ac_cv_tsrm_have___thread = yes; then
+ AC_DEFINE(USE___THREAD, 1, [wether to use native TLS])
+ else
+ AC_MSG_ERROR([__thread specifier not available])
+ fi
+ AC_MSG_RESULT(yes)
+ fi
+])
+
+dnl test and set the memory alignment
+AC_DEFUN([TSRM_MM_ALIGN_CHECK], [
+ AC_CACHE_CHECK([for MM alignment], ac_cv_tsrm_mm_align, [
+ AC_TRY_RUN([
+ #include <stdio.h>
+
+ typedef union _mm_align_test {
+ void *ptr;
+ double dbl;
+ long lng;
+ } mm_align_test;
+
+ #if (defined (__GNUC__) && __GNUC__ >= 2)
+ # define TSRM_MM_ALIGNMENT (__alignof__ (mm_align_test))
+ #else
+ # define TSRM_MM_ALIGNMENT (sizeof(mm_align_test))
+ #endif
+
+ int main()
+ {
+ FILE *fp;
+ fp = fopen("conftest.tsrm", "w");
+ fprintf(fp, "%d\n", TSRM_MM_ALIGNMENT);
+ fclose(fp);
+ return 0;
+ }
+ ],[
+ ac_cv_tsrm_mm_align=`cat conftest.tsrm | cut -d ' ' -f 1`
+ ])
+ ])
+ AC_DEFINE_UNQUOTED(TSRM_MM_ALIGNMENT, $ac_cv_tsrm_mm_align, [ ])
+])
+
+
AC_DEFUN([TSRM_BASIC_CHECKS],[
AC_REQUIRE([AC_PROG_CC])dnl
@@ -29,7 +95,7 @@ AC_REQUIRE([AC_PROG_CC_C_O])dnl
AC_REQUIRE([AC_PROG_RANLIB])dnl
AC_CHECK_HEADERS(stdarg.h)
-
+TSRM_MM_ALIGN_CHECK()
AC_CHECK_FUNCS(sigprocmask)
])
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
index b6ac4231ee..78712e769b 100644
--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -90,7 +90,7 @@ static void tsrm_win32_dtor(tsrm_win32_globals *globals TSRMLS_DC)
TSRM_API void tsrm_win32_startup(void)
{
#ifdef ZTS
- ts_allocate_id(&win32_globals_id, sizeof(tsrm_win32_globals), (ts_allocate_ctor)tsrm_win32_ctor, (ts_allocate_ctor)tsrm_win32_dtor);
+ TSRMG_ALLOCATE(win32_globals_id, sizeof(tsrm_win32_globals), (ts_allocate_ctor)tsrm_win32_ctor, (ts_allocate_dtor)tsrm_win32_dtor);
#else
tsrm_win32_ctor(&win32_globals TSRMLS_CC);
#endif
diff --git a/Zend/zend.c b/Zend/zend.c
index 9e414f9027..1b05d58d30 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -113,8 +113,8 @@ ZEND_INI_END()
#ifdef ZTS
-ZEND_API int compiler_globals_id;
-ZEND_API int executor_globals_id;
+TSRMG_D(zend_compiler_globals, compiler_globals_id);
+TSRMG_D(zend_executor_globals, executor_globals_id);
static HashTable *global_function_table = NULL;
static HashTable *global_class_table = NULL;
static HashTable *global_constants_table = NULL;
@@ -647,8 +647,8 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions TS
#ifdef ZTS
zend_compiler_globals *compiler_globals;
zend_executor_globals *executor_globals;
- extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
- extern ZEND_API ts_rsrc_id language_scanner_globals_id;
+ TSRMG_DH(zend_ini_scanner_globals, ini_scanner_globals_id);
+ TSRMG_DH(zend_php_scanner_globals, language_scanner_globals_id);
#else
extern zend_ini_scanner_globals ini_scanner_globals;
extern zend_php_scanner_globals language_scanner_globals;
@@ -721,10 +721,10 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions TS
zend_init_rsrc_list_dtors();
#ifdef ZTS
- ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
- ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
- ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
- ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
+ TSRMG_ALLOCATE(compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
+ TSRMG_ALLOCATE(executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
+ TSRMG_ALLOCATE(language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
+ TSRMG_ALLOCATE(ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
compiler_globals = ts_resource(compiler_globals_id);
executor_globals = ts_resource(executor_globals_id);
@@ -798,16 +798,16 @@ void zend_post_startup(TSRMLS_D) /* {{{ */
free(compiler_globals->function_table);
free(compiler_globals->class_table);
if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
- compiler_globals_ctor(compiler_globals, tsrm_ls);
+ compiler_globals_ctor(compiler_globals TSRMLS_CC);
compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
} else {
- compiler_globals_ctor(compiler_globals, tsrm_ls);
+ compiler_globals_ctor(compiler_globals TSRMLS_CC);
}
free(EG(zend_constants));
virtual_cwd_deactivate(TSRMLS_C);
- executor_globals_ctor(executor_globals, tsrm_ls);
+ executor_globals_ctor(executor_globals TSRMLS_CC);
global_persistent_list = &EG(persistent_list);
zend_copy_ini_directives(TSRMLS_C);
#else
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 41adbeba8f..bfb2f0e5a1 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -1876,7 +1876,7 @@ ZEND_API int zend_startup_module_ex(zend_module_entry *module TSRMLS_DC) /* {{{
/* Initialize module globals */
if (module->globals_size) {
#ifdef ZTS
- ts_allocate_id(module->globals_id_ptr, module->globals_size, (ts_allocate_ctor) module->globals_ctor, (ts_allocate_dtor) module->globals_dtor);
+ TSRMG_ALLOCATE_EX((*module->globals_id_ptr), (*module->globals_offset), module->globals_size, module->globals_ctor, module->globals_dtor);
#else
if (module->globals_ctor) {
module->globals_ctor(module->globals_ptr TSRMLS_CC);
diff --git a/Zend/zend_API.h b/Zend/zend_API.h
index 657d1d04de..4c920ae9ac 100644
--- a/Zend/zend_API.h
+++ b/Zend/zend_API.h
@@ -145,11 +145,11 @@ typedef struct _zend_fcall_info_cache {
#ifdef ZTS
#define ZEND_DECLARE_MODULE_GLOBALS(module_name) \
- ts_rsrc_id module_name##_globals_id;
+ TSRMG_D(zend_##module_name##_globals, module_name##_globals_id);
#define ZEND_EXTERN_MODULE_GLOBALS(module_name) \
- extern ts_rsrc_id module_name##_globals_id;
+ TSRMG_DH(zend_##module_name##_globals, module_name##_globals_id);
#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor) \
- ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
+ TSRMG_ALLOCATE(module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
#else
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index ac403617a6..57b3b5d281 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -2008,7 +2008,7 @@ typedef struct _zend_alloc_globals {
} zend_alloc_globals;
#ifdef ZTS
-static int alloc_globals_id;
+TSRMG_D(zend_alloc_globals, alloc_globals_id);
# define AG(v) TSRMG(alloc_globals_id, zend_alloc_globals *, v)
#else
# define AG(v) (alloc_globals.v)
@@ -2340,7 +2340,7 @@ static void alloc_globals_dtor(zend_alloc_globals *alloc_globals TSRMLS_DC)
ZEND_API void start_memory_manager(TSRMLS_D)
{
#ifdef ZTS
- ts_allocate_id(&alloc_globals_id, sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, (ts_allocate_dtor) alloc_globals_dtor);
+ TSRMG_ALLOCATE(alloc_globals_id, sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, (ts_allocate_dtor) alloc_globals_dtor);
#else
alloc_globals_ctor(&alloc_globals);
#endif
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 91ab77e6c5..7e10406ecc 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -339,7 +339,7 @@ zend_module_entry zend_builtin_module = { /* {{{ */
NULL,
NULL,
ZEND_VERSION,
- STANDARD_MODULE_PROPERTIES
+ STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index c5337595c5..0b114552cc 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3140,11 +3140,7 @@ static void zend_free_foreach_and_switch_variables(TSRMLS_D) /* {{{ */
opnum_start = get_next_op_number(CG(active_op_array));
-#ifdef ZTS
- zend_stack_apply_with_argument(&CG(loop_var_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element, void *)) generate_free_loop_var TSRMLS_CC);
-#else
- zend_stack_apply(&CG(loop_var_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element)) generate_free_loop_var);
-#endif
+ zend_stack_apply(&CG(loop_var_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element)) generate_free_loop_var);
opnum_end = get_next_op_number(CG(active_op_array));
diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c
index b331f979fd..a848e8eb58 100644
--- a/Zend/zend_gc.c
+++ b/Zend/zend_gc.c
@@ -26,7 +26,7 @@
#define GC_ROOT_BUFFER_MAX_ENTRIES 10001
#ifdef ZTS
-ZEND_API int gc_globals_id;
+TSRMG_D(zend_gc_globals, gc_globals_id);
#else
ZEND_API zend_gc_globals gc_globals;
#endif
@@ -82,7 +82,7 @@ static void gc_globals_ctor_ex(zend_gc_globals *gc_globals TSRMLS_DC)
ZEND_API void gc_globals_ctor(TSRMLS_D)
{
#ifdef ZTS
- ts_allocate_id(&gc_globals_id, sizeof(zend_gc_globals), (ts_allocate_ctor) gc_globals_ctor_ex, (ts_allocate_dtor) root_buffer_dtor);
+ TSRMG_ALLOCATE(gc_globals_id, sizeof(zend_gc_globals), (ts_allocate_ctor) gc_globals_ctor_ex, (ts_allocate_dtor) root_buffer_dtor);
#else
gc_globals_ctor_ex(&gc_globals);
#endif
diff --git a/Zend/zend_gc.h b/Zend/zend_gc.h
index 2eb8ea6ea3..05cde67874 100644
--- a/Zend/zend_gc.h
+++ b/Zend/zend_gc.h
@@ -110,7 +110,7 @@ typedef struct _zend_gc_globals {
#ifdef ZTS
BEGIN_EXTERN_C()
-ZEND_API extern int gc_globals_id;
+TSRMG_DH(zend_gc_globals, gc_globals_id);
END_EXTERN_C()
#define GC_G(v) TSRMG(gc_globals_id, zend_gc_globals *, v)
#else
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index 69e1cf9e68..66376837f2 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -44,8 +44,8 @@
#ifdef ZTS
BEGIN_EXTERN_C()
-ZEND_API extern int compiler_globals_id;
-ZEND_API extern int executor_globals_id;
+TSRMG_DH(zend_compiler_globals, compiler_globals_id);
+TSRMG_DH(zend_executor_globals, executor_globals_id);
END_EXTERN_C()
#endif
diff --git a/Zend/zend_globals_macros.h b/Zend/zend_globals_macros.h
index ac9b793775..67b5b66317 100644
--- a/Zend/zend_globals_macros.h
+++ b/Zend/zend_globals_macros.h
@@ -32,13 +32,16 @@ BEGIN_EXTERN_C()
/* Compiler */
#ifdef ZTS
# define CG(v) TSRMG(compiler_globals_id, zend_compiler_globals *, v)
-int zendparse(void *compiler_globals);
#else
# define CG(v) (compiler_globals.v)
extern ZEND_API struct _zend_compiler_globals compiler_globals;
-int zendparse(void);
#endif
+#ifdef PASS_TSRMLS
+int zendparse(void *compiler_globals);
+#else
+int zend_parse(void);
+#endif
/* Executor */
#ifdef ZTS
@@ -51,7 +54,7 @@ extern ZEND_API zend_executor_globals executor_globals;
/* Language Scanner */
#ifdef ZTS
# define LANG_SCNG(v) TSRMG(language_scanner_globals_id, zend_php_scanner_globals *, v)
-extern ZEND_API ts_rsrc_id language_scanner_globals_id;
+TSRMG_DH(zend_php_scanner_globals, language_scanner_globals_id);
#else
# define LANG_SCNG(v) (language_scanner_globals.v)
extern ZEND_API zend_php_scanner_globals language_scanner_globals;
@@ -61,7 +64,7 @@ extern ZEND_API zend_php_scanner_globals language_scanner_globals;
/* INI Scanner */
#ifdef ZTS
# define INI_SCNG(v) TSRMG(ini_scanner_globals_id, zend_ini_scanner_globals *, v)
-extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
+TSRMG_DH(zend_ini_scanner_globals, ini_scanner_globals_id);
#else
# define INI_SCNG(v) (ini_scanner_globals.v)
extern ZEND_API zend_ini_scanner_globals ini_scanner_globals;
diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y
index e343fcd92a..4a8c03cd02 100644
--- a/Zend/zend_ini_parser.y
+++ b/Zend/zend_ini_parser.y
@@ -32,7 +32,7 @@
#define YYERROR_VERBOSE
#define YYSTYPE zval
-#ifdef ZTS
+#ifdef PASS_TSRMLS
#define YYPARSE_PARAM tsrm_ls
#define YYLEX_PARAM tsrm_ls
int ini_parse(void *arg);
diff --git a/Zend/zend_ini_scanner.c b/Zend/zend_ini_scanner.c
index 2abf1140fc..7b2a0e25ff 100644
--- a/Zend/zend_ini_scanner.c
+++ b/Zend/zend_ini_scanner.c
@@ -103,7 +103,7 @@
/* Globals Macros */
#define SCNG INI_SCNG
#ifdef ZTS
-ZEND_API ts_rsrc_id ini_scanner_globals_id;
+TSRMG_D(zend_ini_scanner_globals, ini_scanner_globals_id);
#else
ZEND_API zend_ini_scanner_globals ini_scanner_globals;
#endif
diff --git a/Zend/zend_ini_scanner.l b/Zend/zend_ini_scanner.l
index 3bfb1557b1..2c4801e00a 100644
--- a/Zend/zend_ini_scanner.l
+++ b/Zend/zend_ini_scanner.l
@@ -101,7 +101,7 @@
/* Globals Macros */
#define SCNG INI_SCNG
#ifdef ZTS
-ZEND_API ts_rsrc_id ini_scanner_globals_id;
+TSRMG_D(zend_ini_scanner_globals, ini_scanner_globals_id);
#else
ZEND_API zend_ini_scanner_globals ini_scanner_globals;
#endif
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 6bfef2219e..407d78be29 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -49,7 +49,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%expect 2
%code requires {
-#ifdef ZTS
+#ifdef PASS_TSRMLS
# define YYPARSE_PARAM tsrm_ls
# define YYLEX_PARAM tsrm_ls
#endif
diff --git a/Zend/zend_language_scanner.c b/Zend/zend_language_scanner.c
index 5bd2798cde..51c585dd66 100644
--- a/Zend/zend_language_scanner.c
+++ b/Zend/zend_language_scanner.c
@@ -90,7 +90,7 @@
/* Globals Macros */
#define SCNG LANG_SCNG
#ifdef ZTS
-ZEND_API ts_rsrc_id language_scanner_globals_id;
+TSRMG_D(zend_php_scanner_globals, language_scanner_globals_id);
#else
ZEND_API zend_php_scanner_globals language_scanner_globals;
#endif
diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l
index bcc341e8a1..4875c37d1b 100644
--- a/Zend/zend_language_scanner.l
+++ b/Zend/zend_language_scanner.l
@@ -88,7 +88,7 @@
/* Globals Macros */
#define SCNG LANG_SCNG
#ifdef ZTS
-ZEND_API ts_rsrc_id language_scanner_globals_id;
+TSRMG_D(zend_php_scanner_globals, language_scanner_globals_id);
#else
ZEND_API zend_php_scanner_globals language_scanner_globals;
#endif
diff --git a/Zend/zend_modules.h b/Zend/zend_modules.h
index 0cd9ca4d16..142e73e7dc 100644
--- a/Zend/zend_modules.h
+++ b/Zend/zend_modules.h
@@ -53,7 +53,7 @@
#define NO_MODULE_GLOBALS 0, NULL, NULL, NULL
#ifdef ZTS
-# define ZEND_MODULE_GLOBALS(module_name) sizeof(zend_##module_name##_globals), &module_name##_globals_id
+# define ZEND_MODULE_GLOBALS(module_name) sizeof(zend_##module_name##_globals), &module_name##_globals_id, &module_name##_globals_id_offset
#else
# define ZEND_MODULE_GLOBALS(module_name) sizeof(zend_##module_name##_globals), &module_name##_globals
#endif
@@ -88,6 +88,7 @@ struct _zend_module_entry {
size_t globals_size;
#ifdef ZTS
ts_rsrc_id* globals_id_ptr;
+ ts_rsrc_offset* globals_offset;
#else
void* globals_ptr;
#endif
diff --git a/Zend/zend_stack.c b/Zend/zend_stack.c
index 03b23427cb..a006a0581b 100644
--- a/Zend/zend_stack.c
+++ b/Zend/zend_stack.c
@@ -124,7 +124,6 @@ ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function
}
}
-
ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
{
int i;
@@ -132,14 +131,14 @@ ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*
switch (type) {
case ZEND_STACK_APPLY_TOPDOWN:
for (i=stack->top-1; i>=0; i--) {
- if (apply_function(ZEND_STACK_ELEMENT(stack, i), arg)) {
+ if (apply_function(ZEND_STACK_ELEMENT(stack, i), arg)) {
break;
}
}
break;
case ZEND_STACK_APPLY_BOTTOMUP:
for (i=0; i<stack->top; i++) {
- if (apply_function(ZEND_STACK_ELEMENT(stack, i), arg)) {
+ if (apply_function(ZEND_STACK_ELEMENT(stack, i), arg)) {
break;
}
}
diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c
index 9f5a74aff6..8941ab924a 100644
--- a/Zend/zend_virtual_cwd.c
+++ b/Zend/zend_virtual_cwd.c
@@ -76,7 +76,7 @@ MUTEX_T cwd_mutex;
#endif
#ifdef ZTS
-ts_rsrc_id cwd_globals_id;
+TSRMG_D(virtual_cwd_globals, cwd_globals_id);
#else
virtual_cwd_globals cwd_globals;
#endif
@@ -475,7 +475,7 @@ CWD_API void virtual_cwd_startup(void) /* {{{ */
main_cwd_state.cwd = strdup(cwd);
#ifdef ZTS
- ts_allocate_id(&cwd_globals_id, sizeof(virtual_cwd_globals), (ts_allocate_ctor) cwd_globals_ctor, (ts_allocate_dtor) cwd_globals_dtor);
+ TSRMG_ALLOCATE(cwd_globals_id, sizeof(virtual_cwd_globals), (ts_allocate_ctor) cwd_globals_ctor, (ts_allocate_dtor) cwd_globals_dtor);
#else
cwd_globals_ctor(&cwd_globals TSRMLS_CC);
#endif
diff --git a/Zend/zend_virtual_cwd.h b/Zend/zend_virtual_cwd.h
index f40a2deb7e..5878a5506b 100644
--- a/Zend/zend_virtual_cwd.h
+++ b/Zend/zend_virtual_cwd.h
@@ -236,7 +236,7 @@ typedef struct _virtual_cwd_globals {
} virtual_cwd_globals;
#ifdef ZTS
-extern ts_rsrc_id cwd_globals_id;
+TSRMG_DH(virtual_cwd_globals, cwd_globals_id);
# define CWDG(v) TSRMG(cwd_globals_id, virtual_cwd_globals *, v)
#else
extern virtual_cwd_globals cwd_globals;
diff --git a/acinclude.m4 b/acinclude.m4
index 81dc0db34a..ef1063c07f 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -2736,7 +2736,7 @@ AC_DEFUN([PHP_CHECK_CONFIGURE_OPTIONS],[
enable-libtool-lock | with-pic | with-tags | enable-shared | enable-static | enable-fast-install | with-gnu-ld[)];;
# Allow certain TSRM options
- with-tsrm-pth | with-tsrm-st | with-tsrm-pthreads[)];;
+ with-tsrm-pth | with-tsrm-st | with-tsrm-pthreads | --with-tsrm-native-tls [)];;
# Allow certain Zend options
with-zend-vm | enable-maintainer-zts | enable-inline-optimization[)];;
diff --git a/configure.in b/configure.in
index 616fc502a4..2f7f837811 100644
--- a/configure.in
+++ b/configure.in
@@ -1156,6 +1156,7 @@ PHP_CONFIGURE_PART(Configuring TSRM)
TSRM_BASIC_CHECKS
if test "$PHP_THREAD_SAFETY" = "yes"; then
TSRM_THREADS_CHECKS
+ TSRM___THREAD_CHECKS
fi
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LDFLAGS"
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index c99f066834..2d1157ee15 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -6182,7 +6182,7 @@ zend_module_entry reflection_module_entry = { /* {{{ */
NULL,
PHP_MINFO(reflection),
"$Id$",
- STANDARD_MODULE_PROPERTIES
+ STANDARD_MODULE_PROPERTIES_EX
}; /* }}} */
/*
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 36611b812b..6c652cdd38 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -108,7 +108,7 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
#include "php_ticks.h"
#ifdef ZTS
-PHPAPI int basic_globals_id;
+TSRMG_D(php_basic_globals, basic_globals_id);
#else
PHPAPI php_basic_globals basic_globals;
#endif
@@ -3375,7 +3375,7 @@ zend_module_entry basic_functions_module = { /* {{{ */
PHP_RSHUTDOWN(basic), /* request shutdown */
PHP_MINFO(basic), /* extension info */
PHP_VERSION, /* extension version */
- STANDARD_MODULE_PROPERTIES
+ STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
@@ -3530,9 +3530,9 @@ PHPAPI double php_get_inf(void) /* {{{ */
PHP_MINIT_FUNCTION(basic) /* {{{ */
{
#ifdef ZTS
- ts_allocate_id(&basic_globals_id, sizeof(php_basic_globals), (ts_allocate_ctor) basic_globals_ctor, (ts_allocate_dtor) basic_globals_dtor);
+ TSRMG_ALLOCATE(basic_globals_id, sizeof(php_basic_globals), (ts_allocate_ctor) basic_globals_ctor, (ts_allocate_dtor) basic_globals_dtor);
#ifdef PHP_WIN32
- ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor)php_win32_core_globals_ctor, (ts_allocate_dtor)php_win32_core_globals_dtor );
+ TSRMG_ALLOCATE(php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor)php_win32_core_globals_ctor, (ts_allocate_dtor)php_win32_core_globals_dtor);
#endif
#else
basic_globals_ctor(&basic_globals TSRMLS_CC);
diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h
index 1b0325caa8..9490754b23 100644
--- a/ext/standard/basic_functions.h
+++ b/ext/standard/basic_functions.h
@@ -232,7 +232,7 @@ typedef struct _php_basic_globals {
#ifdef ZTS
#define BG(v) TSRMG(basic_globals_id, php_basic_globals *, v)
-PHPAPI extern int basic_globals_id;
+TSRMG_DH(php_basic_globals, basic_globals_id);
#else
#define BG(v) (basic_globals.v)
PHPAPI extern php_basic_globals basic_globals;
diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c
index 9c54aa4897..a9c9c8bd1b 100644
--- a/ext/standard/browscap.c
+++ b/ext/standard/browscap.c
@@ -311,8 +311,7 @@ PHP_MINIT_FUNCTION(browscap) /* {{{ */
char *browscap = INI_STR("browscap");
#ifdef ZTS
- ts_allocate_id(&browscap_globals_id, sizeof(browser_data),
- browscap_globals_ctor, NULL);
+ TSRMG_ALLOCATE(browscap_globals_id, sizeof(browser_data), (ts_allocate_ctor) browscap_globals_ctor, NULL);
#endif
/* ctor call not really needed for non-ZTS */
diff --git a/ext/standard/dir.c b/ext/standard/dir.c
index 7b4ab1cd3e..6d62a5f9ef 100644
--- a/ext/standard/dir.c
+++ b/ext/standard/dir.c
@@ -57,7 +57,7 @@ typedef struct {
#ifdef ZTS
#define DIRG(v) TSRMG(dir_globals_id, php_dir_globals *, v)
-int dir_globals_id;
+TSRMG_D(php_dir_globals, dir_globals_id);
#else
#define DIRG(v) (dir_globals.v)
php_dir_globals dir_globals;
@@ -137,7 +137,7 @@ PHP_MINIT_FUNCTION(dir)
dir_class_entry_ptr = zend_register_internal_class(&dir_class_entry TSRMLS_CC);
#ifdef ZTS
- ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL);
+ TSRMG_ALLOCATE(dir_globals_id, sizeof(php_dir_globals), NULL, NULL);
#endif
dirsep_str[0] = DEFAULT_SLASH;
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 66b0f0f5ff..74ec941803 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -106,7 +106,7 @@ extern int fclose(FILE *);
#include "zend_API.h"
#ifdef ZTS
-int file_globals_id;
+TSRMG_D(php_file_globals, file_globals_id);
#else
php_file_globals file_globals;
#endif
@@ -181,7 +181,7 @@ PHP_MINIT_FUNCTION(file)
le_stream_context = zend_register_list_destructors_ex(file_context_dtor, NULL, "stream-context", module_number);
#ifdef ZTS
- ts_allocate_id(&file_globals_id, sizeof(php_file_globals), (ts_allocate_ctor) file_globals_ctor, (ts_allocate_dtor) file_globals_dtor);
+ TSRMG_ALLOCATE(file_globals_id, sizeof(php_file_globals), (ts_allocate_ctor) file_globals_ctor, (ts_allocate_dtor) file_globals_dtor);
#else
file_globals_ctor(&file_globals TSRMLS_CC);
#endif
diff --git a/ext/standard/file.h b/ext/standard/file.h
index fdace75d3b..1b9c90478d 100644
--- a/ext/standard/file.h
+++ b/ext/standard/file.h
@@ -131,7 +131,7 @@ typedef struct {
#ifdef ZTS
#define FG(v) TSRMG(file_globals_id, php_file_globals *, v)
-extern PHPAPI int file_globals_id;
+TSRMG_DH(php_file_globals, file_globals_id);
#else
#define FG(v) (file_globals.v)
extern PHPAPI php_file_globals file_globals;
diff --git a/ext/standard/info.c b/ext/standard/info.c
index bc0ddddcc0..932a8f4226 100644
--- a/ext/standard/info.c
+++ b/ext/standard/info.c
@@ -778,7 +778,11 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
#endif
#ifdef ZTS
+# ifdef USE___THREAD
+ php_info_print_table_row(2, "Thread Safety", "enabled, native TLS" );
+# else
php_info_print_table_row(2, "Thread Safety", "enabled" );
+# endif
#else
php_info_print_table_row(2, "Thread Safety", "disabled" );
#endif
diff --git a/ext/standard/lcg.c b/ext/standard/lcg.c
index 8bfa05555b..4cb4064927 100644
--- a/ext/standard/lcg.c
+++ b/ext/standard/lcg.c
@@ -32,7 +32,7 @@
#endif
#ifdef ZTS
-int lcg_globals_id;
+TSRMG_D(php_lcg_globals, lcg_globals_id);
#else
static php_lcg_globals lcg_globals;
#endif
@@ -106,7 +106,7 @@ static void lcg_init_globals(php_lcg_globals *lcg_globals_p TSRMLS_DC) /* {{{ */
PHP_MINIT_FUNCTION(lcg) /* {{{ */
{
#ifdef ZTS
- ts_allocate_id(&lcg_globals_id, sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL);
+ TSRMG_ALLOCATE(lcg_globals_id, sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL);
#else
lcg_init_globals(&lcg_globals);
#endif
diff --git a/main/SAPI.c b/main/SAPI.c
index 50ea8c0a16..f00e3c728b 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -52,7 +52,7 @@
#include "php_content_types.h"
#ifdef ZTS
-SAPI_API int sapi_globals_id;
+TSRMG_D(sapi_globals_struct, sapi_globals_id);
#else
sapi_globals_struct sapi_globals;
#endif
@@ -88,7 +88,7 @@ SAPI_API void sapi_startup(sapi_module_struct *sf)
sapi_module = *sf;
#ifdef ZTS
- ts_allocate_id(&sapi_globals_id, sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, (ts_allocate_dtor) sapi_globals_dtor);
+ TSRMG_ALLOCATE(sapi_globals_id, sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, (ts_allocate_dtor) sapi_globals_dtor);
# ifdef PHP_WIN32
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
# endif
diff --git a/main/SAPI.h b/main/SAPI.h
index 79661371d9..4e2b4cd420 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -143,7 +143,7 @@ typedef struct _sapi_globals_struct {
BEGIN_EXTERN_C()
#ifdef ZTS
# define SG(v) TSRMG(sapi_globals_id, sapi_globals_struct *, v)
-SAPI_API extern int sapi_globals_id;
+TSRMG_DH(sapi_globals_struct, sapi_globals_id);
#else
# define SG(v) (sapi_globals.v)
extern SAPI_API sapi_globals_struct sapi_globals;
diff --git a/main/main.c b/main/main.c
index 63144de418..2a78d4b0d2 100644
--- a/main/main.c
+++ b/main/main.c
@@ -124,7 +124,7 @@ PHPAPI int (*php_register_internal_extensions_func)(TSRMLS_D) = php_register_int
#ifndef ZTS
php_core_globals core_globals;
#else
-PHPAPI int core_globals_id;
+TSRMG_D(php_core_globals, core_globals_id);
#endif
#ifdef PHP_WIN32
@@ -2048,7 +2048,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
zend_module_entry *module;
#ifdef ZTS
zend_executor_globals *executor_globals;
- void ***tsrm_ls;
php_core_globals *core_globals;
#endif
@@ -2073,7 +2072,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
#endif
#ifdef ZTS
- tsrm_ls = ts_resource(0);
+ TSRMLS_INIT();
#endif
#ifdef PHP_WIN32
@@ -2112,10 +2111,10 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
#ifdef ZTS
executor_globals = ts_resource(executor_globals_id);
- ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
+ TSRMG_ALLOCATE(core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
core_globals = ts_resource(core_globals_id);
#ifdef PHP_WIN32
- ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
+ TSRMG_ALLOCATE(php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
#endif
#else
php_startup_ticks(TSRMLS_C);
diff --git a/main/output.c b/main/output.c
index f44ae178b4..65c8152bc0 100644
--- a/main/output.c
+++ b/main/output.c
@@ -160,7 +160,7 @@ PHPAPI void php_output_shutdown(void)
PHPAPI int php_output_activate(TSRMLS_D)
{
#ifdef ZTS
- memset((*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(output_globals_id)], 0, sizeof(zend_output_globals));
+ //memset((*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(output_globals_id)], 0, sizeof(zend_output_globals));
#else
memset(&output_globals, 0, sizeof(zend_output_globals));
#endif
diff --git a/main/php.h b/main/php.h
index 2a683e1924..224a65dd82 100644
--- a/main/php.h
+++ b/main/php.h
@@ -301,7 +301,7 @@ static inline ZEND_ATTRIBUTE_DEPRECATED void php_std_error_handling() {}
PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC) PHP_ATTRIBUTE_FORMAT(printf, 4, 0);
-#ifdef ZTS
+#ifdef PASS_TSRMLS
#define PHP_ATTR_FMT_OFFSET 1
#else
#define PHP_ATTR_FMT_OFFSET 0
diff --git a/main/php_globals.h b/main/php_globals.h
index a60efe69de..0e088d20f0 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -27,7 +27,7 @@ typedef struct _php_core_globals php_core_globals;
#ifdef ZTS
# define PG(v) TSRMG(core_globals_id, php_core_globals *, v)
-extern PHPAPI int core_globals_id;
+TSRMG_DH(php_core_globals, core_globals_id);
#else
# define PG(v) (core_globals.v)
extern ZEND_API struct _php_core_globals core_globals;
diff --git a/main/php_output.h b/main/php_output.h
index 02b2b85d13..d3c3e072d0 100644
--- a/main/php_output.h
+++ b/main/php_output.h
@@ -153,6 +153,7 @@ ZEND_END_MODULE_GLOBALS(output)
/* there should not be a need to use OG() from outside of output.c */
#ifdef ZTS
+TSRMG_DH(php_output_globals, output_globals_id);
# define OG(v) TSRMG(output_globals_id, zend_output_globals *, v)
#else
# define OG(v) (output_globals.v)
diff --git a/sapi/apache/php_apache.c b/sapi/apache/php_apache.c
index f6e9e61203..05bf75b226 100644
--- a/sapi/apache/php_apache.c
+++ b/sapi/apache/php_apache.c
@@ -129,7 +129,7 @@ static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRML
static PHP_MINIT_FUNCTION(apache)
{
#ifdef ZTS
- ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
+ TSRMG_ALLOCATE(php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
#else
php_apache_globals_ctor(&php_apache_info TSRMLS_CC);
#endif
diff --git a/sapi/apache2handler/php_apache.h b/sapi/apache2handler/php_apache.h
index f6f4f7a7c9..674eb9fbc6 100644
--- a/sapi/apache2handler/php_apache.h
+++ b/sapi/apache2handler/php_apache.h
@@ -78,7 +78,7 @@ typedef struct {
extern zend_module_entry apache2_module_entry;
#ifdef ZTS
-extern int php_apache2_info_id;
+TSRMG_DH(php_apache2_info_struct, php_apache2_info_id);
#define AP2(v) TSRMG(php_apache2_info_id, php_apache2_info_struct *, v)
#else
extern php_apache2_info_struct php_apache2_info;
diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c
index 27643b8917..c79af0e3db 100644
--- a/sapi/apache2handler/php_functions.c
+++ b/sapi/apache2handler/php_functions.c
@@ -49,7 +49,7 @@
#include "php_apache.h"
#ifdef ZTS
-int php_apache2_info_id;
+TSRMG_D(php_apache2_info_struct, php_apache2_info_id);
#else
php_apache2_info_struct php_apache2_info;
#endif
@@ -536,7 +536,7 @@ PHP_INI_END()
static PHP_MINIT_FUNCTION(apache)
{
#ifdef ZTS
- ts_allocate_id(&php_apache2_info_id, sizeof(php_apache2_info_struct), (ts_allocate_ctor) NULL, NULL);
+ TSRMG_ALLOCATE(php_apache2_info_id, sizeof(php_apache2_info_struct), NULL, NULL);
#endif
REGISTER_INI_ENTRIES();
return SUCCESS;
diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c
index 08e6caff3c..f993b478bc 100644
--- a/sapi/apache2handler/sapi_apache2.c
+++ b/sapi/apache2handler/sapi_apache2.c
@@ -451,6 +451,7 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp
}
#ifdef ZTS
tsrm_startup(1, 1, 0, NULL);
+ TSRMLS_INIT();
#endif
sapi_startup(&apache2_sapi_module);
apache2_sapi_module.startup(&apache2_sapi_module);
@@ -540,7 +541,7 @@ static int php_handler(request_rec *r)
apr_bucket *bucket;
apr_status_t rv;
request_rec * volatile parent_req = NULL;
- TSRMLS_FETCH();
+ TSRMLS_INIT();
#define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req TSRMLS_CC);
diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c
index e5bd3f5d61..771ebf821c 100644
--- a/sapi/apache_hooks/php_apache.c
+++ b/sapi/apache_hooks/php_apache.c
@@ -1392,7 +1392,7 @@ static PHP_MINIT_FUNCTION(apache)
zend_class_entry ce;
#ifdef ZTS
- ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
+ TSRMG_ALLOCATE(php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
#else
php_apache_globals_ctor(&php_apache_info TSRMLS_CC);
#endif
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index dead1c3213..4c7ffceab0 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -197,7 +197,7 @@ static void user_config_cache_entry_dtor(zval *el)
/* }}} */
#ifdef ZTS
-static int php_cgi_globals_id;
+TSRMG_D(php_cgi_globals_struct, php_cgi_globals_id);
#define CGIG(v) TSRMG(php_cgi_globals_id, php_cgi_globals_struct *, v)
#else
static php_cgi_globals_struct php_cgi_globals;
@@ -1486,7 +1486,7 @@ static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_
static PHP_MINIT_FUNCTION(cgi)
{
#ifdef ZTS
- ts_allocate_id(&php_cgi_globals_id, sizeof(php_cgi_globals_struct), (ts_allocate_ctor) php_cgi_globals_ctor, NULL);
+ TSRMG_ALLOCATE(php_cgi_globals_id, sizeof(php_cgi_globals_struct), (ts_allocate_ctor) php_cgi_globals_ctor, NULL);
#else
php_cgi_globals_ctor(&php_cgi_globals TSRMLS_CC);
#endif
@@ -1719,7 +1719,7 @@ static zend_module_entry cgi_module_entry = {
NULL,
PHP_MINFO(cgi),
NO_VERSION_YET,
- STANDARD_MODULE_PROPERTIES
+ STANDARD_MODULE_PROPERTIES_EX
};
/* {{{ main
@@ -1741,10 +1741,6 @@ int main(int argc, char *argv[])
int ini_entries_len = 0;
/* end of temporary locals */
-#ifdef ZTS
- void ***tsrm_ls;
-#endif
-
int max_requests = 500;
int requests = 0;
int fastcgi;
@@ -1789,7 +1785,7 @@ int main(int argc, char *argv[])
#ifdef ZTS
tsrm_startup(1, 1, 0, NULL);
- tsrm_ls = ts_resource(0);
+ TSRMLS_INIT();
#endif
sapi_startup(&cgi_sapi_module);
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 04cbdeb8f1..8c9792162b 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -1177,9 +1177,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
int main(int argc, char *argv[])
#endif
{
-#ifdef ZTS
- void ***tsrm_ls;
-#endif
#ifdef PHP_CLI_WIN32_NO_CONSOLE
int argc = __argc;
char **argv = __argv;
@@ -1235,7 +1232,7 @@ int main(int argc, char *argv[])
#ifdef ZTS
tsrm_startup(1, 1, 0, NULL);
- tsrm_ls = ts_resource(0);
+ TSRMLS_INIT();
#endif
#ifdef PHP_WIN32
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index b2defe0841..869c868edb 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -515,7 +515,7 @@ zend_module_entry cli_server_module_entry = {
NULL,
PHP_MINFO(cli_server),
PHP_VERSION,
- STANDARD_MODULE_PROPERTIES
+ STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
@@ -1188,7 +1188,7 @@ static void php_cli_server_logf(const char *format TSRMLS_DC, ...) /* {{{ */
{
char *buf = NULL;
va_list ap;
-#ifdef ZTS
+#ifdef PASS_TSRMLS
va_start(ap, tsrm_ls);
#else
va_start(ap, format);
@@ -2364,9 +2364,6 @@ typedef struct php_cli_server_do_event_for_each_fd_callback_params {
static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socket_t fd, int event) /* {{{ */
{
php_cli_server_do_event_for_each_fd_callback_params *params = _params;
-#ifdef ZTS
- void ***tsrm_ls = params->tsrm_ls;
-#endif
php_cli_server *server = params->server;
if (server->server_sock == fd) {
php_cli_server_client *client = NULL;
@@ -2418,7 +2415,7 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socke
static void php_cli_server_do_event_for_each_fd(php_cli_server *server, int(*rhandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC), int(*whandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC) TSRMLS_DC) /* {{{ */
{
php_cli_server_do_event_for_each_fd_callback_params params = {
-#ifdef ZTS
+#ifdef PASS_TSRMLS
tsrm_ls,
#endif
server,
diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c
index e0df666108..1884604b77 100644
--- a/sapi/embed/php_embed.c
+++ b/sapi/embed/php_embed.c
@@ -155,9 +155,6 @@ static const zend_function_entry additional_functions[] = {
EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC)
{
zend_llist global_vars;
-#ifdef ZTS
- void ***tsrm_ls = NULL;
-#endif
#ifdef HAVE_SIGNAL_H
#if defined(SIGPIPE) && defined(SIG_IGN)
@@ -172,8 +169,8 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC)
#ifdef ZTS
tsrm_startup(1, 1, 0, NULL);
- tsrm_ls = ts_resource(0);
- *ptsrm_ls = tsrm_ls;
+ TSRMLS_INIT();
+ *ptsrm_ls = ts_resource_ex(0, NULL);
#endif
sapi_startup(&php_embed_module);
diff --git a/sapi/embed/php_embed.h b/sapi/embed/php_embed.h
index b62fd9fe24..a109a1bba2 100644
--- a/sapi/embed/php_embed.h
+++ b/sapi/embed/php_embed.h
@@ -27,14 +27,14 @@
#include <main/php_ini.h>
#include <zend_ini.h>
-#ifdef ZTS
-#define PTSRMLS_D void ****ptsrm_ls
+#ifdef PASS_TSRMLS
+#define PTSRMLS_D void ***ptsrm_ls
#define PTSRMLS_DC , PTSRMLS_D
#define PTSRMLS_C &tsrm_ls
#define PTSRMLS_CC , PTSRMLS_C
#define PHP_EMBED_START_BLOCK(x,y) { \
- void ***tsrm_ls; \
+ void **tsrm_ls; \
php_embed_init(x, y PTSRMLS_CC); \
zend_first_try {