2010-04-20 19:05:54 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2019-01-30 17:23:29 +08:00
|
|
|
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
|
2010-04-20 19:05:54 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
2015-01-03 17:22:58 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2010-04-20 19:05:54 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
2018-11-01 23:20:07 +08:00
|
|
|
| Authors: Dmitry Stogov <dmitry@php.net> |
|
2010-04-20 19:05:54 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_globals.h"
|
|
|
|
|
2017-12-06 20:32:31 +08:00
|
|
|
#ifdef HAVE_VALGRIND
|
|
|
|
# include "valgrind/callgrind.h"
|
|
|
|
#endif
|
|
|
|
|
2018-04-04 06:12:59 +08:00
|
|
|
ZEND_API zend_new_interned_string_func_t zend_new_interned_string;
|
|
|
|
ZEND_API zend_string_init_interned_func_t zend_string_init_interned;
|
2021-08-12 17:18:26 +08:00
|
|
|
ZEND_API zend_string_init_existing_interned_func_t zend_string_init_existing_interned;
|
2010-05-25 17:00:20 +08:00
|
|
|
|
2018-04-04 06:12:59 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_new_interned_string_permanent(zend_string *str);
|
|
|
|
static zend_string* ZEND_FASTCALL zend_new_interned_string_request(zend_string *str);
|
2020-08-28 21:41:27 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_string_init_interned_permanent(const char *str, size_t size, bool permanent);
|
2021-08-12 17:18:26 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_string_init_existing_interned_permanent(const char *str, size_t size, bool permanent);
|
2020-08-28 21:41:27 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_string_init_interned_request(const char *str, size_t size, bool permanent);
|
2021-08-12 17:18:26 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_string_init_existing_interned_request(const char *str, size_t size, bool permanent);
|
2017-03-04 17:39:13 +08:00
|
|
|
|
|
|
|
/* Any strings interned in the startup phase. Common to all the threads,
|
2017-12-06 20:32:31 +08:00
|
|
|
won't be free'd until process exit. If we want an ability to
|
2017-03-04 17:39:13 +08:00
|
|
|
add permanent strings even after startup, it would be still
|
|
|
|
possible on costs of locking in the thread safe builds. */
|
|
|
|
static HashTable interned_strings_permanent;
|
|
|
|
|
|
|
|
static zend_new_interned_string_func_t interned_string_request_handler = zend_new_interned_string_request;
|
2017-10-19 05:02:56 +08:00
|
|
|
static zend_string_init_interned_func_t interned_string_init_request_handler = zend_string_init_interned_request;
|
2021-08-12 17:18:26 +08:00
|
|
|
static zend_string_init_existing_interned_func_t interned_string_init_existing_request_handler = zend_string_init_existing_interned_request;
|
2017-03-04 17:39:13 +08:00
|
|
|
|
|
|
|
ZEND_API zend_string *zend_empty_string = NULL;
|
|
|
|
ZEND_API zend_string *zend_one_char_string[256];
|
|
|
|
ZEND_API zend_string **zend_known_strings = NULL;
|
2010-04-20 19:05:54 +08:00
|
|
|
|
2018-05-08 05:22:04 +08:00
|
|
|
ZEND_API zend_ulong ZEND_FASTCALL zend_string_hash_func(zend_string *str)
|
|
|
|
{
|
|
|
|
return ZSTR_H(str) = zend_hash_func(ZSTR_VAL(str), ZSTR_LEN(str));
|
|
|
|
}
|
|
|
|
|
2018-04-04 06:12:59 +08:00
|
|
|
ZEND_API zend_ulong ZEND_FASTCALL zend_hash_func(const char *str, size_t len)
|
2014-02-10 14:04:30 +08:00
|
|
|
{
|
|
|
|
return zend_inline_hash_func(str, len);
|
|
|
|
}
|
|
|
|
|
2014-02-17 21:59:18 +08:00
|
|
|
static void _str_dtor(zval *zv)
|
|
|
|
{
|
|
|
|
zend_string *str = Z_STR_P(zv);
|
2015-04-28 11:14:21 +08:00
|
|
|
pefree(str, GC_FLAGS(str) & IS_STR_PERSISTENT);
|
2014-02-17 21:59:18 +08:00
|
|
|
}
|
2016-05-12 18:47:22 +08:00
|
|
|
|
|
|
|
static const char *known_strings[] = {
|
|
|
|
#define _ZEND_STR_DSC(id, str) str,
|
|
|
|
ZEND_KNOWN_STRINGS(_ZEND_STR_DSC)
|
|
|
|
#undef _ZEND_STR_DSC
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2020-08-28 21:41:27 +08:00
|
|
|
static zend_always_inline void zend_init_interned_strings_ht(HashTable *interned_strings, bool permanent)
|
2016-06-02 23:55:48 +08:00
|
|
|
{
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_hash_init(interned_strings, 1024, NULL, _str_dtor, permanent);
|
2019-01-24 21:01:04 +08:00
|
|
|
if (permanent) {
|
|
|
|
zend_hash_real_init_mixed(interned_strings);
|
|
|
|
}
|
2016-06-02 23:55:48 +08:00
|
|
|
}
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
ZEND_API void zend_interned_strings_init(void)
|
2010-04-20 19:05:54 +08:00
|
|
|
{
|
2017-03-04 17:39:13 +08:00
|
|
|
char s[2];
|
2019-01-09 05:08:40 +08:00
|
|
|
unsigned int i;
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_string *str;
|
2010-04-20 19:05:54 +08:00
|
|
|
|
2018-01-26 20:22:36 +08:00
|
|
|
interned_string_request_handler = zend_new_interned_string_request;
|
2018-01-26 20:25:03 +08:00
|
|
|
interned_string_init_request_handler = zend_string_init_interned_request;
|
2021-08-12 17:18:26 +08:00
|
|
|
interned_string_init_existing_request_handler = zend_string_init_existing_interned_request;
|
2018-01-26 20:22:36 +08:00
|
|
|
|
|
|
|
zend_empty_string = NULL;
|
|
|
|
zend_known_strings = NULL;
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_init_interned_strings_ht(&interned_strings_permanent, 1);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_new_interned_string = zend_new_interned_string_permanent;
|
2017-10-19 05:02:56 +08:00
|
|
|
zend_string_init_interned = zend_string_init_interned_permanent;
|
2021-08-12 17:18:26 +08:00
|
|
|
zend_string_init_existing_interned = zend_string_init_existing_interned_permanent;
|
2014-02-10 14:04:30 +08:00
|
|
|
|
|
|
|
/* interned empty string */
|
2014-08-26 01:24:55 +08:00
|
|
|
str = zend_string_alloc(sizeof("")-1, 1);
|
2015-06-30 18:59:27 +08:00
|
|
|
ZSTR_VAL(str)[0] = '\000';
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_empty_string = zend_new_interned_string_permanent(str);
|
2010-04-20 19:05:54 +08:00
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
s[1] = 0;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
s[0] = i;
|
|
|
|
zend_one_char_string[i] = zend_new_interned_string_permanent(zend_string_init(s, 1, 1));
|
|
|
|
}
|
2014-05-06 03:16:49 +08:00
|
|
|
|
2016-05-12 18:47:22 +08:00
|
|
|
/* known strings */
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_known_strings = pemalloc(sizeof(zend_string*) * ((sizeof(known_strings) / sizeof(known_strings[0]) - 1)), 1);
|
|
|
|
for (i = 0; i < (sizeof(known_strings) / sizeof(known_strings[0])) - 1; i++) {
|
|
|
|
str = zend_string_init(known_strings[i], strlen(known_strings[i]), 1);
|
|
|
|
zend_known_strings[i] = zend_new_interned_string_permanent(str);
|
|
|
|
}
|
2010-04-20 19:05:54 +08:00
|
|
|
}
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
ZEND_API void zend_interned_strings_dtor(void)
|
2010-04-20 19:05:54 +08:00
|
|
|
{
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_hash_destroy(&interned_strings_permanent);
|
2016-05-12 18:47:22 +08:00
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
free(zend_known_strings);
|
|
|
|
zend_known_strings = NULL;
|
2010-04-20 19:05:54 +08:00
|
|
|
}
|
|
|
|
|
2017-10-19 05:02:56 +08:00
|
|
|
static zend_always_inline zend_string *zend_interned_string_ht_lookup_ex(zend_ulong h, const char *str, size_t size, HashTable *interned_strings)
|
2010-04-20 19:05:54 +08:00
|
|
|
{
|
2016-11-26 22:18:42 +08:00
|
|
|
uint32_t nIndex;
|
|
|
|
uint32_t idx;
|
2010-04-20 19:05:54 +08:00
|
|
|
Bucket *p;
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
nIndex = h | interned_strings->nTableMask;
|
|
|
|
idx = HT_HASH(interned_strings, nIndex);
|
2015-03-13 22:13:19 +08:00
|
|
|
while (idx != HT_INVALID_IDX) {
|
2017-03-04 17:39:13 +08:00
|
|
|
p = HT_HASH_TO_BUCKET(interned_strings, idx);
|
2022-03-31 22:27:58 +08:00
|
|
|
if ((p->h == h) && zend_string_equals_cstr(p->key, str, size)) {
|
|
|
|
return p->key;
|
2010-04-20 19:05:54 +08:00
|
|
|
}
|
2014-04-02 18:34:44 +08:00
|
|
|
idx = Z_NEXT(p->val);
|
2010-04-20 19:05:54 +08:00
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-19 05:02:56 +08:00
|
|
|
static zend_always_inline zend_string *zend_interned_string_ht_lookup(zend_string *str, HashTable *interned_strings)
|
|
|
|
{
|
2017-12-04 22:17:02 +08:00
|
|
|
zend_ulong h = ZSTR_H(str);
|
|
|
|
uint32_t nIndex;
|
|
|
|
uint32_t idx;
|
|
|
|
Bucket *p;
|
|
|
|
|
|
|
|
nIndex = h | interned_strings->nTableMask;
|
|
|
|
idx = HT_HASH(interned_strings, nIndex);
|
|
|
|
while (idx != HT_INVALID_IDX) {
|
|
|
|
p = HT_HASH_TO_BUCKET(interned_strings, idx);
|
|
|
|
if ((p->h == h) && zend_string_equal_content(p->key, str)) {
|
|
|
|
return p->key;
|
|
|
|
}
|
|
|
|
idx = Z_NEXT(p->val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2017-10-19 05:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
/* This function might be not thread safe at least because it would update the
|
|
|
|
hash val in the passed string. Be sure it is called in the appropriate context. */
|
|
|
|
static zend_always_inline zend_string *zend_add_interned_string(zend_string *str, HashTable *interned_strings, uint32_t flags)
|
|
|
|
{
|
2017-03-08 02:01:00 +08:00
|
|
|
zval val;
|
2017-03-04 17:39:13 +08:00
|
|
|
|
2017-10-27 06:28:58 +08:00
|
|
|
GC_SET_REFCOUNT(str, 1);
|
2018-02-28 05:52:12 +08:00
|
|
|
GC_ADD_FLAGS(str, IS_STR_INTERNED | flags);
|
2017-03-04 17:39:13 +08:00
|
|
|
|
2017-03-08 02:01:00 +08:00
|
|
|
ZVAL_INTERNED_STR(&val, str);
|
2010-04-20 19:05:54 +08:00
|
|
|
|
2017-03-08 02:01:00 +08:00
|
|
|
zend_hash_add_new(interned_strings, str, &val);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
return str;
|
2010-04-20 19:05:54 +08:00
|
|
|
}
|
|
|
|
|
2018-04-04 06:12:59 +08:00
|
|
|
ZEND_API zend_string* ZEND_FASTCALL zend_interned_string_find_permanent(zend_string *str)
|
2010-04-20 19:05:54 +08:00
|
|
|
{
|
2017-10-19 05:02:56 +08:00
|
|
|
zend_string_hash_val(str);
|
2017-03-04 17:39:13 +08:00
|
|
|
return zend_interned_string_ht_lookup(str, &interned_strings_permanent);
|
|
|
|
}
|
|
|
|
|
2018-04-04 06:12:59 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_new_interned_string_permanent(zend_string *str)
|
2017-03-04 17:39:13 +08:00
|
|
|
{
|
|
|
|
zend_string *ret;
|
|
|
|
|
|
|
|
if (ZSTR_IS_INTERNED(str)) {
|
|
|
|
return str;
|
|
|
|
}
|
2014-02-10 14:04:30 +08:00
|
|
|
|
2017-10-19 05:02:56 +08:00
|
|
|
zend_string_hash_val(str);
|
2017-03-04 17:39:13 +08:00
|
|
|
ret = zend_interned_string_ht_lookup(str, &interned_strings_permanent);
|
|
|
|
if (ret) {
|
|
|
|
zend_string_release(str);
|
|
|
|
return ret;
|
2014-02-10 14:04:30 +08:00
|
|
|
}
|
2017-03-04 17:39:13 +08:00
|
|
|
|
2017-11-04 02:00:07 +08:00
|
|
|
ZEND_ASSERT(GC_FLAGS(str) & GC_PERSISTENT);
|
|
|
|
if (GC_REFCOUNT(str) > 1) {
|
|
|
|
zend_ulong h = ZSTR_H(str);
|
|
|
|
zend_string_delref(str);
|
|
|
|
str = zend_string_init(ZSTR_VAL(str), ZSTR_LEN(str), 1);
|
|
|
|
ZSTR_H(str) = h;
|
|
|
|
}
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
return zend_add_interned_string(str, &interned_strings_permanent, IS_STR_PERMANENT);
|
2010-04-20 19:05:54 +08:00
|
|
|
}
|
|
|
|
|
2018-04-04 06:12:59 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_new_interned_string_request(zend_string *str)
|
2010-04-20 19:05:54 +08:00
|
|
|
{
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_string *ret;
|
|
|
|
|
|
|
|
if (ZSTR_IS_INTERNED(str)) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-10-19 05:02:56 +08:00
|
|
|
zend_string_hash_val(str);
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
/* Check for permanent strings, the table is readonly at this point. */
|
|
|
|
ret = zend_interned_string_ht_lookup(str, &interned_strings_permanent);
|
|
|
|
if (ret) {
|
|
|
|
zend_string_release(str);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = zend_interned_string_ht_lookup(str, &CG(interned_strings));
|
|
|
|
if (ret) {
|
|
|
|
zend_string_release(str);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a short living interned, freed after the request. */
|
2019-04-18 19:26:15 +08:00
|
|
|
#if ZEND_RC_DEBUG
|
|
|
|
if (zend_rc_debug) {
|
|
|
|
/* PHP shouldn't create persistent interned string during request,
|
|
|
|
* but at least dl() may do this */
|
|
|
|
ZEND_ASSERT(!(GC_FLAGS(str) & GC_PERSISTENT));
|
|
|
|
}
|
|
|
|
#endif
|
2017-11-04 02:00:07 +08:00
|
|
|
if (GC_REFCOUNT(str) > 1) {
|
|
|
|
zend_ulong h = ZSTR_H(str);
|
|
|
|
zend_string_delref(str);
|
|
|
|
str = zend_string_init(ZSTR_VAL(str), ZSTR_LEN(str), 0);
|
|
|
|
ZSTR_H(str) = h;
|
|
|
|
}
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
ret = zend_add_interned_string(str, &CG(interned_strings), 0);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-08-28 21:41:27 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_string_init_interned_permanent(const char *str, size_t size, bool permanent)
|
2017-10-19 05:02:56 +08:00
|
|
|
{
|
|
|
|
zend_string *ret;
|
2017-10-19 16:26:39 +08:00
|
|
|
zend_ulong h = zend_inline_hash_func(str, size);
|
2017-10-19 05:02:56 +08:00
|
|
|
|
|
|
|
ret = zend_interned_string_ht_lookup_ex(h, str, size, &interned_strings_permanent);
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-04-18 19:26:15 +08:00
|
|
|
ZEND_ASSERT(permanent);
|
2017-10-19 05:02:56 +08:00
|
|
|
ret = zend_string_init(str, size, permanent);
|
|
|
|
ZSTR_H(ret) = h;
|
|
|
|
return zend_add_interned_string(ret, &interned_strings_permanent, IS_STR_PERMANENT);
|
|
|
|
}
|
|
|
|
|
2021-08-12 17:18:26 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_string_init_existing_interned_permanent(const char *str, size_t size, bool permanent)
|
|
|
|
{
|
|
|
|
zend_ulong h = zend_inline_hash_func(str, size);
|
|
|
|
zend_string *ret = zend_interned_string_ht_lookup_ex(h, str, size, &interned_strings_permanent);
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_ASSERT(permanent);
|
|
|
|
ret = zend_string_init(str, size, permanent);
|
|
|
|
ZSTR_H(ret) = h;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-08-28 21:41:27 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_string_init_interned_request(const char *str, size_t size, bool permanent)
|
2017-10-19 05:02:56 +08:00
|
|
|
{
|
|
|
|
zend_string *ret;
|
2017-10-19 16:26:39 +08:00
|
|
|
zend_ulong h = zend_inline_hash_func(str, size);
|
2017-10-19 05:02:56 +08:00
|
|
|
|
|
|
|
/* Check for permanent strings, the table is readonly at this point. */
|
|
|
|
ret = zend_interned_string_ht_lookup_ex(h, str, size, &interned_strings_permanent);
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = zend_interned_string_ht_lookup_ex(h, str, size, &CG(interned_strings));
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-04-18 19:26:15 +08:00
|
|
|
#if ZEND_RC_DEBUG
|
|
|
|
if (zend_rc_debug) {
|
|
|
|
/* PHP shouldn't create persistent interned string during request,
|
|
|
|
* but at least dl() may do this */
|
|
|
|
ZEND_ASSERT(!permanent);
|
|
|
|
}
|
|
|
|
#endif
|
2017-10-19 05:02:56 +08:00
|
|
|
ret = zend_string_init(str, size, permanent);
|
|
|
|
ZSTR_H(ret) = h;
|
|
|
|
|
|
|
|
/* Create a short living interned, freed after the request. */
|
|
|
|
return zend_add_interned_string(ret, &CG(interned_strings), 0);
|
|
|
|
}
|
|
|
|
|
2021-08-12 17:18:26 +08:00
|
|
|
static zend_string* ZEND_FASTCALL zend_string_init_existing_interned_request(const char *str, size_t size, bool permanent)
|
|
|
|
{
|
|
|
|
zend_ulong h = zend_inline_hash_func(str, size);
|
|
|
|
zend_string *ret = zend_interned_string_ht_lookup_ex(h, str, size, &interned_strings_permanent);
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = zend_interned_string_ht_lookup_ex(h, str, size, &CG(interned_strings));
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_ASSERT(!permanent);
|
|
|
|
ret = zend_string_init(str, size, permanent);
|
|
|
|
ZSTR_H(ret) = h;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
ZEND_API void zend_interned_strings_activate(void)
|
|
|
|
{
|
|
|
|
zend_init_interned_strings_ht(&CG(interned_strings), 0);
|
|
|
|
}
|
2010-04-20 19:05:54 +08:00
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
ZEND_API void zend_interned_strings_deactivate(void)
|
|
|
|
{
|
|
|
|
zend_hash_destroy(&CG(interned_strings));
|
|
|
|
}
|
|
|
|
|
2021-08-12 17:18:26 +08:00
|
|
|
ZEND_API void zend_interned_strings_set_request_storage_handlers(zend_new_interned_string_func_t handler, zend_string_init_interned_func_t init_handler, zend_string_init_existing_interned_func_t init_existing_handler)
|
2017-03-04 17:39:13 +08:00
|
|
|
{
|
|
|
|
interned_string_request_handler = handler;
|
2017-10-19 05:02:56 +08:00
|
|
|
interned_string_init_request_handler = init_handler;
|
2021-08-12 17:18:26 +08:00
|
|
|
interned_string_init_existing_request_handler = init_existing_handler;
|
2017-03-04 17:39:13 +08:00
|
|
|
}
|
|
|
|
|
2021-01-15 19:30:54 +08:00
|
|
|
ZEND_API void zend_interned_strings_switch_storage(bool request)
|
2017-03-04 17:39:13 +08:00
|
|
|
{
|
2017-11-03 04:29:21 +08:00
|
|
|
if (request) {
|
|
|
|
zend_new_interned_string = interned_string_request_handler;
|
|
|
|
zend_string_init_interned = interned_string_init_request_handler;
|
2021-08-12 17:18:26 +08:00
|
|
|
zend_string_init_existing_interned = interned_string_init_existing_request_handler;
|
2017-11-03 04:29:21 +08:00
|
|
|
} else {
|
|
|
|
zend_new_interned_string = zend_new_interned_string_permanent;
|
|
|
|
zend_string_init_interned = zend_string_init_interned_permanent;
|
2021-08-12 17:18:26 +08:00
|
|
|
zend_string_init_existing_interned = zend_string_init_existing_interned_permanent;
|
2017-03-04 17:39:13 +08:00
|
|
|
}
|
2010-04-20 19:05:54 +08:00
|
|
|
}
|
|
|
|
|
2021-05-22 03:00:34 +08:00
|
|
|
/* Even if we don't build with valgrind support, include the symbol so that valgrind available
|
|
|
|
* only at runtime will not result in false positives. */
|
2022-05-03 16:35:52 +08:00
|
|
|
#ifndef I_REPLACE_SONAME_FNNAME_ZU
|
2021-05-22 03:00:34 +08:00
|
|
|
# define I_REPLACE_SONAME_FNNAME_ZU(soname, fnname) _vgr00000ZU_ ## soname ## _ ## fnname
|
|
|
|
#endif
|
|
|
|
|
2022-04-20 22:56:51 +08:00
|
|
|
ZEND_API bool ZEND_FASTCALL I_REPLACE_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(const zend_string *s1, const zend_string *s2)
|
2021-05-22 03:00:34 +08:00
|
|
|
{
|
|
|
|
return !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1));
|
|
|
|
}
|
|
|
|
|
2017-12-05 04:40:54 +08:00
|
|
|
#if defined(__GNUC__) && defined(__i386__)
|
2022-04-20 22:56:51 +08:00
|
|
|
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(const zend_string *s1, const zend_string *s2)
|
2017-12-05 04:40:54 +08:00
|
|
|
{
|
2022-04-20 22:56:51 +08:00
|
|
|
const char *ptr = ZSTR_VAL(s1);
|
|
|
|
size_t delta = (const char*)s2 - (const char*)s1;
|
2017-12-06 20:32:31 +08:00
|
|
|
size_t len = ZSTR_LEN(s1);
|
2017-12-05 04:40:54 +08:00
|
|
|
zend_ulong ret;
|
|
|
|
|
|
|
|
__asm__ (
|
2017-12-21 02:44:24 +08:00
|
|
|
".LL0%=:\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"movl (%2,%3), %0\n\t"
|
|
|
|
"xorl (%2), %0\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"jne .LL1%=\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"addl $0x4, %2\n\t"
|
|
|
|
"subl $0x4, %1\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"ja .LL0%=\n\t"
|
2017-12-05 04:40:54 +08:00
|
|
|
"movl $0x1, %0\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"jmp .LL3%=\n\t"
|
|
|
|
".LL1%=:\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"cmpl $0x4,%1\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"jb .LL2%=\n\t"
|
2017-12-05 04:40:54 +08:00
|
|
|
"xorl %0, %0\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"jmp .LL3%=\n\t"
|
|
|
|
".LL2%=:\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"negl %1\n\t"
|
2018-01-31 17:38:02 +08:00
|
|
|
"lea 0x20(,%1,8), %1\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"shll %b1, %0\n\t"
|
2017-12-05 04:40:54 +08:00
|
|
|
"sete %b0\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"movzbl %b0, %0\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
".LL3%=:\n"
|
2017-12-06 20:32:31 +08:00
|
|
|
: "=&a"(ret),
|
|
|
|
"+c"(len),
|
|
|
|
"+r"(ptr)
|
|
|
|
: "r"(delta)
|
|
|
|
: "cc");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-25 05:02:33 +08:00
|
|
|
#elif defined(__GNUC__) && defined(__x86_64__) && !defined(__ILP32__)
|
2022-04-20 22:56:51 +08:00
|
|
|
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(const zend_string *s1, const zend_string *s2)
|
2017-12-05 04:40:54 +08:00
|
|
|
{
|
2022-04-20 22:56:51 +08:00
|
|
|
const char *ptr = ZSTR_VAL(s1);
|
|
|
|
size_t delta = (const char*)s2 - (const char*)s1;
|
2017-12-06 20:32:31 +08:00
|
|
|
size_t len = ZSTR_LEN(s1);
|
2017-12-05 04:40:54 +08:00
|
|
|
zend_ulong ret;
|
|
|
|
|
|
|
|
__asm__ (
|
2017-12-21 02:44:24 +08:00
|
|
|
".LL0%=:\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"movq (%2,%3), %0\n\t"
|
|
|
|
"xorq (%2), %0\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"jne .LL1%=\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"addq $0x8, %2\n\t"
|
|
|
|
"subq $0x8, %1\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"ja .LL0%=\n\t"
|
2017-12-05 04:40:54 +08:00
|
|
|
"movq $0x1, %0\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"jmp .LL3%=\n\t"
|
|
|
|
".LL1%=:\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"cmpq $0x8,%1\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"jb .LL2%=\n\t"
|
2017-12-05 04:40:54 +08:00
|
|
|
"xorq %0, %0\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
"jmp .LL3%=\n\t"
|
|
|
|
".LL2%=:\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"negq %1\n\t"
|
2018-01-31 17:38:02 +08:00
|
|
|
"lea 0x40(,%1,8), %1\n\t"
|
2017-12-06 20:32:31 +08:00
|
|
|
"shlq %b1, %0\n\t"
|
2017-12-05 04:40:54 +08:00
|
|
|
"sete %b0\n\t"
|
2017-12-07 06:15:09 +08:00
|
|
|
"movzbq %b0, %0\n\t"
|
2017-12-21 02:44:24 +08:00
|
|
|
".LL3%=:\n"
|
2017-12-06 20:32:31 +08:00
|
|
|
: "=&a"(ret),
|
|
|
|
"+c"(len),
|
|
|
|
"+r"(ptr)
|
|
|
|
: "r"(delta)
|
|
|
|
: "cc");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
2020-04-09 21:06:53 +08:00
|
|
|
|
2020-04-14 23:17:38 +08:00
|
|
|
ZEND_API zend_string *zend_string_concat2(
|
|
|
|
const char *str1, size_t str1_len,
|
|
|
|
const char *str2, size_t str2_len)
|
|
|
|
{
|
|
|
|
size_t len = str1_len + str2_len;
|
|
|
|
zend_string *res = zend_string_alloc(len, 0);
|
|
|
|
|
|
|
|
memcpy(ZSTR_VAL(res), str1, str1_len);
|
|
|
|
memcpy(ZSTR_VAL(res) + str1_len, str2, str2_len);
|
|
|
|
ZSTR_VAL(res)[len] = '\0';
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-04-09 21:06:53 +08:00
|
|
|
ZEND_API zend_string *zend_string_concat3(
|
|
|
|
const char *str1, size_t str1_len,
|
|
|
|
const char *str2, size_t str2_len,
|
|
|
|
const char *str3, size_t str3_len)
|
|
|
|
{
|
|
|
|
size_t len = str1_len + str2_len + str3_len;
|
|
|
|
zend_string *res = zend_string_alloc(len, 0);
|
|
|
|
|
|
|
|
memcpy(ZSTR_VAL(res), str1, str1_len);
|
|
|
|
memcpy(ZSTR_VAL(res) + str1_len, str2, str2_len);
|
|
|
|
memcpy(ZSTR_VAL(res) + str1_len + str2_len, str3, str3_len);
|
|
|
|
ZSTR_VAL(res)[len] = '\0';
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|