Skip to content

Commit 70600f1

Browse files
committed
ZEND_VM_ENTER_BIT
1 parent a63ef20 commit 70600f1

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

Zend/zend_portability.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,4 +870,8 @@ static zend_always_inline uint64_t ZEND_BYTES_SWAP64(uint64_t u)
870870
# define ZEND_OPCACHE_SHM_REATTACHMENT 1
871871
#endif
872872

873+
#ifndef UINTPTR_WIDTH
874+
# define UINTPTR_WIDTH (CHAR_BITS * sizeof(uintptr_t))
875+
#endif
876+
873877
#endif /* ZEND_PORTABILITY_H */

Zend/zend_vm_gen.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,9 +1944,10 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
19441944
out($f,"# define ZEND_VM_ENTER() opline = EG(current_execute_data)->opline; ZEND_VM_ENTER_EX()\n");
19451945
out($f,"# define ZEND_VM_LEAVE() return 2\n");
19461946
out($f,"#else\n");
1947-
out($f,"# define ZEND_VM_ENTER_EX() return (zend_op*)((uintptr_t)opline | (1ULL<<63))\n");
1947+
out($f,"# define ZEND_VM_ENTER_BIT (1ULL<<(UINTPTR_WIDTH-1))\n");
1948+
out($f,"# define ZEND_VM_ENTER_EX() return (zend_op*)((uintptr_t)opline | ZEND_VM_ENTER_BIT)\n");
19481949
out($f,"# define ZEND_VM_ENTER() execute_data = EG(current_execute_data); LOAD_OPLINE(); ZEND_VM_ENTER_EX()\n");
1949-
out($f,"# define ZEND_VM_LEAVE() return (zend_op*)((uintptr_t)opline | (1ULL<<63))\n");
1950+
out($f,"# define ZEND_VM_LEAVE() return (zend_op*)((uintptr_t)opline | ZEND_VM_ENTER_BIT)\n");
19501951
out($f,"#endif\n");
19511952
out($f,"#define ZEND_VM_INTERRUPT() ZEND_VM_TAIL_CALL(zend_interrupt_helper".($spec?"_SPEC":"")."(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU));\n");
19521953
out($f,"#define ZEND_VM_LOOP_INTERRUPT() zend_interrupt_helper".($spec?"_SPEC":"")."(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);\n");
@@ -2175,8 +2176,8 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
21752176
"# endif\n" .
21762177
$m[1]."return;\n" .
21772178
"#else\n" .
2178-
$m[1]."if (EXPECTED(opline != NULL && (uintptr_t)opline != (1ULL<<63))) {\n" .
2179-
$m[1]."\topline = (zend_op*)((uintptr_t)opline & ~(1ULL<<63));\n".
2179+
$m[1]."if (EXPECTED(opline != NULL && (uintptr_t)opline != ZEND_VM_ENTER_BIT)) {\n" .
2180+
$m[1]."\topline = (zend_op*)((uintptr_t)opline & ~ZEND_VM_ENTER_BIT);\n".
21802181
$m[1]."\texecute_data = EG(current_execute_data);\n".
21812182
$m[1]."\tZEND_VM_LOOP_INTERRUPT_CHECK();\n".
21822183
$m[1]."} else {\n" .

ext/opcache/jit/zend_jit_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ extern const zend_op *zend_jit_halt_op;
200200
handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU_CC arg); \
201201
return; \
202202
} while(0)
203+
# define ZEND_VM_ENTER_BIT 0
203204
#else
204205
# define EXECUTE_DATA_D zend_execute_data* execute_data
205206
# define EXECUTE_DATA_C execute_data
@@ -221,6 +222,7 @@ extern const zend_op *zend_jit_halt_op;
221222
# define ZEND_OPCODE_TAIL_CALL_EX(handler, arg) do { \
222223
return handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU_CC arg); \
223224
} while(0)
225+
# define ZEND_VM_ENTER_BIT (1ULL<<(UINTPTR_WIDTH-1))
224226
#endif
225227

226228
/* VM handlers */

ext/opcache/jit/zend_jit_ir.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,13 +1887,13 @@ static void zend_jit_check_timeout(zend_jit_ctx *jit, const zend_op *opline, con
18871887
static void zend_jit_vm_enter(zend_jit_ctx *jit, ir_ref to_opline)
18881888
{
18891889
// ZEND_VM_ENTER()
1890-
ir_RETURN(ir_OR_A(to_opline, ir_CONST_ADDR((uintptr_t)1ULL<<63)));
1890+
ir_RETURN(ir_OR_A(to_opline, ir_CONST_ADDR(ZEND_VM_ENTER_BIT)));
18911891
}
18921892

18931893
static void zend_jit_vm_leave(zend_jit_ctx *jit, ir_ref to_opline)
18941894
{
18951895
// ZEND_VM_LEAVE()
1896-
ir_RETURN(ir_OR_A(to_opline, ir_CONST_ADDR((uintptr_t)1ULL<<63)));
1896+
ir_RETURN(ir_OR_A(to_opline, ir_CONST_ADDR(ZEND_VM_ENTER_BIT)));
18971897
}
18981898

18991899
/* stubs */
@@ -17043,7 +17043,7 @@ static int zend_jit_trace_handler(zend_jit_ctx *jit, const zend_op_array *op_arr
1704317043
opline->opcode == ZEND_RETURN_BY_REF ||
1704417044
opline->opcode == ZEND_GENERATOR_CREATE) {
1704517045
// TODO: what other ops need this?
17046-
ref = ir_AND_A(ref, ir_CONST_ADDR(~(1ULL<<63)));
17046+
ref = ir_AND_A(ref, ir_CONST_ADDR(~ZEND_VM_ENTER_BIT));
1704717047
}
1704817048
jit_LOAD_IP(jit, ref);
1704917049
}

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_leave_nested_func_helper(ZEND_OPC
7575
zval_ptr_dtor(EX_VAR(old_opline->result.var));
7676
}
7777
#ifndef HAVE_GCC_GLOBAL_REGS
78-
return (zend_op*)((uintptr_t)EG(current_execute_data)->opline | (1ULL<<63));
78+
return (zend_op*)((uintptr_t)EG(current_execute_data)->opline | ZEND_VM_ENTER_BIT);
7979
#endif
8080
} else {
8181
EX(opline)++;
8282
#ifdef HAVE_GCC_GLOBAL_REGS
8383
opline = EX(opline);
8484
#else
85-
return (zend_op*)((uintptr_t)EX(opline) | (1ULL<<63));
85+
return (zend_op*)((uintptr_t)EX(opline) | ZEND_VM_ENTER_BIT);
8686
#endif
8787
}
8888
}
@@ -372,7 +372,7 @@ static zend_always_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_trace_c
372372
#ifdef HAVE_GCC_GLOBAL_REGS
373373
return;
374374
#else
375-
return opline ? (zend_op*)((uintptr_t)opline | (1ULL<<63)) : NULL; // ZEND_VM_ENTER() : ZEND_VM_RETURN()
375+
return opline ? (zend_op*)((uintptr_t)opline | ZEND_VM_ENTER_BIT) : NULL; // ZEND_VM_ENTER() : ZEND_VM_RETURN()
376376
#endif
377377
} else {
378378
zend_vm_opcode_handler_t handler = (zend_vm_opcode_handler_t)ZEND_OP_TRACE_INFO(opline, offset)->orig_handler;
@@ -952,7 +952,7 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
952952
/* return after interrupt handler */
953953
ZEND_ASSERT(0 && "TODO");
954954
}
955-
opline = (zend_op*)((uintptr_t)opline & ~(1ULL<<63));
955+
opline = (zend_op*)((uintptr_t)opline & ~ZEND_VM_ENTER_BIT);
956956
execute_data = EG(current_execute_data);
957957
#endif
958958

0 commit comments

Comments
 (0)