| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Linux::Perl::getrandom; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2370
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=encoding utf-8 |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Linux::Perl::getrandom |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $numbytes = Linux::Perl::getrandom::x86_64->getrandom( |
|
15
|
|
|
|
|
|
|
buffer => \$buffer, |
|
16
|
|
|
|
|
|
|
flags => [ 'RANDOM', 'NONBLOCK' ], |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# … or, platform-neutral: |
|
20
|
|
|
|
|
|
|
my $numbytes = Linux::Perl::getrandom->getrandom( |
|
21
|
|
|
|
|
|
|
buffer => \$buffer, |
|
22
|
|
|
|
|
|
|
flags => [ 'RANDOM', 'NONBLOCK' ], |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This is an interface to Linux’s C system call. This system |
|
28
|
|
|
|
|
|
|
call is documented only for kernel 3.17 and after; however, it appears |
|
29
|
|
|
|
|
|
|
to be present in some earlier kernel versions. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
|
32
|
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
332
|
use Linux::Perl; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
34
|
1
|
|
|
1
|
|
309
|
use Linux::Perl::Pointer; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
194
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my %FLAG_VALUE = ( |
|
37
|
|
|
|
|
|
|
NONBLOCK => 1, |
|
38
|
|
|
|
|
|
|
RANDOM => 2, |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub getrandom { |
|
42
|
1
|
|
|
1
|
0
|
250
|
my ($class, %opts) = @_; |
|
43
|
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
10
|
if (!$class->can('NR_getrandom')) { |
|
45
|
1
|
|
|
|
|
629
|
require Linux::Perl::ArchLoader; |
|
46
|
1
|
|
|
|
|
4
|
$class = Linux::Perl::ArchLoader::get_arch_module($class); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
2
|
my $flags = 0; |
|
50
|
1
|
50
|
|
|
|
4
|
if ($opts{'flags'}) { |
|
51
|
0
|
|
|
|
|
0
|
for my $f ( @{ $opts{'flags'} } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
52
|
0
|
|
0
|
|
|
0
|
$flags |= $FLAG_VALUE{$f} || do { |
|
53
|
|
|
|
|
|
|
die "Invalid flag: “$f”!"; |
|
54
|
|
|
|
|
|
|
}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
1
|
50
|
|
|
|
4
|
if ('SCALAR' ne ref $opts{'buffer'}) { |
|
59
|
0
|
|
|
|
|
0
|
die "“buffer” must be a scalar reference, not “$opts{'buffer'}”!"; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return Linux::Perl::call( |
|
63
|
|
|
|
|
|
|
$class->NR_getrandom(), |
|
64
|
1
|
|
|
|
|
4
|
Linux::Perl::Pointer::get_address( ${ $opts{'buffer'} } ), |
|
65
|
1
|
|
|
|
|
9
|
length( ${ $opts{'buffer'} } ), |
|
|
1
|
|
|
|
|
5
|
|
|
66
|
|
|
|
|
|
|
0 + $flags, |
|
67
|
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |