Skip to content

Commit 3e378f8

Browse files
authored
Add function for requesting VM interrupt (#257)
1 parent 7b35476 commit 3e378f8

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

allowed_bindings.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,7 @@ bind! {
243243
php_printf,
244244
__zend_malloc,
245245
tsrm_get_ls_cache,
246-
executor_globals_offset
246+
executor_globals_offset,
247+
zend_atomic_bool_store,
248+
zend_interrupt_function
247249
}

docsrs_bindings.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ pub struct _zend_class_entry__bindgen_ty_4__bindgen_ty_2 {
670670
pub builtin_functions: *const _zend_function_entry,
671671
pub module: *mut _zend_module_entry,
672672
}
673+
extern "C" {
674+
pub static mut zend_interrupt_function:
675+
::std::option::Option<unsafe extern "C" fn(execute_data: *mut zend_execute_data)>;
676+
}
673677
extern "C" {
674678
pub static mut zend_standard_class_def: *mut zend_class_entry;
675679
}
@@ -1053,6 +1057,9 @@ pub struct zend_atomic_bool_s {
10531057
pub value: u8,
10541058
}
10551059
pub type zend_atomic_bool = zend_atomic_bool_s;
1060+
extern "C" {
1061+
pub fn zend_atomic_bool_store(obj: *mut zend_atomic_bool, desired: bool);
1062+
}
10561063
#[repr(C)]
10571064
#[derive(Debug, Copy, Clone)]
10581065
pub struct _zend_stack {

src/zend/globals.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use std::ops::{Deref, DerefMut};
55
use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard};
66

77
use crate::boxed::ZBox;
8+
#[cfg(php82)]
9+
use crate::ffi::zend_atomic_bool_store;
810
use crate::ffi::{_zend_executor_globals, ext_php_rs_executor_globals};
9-
1011
use crate::types::{ZendHashTable, ZendObject};
1112

1213
/// Stores global variables used in the PHP executor.
@@ -70,6 +71,21 @@ impl ExecutorGlobals {
7071
// SAFETY: `as_mut` checks for null.
7172
Some(unsafe { ZBox::from_raw(exception_ptr.as_mut()?) })
7273
}
74+
75+
/// Request an interrupt of the PHP VM. This will call the registered
76+
/// interrupt handler function.
77+
/// set with [`crate::ffi::zend_interrupt_function`].
78+
pub fn request_interrupt(&mut self) {
79+
cfg_if::cfg_if! {
80+
if #[cfg(php82)] {
81+
unsafe {
82+
zend_atomic_bool_store(&mut self.vm_interrupt, true);
83+
}
84+
} else {
85+
self.vm_interrupt = true;
86+
}
87+
}
88+
}
7389
}
7490

7591
/// Executor globals rwlock.

0 commit comments

Comments
 (0)