Skip to content

Commit 6501082

Browse files
committed
Merge branch 'master' into process-globals
2 parents e30f127 + 42ef04a commit 6501082

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

allowed_bindings.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ bind! {
217217
_ZEND_TYPE_NULLABLE_BIT,
218218
ts_rsrc_id,
219219
_ZEND_TYPE_NAME_BIT,
220+
ZEND_INTERNAL_FUNCTION,
221+
ZEND_USER_FUNCTION,
222+
ZEND_EVAL_CODE,
220223
zval_ptr_dtor,
221224
zend_refcounted_h,
222225
zend_is_true,
@@ -264,5 +267,7 @@ bind! {
264267
sapi_header_struct,
265268
zend_is_auto_global,
266269
zend_llist_get_next_ex,
267-
zend_llist_get_prev_ex
270+
zend_llist_get_prev_ex,
271+
zend_atomic_bool_store,
272+
zend_interrupt_function
268273
}

docsrs_bindings.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ pub const ZEND_ACC_GENERATOR: u32 = 16777216;
171171
pub const ZEND_ACC_DONE_PASS_TWO: u32 = 33554432;
172172
pub const ZEND_ACC_HEAP_RT_CACHE: u32 = 67108864;
173173
pub const ZEND_ACC_STRICT_TYPES: u32 = 2147483648;
174+
pub const ZEND_INTERNAL_FUNCTION: u32 = 1;
175+
pub const ZEND_USER_FUNCTION: u32 = 2;
176+
pub const ZEND_EVAL_CODE: u32 = 4;
174177
pub const ZEND_ISEMPTY: u32 = 1;
175178
pub const _ZEND_SEND_MODE_SHIFT: u32 = 25;
176179
pub const _ZEND_IS_VARIADIC_BIT: u32 = 134217728;
@@ -901,6 +904,10 @@ pub struct _zend_class_entry__bindgen_ty_4__bindgen_ty_2 {
901904
pub builtin_functions: *const _zend_function_entry,
902905
pub module: *mut _zend_module_entry,
903906
}
907+
extern "C" {
908+
pub static mut zend_interrupt_function:
909+
::std::option::Option<unsafe extern "C" fn(execute_data: *mut zend_execute_data)>;
910+
}
904911
extern "C" {
905912
pub static mut zend_standard_class_def: *mut zend_class_entry;
906913
}
@@ -1284,6 +1291,9 @@ pub struct zend_atomic_bool_s {
12841291
pub value: u8,
12851292
}
12861293
pub type zend_atomic_bool = zend_atomic_bool_s;
1294+
extern "C" {
1295+
pub fn zend_atomic_bool_store(obj: *mut zend_atomic_bool, desired: bool);
1296+
}
12871297
#[repr(C)]
12881298
#[derive(Debug, Copy, Clone)]
12891299
pub struct _zend_stack {

src/convert.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,13 @@ impl<T: IntoZval + Clone> IntoZvalDyn for T {
218218
Self::TYPE
219219
}
220220
}
221+
222+
impl IntoZvalDyn for Zval {
223+
fn as_zval(&self, _persistent: bool) -> Result<Zval> {
224+
Ok(self.shallow_clone())
225+
}
226+
227+
fn get_type(&self) -> DataType {
228+
self.get_type()
229+
}
230+
}

src/flags.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ use crate::ffi::{
2020
ZEND_ACC_PROMOTED, ZEND_ACC_PROTECTED, ZEND_ACC_PUBLIC, ZEND_ACC_RESOLVED_INTERFACES,
2121
ZEND_ACC_RESOLVED_PARENT, ZEND_ACC_RETURN_REFERENCE, ZEND_ACC_STATIC, ZEND_ACC_STRICT_TYPES,
2222
ZEND_ACC_TOP_LEVEL, ZEND_ACC_TRAIT, ZEND_ACC_TRAIT_CLONE, ZEND_ACC_UNRESOLVED_VARIANCE,
23-
ZEND_ACC_USES_THIS, ZEND_ACC_USE_GUARDS, ZEND_ACC_VARIADIC, ZEND_HAS_STATIC_IN_METHODS,
24-
Z_TYPE_FLAGS_SHIFT, _IS_BOOL,
23+
ZEND_ACC_USES_THIS, ZEND_ACC_USE_GUARDS, ZEND_ACC_VARIADIC, ZEND_EVAL_CODE,
24+
ZEND_HAS_STATIC_IN_METHODS, ZEND_INTERNAL_FUNCTION, ZEND_USER_FUNCTION, Z_TYPE_FLAGS_SHIFT,
25+
_IS_BOOL,
2526
};
2627

2728
use std::{convert::TryFrom, fmt::Display};
@@ -193,6 +194,24 @@ bitflags! {
193194
const UserDeprecated = E_USER_DEPRECATED;
194195
}
195196
}
197+
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
198+
pub enum FunctionType {
199+
Internal,
200+
User,
201+
Eval,
202+
}
203+
204+
impl From<u8> for FunctionType {
205+
#[allow(clippy::bad_bit_mask)]
206+
fn from(value: u8) -> Self {
207+
match value as _ {
208+
ZEND_INTERNAL_FUNCTION => Self::Internal,
209+
ZEND_USER_FUNCTION => Self::User,
210+
ZEND_EVAL_CODE => Self::Eval,
211+
_ => panic!("Unknown function type: {}", value),
212+
}
213+
}
214+
}
196215

197216
/// Valid data types for PHP.
198217
#[repr(C, u8)]

src/zend/class.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ impl ClassEntry {
7979
Self::try_find(name.as_str().ok()?)
8080
}
8181
}
82+
83+
pub fn name(&self) -> Option<&str> {
84+
unsafe { self.name.as_ref().and_then(|s| s.as_str().ok()) }
85+
}
8286
}
8387

8488
impl PartialEq for ClassEntry {

src/zend/globals.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::str;
77
use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard};
88

99
use crate::boxed::ZBox;
10+
#[cfg(php82)]
11+
use crate::ffi::zend_atomic_bool_store;
1012
use crate::ffi::{
1113
_zend_executor_globals, ext_php_rs_executor_globals, ext_php_rs_file_globals,
1214
ext_php_rs_process_globals, ext_php_rs_sapi_globals, php_core_globals, php_file_globals,
@@ -80,6 +82,21 @@ impl ExecutorGlobals {
8082
// SAFETY: `as_mut` checks for null.
8183
Some(unsafe { ZBox::from_raw(exception_ptr.as_mut()?) })
8284
}
85+
86+
/// Request an interrupt of the PHP VM. This will call the registered
87+
/// interrupt handler function.
88+
/// set with [`crate::ffi::zend_interrupt_function`].
89+
pub fn request_interrupt(&mut self) {
90+
cfg_if::cfg_if! {
91+
if #[cfg(php82)] {
92+
unsafe {
93+
zend_atomic_bool_store(&mut self.vm_interrupt, true);
94+
}
95+
} else {
96+
self.vm_interrupt = true;
97+
}
98+
}
99+
}
83100
}
84101

85102
/// Stores global variables used in the PHP executor.

0 commit comments

Comments
 (0)