mirror of
https://github.com/danog/ext-php-rs.git
synced 2025-01-22 13:01:24 +01:00
Add FileGlobals too
This commit is contained in:
parent
48980a1d52
commit
5acdfe67c2
@ -234,6 +234,8 @@ bind! {
|
|||||||
executor_globals_offset,
|
executor_globals_offset,
|
||||||
core_globals_offset,
|
core_globals_offset,
|
||||||
sapi_globals_offset,
|
sapi_globals_offset,
|
||||||
|
php_file_globals,
|
||||||
|
file_globals,
|
||||||
TRACK_VARS_POST,
|
TRACK_VARS_POST,
|
||||||
TRACK_VARS_GET,
|
TRACK_VARS_GET,
|
||||||
TRACK_VARS_COOKIE,
|
TRACK_VARS_COOKIE,
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "php.h"
|
#include "php.h"
|
||||||
|
|
||||||
#include "ext/standard/info.h"
|
#include "ext/standard/info.h"
|
||||||
|
#include "ext/standard/file.h"
|
||||||
#include "zend_exceptions.h"
|
#include "zend_exceptions.h"
|
||||||
#include "zend_inheritance.h"
|
#include "zend_inheritance.h"
|
||||||
#include "zend_interfaces.h"
|
#include "zend_interfaces.h"
|
||||||
|
@ -12,6 +12,7 @@ use crate::ffi::{
|
|||||||
ext_php_rs_sapi_globals, php_core_globals, sapi_globals_struct, sapi_header_struct,
|
ext_php_rs_sapi_globals, php_core_globals, sapi_globals_struct, sapi_header_struct,
|
||||||
sapi_headers_struct, sapi_request_info, zend_is_auto_global, TRACK_VARS_COOKIE, TRACK_VARS_ENV,
|
sapi_headers_struct, sapi_request_info, zend_is_auto_global, TRACK_VARS_COOKIE, TRACK_VARS_ENV,
|
||||||
TRACK_VARS_FILES, TRACK_VARS_GET, TRACK_VARS_POST, TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
|
TRACK_VARS_FILES, TRACK_VARS_GET, TRACK_VARS_POST, TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
|
||||||
|
php_file_globals, file_globals
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::types::{ZendHashTable, ZendObject, ZendStr};
|
use crate::types::{ZendHashTable, ZendObject, ZendStr};
|
||||||
@ -358,6 +359,45 @@ impl SapiRequestInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Stores global variables used in the SAPI.
|
||||||
|
pub type FileGlobals = php_file_globals;
|
||||||
|
|
||||||
|
impl FileGlobals {
|
||||||
|
/// Returns a reference to the PHP process globals.
|
||||||
|
///
|
||||||
|
/// The process globals are guarded by a RwLock. There can be multiple
|
||||||
|
/// immutable references at one time but only ever one mutable reference.
|
||||||
|
/// Attempting to retrieve the globals while already holding the global
|
||||||
|
/// guard will lead to a deadlock. Dropping the globals guard will release
|
||||||
|
/// the lock.
|
||||||
|
pub fn get() -> GlobalReadGuard<Self> {
|
||||||
|
// SAFETY: PHP executor globals are statically declared therefore should never
|
||||||
|
// return an invalid pointer.
|
||||||
|
let globals = unsafe { &file_globals };
|
||||||
|
let guard = FILE_GLOBALS_LOCK.read();
|
||||||
|
GlobalReadGuard { globals, guard }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a mutable reference to the PHP executor globals.
|
||||||
|
///
|
||||||
|
/// The executor globals are guarded by a RwLock. There can be multiple
|
||||||
|
/// immutable references at one time but only ever one mutable reference.
|
||||||
|
/// Attempting to retrieve the globals while already holding the global
|
||||||
|
/// guard will lead to a deadlock. Dropping the globals guard will release
|
||||||
|
/// the lock.
|
||||||
|
pub fn get_mut() -> GlobalWriteGuard<Self> {
|
||||||
|
// SAFETY: PHP executor globals are statically declared therefore should never
|
||||||
|
// return an invalid pointer.
|
||||||
|
let globals = unsafe { &mut file_globals };
|
||||||
|
let guard = SAPI_GLOBALS_LOCK.write();
|
||||||
|
GlobalWriteGuard { globals, guard }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stream_wrappers(&self) -> Option<&'static ZendHashTable> {
|
||||||
|
unsafe { self.stream_wrappers.as_ref() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Executor globals rwlock.
|
/// Executor globals rwlock.
|
||||||
///
|
///
|
||||||
/// PHP provides no indication if the executor globals are being accessed so
|
/// PHP provides no indication if the executor globals are being accessed so
|
||||||
@ -365,6 +405,7 @@ impl SapiRequestInfo {
|
|||||||
static GLOBALS_LOCK: RwLock<()> = const_rwlock(());
|
static GLOBALS_LOCK: RwLock<()> = const_rwlock(());
|
||||||
static PROCESS_GLOBALS_LOCK: RwLock<()> = const_rwlock(());
|
static PROCESS_GLOBALS_LOCK: RwLock<()> = const_rwlock(());
|
||||||
static SAPI_GLOBALS_LOCK: RwLock<()> = const_rwlock(());
|
static SAPI_GLOBALS_LOCK: RwLock<()> = const_rwlock(());
|
||||||
|
static FILE_GLOBALS_LOCK: RwLock<()> = const_rwlock(());
|
||||||
|
|
||||||
/// Wrapper guard that contains a reference to a given type `T`. Dropping a
|
/// Wrapper guard that contains a reference to a given type `T`. Dropping a
|
||||||
/// guard releases the lock on the relevant rwlock.
|
/// guard releases the lock on the relevant rwlock.
|
||||||
|
@ -20,6 +20,7 @@ pub use function::FunctionEntry;
|
|||||||
pub use globals::ExecutorGlobals;
|
pub use globals::ExecutorGlobals;
|
||||||
pub use globals::ProcessGlobals;
|
pub use globals::ProcessGlobals;
|
||||||
pub use globals::SapiGlobals;
|
pub use globals::SapiGlobals;
|
||||||
|
pub use globals::FileGlobals;
|
||||||
pub use handlers::ZendObjectHandlers;
|
pub use handlers::ZendObjectHandlers;
|
||||||
pub use linked_list::ZendLinkedList;
|
pub use linked_list::ZendLinkedList;
|
||||||
pub use module::ModuleEntry;
|
pub use module::ModuleEntry;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user