Support ZTS

This commit is contained in:
Joe Hoyle 2023-07-07 14:21:16 +02:00
parent 21c4bf68da
commit 01060ff08e
4 changed files with 20 additions and 6 deletions

View File

@ -26,6 +26,7 @@ extern "C" {
pub fn ext_php_rs_zend_object_alloc(obj_size: usize, ce: *mut zend_class_entry) -> *mut c_void; pub fn ext_php_rs_zend_object_alloc(obj_size: usize, ce: *mut zend_class_entry) -> *mut c_void;
pub fn ext_php_rs_zend_object_release(obj: *mut zend_object); pub fn ext_php_rs_zend_object_release(obj: *mut zend_object);
pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals; pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals;
pub fn ext_php_rs_process_globals() -> *mut php_core_globals;
} }
include!(concat!(env!("OUT_DIR"), "/bindings.rs")); include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

View File

@ -39,3 +39,15 @@ zend_executor_globals *ext_php_rs_executor_globals() {
return &executor_globals; return &executor_globals;
#endif #endif
} }
php_core_globals *ext_php_rs_process_globals() {
#ifdef ZTS
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
return TSRMG_FAST_BULK_STATIC(core_globals_offset, php_core_globals);
#else
return TSRMG_FAST_BULK(core_globals_offset, php_core_globals *);
#endif
#else
return &core_globals;
#endif
}

View File

@ -29,4 +29,5 @@ void ext_php_rs_set_known_valid_utf8(zend_string *zs);
const char *ext_php_rs_php_build_id(); const char *ext_php_rs_php_build_id();
void *ext_php_rs_zend_object_alloc(size_t obj_size, zend_class_entry *ce); void *ext_php_rs_zend_object_alloc(size_t obj_size, zend_class_entry *ce);
void ext_php_rs_zend_object_release(zend_object *obj); void ext_php_rs_zend_object_release(zend_object *obj);
zend_executor_globals *ext_php_rs_executor_globals(); zend_executor_globals *ext_php_rs_executor_globals();
php_core_globals *ext_php_rs_process_globals();

View File

@ -6,9 +6,9 @@ use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard};
use crate::boxed::ZBox; use crate::boxed::ZBox;
use crate::ffi::{ use crate::ffi::{
_zend_executor_globals, core_globals, ext_php_rs_executor_globals, php_core_globals, _zend_executor_globals, ext_php_rs_executor_globals, ext_php_rs_process_globals,
TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET, TRACK_VARS_POST, php_core_globals, TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET,
TRACK_VARS_REQUEST, TRACK_VARS_SERVER, TRACK_VARS_POST, TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
}; };
use crate::types::{ZendHashTable, ZendObject}; use crate::types::{ZendHashTable, ZendObject};
@ -85,7 +85,7 @@ impl ProcessGlobals {
pub fn get() -> GlobalReadGuard<Self> { pub fn get() -> GlobalReadGuard<Self> {
// SAFETY: PHP executor globals are statically declared therefore should never // SAFETY: PHP executor globals are statically declared therefore should never
// return an invalid pointer. // return an invalid pointer.
let globals = unsafe { &core_globals }; let globals = unsafe { &*ext_php_rs_process_globals() };
let guard = PROCESS_GLOBALS_LOCK.read(); let guard = PROCESS_GLOBALS_LOCK.read();
GlobalReadGuard { globals, guard } GlobalReadGuard { globals, guard }
} }
@ -100,7 +100,7 @@ impl ProcessGlobals {
pub fn get_mut() -> GlobalWriteGuard<Self> { pub fn get_mut() -> GlobalWriteGuard<Self> {
// SAFETY: PHP executor globals are statically declared therefore should never // SAFETY: PHP executor globals are statically declared therefore should never
// return an invalid pointer. // return an invalid pointer.
let globals = unsafe { &mut core_globals }; let globals = unsafe { &mut *ext_php_rs_process_globals() };
let guard = PROCESS_GLOBALS_LOCK.write(); let guard = PROCESS_GLOBALS_LOCK.write();
GlobalWriteGuard { globals, guard } GlobalWriteGuard { globals, guard }
} }