Passed
Push — 0.6.x ( 9a1948...a98caa )
by Shinji
03:23 queued 01:32
created

X64LinuxThreadPointerRetriever   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createDefault() 0 6 1
A __construct() 0 3 1
A getThreadPointer() 0 6 2
1
<?php
2
3
/**
4
 * This file is part of the reliforp/reli-prof package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Reli\Lib\Elf\Tls;
15
16
use Reli\Lib\Libc\Errno\Errno;
17
use Reli\Lib\Libc\Sys\Ptrace\PtraceX64;
18
use Reli\Lib\Process\RegisterReader\RegisterReaderException;
19
use Reli\Lib\Process\RegisterReader\X64RegisterReader;
20
21
final class X64LinuxThreadPointerRetriever implements ThreadPointerRetrieverInterface
22
{
23
    public static function createDefault(): self
24
    {
25
        return new self(
26
            new X64RegisterReader(
27
                new PtraceX64(),
28
                new Errno(),
29
            )
30
        );
31
    }
32
33
    public function __construct(
34
        private X64RegisterReader $register_reader,
35
    ) {
36
    }
37
38
    /**
39
     * @throws TlsFinderException
40
     */
41
    public function getThreadPointer(int $pid): int
42
    {
43
        try {
44
            return $this->register_reader->attachAndReadOne($pid, X64RegisterReader::FS_BASE);
45
        } catch (RegisterReaderException $e) {
46
            throw new TlsFinderException('cannot find thread pointer', 0, $e);
47
        }
48
    }
49
}
50