diff --git a/allowed_bindings.rs b/allowed_bindings.rs index b1e2748fbc..0cd8270c13 100644 --- a/allowed_bindings.rs +++ b/allowed_bindings.rs @@ -243,5 +243,7 @@ bind! { php_printf, __zend_malloc, tsrm_get_ls_cache, - executor_globals_offset + executor_globals_offset, + zend_atomic_bool_store, + zend_interrupt_function } diff --git a/docsrs_bindings.rs b/docsrs_bindings.rs index 1888949c30..a7cc5a163a 100644 --- a/docsrs_bindings.rs +++ b/docsrs_bindings.rs @@ -670,6 +670,10 @@ pub struct _zend_class_entry__bindgen_ty_4__bindgen_ty_2 { pub builtin_functions: *const _zend_function_entry, pub module: *mut _zend_module_entry, } +extern "C" { + pub static mut zend_interrupt_function: + ::std::option::Option; +} extern "C" { pub static mut zend_standard_class_def: *mut zend_class_entry; } @@ -1053,6 +1057,9 @@ pub struct zend_atomic_bool_s { pub value: u8, } pub type zend_atomic_bool = zend_atomic_bool_s; +extern "C" { + pub fn zend_atomic_bool_store(obj: *mut zend_atomic_bool, desired: bool); +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct _zend_stack { diff --git a/src/builders/module.rs b/src/builders/module.rs index 01bc9e4eb8..ee2b219fdd 100644 --- a/src/builders/module.rs +++ b/src/builders/module.rs @@ -131,7 +131,8 @@ impl ModuleBuilder { /// This function can be useful if you need to do any final cleanup at the /// very end of a request, after all other resources have been released. For /// example, if your extension creates any persistent resources that last - /// beyond a single request, you could use this function to clean those up. # Arguments + /// beyond a single request, you could use this function to clean those up. + /// # Arguments /// /// * `func` - The function to be called when shutdown is requested. pub fn post_deactivate_function(mut self, func: extern "C" fn() -> i32) -> Self { diff --git a/src/zend/globals.rs b/src/zend/globals.rs index 0f2cae8e55..c9a7a0d91c 100644 --- a/src/zend/globals.rs +++ b/src/zend/globals.rs @@ -5,8 +5,9 @@ use std::ops::{Deref, DerefMut}; use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::boxed::ZBox; +#[cfg(php82)] +use crate::ffi::zend_atomic_bool_store; use crate::ffi::{_zend_executor_globals, ext_php_rs_executor_globals}; - use crate::types::{ZendHashTable, ZendObject}; /// Stores global variables used in the PHP executor. @@ -70,6 +71,21 @@ impl ExecutorGlobals { // SAFETY: `as_mut` checks for null. Some(unsafe { ZBox::from_raw(exception_ptr.as_mut()?) }) } + + /// Request an interrupt of the PHP VM. This will call the registered + /// interrupt handler function. + /// set with [`crate::ffi::zend_interrupt_function`]. + pub fn request_interrupt(&mut self) { + cfg_if::cfg_if! { + if #[cfg(php82)] { + unsafe { + zend_atomic_bool_store(&mut self.vm_interrupt, true); + } + } else { + self.vm_interrupt = true; + } + } + } } /// Executor globals rwlock.