File Coverage

blib/lib/Linux/Personality.pm
Criterion Covered Total %
statement 25 26 96.1
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 34 37 91.8


line stmt bran cond sub pod time code
1             package Linux::Personality;
2              
3 1     1   83058 use strict;
  1         6  
  1         160  
4 1     1   10 use warnings;
  1         4  
  1         48  
5 1     1   6 use Carp;
  1         10  
  1         9625  
6              
7             require Exporter;
8 1     1   6376 use AutoLoader;
  1         3795  
  1         8  
9              
10             our @ISA = qw(Exporter);
11              
12             # Items to export into callers namespace by default. Note: do not export
13             # names by default without a very good reason. Use EXPORT_OK instead.
14             # Do not simply export all your public functions/methods/constants.
15              
16             # This allows declaration use Linux::Personality ':all';
17             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18             # will save memory.
19              
20             our @EXPORT = ();
21             our %EXPORT_TAGS = (
22             'funcs' => [ qw/ personality / ],
23             'consts' => [ qw/ ADDR_LIMIT_32BIT
24             ADDR_LIMIT_3GB
25             ADDR_NO_RANDOMIZE
26             MMAP_PAGE_ZERO
27             PER_BSD
28             PER_HPUX
29             PER_IRIX32
30             PER_IRIX64
31             PER_IRIXN32
32             PER_ISCR4
33             PER_LINUX
34             PER_LINUX32
35             PER_LINUX32_3GB
36             PER_LINUX_32BIT
37             PER_MASK
38             PER_OSF4
39             PER_OSR5
40             PER_RISCOS
41             PER_SCOSVR3
42             PER_SOLARIS
43             PER_SUNOS
44             PER_SVR3
45             PER_SVR4
46             PER_UW7
47             PER_WYSEV386
48             PER_XENIX
49             SHORT_INODE
50             STICKY_TIMEOUTS
51             WHOLE_SECONDS
52             / ],
53             # ADDR_COMPAT_LAYOUT # not in 2.6.28
54             # READ_IMPLIES_EXEC # not in 2.6.28
55             );
56             our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
57             $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
58              
59             our $VERSION = '0.01';
60              
61             sub AUTOLOAD {
62             # This AUTOLOAD is used to 'autoload' constants from the constant()
63             # XS function.
64              
65 1     1   663 my $constname;
66 1         2 our $AUTOLOAD;
67 1         7 ($constname = $AUTOLOAD) =~ s/.*:://;
68 1 50       7 croak "&Linux::Personality::constant not defined" if $constname eq 'constant';
69 1         10 my ($error, $val) = constant($constname);
70 1 50       5 if ($error) { croak $error; }
  0         0  
71             {
72 1     1   390 no strict 'refs';
  1         3  
  1         128  
  1         2  
73             # Fixed between 5.005_53 and 5.005_61
74             #XXX if ($] >= 5.00561) {
75             #XXX *$AUTOLOAD = sub () { $val };
76             #XXX }
77             #XXX else {
78 1     2   9 *$AUTOLOAD = sub { $val };
  2         53656  
79             #XXX }
80             }
81 1         6 goto &$AUTOLOAD;
82             }
83              
84             require XSLoader;
85             XSLoader::load('Linux::Personality', $VERSION);
86              
87             # Preloaded methods go here.
88              
89             # Autoload methods go after =cut, and are processed by the autosplit program.
90              
91             1;
92             __END__
93             # Below is stub documentation for your module. You'd better edit it!
94              
95             =head1 NAME
96              
97             Linux::Personality - Perl interface to the personality(2) Linux system call.
98              
99             =head1 SYNOPSIS
100              
101             Common usage:
102              
103             use Linux::Personality qw/personality PER_LINUX32 /;
104             print `uname -m`; # x86_64
105             personality(PER_LINUX32);
106             print `uname -m`; # i686
107              
108             Use flags for bugs emulation:
109              
110             use Linux::Personality qw/personality
111             PER_LINUX32
112             ADDR_LIMIT_3GB
113             SHORT_INODE
114             MMAP_PAGE_ZERO /;
115             personality(PER_LINUX32 | ADDR_LIMIT_3GB | SHORT_INODE | MMAP_PAGE_ZERO);
116              
117             =head1 DESCRIPTION
118              
119             You can use this for instance when running 32bit compiles started from
120             inside a Perl program in a 32bit chroot but running on a 64bit host
121             kernel. Without hints the compile tools get confused and try do do
122             64bit in the 32bit environment.
123              
124             It's somewhat comparable to the C<setarch> (also known as C<linux32>)
125             utility. With C<personality> you can get similar effect inside a Perl
126             program.
127              
128             From "man 2 personality":
129              
130             NAME
131             personality - set the process execution domain
132            
133             SYNOPSIS
134             #include <sys/personality.h>
135             int personality(unsigned long persona);
136            
137             DESCRIPTION
138             Linux supports different execution domains, or personalities,
139             for each process. Among other things, execution domains tell
140             Linux how to map signal numbers into signal actions. The
141             execution domain system allows Linux to provide limited
142             support for binaries compiled under other Unix-like operating
143             systems.
144              
145             This function will return the current personality() when
146             persona equals 0xffffffff. Otherwise, it will make the
147             execution domain referenced by persona the new execution
148             domain of the calling process.
149            
150             RETURN VALUE
151             On success, the previous persona is returned. On error, -1 is
152             returned, and errno is set appropriately.
153            
154             ERRORS
155             EINVAL The kernel was unable to change the personality.
156            
157             CONFORMING TO
158             personality() is Linux-specific and should not be used in
159             programs intended to be portable.
160              
161             =head2 EXPORT
162              
163             None by default.
164              
165             =head2 Exportable functions
166              
167             personality
168              
169             =head2 Exportable constants
170              
171             ADDR_LIMIT_32BIT
172             ADDR_LIMIT_3GB
173             ADDR_NO_RANDOMIZE
174             MMAP_PAGE_ZERO
175             PER_BSD
176             PER_HPUX
177             PER_IRIX32
178             PER_IRIX64
179             PER_IRIXN32
180             PER_ISCR4
181             PER_LINUX
182             PER_LINUX32
183             PER_LINUX32_3GB
184             PER_LINUX_32BIT
185             PER_MASK
186             PER_OSF4
187             PER_OSR5
188             PER_RISCOS
189             PER_SCOSVR3
190             PER_SOLARIS
191             PER_SUNOS
192             PER_SVR3
193             PER_SVR4
194             PER_UW7
195             PER_WYSEV386
196             PER_XENIX
197             SHORT_INODE
198             STICKY_TIMEOUTS
199             WHOLE_SECONDS
200              
201             =head1 SEE ALSO
202              
203             man 2 personality
204             /usr/include/sys/personality.h
205              
206             =head1 AUTHOR
207              
208             Steffen Schwigon, C<< <ss5@renormalist.net> >>
209              
210             =head1 CREDITS
211              
212             Maik Hentsche C<< <maik.hentsche@amd.com> >> for having the problem in
213             the first place and digging the according solution.
214              
215             Florian Ragwitz C<< <rafl@debian.org> >> for the usual Perl low-level
216             support.
217              
218             =head1 COPYRIGHT AND LICENSE
219              
220             Copyright (C) 2010 by Steffen Schwigon
221              
222             This library is free software; you can redistribute it and/or modify
223             it under the same terms as Perl itself, either Perl version 5.10.1 or,
224             at your option, any later version of Perl 5 you may have available.
225              
226             =cut