Skip to content

Commit 2fef474

Browse files
committed
WIP: debug
1 parent 27fcba1 commit 2fef474

File tree

4 files changed

+46
-23
lines changed

4 files changed

+46
-23
lines changed

library/std_detect/src/detect/os/linux/auxvec.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{
@@ -153,20 +153,27 @@ fn getauxval(key: usize) -> Result<usize, ()> {
153153
Ok(unsafe { ffi_getauxval(key as libc::c_ulong) as usize })
154154
}
155155

156+
#[cfg(feature = "std_detect_file_io")]
157+
use alloc::string::String;
158+
156159
/// Tries to read the auxiliary vector from the `file`. If this fails, this
157160
/// function returns `Err`.
158161
#[cfg(feature = "std_detect_file_io")]
159-
pub(super) fn auxv_from_file(file: &str) -> Result<AuxVec, ()> {
162+
pub(super) fn auxv_from_file(file: &str) -> Result<AuxVec, String> {
160163
let file = super::read_file(file)?;
164+
auxv_from_file_bytes(&file)
165+
}
161166

167+
#[cfg(feature = "std_detect_file_io")]
168+
pub(super) fn auxv_from_file_bytes(bytes: &[u8]) -> Result<AuxVec, String> {
162169
// See <https://github.com/torvalds/linux/blob/v5.15/include/uapi/linux/auxvec.h>.
163170
//
164171
// The auxiliary vector contains at most 34 (key,value) fields: from
165172
// `AT_MINSIGSTKSZ` to `AT_NULL`, but its number may increase.
166-
let len = file.len();
173+
let len = bytes.len();
167174
let mut buf = alloc::vec![0_usize; 1 + len / core::mem::size_of::<usize>()];
168175
unsafe {
169-
core::ptr::copy_nonoverlapping(file.as_ptr(), buf.as_mut_ptr() as *mut u8, len);
176+
core::ptr::copy_nonoverlapping(bytes.as_ptr(), buf.as_mut_ptr() as *mut u8, len);
170177
}
171178

172179
auxv_from_buf(&buf)
@@ -175,7 +182,7 @@ pub(super) fn auxv_from_file(file: &str) -> Result<AuxVec, ()> {
175182
/// Tries to interpret the `buffer` as an auxiliary vector. If that fails, this
176183
/// function returns `Err`.
177184
#[cfg(feature = "std_detect_file_io")]
178-
fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, ()> {
185+
fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, String> {
179186
// Targets with only AT_HWCAP:
180187
#[cfg(any(
181188
target_arch = "riscv32",
@@ -220,7 +227,7 @@ fn auxv_from_buf(buf: &[usize]) -> Result<AuxVec, ()> {
220227
}
221228
// Suppress unused variable
222229
let _ = buf;
223-
Err(())
230+
Err(String::from("hwcap not found"))
224231
}
225232

226233
#[cfg(test)]

library/std_detect/src/detect/os/linux/auxvec/tests.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,34 @@ cfg_if::cfg_if! {
4646
if #[cfg(target_arch = "arm")] {
4747
#[test]
4848
fn linux_rpi3() {
49-
let file = concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-rpi3.auxv");
50-
println!("file: {file}");
51-
let v = auxv_from_file(file).unwrap();
49+
let auxv = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-rpi3.auxv"));
50+
let v = auxv_from_file_bytes(auxv).unwrap();
5251
assert_eq!(v.hwcap, 4174038);
5352
assert_eq!(v.hwcap2, 16);
5453
}
5554

5655
#[test]
5756
fn linux_macos_vb() {
58-
let file = concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/macos-virtualbox-linux-x86-4850HQ.auxv");
59-
println!("file: {file}");
57+
let auxv = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/macos-virtualbox-linux-x86-4850HQ.auxv"));
6058
// The file contains HWCAP but not HWCAP2. In that case, we treat HWCAP2 as zero.
61-
let v = auxv_from_file(file).unwrap();
59+
let v = auxv_from_file_bytes(auxv).unwrap();
6260
assert_eq!(v.hwcap, 126614527);
6361
assert_eq!(v.hwcap2, 0);
6462
}
6563
} else if #[cfg(target_arch = "aarch64")] {
6664
#[cfg(target_endian = "little")]
6765
#[test]
6866
fn linux_artificial_aarch64() {
69-
let file = concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-artificial-aarch64.auxv");
70-
println!("file: {file}");
71-
let v = auxv_from_file(file).unwrap();
67+
let auxv = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-artificial-aarch64.auxv"));
68+
let v = auxv_from_file_bytes(auxv).unwrap();
7269
assert_eq!(v.hwcap, 0x0123456789abcdef);
7370
assert_eq!(v.hwcap2, 0x02468ace13579bdf);
7471
}
7572
#[cfg(target_endian = "little")]
7673
#[test]
7774
fn linux_no_hwcap2_aarch64() {
78-
let file = concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-no-hwcap2-aarch64.auxv");
79-
println!("file: {file}");
80-
let v = auxv_from_file(file).unwrap();
75+
let auxv = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/detect/test_data/linux-no-hwcap2-aarch64.auxv"));
76+
let v = auxv_from_file_bytes(auxv).unwrap();
8177
// An absent HWCAP2 is treated as zero, and does not prevent acceptance of HWCAP.
8278
assert_ne!(v.hwcap, 0);
8379
assert_eq!(v.hwcap2, 0);

library/std_detect/src/detect/os/linux/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
//! Run-time feature detection on Linux
22
//!
33
#[cfg(feature = "std_detect_file_io")]
4+
use alloc::format;
5+
#[cfg(feature = "std_detect_file_io")]
6+
use alloc::string::String;
7+
#[cfg(feature = "std_detect_file_io")]
48
use alloc::vec::Vec;
59

610
mod auxvec;
711

812
#[cfg(feature = "std_detect_file_io")]
9-
fn read_file(path: &str) -> Result<Vec<u8>, ()> {
10-
let mut path = Vec::from(path.as_bytes());
13+
fn read_file(orig_path: &str) -> Result<Vec<u8>, String> {
14+
let mut path = Vec::from(orig_path.as_bytes());
1115
path.push(0);
1216

1317
unsafe {
1418
let file = libc::open(path.as_ptr() as *const libc::c_char, libc::O_RDONLY);
1519
if file == -1 {
16-
return Err(());
20+
return Err(format!("Cannot open file at {orig_path}: {}", *libc::__errno_location()));
1721
}
1822

1923
let mut data = Vec::new();
@@ -23,7 +27,7 @@ fn read_file(path: &str) -> Result<Vec<u8>, ()> {
2327
match libc::read(file, spare.as_mut_ptr() as *mut _, spare.len()) {
2428
-1 => {
2529
libc::close(file);
26-
return Err(());
30+
return Err(format!("Error while reading from file at {orig_path}"));
2731
}
2832
0 => break,
2933
n => data.set_len(data.len() + n as usize),

src/ci/docker/host-x86_64/armhf-gnu/Dockerfile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ RUN sh /scripts/sccache.sh
8383
COPY static/gitconfig /etc/gitconfig
8484

8585
ENV RUST_CONFIGURE_ARGS --qemu-armhf-rootfs=/tmp/rootfs
86-
ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target arm-unknown-linux-gnueabihf
86+
ENV SCRIPT \
87+
ls -lha /checkout && \
88+
ls -lha /checkout/library && \
89+
ls -lha /checkout/library/std_detect && \
90+
ls -lha /checkout/library/std_detect/src && \
91+
ls -lha /checkout/library/std_detect/src/detect && \
92+
ls -lha /checkout/library/std_detect/src/detect/test_data && \
93+
ls -lha /checkout/library/std_detect/src/detect/test_data/linux-rpi3.auxv && \
94+
(python3 ../x.py --stage 2 test --host='' --target arm-unknown-linux-gnueabihf || exit 0) && \
95+
ls -lha /checkout && \
96+
ls -lha /checkout/library && \
97+
ls -lha /checkout/library/std_detect && \
98+
ls -lha /checkout/library/std_detect/src && \
99+
ls -lha /checkout/library/std_detect/src/detect && \
100+
ls -lha /checkout/library/std_detect/src/detect/test_data && \
101+
ls -lha /checkout/library/std_detect/src/detect/test_data/linux-rpi3.auxv && \
102+
exit 1
87103

88104
ENV NO_CHANGE_USER=1

0 commit comments

Comments
 (0)