Commit graph

2425 commits

Author SHA1 Message Date
Arnaud Le Blanc
7b3e68ff69
Fix error handling inconsistency with opcache
When opcache is enabled, error handling is altered in the following ways:

 * Errors emitted during compilation bypass the user-defined error handler
 * Exceptions emitted during class linking are turned into fatal errors

Changes here make the behavior consistent regardless of opcache being enabled or
not:

 * Errors emitted during compilation and class linking are always delayed and
   handled after compilation or class linking. During handling, user-defined
   error handlers are not bypassed. Fatal errors emitted during compilation or
   class linking cause any delayed errors to be handled immediately (without
   calling user-defined error handlers, as it would be unsafe).
 * Exceptions thrown by user-defined error handlers when handling class linking
   error are not promoted to fatal errors anymore and do not prevent linking.

Fixes GH-17422.
Closes GH-18541.
Closes GH-17627.

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
2025-07-27 11:01:49 +02:00
Peter Kokot
aa366b5113
Update re2c minimum versions in Windows checks and docs (#19039) 2025-07-07 07:54:29 +02:00
Peter Kokot
93e3aca5fa
Remove HAVE_INTMAX_T and SIZEOF_INTMAX_T (#18971)
The intmax_t is a C99 standard type defined in `<stdint.h>` and widely
available on current platforms. On Windows they are available as of
Visual Studio 2013. Using it conditionally as in these occurrences is
not needed anymore.
2025-06-29 19:50:27 +02:00
Peter Kokot
fffe642d67
Remove HAVE_PTRDIFF_T and SIZEOF_PTRDIFF_T (#18968)
The ptrdiff_t is a C89 standard type defined in `<stddef.h>` and widely
available on current platforms. Using it conditionally as in these
occurrences is not needed anymore.
2025-06-28 20:16:12 +02:00
Peter Kokot
3df665a888
[Windows build] Remove redundant flags definitions (#18890)
The /d2FuncCache1 compile option is already added by
toolset_setup_common_cflags() in confutils.js to all targets.

ZEND_DVAL_TO_LVAL_CAST_OK was removed in
3725717de1.
2025-06-22 15:19:08 +02:00
Peter Kokot
3ff6874658
Remove HAVE_GETLOGIN from win32/config.w32.h.in template (#18865)
PHP once had getlogin() emulation implemented on Windows. This isn't the
case anymore since 2006 (dc34d34230),
neither Windows has getlogin() function.
2025-06-19 14:07:40 +02:00
Calvin Buckley
76791e90b9
Use win32 glob implementation on all platforms (#18164)
* Move glob to main/ from win32/

In preparation to make the Win32 reimplementation the standard
cross-platform one. Currently, it doesn't do that and just passes
through the original glob implementation. We could consider also having
an option to use the standard glob for systems that have a sufficient
one.

* Enable building with win32 glob on non-windows

Kind of broken. We're namespacing the function and struct, but not yet
the GLOB_* defines. There are a lot of places callers check if i.e.
NOMATCH is defined that would likely become redundant.

Currently it also has php_glob and #defines glob php_glob (etc.) - I
suspect doing the opposite and changing the callers would make more
sense, just doing MVP to geet it to build (even if it fails tests).

* Massive first pass at conversion to internal glob

Have not tested yet. the big things are:

- Should be invisible to userland PHP code.
- A lot of :%s/GLOB_/PHP_GLOB_/g; the diff can be noisy as a result,
  especially in comments.
- Prefixes everything with PHP_ to avoid conflicts with system glob in
  case it gets included transitively.
- A lot of weird shared definitions that were sprawled out to other
  headers are now included in php_glob.h.
- A lot of (but not yet all cases) of HAVE_GLOB are removed, since we
  can always fall back to php_glob.
- Using the system glob is not wired up yet; it'll need more shim
  ifdefs for each flag type than just glob_t/glob/globfree defs.

* Fix inclusion of GLOB_ONLYDIR

This is a GNU extension, but we don't need to implement it, as the GNU
implementation is flawed enough that callers have to manually filter it
anyways; just provide a stub definition for the constant.

We could consideer implementing this properly later. For now, fixes the
basic glob constant tests.

* Remove HAVE_GLOBs

We now always have a glob implementation that works. HAVE_GLOB should
only be used to check if we have a system implementation, for if we
decide to wrap the system implementation instead.

* We don't need to care about being POSIXly correct for internal glob

* Check for reallocarray

Ideally temporary until GH-17433.

* Forgot to move this file from win32/ to main/

* Check for issetugid (BSD function)

* Allow using the system glob with --enable-system-glob

* Style fix after removing ifdef

* Remove empty case for system glob
2025-05-20 16:20:59 -03:00
Ilija Tovilo
905bba637a
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix missing include in win32/globals.c
2025-05-06 15:52:38 +02:00
Ilija Tovilo
14ff4b75a2
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix missing include in win32/globals.c
2025-05-06 15:52:30 +02:00
Ilija Tovilo
69f0882d3b
Fix missing include in win32/globals.c
This previously errored with:

win32\globals.c(66): error C2220: the following warning is treated as an error
win32\globals.c(66): warning C4013: 'php_win32_signal_ctrl_handler_request_shutdown' undefined; assuming extern returning int

This only errors on master because of 2473f57ba (thanks to Niels for
that info!).

Closes GH-18508
2025-05-06 15:51:37 +02:00
Niels Dossche
3c84b01e02
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix leak+crash with sapi_windows_set_ctrl_handler()
2025-05-05 19:14:19 +02:00
Niels Dossche
d4a3e437ae
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix leak+crash with sapi_windows_set_ctrl_handler()
2025-05-05 19:14:13 +02:00
Niels Dossche
fb3536fd60
Fix leak+crash with sapi_windows_set_ctrl_handler()
The ctrl_handler is never destroyed. We have to destroy it at request
end so we avoid leaking it and also avoid keeping a reference to
previous request memory in a next request. The latter can result in a
crash and can be demonstrated with this script and `--repeat 2`:

```php
class Test {
	public function set() {
		sapi_windows_set_ctrl_handler(self::cb(...));
	}
	public function cb() {
	}
}

$test = new Test;
$test->set();
sleep(3);
```
When you hit CTRL+C in the second request you can crash.

This patch resolves both the leak and crash by destroying the
ctrl_handler after a request.

Closes GH-18231.
2025-05-05 19:13:39 +02:00
Niels Dossche
864ad1b5bb
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18136: tracing JIT floating point register clobbering on Windows and ARM64
2025-04-21 13:15:50 +02:00
Niels Dossche
1a1a83f1fc
Fix GH-18136: tracing JIT floating point register clobbering on Windows and ARM64
On win64, xmm6-xmm15 are preserved registers, but the prologues and
epilogues of JITted code don't handle these. The issue occurs when
calling into the JIT code again via an internal handler
(like call_user_func). Therefore, we want to save/restore xmm registers
upon entering/leaving execute_ex. Since MSVC x64 does not support inline
assembly, we create an assembly wrapper around the real execute_ex
function.
The alternative is to always save/restore these xmm registers into the
fixed call frame, but this causes unnecessary overhead.
The same issue occurs for ARM64 platforms for floating point register
8 to 15. However, there we can use inline asm to fix this.

Closes GH-18352.
2025-04-21 13:15:43 +02:00
Christoph M. Becker
e9ffe02fa1
Merge branch 'PHP-8.4'
* PHP-8.4:
  [skip ci] Fix phpize for Windows 11 (24H2)
2025-02-14 17:19:50 +01:00
Christoph M. Becker
974ed3130e
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  [skip ci] Fix phpize for Windows 11 (24H2)
2025-02-14 17:19:18 +01:00
Christoph M. Becker
302165837f
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [skip ci] Fix phpize for Windows 11 (24H2)
2025-02-14 17:17:51 +01:00
Christoph M. Becker
595e616292
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Fix phpize for Windows 11 (24H2)
2025-02-14 17:16:04 +01:00
Bob Weinand
7f6c05116e
[skip ci] Fix phpize for Windows 11 (24H2)
It seems like n === undefined must have worked on older versions of
jscript, but currently it just causes the insertion to silently fail.
This sets n to an empty string, allowing phpize to include the local
config.w32 files.
2025-02-14 17:15:24 +01:00
Christoph M. Becker
107bd080a5
Fix Clang style nits (GH-17685)
This addresses all `-Wlogical-op-parentheses` and `-Wmissing-braces`
warnings across the whole code base (all Windows specific code).
2025-02-05 14:13:56 +01:00
Christoph M. Becker
4e6a3cecf5
Don't forward declare static functions in sendmail.h (GH-17684)
sendmail.h is not only included by sendmail.c, but also by
php_win32_globals.h, because that header uses some of the defined
macros.  However, the forward declarations of the static functions are
not needed anywhere else than in sendmail.c, and Clang warns about the
unused functions elsewhere (`-Wunused-function`).  Thus we move the
forward declarations to sendmail.c.
2025-02-03 16:50:32 +01:00
Christoph M. Becker
3fa9e283a0
Drop unused local variables (GH-17682) 2025-02-03 16:42:29 +01:00
Christoph M. Becker
caf5e8a167
Solve C4267 warnings in win32/ioutil for x64 (GH-17674)
C4267[1] are about conversion from `size_t` to a "smaller" type,
causing potential loss of data (aka. truncation).

In this case we can solve that cleanly (i.e. without casting and
further checks) by changing the affected variables to be of type
`DWORD`.

[1] <https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4267>
2025-02-03 00:13:58 +01:00
Shivam Mathur
0d8aebf1d9
Fix condition to check for config.w32 in phpize (#17667) 2025-02-02 08:49:16 +05:30
Christoph M. Becker
f1702d2bb1
Suppress MSVC C4995 warnings (deprecations)
These have the same meaning as C4996[1] (which we already suppress),
but are triggered by a different mechanism[2].  It makes no sense to
suppress one, but not both.

Of course it would be better not to suppress either, but wrt the two
C4995 warnings we see in php-src, that requires deprecation of using
the ODBC cursor library[3], so might take a while.

[1] <https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996>
[2] <https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4995>
[3] <https://externals.io/message/126264>

Closes GH-17664.
2025-02-01 22:48:43 +01:00
Christoph M. Becker
236e12e5f0
Drop --with-uncritical-warn-choke configuration option
This selection of suppressed warnings is pretty arbitrary, and
apparently disabling it does not raise any more warning for whole
php-src (except for `-Wno-deprecated-declarations`).  As such it
appears to be pretty useless, and it seems to be more appropriate to
let users select which warnings to suppress via manually set `CFLAGS`.

Since we already apply `/wd4996`[1] when building with MSVC, and there
are indeed plenty of deprecation warnings, for now, we apply
`-Wno-deprecated-declarations` for Clang builds unconditionally.

[1] <https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996>

Closes GH-17554.
2025-02-01 15:09:40 +01:00
Christoph M. Becker
3955b01653
Avoid duplicate build rules
On Windows, the cli and phpdbg SAPIs have variants (cli-win32 and
phpdbgs, respectively) which are build by default.  However, the
variants share some files, what leads to duplicate build rules in the
generated Makefile.  NMake throws warning U4004[1], but proceeds
happily, ignoring the second build rule.  That means that different
flags for duplicate rules are ignored, hinting at a potential problem.

We solve this by introducing an additional (optional) argument to
`SAPI()` and `ADD_SOURCES()` which can be used to avoid such duplicate
build rules.  It's left to the SAPI maintainers to make sure that
appropriate rules are created.  We fix this for phpdbgs right away,
which currently couldn't be build without phpdbg due to the missing
define; we remove the unused `PHP_PHPDBG_EXPORTS` flag altogether.

[1] <https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/nmake-warning-u4004>

Closes GH-17545.
2025-02-01 11:21:09 +01:00
Christoph M. Becker
75d7684e9f
Remove useless compiler options (GH-17553)
* `/Fp` provides a path name for procompiled headers[1], but we don't use
  these.
* `/FR` is used to generate .sbr files; these have been important long
  ago for Visual Studio support, but as of Visual Studio 2008 the IDE
  no longer uses .sbr files.
* `/LD` is used to inform the *compiler* that it should build a DLL[3];
  however, we build all DLLs with the *linker*.

[1] <https://learn.microsoft.com/en-us/cpp/build/reference/fp-name-dot-pch-file>
[2] <https://learn.microsoft.com/en-us/cpp/build/reference/fr-fr-create-dot-sbr-file>
[3] <https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library>
2025-01-25 19:59:12 +01:00
Christoph M. Becker
aa76127d01
Address more Clang warnings (GH-17506)
We prefer clean solutions (such as declaring the proper type in the
first place, or introducing a portable format specifier) where easily
possible, but resort to casts otherwise.

We also port f1480ab14b.
2025-01-21 20:05:29 +01:00
David CARLIER
252c0c9164
win32: switch handful of memmove over memcpy. (#17508) 2025-01-18 14:47:48 +00:00
Christoph M. Becker
7dbfacb27e Suppress UB warnings regarding indirect function calls
Like for POSIX systems, we pass `-fno-sanitize=function`.

Closes GH-17462.
2025-01-17 23:00:57 +01:00
Christoph M. Becker
e1c4c0300e Fix Clang lib folder detection on Windows
First, more recent versions of Clang do no longer have trailing info in
parentheses, so the detection would fail.  Since we're not interested
in this information, we just ignore it.

Then we should not rely on Clang being installed in the default program
folder.  Instead we look up where the first clang.exe can be found, and
assume that it is located in a bin/ folder in the installation path.
From there we construct the library path, which is
`lib\clang\<ver>\lib\windows` where `<ver>` is either the full version
(older Clang) or only the major version.  Note that this is the case
for stand-alone LLVM installations as well as Visual Studio supplied
ones.

Finally, we clean up by improving the error messages, and removing the
duplicate clang version detection in `add_asan_opts()`.

While we're at it, we also apply a cosmetic improvement to avoid
(trailing) whitespace in the compiler name (e.g. shown by `-v`).
2025-01-17 23:00:57 +01:00
Christoph M. Becker
8a9095a92e
Define PHP_HAVE_BUILTIN_EXPECT for Clang on Windows (GH-17457)
Clang supports `__builtin_expect()` at least as of 4.0.0, which is the
(theoretical) minimum required on Windows, so we define it
unconditionally.  This also solves some macro redefinition warnings in
JIT-IR.
2025-01-17 14:21:02 +01:00
Christoph M. Becker
5c39a4636b
Replace __forceinline with zend_always_inline in win32/ (GH-17482)
`__forceinline` is MSVC specific (and also understood by Clang on
Windows), but the code in win32/ should not be constrained to these
compilers.  Since we already have `zend_always_inline`, we use this
instead.
2025-01-16 15:05:24 +01:00
Christoph M. Becker
6967de563e
Simplify ZEND_SIGNED_MULTIPLY_LONG() on Windows (GH-17477)
For Clang, we just need to define the respective macros, since these
built-ins are available in all supported Clang versions (>= 4.0.0,
currently)[1].

For MSVC (and possibly other compilers) we use the respective APIs of
intsafe.h[2] which are available as of Windows 7/Server 2008 R2.

For x86 (and to a lesser extend for ARM64) that should also notably
improve performance.

[1] <https://releases.llvm.org/4.0.0/tools/clang/docs/LanguageExtensions.html>
[2] <https://learn.microsoft.com/en-us/windows/win32/api/intsafe/>
2025-01-16 13:57:07 +01:00
Christoph M. Becker
39f1d253b1
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix potential OOB when checking for trailing spaces
2025-01-16 00:03:16 +01:00
Christoph M. Becker
b702eafbff
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix potential OOB when checking for trailing spaces
2025-01-16 00:02:39 +01:00
Christoph M. Becker
ed8b11188b
Fix potential OOB when checking for trailing spaces
If `path_len` is zero, we must not access `path`, let alone try to
subtract `-1` from it.

Since `path` and `path_len` are supposed to come from a `zend_string`,
this is not a security issue.

Closes GH-17471.
2025-01-16 00:01:22 +01:00
Christoph M. Becker
7512685767
Use built-ins for addition and subtraction on Windows (GH-17472)
For Clang, we just need to define the respective macros, since these
built-ins are available in all supported Clang versions (>= 4.0.0,
currently)[1].

For MSVC (and possibly other compilers) we use the respective APIs of
intsafe.h[2] which are available as of Windows 7/Server 2008 R2.

This avoids the UB due to signed integer overflow that may happen with
our fallback implementations.

We also drop the superfluous SHORT_MAX definition from pdo_firebird.
This shouldn't be defined unconditionally, but since it is apparently
unused, we remove it altogether.

[1] <https://releases.llvm.org/4.0.0/tools/clang/docs/LanguageExtensions.html>
[2] <https://learn.microsoft.com/en-us/windows/win32/api/intsafe/>
2025-01-15 12:58:12 +01:00
Christoph M. Becker
634edc8ab3
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix clang compiler detection on Windows
2025-01-14 12:36:58 +01:00
Christoph M. Becker
58628e0cc6
Fix clang compiler detection on Windows
A previous commit[1] left a "debug" statement, which causes clang
builds on Windows to fail always.

[1] <b3d6414b87>

Closes GH-17450.
2025-01-14 12:36:19 +01:00
Christoph M. Becker
1675d32261
Fix printf style issues in Windows specific code (GH-17452)
A couple of calls pass strings as formats (`-Wformat-security`), and
some others mix up types (`-Wformat`).
2025-01-13 11:50:05 +01:00
Christoph M. Becker
c264679fb4
Remove braces around string initializers (#GH-17451)
While MSVC is apparently fine with that, Clang complains about it (`-Wbraced-scalar-init`).
2025-01-12 19:40:15 +01:00
Calvin Buckley
97a26ae97a
Update OpenBSD glob implementation for Windows (#16948)
We're considering making this used as a glob implementation on POSIX as
well, but first, we should rebase it from the latest version of OpenBSD.

This also adds a new internal header (charclass.h) for glob.

See conversation in GH-15564.

Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2025-01-10 11:47:28 -04:00
Christoph M. Becker
6972612e1e
Improve fix for GH-16889
The original patch[1] cared only about pipe handles in the rset, but
would be problematic if there are other handles (e.g. files in the
rset, or pipes/files in the other sets), because `php_select()` would
return immediately, reporting all non read-pipe handles as ready, but
possibly never reporting read-pipe handles.

We fix this by applying different logic for the case where only pipe
handles are supplied in the rset, but no handles in the wset or eset.
In this case `php_select()` only returns when actually one of the
handles is ready, or when the timeout expires.  To avoid busy looping
in this case, we sleep for a short amount of time.  This matches POSIX
behavior.

In all other cases, `php_select()` behaves as before (i.e. prior to the
original fix), that is it returns immediately, reporting all handles as
ready.

We also add a test case that demonstrates multiplexing the output of a
couple of child processes.

See also the discussion on <https://github.com/php/php-src/pull/16917>.

[1] <b614b4a69a>

Closes GH-17174.
2024-12-16 23:25:38 +01:00
Christoph M. Becker
c14bc7b10f
Fail phpize early if config.w32 is missing (GH-17100)
On Windows, phpize happily builds configure even if there is no
config.w32, but running configure then error with "Must be run from the
root of the extension source".  This is confusing.

We bring phpize's behavior on par with POSIX systems, where the missing
config.m4 is detected and reported right away.
2024-12-15 12:02:19 +01:00
Christoph M. Becker
300811f1e2
Remove support for unsupported MSVC versions (GH-17128)
As of PHP 8.4.0, MSVC >= 1920 (aka. Visual Studio 2019 RTW 16.0) is
required anyway[1], so we can clean up a bit.

[1] <b3d6414b87>
2024-12-12 19:50:14 +01:00
Christoph M. Becker
03731570cf
Fix GH-16843: Windows phpize builds ignore source subfolders
phpize builds on Windows ignore the paths of extension sources, and
build all object files in the same folder.  This can't work if there
are multiple source files with the same base name stored in separate
folders and registered as such (e.g. cls/worker.c and src/worker.c).
While extension authors can work around by avoiding duplicate base
names, they may not even be aware of the problem because on POSIX
systems, the object files are usually placed right besides the sources.

Thus we take the relative path (from `configure_module_dirname`) of the
source files into account even for phpize builds.  Since this may break
some extension builds (especially those which use Makefile fragments),
we do not apply this fix to stable branches.

Closes GH-17016.
2024-12-09 12:33:26 +01:00
Christoph M. Becker
c0385e978a
Guard config.w32.h from multiple inclusion (GH-17021)
Besides that is generally good practice to avoid macro redefinitions
(and symbol redeclarations), and we're doing this on POSIX platforms
anyway, there is a particular issue regarding phpize builds, where
config.w32.h actually includes config.pickle.h.  The latter overrides
some macro definitions (e.g. `PHP_BUILD_SYSTEM`) to define the proper
values, but if config.w32.h is included multiple times, different macro
definitions eventually raise C4005 compiler warnings[1], which break
builds with `/WX /W1` enabled.

[1] <https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4005>
2024-12-08 23:42:34 +01:00