Skip to content

Rename zend_instrument -> zend_instrument_fcall #3

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

Merged
merged 1 commit into from
May 3, 2020
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
8 changes: 4 additions & 4 deletions Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ static int zend_create_closure_from_callable(zval *return_value, zval *callable,
call.scope = mptr->common.scope;

// TODO: Is this correct???
static const zend_instrument_cache *dummy_handlers = ZEND_NOT_INSTRUMENTED;
ZEND_MAP_PTR_INIT(call.instrument_cache, (zend_instrument_cache **) &dummy_handlers);
static const zend_instrument_fcall_cache *dummy_handlers = ZEND_INSTRUMENT_FCALL_NOT_INSTRUMENTED;
ZEND_MAP_PTR_INIT(call.instrument_cache, (zend_instrument_fcall_cache **) &dummy_handlers);

zend_free_trampoline(mptr);
mptr = (zend_function *) &call;
Expand Down Expand Up @@ -401,8 +401,8 @@ ZEND_API zend_function *zend_get_closure_invoke_method(zend_object *object) /* {
invoke->internal_function.function_name = ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE);

// TODO: Is this correct???
static const zend_instrument_cache *dummy_handler = ZEND_NOT_INSTRUMENTED;
ZEND_MAP_PTR_INIT(invoke->internal_function.instrument_cache, (zend_instrument_cache **) &dummy_handler);
static const zend_instrument_fcall_cache *dummy_handler = ZEND_INSTRUMENT_FCALL_NOT_INSTRUMENTED;
ZEND_MAP_PTR_INIT(invoke->internal_function.instrument_cache, (zend_instrument_fcall_cache **) &dummy_handler);
return invoke;
}
/* }}} */
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ struct _zend_op_array {
uint32_t num_args;
uint32_t required_num_args;
zend_arg_info *arg_info;
ZEND_MAP_PTR_DEF(struct zend_instrument_cache *, instrument_cache);
ZEND_MAP_PTR_DEF(struct zend_instrument_fcall_cache *, instrument_cache);
/* END of common elements */

int cache_size; /* number of run_time_cache_slots * sizeof(void*) */
Expand Down Expand Up @@ -453,7 +453,7 @@ typedef struct _zend_internal_function {
uint32_t num_args;
uint32_t required_num_args;
zend_internal_arg_info *arg_info;
ZEND_MAP_PTR_DEF(struct zend_instrument_cache *, instrument_cache);
ZEND_MAP_PTR_DEF(struct zend_instrument_fcall_cache *, instrument_cache);
/* END of common elements */

zif_handler handler;
Expand All @@ -477,7 +477,7 @@ union _zend_function {
uint32_t num_args;
uint32_t required_num_args;
zend_arg_info *arg_info; /* index -1 represents the return value info, if any */
ZEND_MAP_PTR_DEF(struct zend_instrument_cache *, instrument_cache);
ZEND_MAP_PTR_DEF(struct zend_instrument_fcall_cache *, instrument_cache);
} common;

zend_op_array op_array;
Expand Down
16 changes: 8 additions & 8 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,7 @@ ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name) /*
init_func_run_time_cache_i(&fbc->op_array);
}
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
zend_instrument_install_handlers(fbc);
zend_instrument_fcall_install(fbc);
}
return fbc;
}
Expand All @@ -3521,7 +3521,7 @@ ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function_str(const char *name,
init_func_run_time_cache_i(&fbc->op_array);
}
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
zend_instrument_install_handlers(fbc);
zend_instrument_fcall_install(fbc);
}
return fbc;
}
Expand Down Expand Up @@ -3559,7 +3559,7 @@ static zend_always_inline void i_init_code_execute_data(zend_execute_data *execu
ZEND_MAP_PTR_INIT(op_array->instrument_cache,
zend_arena_alloc(&CG(arena), sizeof(void*)));
ZEND_MAP_PTR_SET(op_array->instrument_cache, NULL);
zend_instrument_install_handlers((zend_function *) op_array);
zend_instrument_fcall_install((zend_function *)op_array);
}
EX(run_time_cache) = RUN_TIME_CACHE(op_array);

Expand All @@ -3586,7 +3586,7 @@ ZEND_API void zend_init_func_execute_data(zend_execute_data *ex, zend_op_array *
init_func_run_time_cache(op_array);
}
if (UNEXPECTED(!ZEND_MAP_PTR_GET(op_array->instrument_cache))) {
zend_instrument_install_handlers((zend_function *) op_array);
zend_instrument_fcall_install((zend_function *)op_array);
}
i_init_func_execute_data(op_array, return_value, 1 EXECUTE_DATA_CC);

Expand Down Expand Up @@ -3940,7 +3940,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
init_func_run_time_cache(&fbc->op_array);
}
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
zend_instrument_install_handlers(fbc);
zend_instrument_fcall_install(fbc);
}
} else {
if (ZSTR_VAL(function)[0] == '\\') {
Expand All @@ -3961,7 +3961,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
init_func_run_time_cache(&fbc->op_array);
}
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
zend_instrument_install_handlers(fbc);
zend_instrument_fcall_install(fbc);
}
called_scope = NULL;
}
Expand Down Expand Up @@ -4008,7 +4008,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zend_o
init_func_run_time_cache(&fbc->op_array);
}
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
zend_instrument_install_handlers(fbc);
zend_instrument_fcall_install(fbc);
}

return zend_vm_stack_push_call_frame(call_info,
Expand Down Expand Up @@ -4096,7 +4096,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_ar
init_func_run_time_cache(&fbc->op_array);
}
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
zend_instrument_install_handlers(fbc);
zend_instrument_fcall_install(fbc);
}

return zend_vm_stack_push_call_frame(call_info,
Expand Down
11 changes: 5 additions & 6 deletions Zend/zend_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ ZEND_API void zend_init_code_execute_data(zend_execute_data *execute_data, zend_
ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value);
ZEND_API void execute_ex(zend_execute_data *execute_data);

ZEND_API inline void execute_internal(zend_execute_data *execute_data, zval *return_value)
{
zend_instrument_cache *cache = (zend_instrument_cache *)
ZEND_API inline void execute_internal(zend_execute_data *execute_data, zval *return_value) {
zend_instrument_fcall_cache *cache = (zend_instrument_fcall_cache *)
ZEND_MAP_PTR_GET(execute_data->func->common.instrument_cache);
if (UNEXPECTED(cache != ZEND_NOT_INSTRUMENTED)) {
zend_instrument_call_begin_handlers(execute_data, cache);
if (UNEXPECTED(cache != ZEND_INSTRUMENT_FCALL_NOT_INSTRUMENTED)) {
zend_instrument_fcall_call_begin(cache, execute_data);
execute_data->func->internal_function.handler(execute_data, return_value);
zend_instrument_call_end_handlers(execute_data, cache);
zend_instrument_fcall_call_end(cache, execute_data, return_value);
} else {
execute_data->func->internal_function.handler(execute_data, return_value);
}
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,9 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
const zend_op *current_opline_before_exception = EG(opline_before_exception);

zend_init_func_execute_data(call, &func->op_array, fci->retval);
zend_instrument_cache *cache = ZEND_MAP_PTR_GET(func->common.instrument_cache);
if (cache != ZEND_NOT_INSTRUMENTED) {
zend_instrument_call_begin_handlers(call, cache);
zend_instrument_fcall_cache *cache = ZEND_MAP_PTR_GET(func->common.instrument_cache);
if (cache != ZEND_INSTRUMENT_FCALL_NOT_INSTRUMENTED) {
zend_instrument_fcall_call_begin(cache, call);
}
zend_execute_ex(call);
EG(opline_before_exception) = current_opline_before_exception;
Expand All @@ -815,7 +815,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
ZEND_ASSERT(func->type == ZEND_INTERNAL_FUNCTION);

if (UNEXPECTED(!ZEND_MAP_PTR_GET(func->common.instrument_cache))) {
zend_instrument_install_handlers(func);
zend_instrument_fcall_install(func);
}

ZVAL_NULL(fci->retval);
Expand Down
104 changes: 53 additions & 51 deletions Zend/zend_instrument.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,59 +21,61 @@
#include "zend_API.h"
#include "zend_instrument.h"

struct zend_instruments_list {
struct zend_instruments_list *prev;
zend_instrument instrument;
struct zend_instrument_fcall_init_list {
struct zend_instrument_fcall_init_list *prev;
zend_instrument_fcall_init instrument;
};
typedef struct zend_instruments_list zend_instruments_list;
typedef struct zend_instrument_fcall_init_list zend_instrument_fcall_init_list;

static zend_instruments_list *_zend_instruments;
static zend_instrument_fcall_init_list *zend_instrument_fcalls;

ZEND_API void zend_instrument_init(void)
{
_zend_instruments = NULL;
ZEND_API void zend_instrument_init(void) {
zend_instrument_fcalls = NULL;
}

ZEND_API void zend_instrument_shutdown(void)
{
zend_instruments_list *curr, *prev;
for (curr = _zend_instruments; curr; curr = prev) {
ZEND_API void zend_instrument_shutdown(void) {
zend_instrument_fcall_init_list *curr, *prev;
for (curr = zend_instrument_fcalls; curr; curr = prev) {
prev = curr->prev;
free(curr);
}
}

ZEND_API void zend_instrument_register(zend_instrument instrument)
{
zend_instruments_list *node = malloc(sizeof(zend_instruments_list));
node->instrument = instrument;
node->prev = _zend_instruments;
_zend_instruments = node;
ZEND_API void zend_instrument_fcall_register(zend_instrument_fcall_init cb) {
zend_instrument_fcall_init_list *node =
malloc(sizeof(zend_instrument_fcall_init_list));
node->instrument = cb;
node->prev = zend_instrument_fcalls;
zend_instrument_fcalls = node;
}

struct zend_instrument_handlers_list {
struct zend_instrument_handlers_list *prev;
zend_instrument_handlers handlers;
struct zend_instrument_fcall_list {
struct zend_instrument_fcall_list *prev;
zend_instrument_fcall handlers;
size_t count;
};
typedef struct zend_instrument_handlers_list zend_instrument_handlers_list;
typedef struct zend_instrument_fcall_list zend_instrument_fcall_list;


extern inline void zend_instrument_call_begin_handlers(
zend_execute_data *execute_data, zend_instrument_cache *cache);
extern inline void zend_instrument_call_end_handlers(
zend_execute_data *execute_data, zend_instrument_cache *cache);
extern inline void zend_instrument_fcall_call_begin(
zend_instrument_fcall_cache *cache,
zend_execute_data *execute_data);

static zend_instrument_handlers_list *_instrument_add(
zend_instrument_handlers_list *instruments,
zend_instrument_handlers handlers)
extern inline void zend_instrument_fcall_call_end(
zend_instrument_fcall_cache *cache,
zend_execute_data *execute_data,
zval *return_value);

static zend_instrument_fcall_list *zend_instrument_fcall_add(
zend_instrument_fcall_list *instruments,
zend_instrument_fcall handlers)
{
if (!handlers.begin && !handlers.end) {
return instruments;
}

zend_instrument_handlers_list *n =
emalloc(sizeof(zend_instrument_handlers_list));
zend_instrument_fcall_list *n =
emalloc(sizeof(zend_instrument_fcall_list));
if (instruments) {
n->prev = instruments;
n->count = instruments->count + 1;
Expand All @@ -85,18 +87,18 @@ static zend_instrument_handlers_list *_instrument_add(
return n;
}

static zend_instrument_cache *_instrument_attach_handler(
static zend_instrument_fcall_cache *zend_instrument_fcall_list_attach(
zend_function *function,
zend_instrument_handlers_list *handlers_list)
zend_instrument_fcall_list *handlers_list)
{
zend_instrument_cache *cache =
malloc(sizeof(zend_instrument_cache));
zend_instrument_fcall_cache *cache =
malloc(sizeof(zend_instrument_fcall_cache));
cache->instruments_len = handlers_list->count;
cache->handlers =
calloc(handlers_list->count, sizeof(zend_instrument_handlers));
calloc(handlers_list->count, sizeof(zend_instrument_fcall));

zend_instrument_handlers *handlers = cache->handlers;
zend_instrument_handlers_list *curr;
zend_instrument_fcall *handlers = cache->handlers;
zend_instrument_fcall_list *curr;
for (curr = handlers_list; curr; curr = curr->prev) {
*handlers++ = curr->handlers;
}
Expand All @@ -106,26 +108,26 @@ static zend_instrument_cache *_instrument_attach_handler(
return cache;
}

ZEND_API void zend_instrument_install_handlers(zend_function *function)
{
zend_instrument_handlers_list *handlers_list = NULL;
zend_instruments_list *elem;
ZEND_API void zend_instrument_fcall_install(zend_function *function) {
zend_instrument_fcall_list *fcall_list = NULL;
zend_instrument_fcall_init_list *elem;

for (elem = _zend_instruments; elem; elem = elem->prev) {
zend_instrument_handlers handlers = elem->instrument(function);
handlers_list = _instrument_add(handlers_list, handlers);
for (elem = zend_instrument_fcalls; elem; elem = elem->prev) {
zend_instrument_fcall handlers = elem->instrument(function);
fcall_list = zend_instrument_fcall_add(fcall_list, handlers);
}

if (handlers_list) {
_instrument_attach_handler(function, handlers_list);
if (fcall_list) {
zend_instrument_fcall_list_attach(function, fcall_list);

// cleanup handlers_list
zend_instrument_handlers_list *curr, *prev;
for (curr = handlers_list; curr; curr = prev) {
// cleanup fcall_list
zend_instrument_fcall_list *curr, *prev;
for (curr = fcall_list; curr; curr = prev) {
prev = curr->prev;
efree(curr);
}
} else {
ZEND_MAP_PTR_SET(function->common.instrument_cache, ZEND_NOT_INSTRUMENTED);
ZEND_MAP_PTR_SET(function->common.instrument_cache,
ZEND_INSTRUMENT_FCALL_NOT_INSTRUMENTED);
}
}
Loading