Skip to content

Get rid of duplicated rotr3 implementation #8853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions ext/opcache/zend_shared_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,17 @@ void *zend_shared_alloc(size_t size)
return NULL;
}

static zend_always_inline zend_ulong zend_rotr3(zend_ulong key)
{
return (key >> 3) | (key << ((sizeof(key) * 8) - 3));
}

int zend_shared_memdup_size(void *source, size_t size)
{
void *old_p;
zend_ulong key = (zend_ulong)source;

key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
key = zend_rotr3(key);
if ((old_p = zend_hash_index_find_ptr(&ZCG(xlat_table), key)) != NULL) {
/* we already duplicated this pointer */
return 0;
Expand All @@ -383,7 +388,7 @@ static zend_always_inline void *_zend_shared_memdup(void *source, size_t size, b

if (get_xlat) {
key = (zend_ulong)source;
key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
key = zend_rotr3(key);
if ((old_p = zend_hash_index_find_ptr(&ZCG(xlat_table), key)) != NULL) {
/* we already duplicated this pointer */
return old_p;
Expand All @@ -395,7 +400,7 @@ static zend_always_inline void *_zend_shared_memdup(void *source, size_t size, b
if (set_xlat) {
if (!get_xlat) {
key = (zend_ulong)source;
key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
key = zend_rotr3(key);
}
zend_hash_index_add_new_ptr(&ZCG(xlat_table), key, retval);
}
Expand Down Expand Up @@ -535,7 +540,7 @@ void zend_shared_alloc_register_xlat_entry(const void *old, const void *new)
{
zend_ulong key = (zend_ulong)old;

key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
key = zend_rotr3(key);
zend_hash_index_add_new_ptr(&ZCG(xlat_table), key, (void*)new);
}

Expand All @@ -544,7 +549,7 @@ void *zend_shared_alloc_get_xlat_entry(const void *old)
void *retval;
zend_ulong key = (zend_ulong)old;

key = (key >> 3) | (key << ((sizeof(key) * 8) - 3)); /* key = _rotr(key, 3);*/
key = zend_rotr3(key);
if ((retval = zend_hash_index_find_ptr(&ZCG(xlat_table), key)) == NULL) {
return NULL;
}
Expand Down