Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function for requesting VM interrupt #257

Merged
merged 5 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion allowed_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions docsrs_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsafe extern "C" fn(execute_data: *mut zend_execute_data)>;
}
extern "C" {
pub static mut zend_standard_class_def: *mut zend_class_entry;
}
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/builders/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion src/zend/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down