@@ -7,7 +7,11 @@ use crate::{fs::File, io::Read};
7
7
/// Key to access the CPU Hardware capabilities bitfield.
8
8
pub ( crate ) const AT_HWCAP : usize = 16 ;
9
9
/// Key to access the CPU Hardware capabilities 2 bitfield.
10
- #[ cfg( any( target_arch = "arm" , target_arch = "powerpc64" ) ) ]
10
+ #[ cfg( any(
11
+ target_arch = "arm" ,
12
+ target_arch = "powerpc" ,
13
+ target_arch = "powerpc64"
14
+ ) ) ]
11
15
pub ( crate ) const AT_HWCAP2 : usize = 26 ;
12
16
13
17
/// Cache HWCAP bitfields of the ELF Auxiliary Vector.
@@ -17,7 +21,11 @@ pub(crate) const AT_HWCAP2: usize = 26;
17
21
#[ derive( Debug , Copy , Clone ) ]
18
22
pub ( crate ) struct AuxVec {
19
23
pub hwcap : usize ,
20
- #[ cfg( any( target_arch = "arm" , target_arch = "powerpc64" ) ) ]
24
+ #[ cfg( any(
25
+ target_arch = "arm" ,
26
+ target_arch = "powerpc" ,
27
+ target_arch = "powerpc64"
28
+ ) ) ]
21
29
pub hwcap2 : usize ,
22
30
}
23
31
@@ -64,7 +72,11 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
64
72
}
65
73
66
74
// Targets with AT_HWCAP and AT_HWCAP2:
67
- #[ cfg( any( target_arch = "arm" , target_arch = "powerpc64" ) ) ]
75
+ #[ cfg( any(
76
+ target_arch = "arm" ,
77
+ target_arch = "powerpc" ,
78
+ target_arch = "powerpc64"
79
+ ) ) ]
68
80
{
69
81
if let Ok ( hwcap2) = getauxval ( AT_HWCAP2 ) {
70
82
if hwcap != 0 && hwcap2 != 0 {
@@ -74,21 +86,11 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
74
86
}
75
87
drop ( hwcap) ;
76
88
}
77
- #[ cfg( feature = "std_detect_file_io" ) ]
78
- {
79
- // If calling getauxval fails, try to read the auxiliary vector from
80
- // its file:
81
- auxv_from_file ( "/proc/self/auxv" )
82
- }
83
- #[ cfg( not( feature = "std_detect_file_io" ) ) ]
84
- {
85
- Err ( ( ) )
86
- }
87
89
}
88
90
89
91
#[ cfg( not( feature = "std_detect_dlsym_getauxval" ) ) ]
90
92
{
91
- let hwcap = unsafe { ffi_getauxval ( AT_HWCAP ) } ;
93
+ let hwcap = unsafe { libc :: getauxval ( AT_HWCAP ) } ;
92
94
93
95
// Targets with only AT_HWCAP:
94
96
#[ cfg( any( target_arch = "aarch64" , target_arch = "mips" , target_arch = "mips64" ) ) ]
@@ -99,14 +101,29 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
99
101
}
100
102
101
103
// Targets with AT_HWCAP and AT_HWCAP2:
102
- #[ cfg( any( target_arch = "arm" , target_arch = "powerpc64" ) ) ]
104
+ #[ cfg( any(
105
+ target_arch = "arm" ,
106
+ target_arch = "powerpc" ,
107
+ target_arch = "powerpc64"
108
+ ) ) ]
103
109
{
104
- let hwcap2 = unsafe { ffi_getauxval ( AT_HWCAP2 ) } ;
110
+ let hwcap2 = unsafe { libc :: getauxval ( AT_HWCAP2 ) } ;
105
111
if hwcap != 0 && hwcap2 != 0 {
106
112
return Ok ( AuxVec { hwcap, hwcap2 } ) ;
107
113
}
108
114
}
109
115
}
116
+
117
+ #[ cfg( feature = "std_detect_file_io" ) ]
118
+ {
119
+ // If calling getauxval fails, try to read the auxiliary vector from
120
+ // its file:
121
+ auxv_from_file ( "/proc/self/auxv" )
122
+ }
123
+ #[ cfg( not( feature = "std_detect_file_io" ) ) ]
124
+ {
125
+ Err ( ( ) )
126
+ }
110
127
}
111
128
112
129
/// Tries to read the `key` from the auxiliary vector by calling the
@@ -122,7 +139,7 @@ fn getauxval(key: usize) -> Result<usize, ()> {
122
139
return Err ( ( ) ) ;
123
140
}
124
141
125
- let ffi_getauxval: F = mem:: transmute ( ptr) ;
142
+ let ffi_getauxval: F = crate :: mem:: transmute ( ptr) ;
126
143
Ok ( ffi_getauxval ( key) )
127
144
}
128
145
}
@@ -140,7 +157,8 @@ fn auxv_from_file(file: &str) -> Result<AuxVec, ()> {
140
157
// 2*32 `usize` elements is enough to read the whole vector.
141
158
let mut buf = [ 0_usize ; 64 ] ;
142
159
{
143
- let raw: & mut [ u8 ; 64 * mem:: size_of :: < usize > ( ) ] = unsafe { mem:: transmute ( & mut buf) } ;
160
+ let raw: & mut [ u8 ; 64 * crate :: mem:: size_of :: < usize > ( ) ] =
161
+ unsafe { crate :: mem:: transmute ( & mut buf) } ;
144
162
file. read ( raw) . map_err ( |_| ( ) ) ?;
145
163
}
146
164
auxv_from_buf ( & buf)
@@ -161,7 +179,11 @@ fn auxv_from_buf(buf: &[usize; 64]) -> Result<AuxVec, ()> {
161
179
}
162
180
}
163
181
// Targets with AT_HWCAP and AT_HWCAP2:
164
- #[ cfg( any( target_arch = "arm" , target_arch = "powerpc64" ) ) ]
182
+ #[ cfg( any(
183
+ target_arch = "arm" ,
184
+ target_arch = "powerpc" ,
185
+ target_arch = "powerpc64"
186
+ ) ) ]
165
187
{
166
188
let mut hwcap = None ;
167
189
let mut hwcap2 = None ;
@@ -214,7 +236,12 @@ mod tests {
214
236
215
237
// FIXME: on mips/mips64 getauxval returns 0, and /proc/self/auxv
216
238
// does not always contain the AT_HWCAP key under qemu.
217
- #[ cfg( not( any( target_arch = "mips" , target_arch = "mips64" , target_arch = "powerpc" ) ) ) ]
239
+ #[ cfg( any(
240
+ target_arch = "aarch64" ,
241
+ target_arch = "arm" ,
242
+ target_arch = "powerpc" ,
243
+ target_arch = "powerpc64"
244
+ ) ) ]
218
245
#[ test]
219
246
fn auxv_crate ( ) {
220
247
let v = auxv ( ) ;
@@ -224,7 +251,11 @@ mod tests {
224
251
}
225
252
226
253
// Targets with AT_HWCAP and AT_HWCAP2:
227
- #[ cfg( any( target_arch = "arm" , target_arch = "powerpc64" ) ) ]
254
+ #[ cfg( any(
255
+ target_arch = "arm" ,
256
+ target_arch = "powerpc" ,
257
+ target_arch = "powerpc64"
258
+ ) ) ]
228
259
{
229
260
if let Some ( hwcap2) = auxv_crate_getauxval ( AT_HWCAP2 ) {
230
261
let rt_hwcap2 = v. expect ( "failed to find hwcap2 key" ) . hwcap2 ;
@@ -243,7 +274,7 @@ mod tests {
243
274
}
244
275
245
276
#[ cfg( feature = "std_detect_file_io" ) ]
246
- cfg_if ! {
277
+ cfg_if:: cfg_if ! {
247
278
if #[ cfg( target_arch = "arm" ) ] {
248
279
#[ test]
249
280
fn linux_rpi3( ) {
@@ -287,14 +318,19 @@ mod tests {
287
318
}
288
319
289
320
#[ test]
321
+ #[ cfg( feature = "std_detect_file_io" ) ]
290
322
fn auxv_crate_procfs ( ) {
291
323
let v = auxv ( ) ;
292
324
if let Some ( hwcap) = auxv_crate_getprocfs ( AT_HWCAP ) {
293
325
assert_eq ! ( v. unwrap( ) . hwcap, hwcap) ;
294
326
}
295
327
296
328
// Targets with AT_HWCAP and AT_HWCAP2:
297
- #[ cfg( any( target_arch = "arm" , target_arch = "powerpc64" ) ) ]
329
+ #[ cfg( any(
330
+ target_arch = "arm" ,
331
+ target_arch = "powerpc" ,
332
+ target_arch = "powerpc64"
333
+ ) ) ]
298
334
{
299
335
if let Some ( hwcap2) = auxv_crate_getprocfs ( AT_HWCAP2 ) {
300
336
assert_eq ! ( v. unwrap( ) . hwcap2, hwcap2) ;
0 commit comments