@@ -119,7 +119,7 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
119
119
{
120
120
// If calling getauxval fails, try to read the auxiliary vector from
121
121
// its file:
122
- auxv_from_file ( "/proc/self/auxv" )
122
+ auxv_from_file ( "/proc/self/auxv" ) . map_err ( |_| ( ) )
123
123
}
124
124
#[ cfg( not( feature = "std_detect_file_io" ) ) ]
125
125
{
@@ -157,17 +157,22 @@ fn getauxval(key: usize) -> Result<usize, ()> {
157
157
/// Tries to read the auxiliary vector from the `file`. If this fails, this
158
158
/// function returns `Err`.
159
159
#[ cfg( feature = "std_detect_file_io" ) ]
160
- pub ( super ) fn auxv_from_file ( file : & str ) -> Result < AuxVec , ( ) > {
160
+ pub ( super ) fn auxv_from_file ( file : & str ) -> Result < AuxVec , alloc :: string :: String > {
161
161
let file = super :: read_file ( file) ?;
162
+ auxv_from_file_bytes ( & file)
163
+ }
162
164
165
+ /// Read auxiliary vector from a slice of bytes.
166
+ #[ cfg( feature = "std_detect_file_io" ) ]
167
+ pub ( super ) fn auxv_from_file_bytes ( bytes : & [ u8 ] ) -> Result < AuxVec , alloc:: string:: String > {
163
168
// See <https://github.com/torvalds/linux/blob/v5.15/include/uapi/linux/auxvec.h>.
164
169
//
165
170
// The auxiliary vector contains at most 34 (key,value) fields: from
166
171
// `AT_MINSIGSTKSZ` to `AT_NULL`, but its number may increase.
167
- let len = file . len ( ) ;
172
+ let len = bytes . len ( ) ;
168
173
let mut buf = alloc:: vec![ 0_usize ; 1 + len / core:: mem:: size_of:: <usize >( ) ] ;
169
174
unsafe {
170
- core:: ptr:: copy_nonoverlapping ( file . as_ptr ( ) , buf. as_mut_ptr ( ) as * mut u8 , len) ;
175
+ core:: ptr:: copy_nonoverlapping ( bytes . as_ptr ( ) , buf. as_mut_ptr ( ) as * mut u8 , len) ;
171
176
}
172
177
173
178
auxv_from_buf ( & buf)
@@ -176,7 +181,7 @@ pub(super) fn auxv_from_file(file: &str) -> Result<AuxVec, ()> {
176
181
/// Tries to interpret the `buffer` as an auxiliary vector. If that fails, this
177
182
/// function returns `Err`.
178
183
#[ cfg( feature = "std_detect_file_io" ) ]
179
- fn auxv_from_buf ( buf : & [ usize ] ) -> Result < AuxVec , ( ) > {
184
+ fn auxv_from_buf ( buf : & [ usize ] ) -> Result < AuxVec , alloc :: string :: String > {
180
185
// Targets with only AT_HWCAP:
181
186
#[ cfg( any(
182
187
target_arch = "riscv32" ,
@@ -222,7 +227,7 @@ fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, ()> {
222
227
}
223
228
// Suppress unused variable
224
229
let _ = buf;
225
- Err ( ( ) )
230
+ Err ( alloc :: string :: String :: from ( "hwcap not found" ) )
226
231
}
227
232
228
233
#[ cfg( test) ]
0 commit comments