Skip to content

Commit 57b4289

Browse files
morrisonleviSammyK
authored andcommitted
Rename zend_instrument -> zend_instrument_fcall
This leaves room for other types of instruments in the future. Also passes the return_value into the end handler, or an undef one in the case of an exception.
1 parent f9c98d6 commit 57b4289

10 files changed

+250
-224
lines changed

Zend/zend_closures.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ static int zend_create_closure_from_callable(zval *return_value, zval *callable,
310310
call.scope = mptr->common.scope;
311311

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

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

403403
// TODO: Is this correct???
404-
static const zend_instrument_cache *dummy_handler = ZEND_NOT_INSTRUMENTED;
405-
ZEND_MAP_PTR_INIT(invoke->internal_function.instrument_cache, (zend_instrument_cache **) &dummy_handler);
404+
static const zend_instrument_fcall_cache *dummy_handler = ZEND_INSTRUMENT_FCALL_NOT_INSTRUMENTED;
405+
ZEND_MAP_PTR_INIT(invoke->internal_function.instrument_cache, (zend_instrument_fcall_cache **) &dummy_handler);
406406
return invoke;
407407
}
408408
/* }}} */

Zend/zend_compile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ struct _zend_op_array {
403403
uint32_t num_args;
404404
uint32_t required_num_args;
405405
zend_arg_info *arg_info;
406-
ZEND_MAP_PTR_DEF(struct zend_instrument_cache *, instrument_cache);
406+
ZEND_MAP_PTR_DEF(struct zend_instrument_fcall_cache *, instrument_cache);
407407
/* END of common elements */
408408

409409
int cache_size; /* number of run_time_cache_slots * sizeof(void*) */
@@ -453,7 +453,7 @@ typedef struct _zend_internal_function {
453453
uint32_t num_args;
454454
uint32_t required_num_args;
455455
zend_internal_arg_info *arg_info;
456-
ZEND_MAP_PTR_DEF(struct zend_instrument_cache *, instrument_cache);
456+
ZEND_MAP_PTR_DEF(struct zend_instrument_fcall_cache *, instrument_cache);
457457
/* END of common elements */
458458

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

483483
zend_op_array op_array;

Zend/zend_execute.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,7 +3503,7 @@ ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name) /*
35033503
init_func_run_time_cache_i(&fbc->op_array);
35043504
}
35053505
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
3506-
zend_instrument_install_handlers(fbc);
3506+
zend_instrument_fcall_install(fbc);
35073507
}
35083508
return fbc;
35093509
}
@@ -3521,7 +3521,7 @@ ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function_str(const char *name,
35213521
init_func_run_time_cache_i(&fbc->op_array);
35223522
}
35233523
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
3524-
zend_instrument_install_handlers(fbc);
3524+
zend_instrument_fcall_install(fbc);
35253525
}
35263526
return fbc;
35273527
}
@@ -3559,7 +3559,7 @@ static zend_always_inline void i_init_code_execute_data(zend_execute_data *execu
35593559
ZEND_MAP_PTR_INIT(op_array->instrument_cache,
35603560
zend_arena_alloc(&CG(arena), sizeof(void*)));
35613561
ZEND_MAP_PTR_SET(op_array->instrument_cache, NULL);
3562-
zend_instrument_install_handlers((zend_function *) op_array);
3562+
zend_instrument_fcall_install((zend_function *)op_array);
35633563
}
35643564
EX(run_time_cache) = RUN_TIME_CACHE(op_array);
35653565

@@ -3586,7 +3586,7 @@ ZEND_API void zend_init_func_execute_data(zend_execute_data *ex, zend_op_array *
35863586
init_func_run_time_cache(op_array);
35873587
}
35883588
if (UNEXPECTED(!ZEND_MAP_PTR_GET(op_array->instrument_cache))) {
3589-
zend_instrument_install_handlers((zend_function *) op_array);
3589+
zend_instrument_fcall_install((zend_function *)op_array);
35903590
}
35913591
i_init_func_execute_data(op_array, return_value, 1 EXECUTE_DATA_CC);
35923592

@@ -3940,7 +3940,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
39403940
init_func_run_time_cache(&fbc->op_array);
39413941
}
39423942
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
3943-
zend_instrument_install_handlers(fbc);
3943+
zend_instrument_fcall_install(fbc);
39443944
}
39453945
} else {
39463946
if (ZSTR_VAL(function)[0] == '\\') {
@@ -3961,7 +3961,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
39613961
init_func_run_time_cache(&fbc->op_array);
39623962
}
39633963
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
3964-
zend_instrument_install_handlers(fbc);
3964+
zend_instrument_fcall_install(fbc);
39653965
}
39663966
called_scope = NULL;
39673967
}
@@ -4008,7 +4008,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zend_o
40084008
init_func_run_time_cache(&fbc->op_array);
40094009
}
40104010
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
4011-
zend_instrument_install_handlers(fbc);
4011+
zend_instrument_fcall_install(fbc);
40124012
}
40134013

40144014
return zend_vm_stack_push_call_frame(call_info,
@@ -4096,7 +4096,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_ar
40964096
init_func_run_time_cache(&fbc->op_array);
40974097
}
40984098
if (UNEXPECTED(!ZEND_MAP_PTR_GET(fbc->common.instrument_cache))) {
4099-
zend_instrument_install_handlers(fbc);
4099+
zend_instrument_fcall_install(fbc);
41004100
}
41014101

41024102
return zend_vm_stack_push_call_frame(call_info,

Zend/zend_execute.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@ ZEND_API void zend_init_code_execute_data(zend_execute_data *execute_data, zend_
4141
ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value);
4242
ZEND_API void execute_ex(zend_execute_data *execute_data);
4343

44-
ZEND_API inline void execute_internal(zend_execute_data *execute_data, zval *return_value)
45-
{
46-
zend_instrument_cache *cache = (zend_instrument_cache *)
44+
ZEND_API inline void execute_internal(zend_execute_data *execute_data, zval *return_value) {
45+
zend_instrument_fcall_cache *cache = (zend_instrument_fcall_cache *)
4746
ZEND_MAP_PTR_GET(execute_data->func->common.instrument_cache);
48-
if (UNEXPECTED(cache != ZEND_NOT_INSTRUMENTED)) {
49-
zend_instrument_call_begin_handlers(execute_data, cache);
47+
if (UNEXPECTED(cache != ZEND_INSTRUMENT_FCALL_NOT_INSTRUMENTED)) {
48+
zend_instrument_fcall_call_begin(cache, execute_data);
5049
execute_data->func->internal_function.handler(execute_data, return_value);
51-
zend_instrument_call_end_handlers(execute_data, cache);
50+
zend_instrument_fcall_call_end(cache, execute_data, return_value);
5251
} else {
5352
execute_data->func->internal_function.handler(execute_data, return_value);
5453
}

Zend/zend_execute_API.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,9 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
801801
const zend_op *current_opline_before_exception = EG(opline_before_exception);
802802

803803
zend_init_func_execute_data(call, &func->op_array, fci->retval);
804-
zend_instrument_cache *cache = ZEND_MAP_PTR_GET(func->common.instrument_cache);
805-
if (cache != ZEND_NOT_INSTRUMENTED) {
806-
zend_instrument_call_begin_handlers(call, cache);
804+
zend_instrument_fcall_cache *cache = ZEND_MAP_PTR_GET(func->common.instrument_cache);
805+
if (cache != ZEND_INSTRUMENT_FCALL_NOT_INSTRUMENTED) {
806+
zend_instrument_fcall_call_begin(cache, call);
807807
}
808808
zend_execute_ex(call);
809809
EG(opline_before_exception) = current_opline_before_exception;
@@ -817,7 +817,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
817817
ZEND_ASSERT(func->type == ZEND_INTERNAL_FUNCTION);
818818

819819
if (UNEXPECTED(!ZEND_MAP_PTR_GET(func->common.instrument_cache))) {
820-
zend_instrument_install_handlers(func);
820+
zend_instrument_fcall_install(func);
821821
}
822822

823823
ZVAL_NULL(fci->retval);

Zend/zend_instrument.c

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,59 +21,61 @@
2121
#include "zend_API.h"
2222
#include "zend_instrument.h"
2323

24-
struct zend_instruments_list {
25-
struct zend_instruments_list *prev;
26-
zend_instrument instrument;
24+
struct zend_instrument_fcall_init_list {
25+
struct zend_instrument_fcall_init_list *prev;
26+
zend_instrument_fcall_init instrument;
2727
};
28-
typedef struct zend_instruments_list zend_instruments_list;
28+
typedef struct zend_instrument_fcall_init_list zend_instrument_fcall_init_list;
2929

30-
static zend_instruments_list *_zend_instruments;
30+
static zend_instrument_fcall_init_list *zend_instrument_fcalls;
3131

32-
ZEND_API void zend_instrument_init(void)
33-
{
34-
_zend_instruments = NULL;
32+
ZEND_API void zend_instrument_init(void) {
33+
zend_instrument_fcalls = NULL;
3534
}
3635

37-
ZEND_API void zend_instrument_shutdown(void)
38-
{
39-
zend_instruments_list *curr, *prev;
40-
for (curr = _zend_instruments; curr; curr = prev) {
36+
ZEND_API void zend_instrument_shutdown(void) {
37+
zend_instrument_fcall_init_list *curr, *prev;
38+
for (curr = zend_instrument_fcalls; curr; curr = prev) {
4139
prev = curr->prev;
4240
free(curr);
4341
}
4442
}
4543

46-
ZEND_API void zend_instrument_register(zend_instrument instrument)
47-
{
48-
zend_instruments_list *node = malloc(sizeof(zend_instruments_list));
49-
node->instrument = instrument;
50-
node->prev = _zend_instruments;
51-
_zend_instruments = node;
44+
ZEND_API void zend_instrument_fcall_register(zend_instrument_fcall_init cb) {
45+
zend_instrument_fcall_init_list *node =
46+
malloc(sizeof(zend_instrument_fcall_init_list));
47+
node->instrument = cb;
48+
node->prev = zend_instrument_fcalls;
49+
zend_instrument_fcalls = node;
5250
}
5351

54-
struct zend_instrument_handlers_list {
55-
struct zend_instrument_handlers_list *prev;
56-
zend_instrument_handlers handlers;
52+
struct zend_instrument_fcall_list {
53+
struct zend_instrument_fcall_list *prev;
54+
zend_instrument_fcall handlers;
5755
size_t count;
5856
};
59-
typedef struct zend_instrument_handlers_list zend_instrument_handlers_list;
57+
typedef struct zend_instrument_fcall_list zend_instrument_fcall_list;
6058

6159

62-
extern inline void zend_instrument_call_begin_handlers(
63-
zend_execute_data *execute_data, zend_instrument_cache *cache);
64-
extern inline void zend_instrument_call_end_handlers(
65-
zend_execute_data *execute_data, zend_instrument_cache *cache);
60+
extern inline void zend_instrument_fcall_call_begin(
61+
zend_instrument_fcall_cache *cache,
62+
zend_execute_data *execute_data);
6663

67-
static zend_instrument_handlers_list *_instrument_add(
68-
zend_instrument_handlers_list *instruments,
69-
zend_instrument_handlers handlers)
64+
extern inline void zend_instrument_fcall_call_end(
65+
zend_instrument_fcall_cache *cache,
66+
zend_execute_data *execute_data,
67+
zval *return_value);
68+
69+
static zend_instrument_fcall_list *zend_instrument_fcall_add(
70+
zend_instrument_fcall_list *instruments,
71+
zend_instrument_fcall handlers)
7072
{
7173
if (!handlers.begin && !handlers.end) {
7274
return instruments;
7375
}
7476

75-
zend_instrument_handlers_list *n =
76-
emalloc(sizeof(zend_instrument_handlers_list));
77+
zend_instrument_fcall_list *n =
78+
emalloc(sizeof(zend_instrument_fcall_list));
7779
if (instruments) {
7880
n->prev = instruments;
7981
n->count = instruments->count + 1;
@@ -85,18 +87,18 @@ static zend_instrument_handlers_list *_instrument_add(
8587
return n;
8688
}
8789

88-
static zend_instrument_cache *_instrument_attach_handler(
90+
static zend_instrument_fcall_cache *zend_instrument_fcall_list_attach(
8991
zend_function *function,
90-
zend_instrument_handlers_list *handlers_list)
92+
zend_instrument_fcall_list *handlers_list)
9193
{
92-
zend_instrument_cache *cache =
93-
malloc(sizeof(zend_instrument_cache));
94+
zend_instrument_fcall_cache *cache =
95+
malloc(sizeof(zend_instrument_fcall_cache));
9496
cache->instruments_len = handlers_list->count;
9597
cache->handlers =
96-
calloc(handlers_list->count, sizeof(zend_instrument_handlers));
98+
calloc(handlers_list->count, sizeof(zend_instrument_fcall));
9799

98-
zend_instrument_handlers *handlers = cache->handlers;
99-
zend_instrument_handlers_list *curr;
100+
zend_instrument_fcall *handlers = cache->handlers;
101+
zend_instrument_fcall_list *curr;
100102
for (curr = handlers_list; curr; curr = curr->prev) {
101103
*handlers++ = curr->handlers;
102104
}
@@ -106,26 +108,26 @@ static zend_instrument_cache *_instrument_attach_handler(
106108
return cache;
107109
}
108110

109-
ZEND_API void zend_instrument_install_handlers(zend_function *function)
110-
{
111-
zend_instrument_handlers_list *handlers_list = NULL;
112-
zend_instruments_list *elem;
111+
ZEND_API void zend_instrument_fcall_install(zend_function *function) {
112+
zend_instrument_fcall_list *fcall_list = NULL;
113+
zend_instrument_fcall_init_list *elem;
113114

114-
for (elem = _zend_instruments; elem; elem = elem->prev) {
115-
zend_instrument_handlers handlers = elem->instrument(function);
116-
handlers_list = _instrument_add(handlers_list, handlers);
115+
for (elem = zend_instrument_fcalls; elem; elem = elem->prev) {
116+
zend_instrument_fcall handlers = elem->instrument(function);
117+
fcall_list = zend_instrument_fcall_add(fcall_list, handlers);
117118
}
118119

119-
if (handlers_list) {
120-
_instrument_attach_handler(function, handlers_list);
120+
if (fcall_list) {
121+
zend_instrument_fcall_list_attach(function, fcall_list);
121122

122-
// cleanup handlers_list
123-
zend_instrument_handlers_list *curr, *prev;
124-
for (curr = handlers_list; curr; curr = prev) {
123+
// cleanup fcall_list
124+
zend_instrument_fcall_list *curr, *prev;
125+
for (curr = fcall_list; curr; curr = prev) {
125126
prev = curr->prev;
126127
efree(curr);
127128
}
128129
} else {
129-
ZEND_MAP_PTR_SET(function->common.instrument_cache, ZEND_NOT_INSTRUMENTED);
130+
ZEND_MAP_PTR_SET(function->common.instrument_cache,
131+
ZEND_INSTRUMENT_FCALL_NOT_INSTRUMENTED);
130132
}
131133
}

0 commit comments

Comments
 (0)