Skip to content

Commit

Permalink
prepare: do not extend map_ptr region unless a class is actually copied
Browse files Browse the repository at this point in the history
we know already that copying classes on the fly for object sharing is racy (see #73), but this reduces the number of opportunities for a harmful race condition.
  • Loading branch information
dktapps committed Feb 5, 2024
1 parent a5ec24d commit a231c69
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,6 @@ static inline int pmmpthread_prepared_entry_function_prepare(zval *bucket, int a

/* {{{ */
zend_class_entry* pmmpthread_prepare_single_class(const pmmpthread_ident_t* source, zend_class_entry *candidate) {
//this has to be synchronized every time we copy a new class after initial thread bootup, in case new immutable classes want to refer to new offsets in it
zend_map_ptr_extend(PMMPTHREAD_CG(source->ls, map_ptr_last));
return pmmpthread_prepared_entry(source, candidate);
} /* }}} */

Expand Down Expand Up @@ -617,6 +615,9 @@ static zend_class_entry* pmmpthread_create_entry(const pmmpthread_ident_t* sourc
return prepared;
}

//this has to be synchronized every time we copy a new class after initial thread bootup, in case new immutable classes want to refer to new offsets in it
zend_map_ptr_extend(PMMPTHREAD_CG(source->ls, map_ptr_last));

if (candidate->ce_flags & ZEND_ACC_IMMUTABLE) {
//IMMUTABLE classes don't need to be copied and should not be modified
//this may overwrite previously inserted immutable classes on 8.1 (e.g. unlinked opcached class -> linked opcached class)
Expand Down

0 comments on commit a231c69

Please sign in to comment.