Skip to content

Commit d2a0a80

Browse files
committed
Fix the auto ZTS detection to use zend_module_entry
1 parent ff38ab4 commit d2a0a80

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

src/Inspector/Settings/TargetPhpSettings/TargetPhpSettings.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public function __construct(
3333
public string $zts_globals_regex = self::ZTS_GLOBALS_REGEX_DEFAULT,
3434
public string $php_version = self::TARGET_PHP_VERSION_DEFAULT,
3535
public ?string $php_path = null,
36-
public ?string $libpthread_path = null
36+
public ?string $libpthread_path = null,
37+
public bool $zts = false,
3738
) {
3839
}
3940

src/Lib/Elf/Process/ProcessModuleSymbolReaderCreator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function createModuleReaderByNameRegex(
5353

5454
$module_name = $module_memory_map->getModuleName();
5555
$path = $binary_path ?? $this->process_path_resolver->resolve($pid, $module_name);
56+
if (file_exists($path) === false) {
57+
return null;
58+
}
5659

5760
$symbol_resolver = new Elf64CachedSymbolResolver(
5861
new Elf64LazyParseSymbolResolver(

src/Lib/PhpInternals/Types/Zend/ZendModuleEntry.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,11 @@ public function getPointer(): Pointer
8080
{
8181
return $this->pointer;
8282
}
83+
84+
85+
86+
public function isZts(): bool
87+
{
88+
return $this->zts;
89+
}
8390
}

src/Lib/PhpProcessReader/PhpGlobalsFinder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function findTsrmLsCache(
4444
ProcessSpecifier $process_specifier,
4545
TargetPhpSettings $target_php_settings
4646
): ?int {
47+
if (!$target_php_settings->zts) {
48+
return null;
49+
}
4750
$tsrm_ls_cache_cdata = $this->getSymbolReader(
4851
$process_specifier,
4952
$target_php_settings

src/Lib/PhpProcessReader/PhpVersionDetector.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,19 @@ public function decidePhpVersion(
7575
$process_specifier,
7676
$target_php_settings,
7777
);
78-
$version = null;
78+
$version_and_zts = null;
7979
if (!is_null($module_registry_address)) {
80-
$version = $this->detectPhpVersion($process_specifier->pid, $module_registry_address);
80+
$version_and_zts = $this->detectPhpVersion($process_specifier->pid, $module_registry_address);
8181
}
8282

83-
if (is_null($version)) {
83+
if (is_null($version_and_zts)) {
8484
/** @var value-of<ZendTypeReader::ALL_SUPPORTED_VERSIONS> $version */
8585
$version = 'v' . PHP_MAJOR_VERSION . PHP_MINOR_VERSION;
8686
Assert::true(ZendTypeReader::isSupported($version));
87-
}
87+
$is_zts = false;
88+
} else {
89+
[$version, $is_zts] = $version_and_zts;
90+
}
8891

8992
return new TargetPhpSettings(
9093
php_regex: $target_php_settings->php_regex,
@@ -93,14 +96,15 @@ public function decidePhpVersion(
9396
php_version: $version,
9497
php_path: $target_php_settings->php_path,
9598
libpthread_path: $target_php_settings->libpthread_path,
99+
zts: $is_zts,
96100
);
97101
}
98102

99-
/** @return value-of<ZendTypeReader::ALL_SUPPORTED_VERSIONS>|null */
103+
/** @return array{value-of<ZendTypeReader::ALL_SUPPORTED_VERSIONS>, bool}|null */
100104
public function detectPhpVersion(
101105
int $pid,
102106
int $module_registry_address
103-
): ?string {
107+
): ?array {
104108
$fake_php_version = ZendTypeReader::V70;
105109
$dereferencer = $this->getDereferencer($pid, $fake_php_version);
106110
$module_registry = $this->getModuleRegistry(
@@ -127,7 +131,7 @@ public function detectPhpVersion(
127131
$result_string = 'v' . str_replace('.', '', $version);
128132
if (ZendTypeReader::isSupported($result_string)) {
129133
/** @var value-of<ZendTypeReader::ALL_SUPPORTED_VERSIONS> */
130-
return $result_string;
134+
return [$result_string, $basic_module_entry->isZts()];
131135
}
132136
return null;
133137
}

0 commit comments

Comments
 (0)