fix: Qt6 Wayland crash — root cause identified, kded6 fix deployed
ROOT CAUSE: Qt6's auto-generated Wayland wrappers pass NULL proxies to wl_*_add_listener() during initialization. The generated code stores wlRegistryBind() return value in m_wl_* member without null check, then init_listener() calls wl_*_add_listener(m_wl_*, ...) which page-faults at null+8 (write to proxy->object.implementation). FIX (kded6): wrapper script renames libqwayland.so to .disabled before launching kded6.real. QT_QPA_PLATFORM=offscreen alone is not sufficient — Qt6 still loads wayland plugin despite env var. FIX (libwayland): null guards in redox.patch for wl_proxy_add_listener, wl_proxy_get_version, wl_proxy_get_display. Blocked from compilation by pre-existing relibc conflicts (open_memstream, signalfd_siginfo). FIX (Qt6 wrappers): regex-based null guard insertion proven in concept. Blocked by TOML recipe format not supporting backslash escape sequences. Implementation plan: inject null guards via a separate build step script rather than inline in recipe.toml.
This commit is contained in:
@@ -16,48 +16,94 @@ const SECTOR_SIZE: usize = 512;
|
||||
const TEST_PATTERN: &[u8; 24] = b"REDBEAR-USB-RW-PROOF\0\0\0\0";
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
enum CheckResult { Pass, Fail, Skip }
|
||||
enum CheckResult {
|
||||
Pass,
|
||||
Fail,
|
||||
Skip,
|
||||
}
|
||||
|
||||
impl CheckResult {
|
||||
fn label(self) -> &'static str {
|
||||
match self { Self::Pass => "PASS", Self::Fail => "FAIL", Self::Skip => "SKIP" }
|
||||
match self {
|
||||
Self::Pass => "PASS",
|
||||
Self::Fail => "FAIL",
|
||||
Self::Skip => "SKIP",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Check { name: String, result: CheckResult, detail: String }
|
||||
struct Check {
|
||||
name: String,
|
||||
result: CheckResult,
|
||||
detail: String,
|
||||
}
|
||||
|
||||
impl Check {
|
||||
fn pass(name: &str, detail: &str) -> Self {
|
||||
Check { name: name.to_string(), result: CheckResult::Pass, detail: detail.to_string() }
|
||||
Check {
|
||||
name: name.to_string(),
|
||||
result: CheckResult::Pass,
|
||||
detail: detail.to_string(),
|
||||
}
|
||||
}
|
||||
fn fail(name: &str, detail: &str) -> Self {
|
||||
Check { name: name.to_string(), result: CheckResult::Fail, detail: detail.to_string() }
|
||||
Check {
|
||||
name: name.to_string(),
|
||||
result: CheckResult::Fail,
|
||||
detail: detail.to_string(),
|
||||
}
|
||||
}
|
||||
fn skip(name: &str, detail: &str) -> Self {
|
||||
Check { name: name.to_string(), result: CheckResult::Skip, detail: detail.to_string() }
|
||||
Check {
|
||||
name: name.to_string(),
|
||||
result: CheckResult::Skip,
|
||||
detail: detail.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Report { checks: Vec<Check>, json_mode: bool }
|
||||
struct Report {
|
||||
checks: Vec<Check>,
|
||||
json_mode: bool,
|
||||
}
|
||||
|
||||
impl Report {
|
||||
fn new(json_mode: bool) -> Self { Report { checks: Vec::new(), json_mode } }
|
||||
fn add(&mut self, check: Check) { self.checks.push(check); }
|
||||
fn any_failed(&self) -> bool { self.checks.iter().any(|c| c.result == CheckResult::Fail) }
|
||||
fn new(json_mode: bool) -> Self {
|
||||
Report {
|
||||
checks: Vec::new(),
|
||||
json_mode,
|
||||
}
|
||||
}
|
||||
fn add(&mut self, check: Check) {
|
||||
self.checks.push(check);
|
||||
}
|
||||
fn any_failed(&self) -> bool {
|
||||
self.checks.iter().any(|c| c.result == CheckResult::Fail)
|
||||
}
|
||||
fn print(&self) {
|
||||
if self.json_mode { self.print_json(); } else { self.print_human(); }
|
||||
if self.json_mode {
|
||||
self.print_json();
|
||||
} else {
|
||||
self.print_human();
|
||||
}
|
||||
}
|
||||
fn print_human(&self) {
|
||||
for check in &self.checks {
|
||||
let icon = match check.result {
|
||||
CheckResult::Pass => "[PASS]", CheckResult::Fail => "[FAIL]", CheckResult::Skip => "[SKIP]",
|
||||
CheckResult::Pass => "[PASS]",
|
||||
CheckResult::Fail => "[FAIL]",
|
||||
CheckResult::Skip => "[SKIP]",
|
||||
};
|
||||
println!("{icon} {}: {}", check.name, check.detail);
|
||||
}
|
||||
}
|
||||
fn print_json(&self) {
|
||||
#[derive(serde::Serialize)]
|
||||
struct JsonCheck { name: String, result: String, detail: String }
|
||||
struct JsonCheck {
|
||||
name: String,
|
||||
result: String,
|
||||
detail: String,
|
||||
}
|
||||
#[derive(serde::Serialize)]
|
||||
struct JsonReport {
|
||||
device_path: String,
|
||||
@@ -66,21 +112,42 @@ impl Report {
|
||||
sector_restored: bool,
|
||||
checks: Vec<JsonCheck>,
|
||||
}
|
||||
let dev = self.checks.iter().find(|c| c.name == "STORAGE_DISCOVERY")
|
||||
let dev = self
|
||||
.checks
|
||||
.iter()
|
||||
.find(|c| c.name == "STORAGE_DISCOVERY")
|
||||
.map_or("none".to_string(), |c| c.detail.clone());
|
||||
let written = self.checks.iter().any(|c| c.name == "STORAGE_WRITE" && c.result == CheckResult::Pass);
|
||||
let verified = self.checks.iter().any(|c| c.name == "STORAGE_READBACK" && c.result == CheckResult::Pass);
|
||||
let restored = self.checks.iter().any(|c| c.name == "STORAGE_RESTORE" && c.result == CheckResult::Pass);
|
||||
let checks: Vec<JsonCheck> = self.checks.iter().map(|c| JsonCheck {
|
||||
name: c.name.clone(), result: c.result.label().to_string(), detail: c.detail.clone(),
|
||||
}).collect();
|
||||
if let Err(err) = serde_json::to_writer(std::io::stdout(), &JsonReport {
|
||||
device_path: dev,
|
||||
sector_written: written,
|
||||
sector_verified: verified,
|
||||
sector_restored: restored,
|
||||
checks,
|
||||
}) {
|
||||
let written = self
|
||||
.checks
|
||||
.iter()
|
||||
.any(|c| c.name == "STORAGE_WRITE" && c.result == CheckResult::Pass);
|
||||
let verified = self
|
||||
.checks
|
||||
.iter()
|
||||
.any(|c| c.name == "STORAGE_READBACK" && c.result == CheckResult::Pass);
|
||||
let restored = self
|
||||
.checks
|
||||
.iter()
|
||||
.any(|c| c.name == "STORAGE_RESTORE" && c.result == CheckResult::Pass);
|
||||
let checks: Vec<JsonCheck> = self
|
||||
.checks
|
||||
.iter()
|
||||
.map(|c| JsonCheck {
|
||||
name: c.name.clone(),
|
||||
result: c.result.label().to_string(),
|
||||
detail: c.detail.clone(),
|
||||
})
|
||||
.collect();
|
||||
if let Err(err) = serde_json::to_writer(
|
||||
std::io::stdout(),
|
||||
&JsonReport {
|
||||
device_path: dev,
|
||||
sector_written: written,
|
||||
sector_verified: verified,
|
||||
sector_restored: restored,
|
||||
checks,
|
||||
},
|
||||
) {
|
||||
eprintln!("{PROGRAM}: failed to serialize JSON: {err}");
|
||||
}
|
||||
}
|
||||
@@ -92,7 +159,10 @@ fn parse_args() -> Result<bool, String> {
|
||||
for arg in std::env::args().skip(1) {
|
||||
match arg.as_str() {
|
||||
"--json" => json_mode = true,
|
||||
"-h" | "--help" => { println!("{USAGE}"); return Err(String::new()); }
|
||||
"-h" | "--help" => {
|
||||
println!("{USAGE}");
|
||||
return Err(String::new());
|
||||
}
|
||||
_ => return Err(format!("unsupported argument: {arg}")),
|
||||
}
|
||||
}
|
||||
@@ -102,8 +172,10 @@ fn parse_args() -> Result<bool, String> {
|
||||
#[cfg(target_os = "redox")]
|
||||
fn list_dir(path: &str) -> Vec<String> {
|
||||
match fs::read_dir(path) {
|
||||
Ok(entries) => entries.filter_map(|e| e.ok())
|
||||
.filter_map(|e| e.file_name().to_str().map(|s| s.to_string())).collect(),
|
||||
Ok(entries) => entries
|
||||
.filter_map(|e| e.ok())
|
||||
.filter_map(|e| e.file_name().to_str().map(|s| s.to_string()))
|
||||
.collect(),
|
||||
Err(_) => Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -158,14 +230,25 @@ fn check_storage_discovery() -> Check {
|
||||
if let Ok(data) = fs::read_to_string(&desc_path) {
|
||||
if let Ok(desc) = serde_json::from_str::<serde_json::Value>(&data) {
|
||||
let class = desc.get("class").and_then(|v| v.as_u64()).unwrap_or(0);
|
||||
if class == 8 { storage_count += 1; }
|
||||
if class == 8 {
|
||||
storage_count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Check::pass("STORAGE_DISCOVERY", &format!("{} ({} USB storage class device(s) visible)", path, storage_count))
|
||||
Check::pass(
|
||||
"STORAGE_DISCOVERY",
|
||||
&format!(
|
||||
"{} ({} USB storage class device(s) visible)",
|
||||
path, storage_count
|
||||
),
|
||||
)
|
||||
}
|
||||
None => Check::fail("STORAGE_DISCOVERY", "no writable block device found under /scheme/disk/"),
|
||||
None => Check::fail(
|
||||
"STORAGE_DISCOVERY",
|
||||
"no writable block device found under /scheme/disk/",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,17 +258,32 @@ fn check_storage_write(disk_path: &str, original_out: &mut [u8; SECTOR_SIZE]) ->
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
let offset = TEST_SECTOR * SECTOR_SIZE as u64;
|
||||
|
||||
let mut f = match fs::OpenOptions::new().read(true).write(true).open(disk_path) {
|
||||
let mut f = match fs::OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(disk_path)
|
||||
{
|
||||
Ok(f) => f,
|
||||
Err(e) => return Check::fail("STORAGE_WRITE", &format!("failed to open {} for read/write: {e}", disk_path)),
|
||||
Err(e) => {
|
||||
return Check::fail(
|
||||
"STORAGE_WRITE",
|
||||
&format!("failed to open {} for read/write: {e}", disk_path),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Save original content for later restore
|
||||
if let Err(e) = f.seek(SeekFrom::Start(offset)) {
|
||||
return Check::fail("STORAGE_WRITE", &format!("failed to seek to sector {TEST_SECTOR}: {e}"));
|
||||
return Check::fail(
|
||||
"STORAGE_WRITE",
|
||||
&format!("failed to seek to sector {TEST_SECTOR}: {e}"),
|
||||
);
|
||||
}
|
||||
if let Err(e) = f.read_exact(original_out) {
|
||||
return Check::fail("STORAGE_WRITE", &format!("failed to read original sector {TEST_SECTOR}: {e}"));
|
||||
return Check::fail(
|
||||
"STORAGE_WRITE",
|
||||
&format!("failed to read original sector {TEST_SECTOR}: {e}"),
|
||||
);
|
||||
}
|
||||
|
||||
let pattern = make_test_pattern();
|
||||
@@ -193,12 +291,21 @@ fn check_storage_write(disk_path: &str, original_out: &mut [u8; SECTOR_SIZE]) ->
|
||||
return Check::fail("STORAGE_WRITE", &format!("failed to seek for write: {e}"));
|
||||
}
|
||||
if let Err(e) = f.write_all(&pattern) {
|
||||
return Check::fail("STORAGE_WRITE", &format!("failed to write test pattern to sector {TEST_SECTOR}: {e}"));
|
||||
return Check::fail(
|
||||
"STORAGE_WRITE",
|
||||
&format!("failed to write test pattern to sector {TEST_SECTOR}: {e}"),
|
||||
);
|
||||
}
|
||||
if let Err(e) = f.flush() {
|
||||
return Check::fail("STORAGE_WRITE", &format!("failed to flush write: {e}"));
|
||||
}
|
||||
Check::pass("STORAGE_WRITE", &format!("wrote test pattern to sector {TEST_SECTOR} of {}", disk_path))
|
||||
Check::pass(
|
||||
"STORAGE_WRITE",
|
||||
&format!(
|
||||
"wrote test pattern to sector {TEST_SECTOR} of {}",
|
||||
disk_path
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/// Read back the test sector and verify the pattern matches.
|
||||
@@ -209,29 +316,47 @@ fn check_storage_readback(disk_path: &str) -> Check {
|
||||
|
||||
let mut f = match fs::File::open(disk_path) {
|
||||
Ok(f) => f,
|
||||
Err(e) => return Check::fail("STORAGE_READBACK", &format!("failed to reopen {}: {e}", disk_path)),
|
||||
Err(e) => {
|
||||
return Check::fail(
|
||||
"STORAGE_READBACK",
|
||||
&format!("failed to reopen {}: {e}", disk_path),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = f.seek(SeekFrom::Start(offset)) {
|
||||
return Check::fail("STORAGE_READBACK", &format!("failed to seek to sector {TEST_SECTOR}: {e}"));
|
||||
return Check::fail(
|
||||
"STORAGE_READBACK",
|
||||
&format!("failed to seek to sector {TEST_SECTOR}: {e}"),
|
||||
);
|
||||
}
|
||||
|
||||
let mut buf = [0u8; SECTOR_SIZE];
|
||||
if let Err(e) = f.read_exact(&mut buf) {
|
||||
return Check::fail("STORAGE_READBACK", &format!("failed to read sector {TEST_SECTOR}: {e}"));
|
||||
return Check::fail(
|
||||
"STORAGE_READBACK",
|
||||
&format!("failed to read sector {TEST_SECTOR}: {e}"),
|
||||
);
|
||||
}
|
||||
|
||||
let pattern = make_test_pattern();
|
||||
if buf == pattern {
|
||||
Check::pass("STORAGE_READBACK", &format!("sector {TEST_SECTOR} readback matches test pattern"))
|
||||
Check::pass(
|
||||
"STORAGE_READBACK",
|
||||
&format!("sector {TEST_SECTOR} readback matches test pattern"),
|
||||
)
|
||||
} else {
|
||||
let first_mismatch = buf.iter().zip(pattern.iter()).enumerate()
|
||||
let first_mismatch = buf
|
||||
.iter()
|
||||
.zip(pattern.iter())
|
||||
.enumerate()
|
||||
.find(|(_, (a, b))| a != b)
|
||||
.map(|(i, _)| i)
|
||||
.unwrap_or(SECTOR_SIZE);
|
||||
Check::fail("STORAGE_READBACK", &format!(
|
||||
"sector {TEST_SECTOR} readback mismatch at byte offset {first_mismatch}"
|
||||
))
|
||||
Check::fail(
|
||||
"STORAGE_READBACK",
|
||||
&format!("sector {TEST_SECTOR} readback mismatch at byte offset {first_mismatch}"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,25 +368,42 @@ fn check_storage_restore(disk_path: &str, original: &[u8; SECTOR_SIZE]) -> Check
|
||||
|
||||
let mut f = match fs::OpenOptions::new().write(true).open(disk_path) {
|
||||
Ok(f) => f,
|
||||
Err(e) => return Check::fail("STORAGE_RESTORE", &format!("failed to open {} for restore: {e}", disk_path)),
|
||||
Err(e) => {
|
||||
return Check::fail(
|
||||
"STORAGE_RESTORE",
|
||||
&format!("failed to open {} for restore: {e}", disk_path),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = f.seek(SeekFrom::Start(offset)) {
|
||||
return Check::fail("STORAGE_RESTORE", &format!("failed to seek for restore: {e}"));
|
||||
return Check::fail(
|
||||
"STORAGE_RESTORE",
|
||||
&format!("failed to seek for restore: {e}"),
|
||||
);
|
||||
}
|
||||
if let Err(e) = f.write_all(original) {
|
||||
return Check::fail("STORAGE_RESTORE", &format!("failed to restore original sector: {e}"));
|
||||
return Check::fail(
|
||||
"STORAGE_RESTORE",
|
||||
&format!("failed to restore original sector: {e}"),
|
||||
);
|
||||
}
|
||||
if let Err(e) = f.flush() {
|
||||
return Check::fail("STORAGE_RESTORE", &format!("failed to flush restore: {e}"));
|
||||
}
|
||||
Check::pass("STORAGE_RESTORE", &format!("restored original content of sector {TEST_SECTOR}"))
|
||||
Check::pass(
|
||||
"STORAGE_RESTORE",
|
||||
&format!("restored original content of sector {TEST_SECTOR}"),
|
||||
)
|
||||
}
|
||||
|
||||
fn run() -> Result<(), String> {
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
{
|
||||
if std::env::args().any(|a| a == "-h" || a == "--help") { println!("{USAGE}"); return Err(String::new()); }
|
||||
if std::env::args().any(|a| a == "-h" || a == "--help") {
|
||||
println!("{USAGE}");
|
||||
return Err(String::new());
|
||||
}
|
||||
println!("{PROGRAM}: USB storage check requires Redox runtime");
|
||||
return Ok(());
|
||||
}
|
||||
@@ -271,7 +413,11 @@ fn run() -> Result<(), String> {
|
||||
let mut report = Report::new(json_mode);
|
||||
|
||||
let discovery = check_storage_discovery();
|
||||
let disk_path = discovery.detail.split_whitespace().next().map(|s| s.to_string());
|
||||
let disk_path = discovery
|
||||
.detail
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.map(|s| s.to_string());
|
||||
report.add(discovery);
|
||||
|
||||
let disk_path = match disk_path {
|
||||
@@ -290,24 +436,34 @@ fn run() -> Result<(), String> {
|
||||
if write_ok {
|
||||
report.add(check_storage_readback(&disk_path));
|
||||
} else {
|
||||
report.add(Check::skip("STORAGE_READBACK", "skipped because write check failed"));
|
||||
report.add(Check::skip(
|
||||
"STORAGE_READBACK",
|
||||
"skipped because write check failed",
|
||||
));
|
||||
}
|
||||
|
||||
if write_ok {
|
||||
report.add(check_storage_restore(&disk_path, &original));
|
||||
} else {
|
||||
report.add(Check::skip("STORAGE_RESTORE", "skipped because write check failed"));
|
||||
report.add(Check::skip(
|
||||
"STORAGE_RESTORE",
|
||||
"skipped because write check failed",
|
||||
));
|
||||
}
|
||||
|
||||
report.print();
|
||||
if report.any_failed() { return Err("one or more USB storage checks failed".to_string()); }
|
||||
if report.any_failed() {
|
||||
return Err("one or more USB storage checks failed".to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = run() {
|
||||
if err.is_empty() { process::exit(0); }
|
||||
if err.is_empty() {
|
||||
process::exit(0);
|
||||
}
|
||||
eprintln!("{PROGRAM}: {err}");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user