@@ -118,7 +118,7 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> {
118118 {
119119 // If calling getauxval fails, try to read the auxiliary vector from
120120 // its file:
121- auxv_from_file ( "/proc/self/auxv" )
121+ auxv_from_file ( "/proc/self/auxv" ) . map_err ( |_| ( ) )
122122 }
123123 #[ cfg( not( feature = "std_detect_file_io" ) ) ]
124124 {
@@ -156,17 +156,22 @@ fn getauxval(key: usize) -> Result<usize, ()> {
156156/// Tries to read the auxiliary vector from the `file`. If this fails, this
157157/// function returns `Err`.
158158#[ 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 > {
160160 let file = super :: read_file ( file) ?;
161+ auxv_from_file_bytes ( & file)
162+ }
161163
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 > {
162167 // See <https://github.com/torvalds/linux/blob/v5.15/include/uapi/linux/auxvec.h>.
163168 //
164169 // The auxiliary vector contains at most 34 (key,value) fields: from
165170 // `AT_MINSIGSTKSZ` to `AT_NULL`, but its number may increase.
166- let len = file . len ( ) ;
171+ let len = bytes . len ( ) ;
167172 let mut buf = alloc:: vec![ 0_usize ; 1 + len / core:: mem:: size_of:: <usize >( ) ] ;
168173 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) ;
170175 }
171176
172177 auxv_from_buf ( & buf)
@@ -175,7 +180,7 @@ pub(super) fn auxv_from_file(file: &str) -> Result<AuxVec, ()> {
175180/// Tries to interpret the `buffer` as an auxiliary vector. If that fails, this
176181/// function returns `Err`.
177182#[ 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 > {
179184 // Targets with only AT_HWCAP:
180185 #[ cfg( any(
181186 target_arch = "riscv32" ,
@@ -220,7 +225,7 @@ fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, ()> {
220225 }
221226 // Suppress unused variable
222227 let _ = buf;
223- Err ( ( ) )
228+ Err ( alloc :: string :: String :: from ( "hwcap not found" ) )
224229}
225230
226231#[ cfg( test) ]
0 commit comments