Commit graph

189 commits

Author SHA1 Message Date
Tim Düsterhus
3d9d68e1ca
zend_compile: Deprecate backticks as an alias for shell_exec() (#19443)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_backticks_as_an_alias_for_shell_exec
2025-08-12 12:02:13 +02:00
Arnaud Le Blanc
76d7c616bb
Pass opline as argument to opcode handlers in CALL VM
This changes the signature of opcode handlers in the CALL VM so that the opline
is passed directly via arguments. This reduces the number of memory operations
on EX(opline), and makes the CALL VM considerably faster.

Additionally, this unifies the CALL and HYBRID VMs a bit, as EX(opline) is now
handled in the same way in both VMs.

This is a part of GH-17849.

Currently we have two VMs:

 * HYBRID: Used when compiling with GCC. execute_data and opline are global
   register variables
 * CALL: Used when compiling with something else. execute_data is passed as
   opcode handler arg, but opline is passed via execute_data->opline
   (EX(opline)).

The Call VM looks like this:

    while (1) {
        ret = execute_data->opline->handler(execute_data);
        if (UNEXPECTED(ret != 0)) {
            if (ret > 0) { // returned by ZEND_VM_ENTER() / ZEND_VM_LEAVE()
                execute_data = EG(current_execute_data);
            } else {       // returned by ZEND_VM_RETURN()
                return;
            }
        }
    }

    // example op handler
    int ZEND_INIT_FCALL_SPEC_CONST_HANDLER(zend_execute_data *execute_data) {
        // load opline
        const zend_op *opline = execute_data->opline;

        // instruction execution

        // dispatch
        // ZEND_VM_NEXT_OPCODE():
        execute_data->opline++;
        return 0; // ZEND_VM_CONTINUE()
    }

Opcode handlers return a positive value to signal that the loop must load a
new execute_data from EG(current_execute_data), typically when entering
or leaving a function.

Here I make the following changes:

 * Pass opline as opcode handler argument
 * Return next opline from opcode handlers
 * ZEND_VM_ENTER / ZEND_VM_LEAVE return opline|(1<<0) to signal that
   execute_data must be reloaded from EG(current_execute_data)

This gives us:

    while (1) {
        opline = opline->handler(execute_data, opline);
        if (UNEXPECTED((uintptr_t) opline & ZEND_VM_ENTER_BIT) {
            opline = opline & ~ZEND_VM_ENTER_BIT;
            if (opline != 0) { // ZEND_VM_ENTER() / ZEND_VM_LEAVE()
                execute_data = EG(current_execute_data);
            } else {           // ZEND_VM_RETURN()
                return;
            }
        }
    }

    // example op handler
    const zend_op * ZEND_INIT_FCALL_SPEC_CONST_HANDLER(zend_execute_data *execute_data, const zend_op *opline) {
        // opline already loaded

        // instruction execution

        // dispatch
        // ZEND_VM_NEXT_OPCODE():
        return ++opline;
    }

bench.php is 23% faster on Linux / x86_64, 18% faster on MacOS / M1.

Symfony Demo is 2.8% faster.

When using the HYBRID VM, JIT'ed code stores execute_data/opline in two fixed
callee-saved registers and rarely touches EX(opline), just like the VM.

Since the registers are callee-saved, the JIT'ed code doesn't have to
save them before calling other functions, and can assume they always
contain execute_data/opline. The code also avoids saving/restoring them in
prologue/epilogue, as execute_ex takes care of that (JIT'ed code is called
exclusively from there).

The CALL VM can now use a fixed register for execute_data/opline as well, but
we can't rely on execute_ex to save the registers for us as it may use these
registers itself. So we have to save/restore the two registers in JIT'ed code
prologue/epilogue.

Closes GH-17952
2025-04-15 18:51:54 +02:00
Niels Dossche
29bafa6323
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix memory leak in phpdbg calling registered function
  Partially fix GH-17387
2025-01-30 19:31:38 +01:00
ndossche
62bbfdebaa
Fix memory leak in phpdbg calling registered function
Closes GH-17635.
2025-01-30 19:28:26 +01:00
Niels Dossche
2860c3d641
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix crashes in function registration + test
2025-01-06 21:31:03 +01:00
Niels Dossche
1235c74828
Fix crashes in function registration + test
Internal function won't need their refcount increased as they outlive
the debugger session, and userland functions won't be unloaded either.
So no refcount management is necessary for registered functions.
2025-01-06 21:30:34 +01:00
Niels Dossche
5ff67f8720
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-15208: Segfault with breakpoint map and phpdbg_clear()
2024-11-26 22:27:35 +01:00
Niels Dossche
3c3ec0e61a
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-15208: Segfault with breakpoint map and phpdbg_clear()
2024-11-26 22:27:06 +01:00
Niels Dossche
97b03186c4
Fix GH-15208: Segfault with breakpoint map and phpdbg_clear()
It crashes because it's gonna try accessing the breakpoint which was cleared
by user code in `phpdbg_clear();`. Not all breakpoint data was properly
cleaned.

Closes GH-16953.
2024-11-26 22:26:37 +01:00
Christoph M. Becker
980d41cb3a
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16174: Empty string is an invalid expression for phpdbg-ev
2024-10-10 01:47:23 +02:00
Christoph M. Becker
5c6fc09e45
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16174: Empty string is an invalid expression for phpdbg-ev
2024-10-10 01:46:30 +02:00
Christoph M. Becker
6bcba24eb0
Fix GH-16174: Empty string is an invalid expression for phpdbg-ev
Strings may be empty, so we must not assume they are not.

Closes GH-16177.
2024-10-10 01:45:37 +02:00
Christoph M. Becker
3c1af3febb
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16181: phpdbg: exit in exception handler reports fatal error
2024-10-03 11:39:03 +02:00
Christoph M. Becker
95c97c81b7
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16181: phpdbg: exit in exception handler reports fatal error
2024-10-03 11:37:15 +02:00
Christoph M. Becker
f14e5cfaaa
Fix GH-16181: phpdbg: exit in exception handler reports fatal error
When running PHP code, we must not handle `UnwindExit` exceptions, but
rather have to ignore them.

Closes GH-16182.
2024-10-03 11:36:13 +02:00
Christoph M. Becker
7a8767fe62
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-15901: phpdbg: Assertion failure on `i funcs`
2024-09-18 23:51:45 +02:00
Christoph M. Becker
c76913fde0
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-15901: phpdbg: Assertion failure on `i funcs`
2024-09-18 23:50:20 +02:00
Christoph M. Becker
422aa17b9b
Fix GH-15901: phpdbg: Assertion failure on i funcs
New hash tables are not automatically packed, so we must not treat them
as such.  Therefore we guard the foreach appropriately.

Closes GH-15929.
2024-09-18 23:48:31 +02:00
Niels Dossche
c426157823
Merge branch 'PHP-8.3'
* PHP-8.3:
  Add necessary SKIPIFs to new phpdbg tests
2024-08-10 01:11:14 +02:00
Niels Dossche
04adeeaef8
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add necessary SKIPIFs to new phpdbg tests
2024-08-10 01:11:09 +02:00
Niels Dossche
4d71580e00
Add necessary SKIPIFs to new phpdbg tests
Similarly to other watchpoint tests, we add SKIPIFs.
These TRACKED_ALLOC issues should be investigated though [1] [2].

[1] de5c760c69 (comments)
[2] https://github.com/php/php-src/pull/15229#pullrequestreview-2230563480
2024-08-10 01:10:01 +02:00
David Carlier
667a5651ca
Merge branch 'PHP-8.3' 2024-08-09 21:15:07 +01:00
David Carlier
de5c760c69
Merge branch 'PHP-8.2' into PHP-8.3 2024-08-09 21:12:34 +01:00
David Carlier
9aeb6761b5
Fix GH-15210: phpdbg_print_changed_zvals working on a real copy instead.
Close GH-15229
2024-08-09 21:12:11 +01:00
Niels Dossche
a5c834219b
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-15268: heap buffer overflow in phpdbg (zend_hash_num_elements() Zend/zend_hash.h)
2024-08-08 20:35:57 +02:00
Niels Dossche
47e4991d38
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-15268: heap buffer overflow in phpdbg (zend_hash_num_elements() Zend/zend_hash.h)
2024-08-08 20:35:50 +02:00
Niels Dossche
a6c547d1dd
Fix GH-15268: heap buffer overflow in phpdbg (zend_hash_num_elements() Zend/zend_hash.h)
The class is not yet linked, so we cannot access `parent`, but only
`parent_name`.

Closes GH-15277.
2024-08-08 20:35:20 +02:00
Niels Dossche
c69dedabb2
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-14553: Bug in phpdbg8.3 (also 8.1 and 8.2) echo output - trimmed at NULL byte (?)
2024-07-04 18:44:29 +02:00
Niels Dossche
751c267850
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14553: Bug in phpdbg8.3 (also 8.1 and 8.2) echo output - trimmed at NULL byte (?)
2024-07-04 18:44:17 +02:00
Niels Dossche
95889979f2
Fix GH-14553: Bug in phpdbg8.3 (also 8.1 and 8.2) echo output - trimmed at NULL byte (?)
This broke in 6318040df2 when phpdbg
stopped using its custom printing routines. By relying on standard
printing routines, the embedded NUL bytes are causing the strings to be
cut off, even when using %.*s. Solve this by going straight to the
output routine, which is what the printf routine would've done anyway.

Closes GH-14822.
2024-07-04 18:43:42 +02:00
David Carlier
ac947925c0
Merge branch 'PHP-8.3' 2024-06-17 17:46:54 +01:00
David Carlier
8690d522a3
Merge branch 'PHP-8.2' into PHP-8.3 2024-06-17 17:46:24 +01:00
David Carlier
03f0776d08
Fix GH-13681: segfault when adding watchpoint fails.
thus when removing its entry, no watch point is set and crash on
pointer access.

close GH-14513
2024-06-17 17:45:53 +01:00
Niels Dossche
584a7b8e78
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-13931: Applying zero offset to null pointer in Zend/zend_opcode.c
2024-04-15 19:40:08 +02:00
Niels Dossche
550e0ceb79
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-13931: Applying zero offset to null pointer in Zend/zend_opcode.c
2024-04-15 19:39:59 +02:00
Niels Dossche
c3acfb1b57
Fix GH-13931: Applying zero offset to null pointer in Zend/zend_opcode.c
In the test cases, the compiler bails out due to a fatal error.
The data structures used by the compiler will contain stale values.
In particular, for the test case CG(loop_var_stack) will contain data.
The next compilation will incorrectly use elements from the previous
stack.
To solve this, we reset part of the compiler data structures.
We don't do a full re-initialization via init_compiler() because that will
also reset streams and resources.

Closes GH-13938.
2024-04-15 19:39:05 +02:00
Tim Düsterhus
08b2ab22f4
Include the source location in Closure names (#13550)
* Include the source location in Closure names

This change makes stack traces involving Closures, especially multiple
different Closures, much more useful, because it's more easily visible *which*
closure was called for a given stack frame.

The implementation is similar to that of anonymous classes which already
include the file name and line number within their generated classname.

* Update scripts/dev/bless_tests.php for closure naming

* Adjust existing tests for closure naming

* Adjust tests for closure naming that were not caught locally

* Drop the namespace from closure names

This is redundant with the included filename.

* Include filename and line number as separate keys in Closure debug info

* Fix test

* Fix test

* Include the surrounding class and function name in closure names

* Fix test

* Relax test expecations

* Fix tests after merge

* NEWS / UPGRADING
2024-04-12 18:21:13 +02:00
Ilija Tovilo
536305436f
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix opcache dump varying tmps
2024-04-05 14:12:23 +02:00
Ilija Tovilo
017cf41647
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix opcache dump varying tmps
2024-04-05 14:12:08 +02:00
Ilija Tovilo
97162e92be
Fix opcache dump varying tmps 2024-04-05 14:11:41 +02:00
Niels Dossche
f2b2b7f257 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-13827: Null pointer access of type 'zval' in phpdbg_frame
2024-03-29 17:55:52 +01:00
Niels Dossche
508ed9b474 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-13827: Null pointer access of type 'zval' in phpdbg_frame
2024-03-29 17:55:33 +01:00
Niels Dossche
d3f1f3ab40 Fix GH-13827: Null pointer access of type 'zval' in phpdbg_frame
We don't always have the line and filename in a backtrace frame, but
phpdbg assumes we do.

Closes GH-13831.
2024-03-29 17:54:23 +01:00
Máté Kocsis
330cc5cdb2
Deprecate implicit nullable parameter types (#12959)
RFC: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types

Co-authored-by: Gina Peter Banyard <girgias@php.net>
2024-03-13 21:40:26 +01:00
Niels Dossche
c39a8631b7 Merge branch 'PHP-8.3'
* PHP-8.3:
  Use getenv to prevent undefined key warning
2024-01-15 20:15:29 +01:00
Niels Dossche
0887c5e908 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Use getenv to prevent undefined key warning
2024-01-15 20:15:17 +01:00
Niels Dossche
cd483f136c Use getenv to prevent undefined key warning 2024-01-15 20:15:04 +01:00
Niels Dossche
61b7370b6d Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12929: SimpleXMLElement with stream_wrapper_register can segfault
  Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash
  Fix GH-12962: Double free of init_file in phpdbg_prompt.c
2023-12-17 11:52:48 +01:00
Niels Dossche
4fc336c784 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash
  Fix GH-12962: Double free of init_file in phpdbg_prompt.c
2023-12-17 11:50:42 +01:00
Niels Dossche
a6d17bffe1 Fix GH-12962: Double free of init_file in phpdbg_prompt.c
See GH-12962 for analysis.

Closes GH-12963.
2023-12-17 11:46:02 +01:00