Skip to content

Commit 01060ff

Browse files
committed
Support ZTS
1 parent 21c4bf6 commit 01060ff

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C" {
2626
pub fn ext_php_rs_zend_object_alloc(obj_size: usize, ce: *mut zend_class_entry) -> *mut c_void;
2727
pub fn ext_php_rs_zend_object_release(obj: *mut zend_object);
2828
pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals;
29+
pub fn ext_php_rs_process_globals() -> *mut php_core_globals;
2930
}
3031

3132
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

src/wrapper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,15 @@ zend_executor_globals *ext_php_rs_executor_globals() {
3939
return &executor_globals;
4040
#endif
4141
}
42+
43+
php_core_globals *ext_php_rs_process_globals() {
44+
#ifdef ZTS
45+
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
46+
return TSRMG_FAST_BULK_STATIC(core_globals_offset, php_core_globals);
47+
#else
48+
return TSRMG_FAST_BULK(core_globals_offset, php_core_globals *);
49+
#endif
50+
#else
51+
return &core_globals;
52+
#endif
53+
}

src/wrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ void ext_php_rs_set_known_valid_utf8(zend_string *zs);
2929
const char *ext_php_rs_php_build_id();
3030
void *ext_php_rs_zend_object_alloc(size_t obj_size, zend_class_entry *ce);
3131
void ext_php_rs_zend_object_release(zend_object *obj);
32-
zend_executor_globals *ext_php_rs_executor_globals();
32+
zend_executor_globals *ext_php_rs_executor_globals();
33+
php_core_globals *ext_php_rs_process_globals();

src/zend/globals.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard};
66

77
use crate::boxed::ZBox;
88
use crate::ffi::{
9-
_zend_executor_globals, core_globals, ext_php_rs_executor_globals, php_core_globals,
10-
TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET, TRACK_VARS_POST,
11-
TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
9+
_zend_executor_globals, ext_php_rs_executor_globals, ext_php_rs_process_globals,
10+
php_core_globals, TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET,
11+
TRACK_VARS_POST, TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
1212
};
1313

1414
use crate::types::{ZendHashTable, ZendObject};
@@ -85,7 +85,7 @@ impl ProcessGlobals {
8585
pub fn get() -> GlobalReadGuard<Self> {
8686
// SAFETY: PHP executor globals are statically declared therefore should never
8787
// return an invalid pointer.
88-
let globals = unsafe { &core_globals };
88+
let globals = unsafe { &*ext_php_rs_process_globals() };
8989
let guard = PROCESS_GLOBALS_LOCK.read();
9090
GlobalReadGuard { globals, guard }
9191
}
@@ -100,7 +100,7 @@ impl ProcessGlobals {
100100
pub fn get_mut() -> GlobalWriteGuard<Self> {
101101
// SAFETY: PHP executor globals are statically declared therefore should never
102102
// return an invalid pointer.
103-
let globals = unsafe { &mut core_globals };
103+
let globals = unsafe { &mut *ext_php_rs_process_globals() };
104104
let guard = PROCESS_GLOBALS_LOCK.write();
105105
GlobalWriteGuard { globals, guard }
106106
}

0 commit comments

Comments
 (0)