Skip to content

Commit 78ef25b

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix #81679: Tracing JIT crashes on reattaching
2 parents 8eee0d6 + 5910e1d commit 78ef25b

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

ext/opcache/ZendAccelerator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ typedef struct _zend_accel_shared_globals {
278278
/* uninitialized HashTable Support */
279279
uint32_t uninitialized_bucket[-HT_MIN_MASK];
280280

281+
/* Tracing JIT */
282+
void *jit_traces;
283+
const void **jit_exit_groups;
284+
281285
/* Interned Strings Support (must be the last element) */
282286
zend_string_table interned_strings;
283287
} zend_accel_shared_globals;

ext/opcache/jit/zend_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4983,7 +4983,7 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, bool reattached)
49834983
#endif
49844984
}
49854985

4986-
if (zend_jit_trace_startup() != SUCCESS) {
4986+
if (zend_jit_trace_startup(reattached) != SUCCESS) {
49874987
return FAILURE;
49884988
}
49894989

ext/opcache/jit/zend_jit_trace.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,33 @@ static zend_always_inline const char *zend_jit_trace_star_desc(uint8_t trace_fla
4646
}
4747
}
4848

49-
static int zend_jit_trace_startup(void)
49+
static int zend_jit_trace_startup(zend_bool reattached)
5050
{
51-
zend_jit_traces = (zend_jit_trace_info*)zend_shared_alloc(sizeof(zend_jit_trace_info) * JIT_G(max_root_traces));
52-
if (!zend_jit_traces) {
53-
return FAILURE;
54-
}
55-
zend_jit_exit_groups = (const void**)zend_shared_alloc(sizeof(void*) * (ZEND_JIT_TRACE_MAX_EXITS/ZEND_JIT_EXIT_POINTS_PER_GROUP));
56-
if (!zend_jit_exit_groups) {
57-
return FAILURE;
51+
if (!reattached) {
52+
zend_jit_traces = (zend_jit_trace_info*)zend_shared_alloc(sizeof(zend_jit_trace_info) * JIT_G(max_root_traces));
53+
if (!zend_jit_traces) {
54+
return FAILURE;
55+
}
56+
zend_jit_exit_groups = (const void**)zend_shared_alloc(sizeof(void*) * (ZEND_JIT_TRACE_MAX_EXITS/ZEND_JIT_EXIT_POINTS_PER_GROUP));
57+
if (!zend_jit_exit_groups) {
58+
return FAILURE;
59+
}
60+
ZEND_JIT_TRACE_NUM = 1;
61+
ZEND_JIT_COUNTER_NUM = 0;
62+
ZEND_JIT_EXIT_NUM = 0;
63+
ZEND_JIT_EXIT_COUNTERS = 0;
64+
ZCSG(jit_traces) = zend_jit_traces;
65+
ZCSG(jit_exit_groups) = zend_jit_exit_groups;
66+
} else {
67+
zend_jit_traces = ZCSG(jit_traces);
68+
if (!zend_jit_traces) {
69+
return FAILURE;
70+
}
71+
zend_jit_exit_groups = ZCSG(jit_exit_groups);
72+
if (!zend_jit_exit_groups) {
73+
return FAILURE;
74+
}
5875
}
59-
ZEND_JIT_TRACE_NUM = 1;
60-
ZEND_JIT_COUNTER_NUM = 0;
61-
ZEND_JIT_EXIT_NUM = 0;
62-
ZEND_JIT_EXIT_COUNTERS = 0;
6376

6477
memset(&dummy_op_array, 0, sizeof(dummy_op_array));
6578
dummy_op_array.fn_flags = ZEND_ACC_DONE_PASS_TWO;

0 commit comments

Comments
 (0)