From b3aebda9eaf55706af2e21178f229a171725a168 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 20 Sep 2014 20:22:14 +0100 Subject: native tls initial patch --- sapi/embed/php_embed.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'sapi/embed/php_embed.c') 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); -- cgit v1.2.1 From d11734b4b00f57de80d931ad1c522e00082443af Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 25 Sep 2014 18:48:27 +0200 Subject: reworked the patch, less new stuff but worky TLS is already used in TSRM, the way exporting the tsrm cache through a thread local variable is not portable. Additionally, the current patch suffers from bugs which are hard to find, but prevent it to be worky with apache. What is done here is mainly uses the idea from the RFC patch, but - __thread variable is removed - offset math and declarations are removed - extra macros and definitions are removed What is done merely is - use an inline function to access the tsrm cache. The function uses the portable tsrm_tls_get macro which is cheap - all the TSRM_* macros are set to placebo. Thus this opens the way remove them later Except that, the logic is old. TSRMLS_FETCH will have to be done once per thread, then tsrm_get_ls_cache() can be used. Things seeming to be worky are cli, cli server and apache. I also tried to enable bz2 shared and it has worked out of the box. The change is yet minimal diffing to the current master bus is a worky start, IMHO. Though will have to recheck the other previously done SAPIs - embed and cgi. The offsets can be added to the tsrm_resource_type struct, then it'll not be needed to declare them in the userspace. Even the "done" member type can be changed to int16 or smaller, then adding the offset as int16 will not change the struct size. As well on the todo might be removing the hashed storage, thread_id != thread_id and linked list logic in favour of the explicit TLS operations. --- sapi/embed/php_embed.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'sapi/embed/php_embed.c') diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c index 1884604b77..e0df666108 100644 --- a/sapi/embed/php_embed.c +++ b/sapi/embed/php_embed.c @@ -155,6 +155,9 @@ 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) @@ -169,8 +172,8 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC) #ifdef ZTS tsrm_startup(1, 1, 0, NULL); - TSRMLS_INIT(); - *ptsrm_ls = ts_resource_ex(0, NULL); + tsrm_ls = ts_resource(0); + *ptsrm_ls = tsrm_ls; #endif sapi_startup(&php_embed_module); -- cgit v1.2.1 From bdeb220f48825642f84cdbf3ff23a30613c92e86 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 13 Dec 2014 23:06:14 +0100 Subject: first shot remove TSRMLS_* things --- sapi/embed/php_embed.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'sapi/embed/php_embed.c') diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c index 8bfaf9f52d..d326251876 100644 --- a/sapi/embed/php_embed.c +++ b/sapi/embed/php_embed.c @@ -33,12 +33,12 @@ const char HARDCODED_INI[] = "max_execution_time=0\n" "max_input_time=-1\n\0"; -static char* php_embed_read_cookies(TSRMLS_D) +static char* php_embed_read_cookies(void) { return NULL; } -static int php_embed_deactivate(TSRMLS_D) +static int php_embed_deactivate(void) { fflush(stdout); return SUCCESS; @@ -61,7 +61,7 @@ static inline size_t php_embed_single_write(const char *str, size_t str_length) } -static size_t php_embed_ub_write(const char *str, size_t str_length TSRMLS_DC) +static size_t php_embed_ub_write(const char *str, size_t str_length) { const char *ptr = str; size_t remaining = str_length; @@ -79,25 +79,25 @@ static size_t php_embed_ub_write(const char *str, size_t str_length TSRMLS_DC) return str_length; } -static void php_embed_flush(void *server_context TSRMLS_DC) +static void php_embed_flush(void *server_context) { if (fflush(stdout)==EOF) { php_handle_aborted_connection(); } } -static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) +static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context) { } -static void php_embed_log_message(char *message TSRMLS_DC) +static void php_embed_log_message(char *message) { fprintf (stderr, "%s\n", message); } -static void php_embed_register_variables(zval *track_vars_array TSRMLS_DC) +static void php_embed_register_variables(zval *track_vars_array) { - php_import_environment_variables(track_vars_array TSRMLS_CC); + php_import_environment_variables(track_vars_array); } static int php_embed_startup(sapi_module_struct *sapi_module) @@ -205,22 +205,22 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC) SG(request_info).argc=argc; SG(request_info).argv=argv; - if (php_request_startup(TSRMLS_C)==FAILURE) { - php_module_shutdown(TSRMLS_C); + if (php_request_startup()==FAILURE) { + php_module_shutdown(); return FAILURE; } SG(headers_sent) = 1; SG(request_info).no_headers = 1; - php_register_variable("PHP_SELF", "-", NULL TSRMLS_CC); + php_register_variable("PHP_SELF", "-", NULL); return SUCCESS; } -EMBED_SAPI_API void php_embed_shutdown(TSRMLS_D) +EMBED_SAPI_API void php_embed_shutdown(void) { php_request_shutdown((void *) 0); - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); sapi_shutdown(); #ifdef ZTS tsrm_shutdown(); -- cgit v1.2.1 From af21b3b6dcef4ce0c04f3e8126574f5660fd0a83 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 17 Dec 2014 10:52:28 +0100 Subject: get rid of TSRMLS_* in the embed SAPI --- sapi/embed/php_embed.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'sapi/embed/php_embed.c') diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c index d326251876..f5e6129e0f 100644 --- a/sapi/embed/php_embed.c +++ b/sapi/embed/php_embed.c @@ -33,6 +33,10 @@ const char HARDCODED_INI[] = "max_execution_time=0\n" "max_input_time=-1\n\0"; +#if defined(PHP_WIN32) && defined(ZTS) +ZEND_TSRMLS_CACHE_DEFINE; +#endif + static char* php_embed_read_cookies(void) { return NULL; @@ -152,12 +156,9 @@ static const zend_function_entry additional_functions[] = { {NULL, NULL, NULL} }; -EMBED_SAPI_API int php_embed_init(int argc, char **argv PTSRMLS_DC) +EMBED_SAPI_API int php_embed_init(int argc, char **argv) { zend_llist global_vars; -#ifdef ZTS - void ***tsrm_ls = NULL; -#endif #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) @@ -172,8 +173,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; + (void)ts_resource(0); + ZEND_TSRMLS_CACHE_UPDATE; #endif sapi_startup(&php_embed_module); -- cgit v1.2.1