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/apache_hooks/php_apache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/apache_hooks/php_apache.c') 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 -- 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/apache_hooks/php_apache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sapi/apache_hooks/php_apache.c') diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c index 771ebf821c..e5bd3f5d61 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 - TSRMG_ALLOCATE(php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL); + ts_allocate_id(&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 -- 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/apache_hooks/php_apache.c | 78 +++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'sapi/apache_hooks/php_apache.c') diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c index e5bd3f5d61..57b4505f10 100644 --- a/sapi/apache_hooks/php_apache.c +++ b/sapi/apache_hooks/php_apache.c @@ -105,7 +105,7 @@ PHP_INI_BEGIN() PHP_INI_END() /* }}} */ -static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC) +static void php_apache_globals_ctor(php_apache_info_struct *apache_globals) { apache_globals->in_request = 0; } @@ -113,20 +113,20 @@ static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRML #define APREQ_GET_THIS(ZVAL) if (NULL == (ZVAL = getThis())) { \ php_error(E_WARNING, "%s(): underlying ApacheRequest object missing", \ - get_active_function_name(TSRMLS_C)); \ + get_active_function_name()); \ RETURN_FALSE; \ } #define APREQ_GET_REQUEST(ZVAL, R) APREQ_GET_THIS(ZVAL); \ - R = get_apache_request(ZVAL TSRMLS_CC) + R = get_apache_request(ZVAL) -static void php_apache_request_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_apache_request_free(zend_rsrc_list_entry *rsrc) { zval *z = (zval *)rsrc->ptr; /* fprintf(stderr, "%s() %p\n", __FUNCTION__, z); */ zval_ptr_dtor(&z); } -static request_rec *get_apache_request(zval *z TSRMLS_DC) +static request_rec *get_apache_request(zval *z) { request_rec *r; zval **addr; @@ -137,28 +137,28 @@ static request_rec *get_apache_request(zval *z TSRMLS_DC) } if (Z_TYPE_P(z) != IS_OBJECT) { - php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name(TSRMLS_C)); + php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name()); return NULL; } if (zend_hash_index_find(Z_OBJPROP_P(z), 0, (void **)&addr) == FAILURE) { - php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name(TSRMLS_C)); + php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name()); return NULL; } r = (request_rec *)Z_LVAL_PP(addr); if (!r) { - php_error(E_WARNING, "%s(): request_rec invalid", get_active_function_name(TSRMLS_C)); + php_error(E_WARNING, "%s(): request_rec invalid", get_active_function_name()); return NULL; } return r; } -/* {{{ php_apache_request_new(request_rec *r TSRMLS_DC) +/* {{{ php_apache_request_new(request_rec *r) * create a new zval-instance for ApacheRequest that wraps request_rec */ -zval *php_apache_request_new(request_rec *r TSRMLS_DC) +zval *php_apache_request_new(request_rec *r) { zval *req; zval *addr; @@ -210,7 +210,7 @@ static void apache_request_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) int new_value_len; char **target; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &new_value, &new_value_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &new_value, &new_value_len) == FAILURE) { return; } @@ -260,7 +260,7 @@ static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS) long old_value, new_value; long *target; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &new_value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &new_value) == FAILURE) { return; } @@ -504,7 +504,7 @@ PHP_FUNCTION(apache_request_content_length) long zlen; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &zlen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &zlen) == FAILURE) { return; } @@ -584,7 +584,7 @@ static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS) zend_bool replace = 0; HashPosition pos; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zb", &first, &second, &replace) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|zb", &first, &second, &replace) == FAILURE) { RETURN_FALSE; } @@ -614,7 +614,7 @@ static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS) break; case HASH_KEY_IS_LONG: default: - php_error(E_WARNING, "%s(): Can only add STRING keys to headers!", get_active_function_name(TSRMLS_C)); + php_error(E_WARNING, "%s(): Can only add STRING keys to headers!", get_active_function_name()); break; } @@ -715,7 +715,7 @@ PHP_FUNCTION(apache_request_remote_host) request_rec *r; char *res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &type) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &type) == FAILURE) { return; } @@ -743,7 +743,7 @@ PHP_FUNCTION(apache_request_update_mtime) request_rec *r; long mtime = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mtime) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mtime) == FAILURE) { return; } @@ -931,7 +931,7 @@ PHP_FUNCTION(apache_request_basic_auth_pw) const char *pw; long status; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zpw) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zpw) == FAILURE) { return; } @@ -963,7 +963,7 @@ PHP_FUNCTION(apache_request_send_http_header) char *type = NULL; int typelen; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &type, &typelen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() , "|s", &type, &typelen) == FAILURE) { return; } @@ -1034,7 +1034,7 @@ PHP_FUNCTION(apache_request_send_error_response) request_rec *r; long rec = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &rec) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &rec) == FAILURE) { return; } @@ -1049,7 +1049,7 @@ PHP_FUNCTION(apache_request_set_content_length) zval *id; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &length) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &length) == FAILURE) { return; } @@ -1092,7 +1092,7 @@ PHP_FUNCTION(apache_request_rputs) zval *id; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buffer, &buffer_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &buffer, &buffer_len) == FAILURE) { return; } @@ -1136,7 +1136,7 @@ PHP_FUNCTION(apache_request_log_error) long facility = APLOG_ERR; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &z_errstr, &z_errstr_len, &facility) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &z_errstr, &z_errstr_len, &facility) == FAILURE) { return; } @@ -1158,7 +1158,7 @@ PHP_FUNCTION(apache_request_sub_req_lookup_uri) int file_len; request_rec *r, *sub_r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_len) == FAILURE) { return; } @@ -1168,7 +1168,7 @@ PHP_FUNCTION(apache_request_sub_req_lookup_uri) if (!sub_r) { RETURN_FALSE; } - return_value = php_apache_request_new(sub_r TSRMLS_CC); + return_value = php_apache_request_new(sub_r); } /* }}} */ @@ -1183,7 +1183,7 @@ PHP_FUNCTION(apache_request_sub_req_lookup_file) int file_len; request_rec *r, *sub_r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &file, &file_len) == FAILURE) { return; } @@ -1194,7 +1194,7 @@ PHP_FUNCTION(apache_request_sub_req_lookup_file) if (!sub_r) { RETURN_FALSE; } - return_value = php_apache_request_new(sub_r TSRMLS_CC); + return_value = php_apache_request_new(sub_r); } /* }}} */ @@ -1209,7 +1209,7 @@ PHP_FUNCTION(apache_request_sub_req_method_uri) int file_len, method_len; request_rec *r, *sub_r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &method, &method_len, &file, &file_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &method, &method_len, &file, &file_len) == FAILURE) { return; } @@ -1220,7 +1220,7 @@ PHP_FUNCTION(apache_request_sub_req_method_uri) if (!sub_r) { RETURN_FALSE; } - return_value = php_apache_request_new(sub_r TSRMLS_CC); + return_value = php_apache_request_new(sub_r); } /* }}} */ @@ -1255,7 +1255,7 @@ PHP_FUNCTION(apache_request_internal_redirect) int new_uri_len; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &new_uri, &new_uri_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &new_uri, &new_uri_len) == FAILURE) { return; } @@ -1271,7 +1271,7 @@ PHP_FUNCTION(apache_request_send_header_field) zval *id; request_rec *r; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &fieldname, &fieldname_len, &fieldval, &fieldval_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &fieldname, &fieldname_len, &fieldval, &fieldval_len) == FAILURE) { return; } @@ -1394,14 +1394,14 @@ 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); #else - php_apache_globals_ctor(&php_apache_info TSRMLS_CC); + php_apache_globals_ctor(&php_apache_info); #endif REGISTER_INI_ENTRIES(); le_apachereq = zend_register_list_destructors_ex(php_apache_request_free, NULL, "ApacheRequest", module_number); INIT_OVERLOADED_CLASS_ENTRY(ce, "ApacheRequest", php_apache_request_class_functions, NULL, NULL, NULL); - apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL TSRMLS_CC); + apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL); REGISTER_LONG_CONSTANT("OK", OK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DECLINED", DECLINED, CONST_CS | CONST_PERSISTENT); @@ -1551,7 +1551,7 @@ PHP_FUNCTION(apache_note) int arg_name_len, arg_val_len; char *note_val; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &arg_name, &arg_name_len, &arg_val, &arg_val_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &arg_name, &arg_name_len, &arg_val, &arg_val_len) == FAILURE) { return; } @@ -1714,7 +1714,7 @@ PHP_FUNCTION(virtual) int filename_len; request_rec *rr = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { return; } @@ -1732,8 +1732,8 @@ PHP_FUNCTION(virtual) RETURN_FALSE; } - php_output_end_all(TSRMLS_C); - php_header(TSRMLS_C); + php_output_end_all(); + php_header(); if (run_sub_req(rr)) { php_error(E_WARNING, "Unable to include '%s' - request execution failed", filename); @@ -1811,7 +1811,7 @@ PHP_FUNCTION(apache_setenv) char *var = NULL, *val = NULL; request_rec *r = (request_rec *) SG(server_context); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { RETURN_FALSE; } @@ -1835,7 +1835,7 @@ PHP_FUNCTION(apache_lookup_uri) int filename_len; request_rec *rr=NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) { return; } -- cgit v1.2.1