Skip to content

Commit a616c4b

Browse files
committed
ZTS support for file globals
1 parent 06e190e commit a616c4b

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern "C" {
2828
pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals;
2929
pub fn ext_php_rs_process_globals() -> *mut php_core_globals;
3030
pub fn ext_php_rs_sapi_globals() -> *mut sapi_globals_struct;
31+
pub fn ext_php_rs_file_globals() -> *mut php_file_globals;
3132
}
3233

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

src/wrapper.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,12 @@ sapi_globals_struct *ext_php_rs_sapi_globals() {
6464
return &sapi_globals;
6565
#endif
6666
}
67+
68+
69+
php_file_globals *ext_php_rs_file_globals() {
70+
#ifdef ZTS
71+
return TSRMG_FAST_BULK(file_globals_id, php_file_globals *);
72+
#else
73+
return &file_globals;
74+
#endif
75+
}

src/zend/globals.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard};
88

99
use crate::boxed::ZBox;
1010
use crate::ffi::{
11-
_zend_executor_globals, ext_php_rs_executor_globals, ext_php_rs_process_globals,
12-
ext_php_rs_sapi_globals, file_globals, php_core_globals, php_file_globals, sapi_globals_struct,
13-
sapi_header_struct, sapi_headers_struct, sapi_request_info, zend_is_auto_global,
14-
TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET, TRACK_VARS_POST,
15-
TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
11+
_zend_executor_globals, ext_php_rs_executor_globals, ext_php_rs_file_globals,
12+
ext_php_rs_process_globals, ext_php_rs_sapi_globals, php_core_globals, php_file_globals,
13+
sapi_globals_struct, sapi_header_struct, sapi_headers_struct, sapi_request_info,
14+
zend_is_auto_global, TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET,
15+
TRACK_VARS_POST, TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
1616
};
1717

1818
use crate::types::{ZendHashTable, ZendObject, ZendStr};
@@ -378,7 +378,8 @@ impl FileGlobals {
378378
pub fn get() -> GlobalReadGuard<Self> {
379379
// SAFETY: PHP executor globals are statically declared therefore should never
380380
// return an invalid pointer.
381-
let globals = unsafe { &file_globals };
381+
let globals = unsafe { ext_php_rs_file_globals().as_ref() }
382+
.expect("Static file globals were invalid");
382383
let guard = FILE_GLOBALS_LOCK.read();
383384
GlobalReadGuard { globals, guard }
384385
}
@@ -393,7 +394,7 @@ impl FileGlobals {
393394
pub fn get_mut() -> GlobalWriteGuard<Self> {
394395
// SAFETY: PHP executor globals are statically declared therefore should never
395396
// return an invalid pointer.
396-
let globals = unsafe { &mut file_globals };
397+
let globals = unsafe { &mut *ext_php_rs_file_globals() };
397398
let guard = SAPI_GLOBALS_LOCK.write();
398399
GlobalWriteGuard { globals, guard }
399400
}

0 commit comments

Comments
 (0)