History log of /PHP-8.1/TSRM/TSRM.c (Results 1 – 25 of 134)
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 51faf04d 15-Mar-2023 Niels Dossche <7771979+nielsdos@users.noreply.github.com>

Fix GH-10737: PHP 8.1.16 segfaults on line 597 of sapi/apache2handler/sapi_apache2.c

The TSRM keeps a hashtable mapping the thread IDs to the thread resource pointers.
It's possible that

Fix GH-10737: PHP 8.1.16 segfaults on line 597 of sapi/apache2handler/sapi_apache2.c

The TSRM keeps a hashtable mapping the thread IDs to the thread resource pointers.
It's possible that the thread disappears without us knowing, and then another thread
gets spawned some time later with the same ID as the disappeared thread.
Note that since it's a new thread the TSRM key pointer and cached pointer will be NULL.

The Apache request handler `php_handler()` will try to fetch some fields from the SAPI globals.
It uses a lazy thread resource allocation by calling `ts_resource(0);`.
This allocates a thread resource and sets up the TSRM pointers if they haven't been set up yet.

At least, that's what's supposed to happen. But since we are in a situation where the thread ID
still has the resources of the *old* thread associated in the hashtable,
the loop in `ts_resource_ex` will find that thread resource and assume the thread has been setup
already. But this is not the case since this thread is actually a new thread, just reusing the ID
of the old one, without any relation whatsoever to the old thread.
Because of this assumption, the TSRM pointers will not be setup, leading to a
NULL pointer dereference when trying to access the SAPI globals.

We can easily detect this scenario: if we're in the fallback path, and the pointer is NULL,
and we're looking for our own thread resource, we know we're actually reusing a thread ID.
In that case, we'll free up the old thread resources gracefully (gracefully because
there might still be resources open like database connection which need to be
shut down cleanly). After freeing the resources, we'll create the new resources for
this thread as if the stale resources never existed in the first place.
From that point forward, it is as if that situation never occurred.
The fact that this situation happens isn't that bad because a child process containing
threads will eventually be respawned anyway by the SAPI, so the stale thread resources
won't remain forever.

Note that we can't simply assign our own TSRM pointers to the existing
thread resource for our ID, since it was actually from a different thread
(just with the same ID!). Furthermore, the dynamically loaded extensions
have their own pointer, which is only set when their constructor is
called, so we'd have to call their constructor anyway...
I also tried to call the dtor and then the ctor again for those resources
on the pre-existing thread resource to reuse storage, but that didn't work properly
because other code doesn't expect something like that to happen, which breaks assumptions,
and this in turn caused Valgrind to (rightfully) complain about memory bugs.

Note 2: I also had to fix a bug in the core globals destruction because it
always assumed that the thread destroying them was the owning thread,
which on TSRM shutdown isn't always the case. A similar bug was fixed
recently with the JIT globals.

Closes GH-10863.

show more ...


Revision tags: php-8.1.7RC1
# 4c0639df 26-Apr-2022 Christoph M. Becker

Merge branch 'PHP-8.0' into PHP-8.1

* PHP-8.0:
Haiku fix ZTS build disabling `tsrm_ls_cache` usage.


# 4bb0dd49 11-Apr-2022 David Carlier

Haiku fix ZTS build disabling `tsrm_ls_cache` usage.

# 097c9271 11-Apr-2022 Christoph M. Becker

Merge branch 'PHP-8.0' into PHP-8.1

* PHP-8.0:
Move locks in TSRM.c to prevent races


# 1a75269c 03-Apr-2022 ryancaicse <73822648+ryancaicse@users.noreply.github.com>

Move locks in TSRM.c to prevent races

Closes GH-8298.

# 0b1bca6b 11-Mar-2022 Christoph M. Becker

Merge branch 'PHP-8.0' into PHP-8.1

* PHP-8.0:
Fix GH-8160: ZTS support on Alpine is broken


# 2b2aeb98 07-Mar-2022 Michael Voříšek

Fix GH-8160: ZTS support on Alpine is broken

We need to export `__MUSL__` so that phpize builds can see the proper
macro, and also need to fix "_tsrm_ls_cache" usage for musl.

C

Fix GH-8160: ZTS support on Alpine is broken

We need to export `__MUSL__` so that phpize builds can see the proper
macro, and also need to fix "_tsrm_ls_cache" usage for musl.

Closes GH-8180.

show more ...

Revision tags: php-8.1.4RC1, php-8.1.3
# f9bf5f48 11-Jan-2022 Joe Watkins

Merge branch 'PHP-8.0' into PHP-8.1

* PHP-8.0:
Fix TSRM ignoring done


Revision tags: php-8.1.2RC1, php-8.1.0, php-7.3.33
# d7db5f6e 05-Nov-2021 Joe Watkins

Fix TSRM ignoring done

# 00405717 17-Nov-2021 Nikita Popov

Merge branch 'PHP-8.0' into PHP-8.1

* PHP-8.0:
OpenBSD ZTS build fix


# fb3e646f 16-Nov-2021 David Carlier

OpenBSD ZTS build fix

Closes GH-7661.

Revision tags: php-7.3.32, php-7.3.31, php-7.3.30, php-7.3.29
# aff36587 29-Jun-2021 Patrick Allaert

Fixed some spaces used instead of tabs

# 7c2a3a94 31-May-2021 Hao Sun

JIT/AArch64: [macos][ZTS] Support fast path for tlv_get_addr (#7042)

* JIT/AArch64: [macos][ZTS] Support fast path for tlv_get_addr

Access to TLV(thread local variable) in macOS is

JIT/AArch64: [macos][ZTS] Support fast path for tlv_get_addr (#7042)

* JIT/AArch64: [macos][ZTS] Support fast path for tlv_get_addr

Access to TLV(thread local variable) in macOS is in "dynamic" form and
function tlv_get_addr() is invoked to resolve the address. See the
example in [1].

Note there is one struct TLVDescriptor [2] for each TLV. The first
member holds the address of function tlv_get_addr(), and the other two
members, "key" and "offset", would be used inside tlv_get_addr().

The disassembly code for function tlv_get_addr() is shown in [3]. With
the value from system register, i.e. tpidrro_el0, together with "key"
and "offset", the TLV address can be obtained.

Note that the value from tpidrro_el0 varies for different threads, and
unique address for TLV is resolved.

It's worth noting that slow path would be executed, i.e. function
tlv_allocate_and_initialize_for_key(), for the first time of TLV access.

In this patch:
1. "_tsrm_ls_cache" is guaranteed to be accessed before any VM/JIT code
during the request startup, e.g. in init_executor(), therefore, slow
path can be avoided.

2. As TLVDecriptor is immutable and zend_jit_setup() executes once, we
get this structure in tsrm_get_ls_cache_tcb_offset(). Note the 'ldr'
instruction would be patched to 'add' by the linker.

3. Only fast path for tlv_get_addr() is implemented in macro
LOAD_TSRM_CACHE.

With this patch, all ~4k test cases can pass for ZTS+CALL in macOS on
Apple silicon.

[1] https://gist.github.com/shqking/4aab67e0105f7c1f2c549d57d5799f94
[2]
https://opensource.apple.com/source/dyld/dyld-195.6/src/threadLocalVariables.c.auto.html
[3] https://gist.github.com/shqking/329d7712c26bad49786ab0a544a4af43

Change-Id: I613e9c37e3ff2ecc3fab0f53f1e48a0246e12ee3

show more ...

Revision tags: php-7.3.28
# 735e4ccf 26-Apr-2021 Dmitry Stogov

Support for ZTS

# 3b377b51 10-Mar-2021 Dmitry Stogov

Fixed bug #80814 (threaded mod_php won't load on FreeBSD: No space available for static Thread Local Storage)

Revision tags: php-7.3.27, php-7.3.26, php-7.3.26RC1, php-7.3.25, php-7.3.25RC1, php-7.3.24, php-7.3.24RC1, php-7.3.23, php-7.3.23RC1, php-7.3.22, php-7.3.22RC1, php-7.3.21, php-7.3.21RC1, php-7.3.20, php-7.3.20RC1, php-7.3.19
# 88355dd3 07-Jun-2020 twosee

Constify char * arguments of APIs

Closes GH-5676.

# 1b85e749 06-Jun-2020 twosee

Fix warning of strict-prototypes

Closes GH-5673.

Revision tags: php-7.4.7RC1, php-7.3.19RC1
# 1f72dd89 20-May-2020 George Peter Banyard

Fix [-Wundef] warning in TSRM

# 3302ffb0 17-May-2020 George Peter Banyard

Fix bogus check in TSRM and adjust TSRM_ASSERT macro

Closes GH-5562

Revision tags: php-7.3.18RC1, php-7.2.30, php-7.3.17, php-7.3.17RC1, php-7.3.18, php-7.3.16, php-7.3.16RC1, php-7.3.15RC1, php-7.3.15, php-7.3.14, php-7.3.14RC1, php-7.3.13, php-7.3.13RC1, php-7.2.26RC1, php-7.4.0, php-7.2.25, php-7.3.12, php-7.4.0RC6, php-7.3.12RC1, php-7.2.25RC1, php-7.4.0RC5, php-7.1.33, php-7.2.24, php-7.3.11, php-7.4.0RC4, php-7.3.11RC1, php-7.2.24RC1, php-7.4.0RC3, php-7.2.23, php-7.3.10, php-7.4.0RC2, php-7.2.23RC1, php-7.3.10RC1, php-7.4.0RC1, php-7.1.32, php-7.2.22, php-7.3.9, php-7.4.0beta4, php-7.2.22RC1, php-7.3.9RC1, php-7.4.0beta2, php-7.1.31, php-7.2.21, php-7.3.8, php-7.4.0beta1, php-7.2.21RC1, php-7.3.8RC1, php-7.4.0alpha3, php-7.3.7, php-7.2.20
# b98cd071 28-Jun-2019 Joe Watkins

Merge branch 'PHP-7.4'

* PHP-7.4:
implement tsrm_is_shutdown API


# 68485f8a 26-Jun-2019 Joe Watkins

implement tsrm_is_shutdown API

Revision tags: php-7.4.0alpha2, php-7.3.7RC3, php-7.3.7RC2, php-7.2.20RC2
# 7a236b67 17-Jun-2019 Dmitry Stogov

Attempt to fix JIT on Mac OSX ZTS build

Revision tags: php-7.4.0alpha1, php-7.3.7RC1, php-7.2.20RC1, php-7.2.19, php-7.3.6, php-7.1.30, php-7.2.19RC1, php-7.3.6RC1, php-7.1.29, php-7.2.18, php-7.3.5, php-7.2.18RC1, php-7.3.5RC1
# f89f6703 11-Apr-2019 Nikita Popov

Merge branch 'PHP-7.4'


# b213f13a 11-Apr-2019 Nikita Popov

Make tsrm_env_lock() void

We're not checking the return value and the NTS version of this
generates warnings. If we want to handle lock failures, we should
do a hard abort inside tsr

Make tsrm_env_lock() void

We're not checking the return value and the NTS version of this
generates warnings. If we want to handle lock failures, we should
do a hard abort inside tsrm_env_lock() itself.

show more ...

Revision tags: php-7.2.17, php-7.3.4, php-7.1.28
# 9a068760 01-Apr-2019 Dmitry Stogov

Added JIT compiler for x86 and x86_64

123456