mirror of
https://github.com/danog/ext-php-rs.git
synced 2024-11-26 20:15:22 +01:00
Add function for requesting VM interrupt (#257)
This commit is contained in:
parent
7b35476d04
commit
3e378f8cdf
@ -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
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
@ -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 {
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user