Commit Graph

2401 Commits

Author SHA1 Message Date
Nikita Popov
dd9b5c8680 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Handle NULL caller_call_opline
2020-03-23 17:12:12 +01:00
Nikita Popov
34f1266a9c Handle NULL caller_call_opline
This can happen if there is an EXIT in the call arguments, in which
case the DO_CALL opcode may be eliminated as unreachable.
2020-03-23 17:12:01 +01:00
Dmitry Stogov
b6492b4453 identation fix 2020-03-12 22:26:16 +03:00
Dmitry Stogov
3c6e9bed1a Call global code of preloaded script in global context 2020-03-12 22:19:47 +03:00
Dmitry Stogov
2dddab01ae Avoid "Anonymous class wasn't preloaded" error by lazely loading of not preloaded part of a preloaded script 2020-03-12 16:31:24 +03:00
Christoph M. Becker
fea2994ff8 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Enclose INI values containing {TMP} in quotes
2020-03-09 22:51:11 +01:00
Christoph M. Becker
d5e206620b Enclose INI values containing {TMP} in quotes
At least on Windows, the temporary directory may contain tilde signs,
which would result in an INI parse error.
2020-03-09 22:49:08 +01:00
Nikita Popov
a7de98fb12 Try to fix msvc build 2020-02-28 14:48:02 +01:00
Nikita Popov
30ee3f48d4 Fixed bug #79252 2020-02-28 12:47:56 +01:00
Dmitry Stogov
cb88184420 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed incorrect overflow detection
2020-02-27 23:38:09 +03:00
Dmitry Stogov
5b51b633e2 Fixed incorrect overflow detection 2020-02-27 23:37:41 +03:00
Nikita Popov
f70b552326 Fixed bug #79193 2020-01-30 14:55:58 +01:00
Nikita Popov
3291891408 Fixed bug #79128
We need to extend the hash table before performing raw append
operations.

This doesn't matter if preloading happens in the same process,
as the tables will be large enough to hold all entries as a
side-effect of the preloading process. However, if preloading
happens in a different process, we need to reserve space here.
2020-01-24 16:18:48 +01:00
Xinchen Hui
2958cdc0b5 Let's make this safer from maliciously crafted filename 2020-01-20 12:33:37 +08:00
Xinchen Hui
dda2addab2 minor cleanup 2020-01-20 12:28:57 +08:00
Xinchen Hui
9c2fd55d01 Fixed bug #79114 (Eval class during preload causes class to be only half available) 2020-01-20 12:24:49 +08:00
Nikita Popov
59c3ddab13 Remove support for preloading on Windows
Due to ASLR restrictions, preloading on Windows does not work with
any code that has preloading dependencies on internal classes.
This effectively makes it unusable for any non-trivial codebase.

Instead of pretending like preloading is going to work, only to
make people realize that it really doesn't once they get beyond
a dummy example, we disable support for preloading on Windows
entirely.

Closes GH-4999.
2020-01-06 22:41:55 +01:00
Nikita Popov
8abb2ced39 Fixed bug #79055
Fix file cache serialization of property types. I'm changing the
overall type serialization format to perform additional adjustments
in order to yield a plausible pointer for zend_type, rather than
using an entirely separate serialization format, as was previously
done. That would have been annoying to extend to the case of CE
pointers.
2020-01-02 15:53:15 +01:00
Nikita Popov
48622970fb Extract functions for file cache type serialization
This is already done in master.
2020-01-02 15:16:24 +01:00
Nikita Popov
36d5fbbd6b Fix file cache run_time_cache unserialization
If the script was serialized as file_cache_only (thus non-immutable)
and then gets unserialized into SHM, we need to allocate a new
run_time_cache slot and can't use the serialized arena pointer.
2020-01-02 14:56:39 +01:00
Nikita Popov
e576d342bb Update ZCSG(map_ptr_last) only if for_shm
Otherwise we may get a memory protection fault here. Updating of
ZCSG(map_ptr_last) is handled when loading from file cache to SHM.
2020-01-02 11:59:36 +01:00
Nikita Popov
22e9f9fe4d Also propagate include exceptions in opcache 2019-12-30 23:22:26 +01:00
Christoph M. Becker
94063619a0 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #79040: Warning Opcode handlers are unusable due to ASLR
2019-12-30 15:17:41 +01:00
Christoph M. Becker
0cecf83b26 Fix #79040: Warning Opcode handlers are unusable due to ASLR
We must not use the same shared memory OPcache instance for different
SAPIs, since their memory layout is different.  To avoid this, we add
the SAPI name (truncated to at most 20 characters) to the names of the
memory base file, the mutex and the file mapping.
2019-12-30 15:12:58 +01:00
Nikita Popov
bd4fce4f6f Fixed bug #78986
Don't assume that handlers live in the arena, they may also be in
SHM.
2019-12-18 11:40:58 +01:00
Dmitry Stogov
6ef7e53c1b Fixed bug #78961 (erroneous optimization of re-assigned $GLOBALS) 2019-12-16 12:24:47 +03:00
Nikita Popov
0f2cdbf214 Introduce extra counter to avoid RTD key collisions
Also generate a fatal error if a collision occurs in zend_compile.

This is not perfect, because collisions might still be introduced
via opcache, if one file is included multiple times during a request,
invalidate in the meantime and recompiled by different processes.

This still needs to be addressed, but this patch fixes the much
more common case of collisions occuring when opcache is not used.

Fixes bug #78903.
2019-12-13 11:04:44 +01:00
Nikita Popov
be89a5c7f1 Fixed bug #78950: Preloading trait method with static variables
We need to make sure that trait methods with static variables
allocate a separate MAP slot for the static variables pointer,
rather than working in-place.
2019-12-12 11:52:43 +01:00
Nikita Popov
2d03b638dc Fix handling of non-final loop var free in sccp
We only need to preserve the FE_FREE that marks the end of the
loop range. Skip FE_FREEs with the FREE_ON_RETURN flag.
2019-12-12 09:39:52 +01:00
Dmitry Stogov
3280209c03 Addirional fix for bug #78918 2019-12-11 12:21:49 +03:00
Dmitry Stogov
20ef51db22 Fixed bug #78937 (Preloading unlinkable anonymous class can segfault) 2019-12-11 00:46:30 +03:00
Dmitry Stogov
518a8f89c1 Fix error message 2019-12-10 22:17:10 +03:00
Nikita Popov
5ddcacac2e Fix incorrect zend_try usage 2019-12-10 15:22:31 +01:00
Nikita Popov
d6f86caa11 Fix release build failure
GCC complained about potentially uninitialized __orig_bailout,
even though the variable has an initializer. This warning was
quite persistent, I was only able to avoid it by using a separate
function.

Am I missing something?
2019-12-10 13:51:09 +01:00
Christoph M. Becker
9e22c3d4d9 Improve error message
Formerly, the error message was like:

| Can't preload unlinked class MyException: Internal parent (Windows
| only limitation)Exception

Now it's like:

| Can't preload unlinked class MyException: Windows can't link to
| internal parent Exception
2019-12-10 13:19:58 +01:00
Nikita Popov
baf3a9133b Add support for class_alias to preloading
Related to bug #78918.
2019-12-10 13:06:36 +01:00
Nikita Popov
3f86adb0ef Fixed bug #78935: Check that all linked classes can be preloaded
During preloading, check that all classes that have been included
as part of the preload script itself (rather than through opcache_compile_file)
can actually be preloaded, i.e. satisfy Windows restrictions, have
resolved initializers and resolved property types. When resolving
initializers and property types, also autoload additional classes.
Because of this, the resolution runs in a loop.
2019-12-10 13:05:48 +01:00
Nikita Popov
4313659bb9 Fix merge mistake 2019-12-10 09:03:44 +01:00
Nikita Popov
7e028a41e2 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix DCE with FE_FETCH
2019-12-10 09:01:18 +01:00
Nikita Popov
87691e74e5 Fix DCE with FE_FETCH
For now, don't treat FE_FETCH op2 as no-val use. See GH-4982.
2019-12-10 09:00:09 +01:00
Nikita Popov
7cbf31a3c7 Preload: Better reason message for internal parents on windows
Related to bug #78881.
2019-12-04 09:52:40 +01:00
Nikita Popov
39b08ba99c Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix print_r return types in opcache
2019-12-04 07:16:56 +01:00
Tyson Andre
c8e9aa854c Fix print_r return types in opcache
https://www.php.net/print_r

> When the return parameter is TRUE, this function will return a string.
> Otherwise, the return value is TRUE.
2019-12-04 07:16:32 +01:00
Dmitry Stogov
be6fb13873 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix $x = (bool)$x; for undefined with opcache
2019-11-18 11:27:43 +03:00
Dmitry Stogov
e72e3370c6 Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix $x = (bool)$x; for undefined with opcache
2019-11-18 11:26:30 +03:00
Tyson Andre
a2c41c0ea6 Fix $x = (bool)$x; for undefined with opcache
And `$x = !$x`

Noticed while working on GH-4912

The included test would not emit undefined variable errors in php 8.0
with opcache enabled. The command used:

```
php -d zend_extension=opcache.so --no-php-ini -d error_reporting=E_ALL \
    -d opcache.file_cache= -d opcache.enable_cli=1  test.php
```
2019-11-18 11:24:03 +03:00
Christoph M. Becker
39d04f15f8 Fix ASLR related invalid opline handler issues
Opcache stores `opline->handler`s in shared memory.  These pointers are
invalid, if the main PHP DLL is loaded at another base address due to
ASLR.  We therefore store the address of `execute_ex` in the mmap base
file, and check on startup whether it matches its current address.  If
not, we fall back on the file cache if enabled, and bail out otherwise.

This still does not address cases where the opline handler is located
inside of another DLL (e.g. for some profilers, debuggers), but there
seems to be no general solution for now.

(cherry picked from commit 8ba10b8fbc)
2019-11-15 09:46:58 +01:00
Dmitry Stogov
49fcbb4810 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed wrong constant usage
2019-11-12 13:00:27 +03:00
Dmitry Stogov
9083e178f6 Fixed wrong constant usage 2019-11-12 12:59:50 +03:00
Nikita Popov
f1848a4b3f Fix bug #78226: Don't call __set() on uninitialized typed properties
Assigning to an uninitialized typed property will no longer trigger
a call to __set(). However, calls to __set() are still triggered if
the property is explicitly unset().

This gives us both the behavior people generally expect, and still
allows ORMs to do lazy initialization by unsetting properties.

For PHP 8, we should fine a way to forbid unsetting of declared
properties entirely, and provide a different way to achieve lazy
initialization.
2019-10-25 16:31:45 +02:00
Nikita Popov
4d8541debb Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #78747
2019-10-25 12:50:26 +02:00
Nikita Popov
74699533e5 Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fixed bug #78747
2019-10-25 12:50:12 +02:00
Nikita Popov
5249993814 Fixed bug #78747 2019-10-25 12:47:18 +02:00
Nikita Popov
6aece7be0a Optimize VERIFY_RETURN_TYPE for TMP operands as well
Only exclude CONST operands, which use a different instruction
format (they have a return operand).
2019-10-25 11:37:19 +02:00
Nikita Popov
f07565b0eb Check class linking in VERIFY_RETURN_TYPE optimization
instanceof_function() requires linked classes. I'm not reusing
unlinked_instanceof() here, because it performs class loading,
which wouldn't be right here, I think.
2019-10-25 11:24:32 +02:00
Dmitry Stogov
1417352dda Allow loading FFI bindings through ffi.preload directive 2019-10-22 17:52:56 +03:00
Dmitry Stogov
05c5e5dfde Fixed bug #78512 (Cannot make preload work) 2019-10-21 14:52:26 +03:00
Joe Watkins
042e3b227e
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix checksum calculation for opcache
2019-10-14 16:50:23 +02:00
Joe Watkins
22ac57b064
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix checksum calculation for opcache
2019-10-14 16:49:48 +02:00
Mitch Hagstrand
e2a6bf482f
Fix checksum calculation for opcache 2019-10-14 16:46:42 +02:00
Remi Collet
e1362b3cf0 add librt for opcache 2019-10-08 10:48:10 +02:00
Nikita Popov
a6c9c7c2b8 Handle resources used as array keys consistently
Resources used as array keys are generally handled by throwing a
notice and converting the resource to the resource handle. The only
exception is the [$resource => null] syntax, where this was treated
as an illegal offset type instead. However, this also only happened
for VM evaluations, the AST evaluator did handle resources correctly.
2019-09-27 10:40:41 +02:00
Nikita Popov
5bee9c9062 Merge branch 'PHP-7.3' into PHP-7.4 2019-09-19 17:22:28 +02:00
Nikita Popov
85e7668129 Merge branch 'PHP-7.2' into PHP-7.3 2019-09-19 17:21:45 +02:00
Nikita Popov
003c13d7bc Fix iterable return type optimization 2019-09-19 17:21:00 +02:00
Nikita Popov
62b440ffbb Merge branch 'PHP-7.3' into PHP-7.4 2019-09-17 12:09:06 +02:00
Nikita Popov
f98684b06c Merge branch 'PHP-7.2' into PHP-7.3 2019-09-17 12:08:57 +02:00
Tyson Andre
29bced9521 Fix opcache return type for get_headers in zend_func_info
https://www.php.net/manual/en/function.get-headers.php#refsect1-function.get-headers-examples
shows that it will return string keys when the second argument is
non-zero. I've verified that this is the case.

This bug was there since the initial commit in c88ffa9a56.

Closes GH-4702.
2019-09-17 12:08:29 +02:00
Christoph M. Becker
20f73d3d8f Fix #78429: opcache_compile_file(__FILE__); segfaults
We have to ensure that OPcache has been properly started up when
`opcache_compile_file()` is called.
2019-09-16 16:01:09 +02:00
Dmitry Stogov
af9b127fed Make constant and copy propagation only for IS_TMP_VAR operands 2019-09-13 12:38:57 +03:00
Nikita Popov
4b9ebd837b Allow throwing exception while loading parent class
This is a fix for symfony/symfony#32995.

The behavior is:

* Throwing exception when loading parent/interface is allowed
  (and we will also throw one if the class is simply not found).
* If this happens, the bucket key for the class is reset, so
  it's possibly to try registering the same class again.
* However, if the class has already been used due to a variance
  obligation, the exception is upgraded to a fatal error, as we
  cannot safely unregister the class stub anymore.
2019-09-12 16:41:18 +02:00
Nikita Popov
0a24cd4e7c Preloading: Fix handling of static vars in inherited methods
Part of bug #78512.
2019-09-11 09:53:10 +02:00
Tyson Andre
3e89e9a636 Add opcache return type for random_int()
random_int() will throw for incorrect argument counts, types (e.g. float
that can't cast to int), or having min > max.

See ext/standard/random.c
2019-09-09 17:19:04 +02:00
Tyson Andre
45e529d673 Fix opcache zend_func_info for microtime/gettimeofday
microtime() doesn't return an array,
and gettimeofday() doesn't return a string.
See _php_gettimeofday in microtime.c (mode is non-zero for gettimeofday)
2019-09-09 17:13:19 +02:00
Nikita Popov
36a8cf5182 Fixed bug #78514
The property class may have already been translated as part of
some other class. Only translate if xlat returns non-null.
2019-09-09 11:36:50 +02:00
Tyson Andre
94e2f25f07 Add missing opcache return types for functions in spl
(excluding spl_autoload)

spl_object_id() is of the most interest to me,
since I frequently call it in an application.

This includes false/null types caused by wrong argument types and wrong argument
counts.

I can't rule out iterator_to_array returning null in spl_iterator_apply,
so leave MAY_BE_NULL in.

With review comments by nikic:
Co-Authored-By: Nikita Popov <nikita.ppv@googlemail.com>
2019-09-04 11:12:41 +02:00
Dmitry Stogov
5dc37cc306 Execute preload script under user defined by opcache.preload_user directive 2019-09-03 14:23:13 +03:00
Tyson Andre
4de8503c22 Add missing opcache return info for ext/standard.
array_key_first/last returns null for invalid args,
wrong argument counts, and empty arrays.

random_bytes returns a string or throws.
2019-09-03 09:57:51 +02:00
Tyson Andre
1a905bcb1e Add new missing functions from ext/hash 2019-09-03 09:53:41 +02:00
Nikita Popov
632708ac02 Merge branch 'PHP-7.3' into PHP-7.4 2019-09-03 09:24:05 +02:00
Nikita Popov
d66e0f165d Merge branch 'PHP-7.2' into PHP-7.3 2019-09-03 09:23:55 +02:00
Tyson Andre
9c3b7ccda5 Fix opcache return type for hash_update_stream
It can return false if the resource type is wrong.

```
php > var_export(hash_update_stream(hash_init('md5'),
        imagecreate(1,1)));

Warning: hash_update_stream(): supplied resource is not a valid stream
resource in php shell code on line 1
false
```

The return types were initially added in
c88ffa9a56
2019-09-03 09:23:39 +02:00
Nikita Popov
774cdb1d59 Merge branch 'PHP-7.3' into PHP-7.4 2019-08-26 11:13:57 +02:00
Nikita Popov
e4ecadcb62 Merge branch 'PHP-7.2' into PHP-7.3 2019-08-26 11:13:49 +02:00
Tyson Andre
1e82a2d659 Also fix signature for passthru
Backported from a1a8d14485
https://www.php.net/manual/en/function.passthru.php#refsect1-function.passthru-returnvalues

`passthru()` is false with invalid args
`passthru('command')` is null.
2019-08-26 11:13:26 +02:00
Tyson Andre
f5bccc0eb5 Fix opcache optimizer info for time_nanosleep
This can also return an array. See
https://www.php.net/manual/en/function.time-nanosleep.php#refsect1-function.time-nanosleep-returnvalues

> If the delay was interrupted by a signal, an associative array will be
returned with the components:
>
> - seconds - number of seconds remaining in the delay
> - nanoseconds - number of nanoseconds remaining in the delay

Sending a SIGUSR1 to the below program would trigger this behavior.

```
pcntl_signal(\SIGUSR1, function ($signo, $signinfo) {
    echo "Handling a signal $signo\n";
});
echo "Sleeping for 100 seconds\n";
var_export(time_nanosleep(100, 0));
```

The incomplete signature existed since c88ffa9a5.
No phpt tests existed for time_nanosleep returning an array
2019-08-26 11:13:26 +02:00
Nikita Popov
76fecb339f Merge branch 'PHP-7.3' into PHP-7.4 2019-08-13 11:23:06 +02:00
Nikita Popov
a33361a37c Merge branch 'PHP-7.2' into PHP-7.3 2019-08-13 11:22:41 +02:00
Nikita Popov
4eeb41d1ea Fixed bug #77191 2019-08-13 11:19:58 +02:00
Dmitry Stogov
ef35556498 typo 2019-08-06 13:58:17 +03:00
Dmitry Stogov
d5d76ea6e7 Preloading is not comatible with dl() function 2019-08-06 12:44:55 +03:00
Dmitry Stogov
3fc0e2bb80 Fixed bug #78376 (Incorrect preloading of constant static properties) 2019-08-05 22:55:06 +03:00
Nikita Popov
bf53d30fae Fix forwarding of extra args in opcache server tests 2019-08-01 17:00:11 +02:00
Nikita Popov
afd96392a3 Revert "Use RW fetch for argument unpacking"
This reverts commit 6913ec3282.
This reverts commit a9e332e027.

Causes https://bugs.php.net/bug.php?id=78356, which I don't have
a good solution for.
2019-08-01 10:06:53 +02:00
Nikita Popov
a9e332e027 Handle RW UNPACK in inference 2019-07-30 10:31:51 +02:00
Christoph M. Becker
3429370d69 Fix build for --disable-signals 2019-07-29 18:49:44 +02:00
Nikita Popov
6df1665bb3 Merge branch 'PHP-7.3' into PHP-7.4 2019-07-29 17:14:40 +02:00
Nikita Popov
bbed5564eb Merge branch 'PHP-7.2' into PHP-7.3 2019-07-29 16:57:57 +02:00
Nikita Popov
38f1288b64 Fix Zend signals unblocking
There are a few parts here:
 * opcache should not be blocking signals while invoking compile_file,
   otherwise signals may remain blocked on a compile error. While at
   it, also protect SHM memory during compile_file.
 * We should deactivate Zend signals at the end of the request, to make
   sure that we gracefully recover from a missing unblock and signals
   don't remain blocked forever.
 * We don't use a critical section in deactivation, because it should
   not be necessary. Additionally we want to clean up the signal queue,
   if it is non-empty.
 * Enable SIGG(check) in debug builds so we notice issues in the future.
2019-07-29 15:17:32 +02:00
Nikita Popov
a22a06c351 Merge branch 'PHP-7.3' into PHP-7.4 2019-07-29 13:03:53 +02:00