This commit is contained in:
2025-05-12 14:25:25 +02:00
parent ab2db755ef
commit 9e378ca2b7
2719 changed files with 46505 additions and 60181 deletions

View File

@@ -97,7 +97,7 @@ final class FFICaster
return [Caster::PREFIX_VIRTUAL.'returnType' => $returnType];
}
private static function castFFIPointer(Stub $stub, CType $type, CData $data = null): array
private static function castFFIPointer(Stub $stub, CType $type, ?CData $data = null): array
{
$ptr = $type->getPointerType();
@@ -115,11 +115,21 @@ final class FFICaster
private static function castFFIStringValue(CData $data): string|CutStub
{
$result = [];
$ffi = \FFI::cdef(<<<C
size_t zend_get_page_size(void);
C);
for ($i = 0; $i < self::MAX_STRING_LENGTH; ++$i) {
$pageSize = $ffi->zend_get_page_size();
// get cdata address
$start = $ffi->cast('uintptr_t', $ffi->cast('char*', $data))->cdata;
// accessing memory in the same page as $start is safe
$max = min(self::MAX_STRING_LENGTH, ($start | ($pageSize - 1)) - $start);
for ($i = 0; $i < $max; ++$i) {
$result[$i] = $data[$i];
if ("\0" === $result[$i]) {
if ("\0" === $data[$i]) {
return implode('', $result);
}
}
@@ -132,7 +142,7 @@ final class FFICaster
return $stub;
}
private static function castFFIStructLike(CType $type, CData $data = null): array
private static function castFFIStructLike(CType $type, ?CData $data = null): array
{
$isUnion = ($type->getAttributes() & CType::ATTR_UNION) === CType::ATTR_UNION;