Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <Zend/zend_extensions.h>
ZEND_API zend_extension_version_info extension_version_info = {ZEND_EXTENSION_API_NO, ZEND_EXTENSION_BUILD_ID};
typedef struct _op_array_ext_info {
uintptr_t hits;
} op_array_ext_info;
static int op_array_extension = 0;
static zend_arena *op_array_arena;
static int op_array_ext_startup(zend_extension *ext) {
op_array_extension = zend_get_op_array_extension_handle("op_array_ext");
op_array_arena = zend_arena_create(4096);
return SUCCESS;
}
static void op_array_ext_shutdown(zend_extension *ext) {
zend_arena_destroy(op_array_arena);
}
static void op_array_ext_activate(void) {
CG(compiler_options) |= ZEND_COMPILE_EXTENDED_FCALL;
}
static void op_array_ext_startup_fcall_begin_handler(zend_execute_data *ex) {
if (!(ex && ex->call))
return;
const zend_function * const func = ex->call->func;
if (!func)
return;
printf("function %s", ZSTR_VAL(func->common.function_name));
if (func->type == ZEND_USER_FUNCTION && !(func->op_array.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
op_array_ext_info *info = ZEND_OP_ARRAY_EXTENSION(&func->op_array, op_array_extension);
if (!info)
ZEND_OP_ARRAY_EXTENSION(&func->op_array, op_array_extension) = info = zend_arena_calloc(&op_array_arena, 1, sizeof(op_array_ext_info));
printf("@%lu", info->hits++);
}
printf("\n");
}
ZEND_API zend_extension zend_extension_entry = {
"op_array_ext", "0.1.0", "", "", "",
op_array_ext_startup, op_array_ext_shutdown,
op_array_ext_activate, NULL,
NULL,
NULL,
NULL,
op_array_ext_startup_fcall_begin_handler,
NULL,
NULL,
NULL,
STANDARD_ZEND_EXTENSION_PROPERTIES
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment