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