Gate text IPC dumps behind a feature and log them to port 2

This commit is contained in:
pjht 2025-02-26 13:48:03 -06:00
parent 1c8540d851
commit c0d0ad5a1e
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
6 changed files with 35 additions and 17 deletions

7
Cargo.lock generated
View File

@ -224,6 +224,7 @@ dependencies = [
"humansize",
"intrusive-collections",
"linked_list_allocator",
"mutually_exclusive_features",
"pic8259",
"postcard",
"replace_with",
@ -286,6 +287,12 @@ dependencies = [
"autocfg",
]
[[package]]
name = "mutually_exclusive_features"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94e1e6445d314f972ff7395df2de295fe51b71821694f0b0e1e79c4f12c8577"
[[package]]
name = "num-traits"
version = "0.2.19"

View File

@ -32,6 +32,8 @@ unsigned-varint = "0.8.0"
postcard = { version = "1.1.1", features = ["alloc"] }
serde = { version = "1.0.218", features = ["alloc", "derive"], default-features = false }
bitflags = { version = "2.8.0", features = ["serde"] }
mutually_exclusive_features = "0.1.0"
[features]
log-rpc = []
log-rpc-pcapng = []
log-rpc-text = []

View File

@ -1,6 +1,5 @@
use crate::{
bootinfo::BOOTINFO,
ipc_dump::dump_ipc_message,
pit::NUM_INTERRUPTS,
print, println,
tasking::{InvalidPid, IpcMessage, SleepReason},
@ -30,11 +29,14 @@ use x86_64::{
PhysAddr, PrivilegeLevel, VirtAddr,
};
#[cfg(feature = "log-rpc")]
#[cfg(feature = "log-rpc-pcapng")]
use crate::serial::SECOND_PORT;
#[cfg(feature = "log-rpc")]
#[cfg(feature = "log-rpc-pcapng")]
use saturating_cast::SaturatingCast;
#[cfg(feature = "log-rpc-text")]
use crate::ipc_dump::dump_ipc_message;
const IRQ_BASE: u8 = 32;
static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
@ -177,8 +179,9 @@ pub fn send_ipc_to(
)]
TASKING.current_pid().unwrap()
};
#[cfg(feature = "log-rpc-text")]
dump_ipc_message(from, pid, &buffer[0..len]);
#[cfg(feature = "log-rpc")]
#[cfg(feature = "log-rpc-pcapng")]
{
#[expect(
clippy::unwrap_used,

View File

@ -22,7 +22,9 @@ use rpc_header::RpcHeader;
use syslog_ipc::SyslogIpc;
use syslog_rpc::SyslogRpcMessage;
use crate::println;
use crate::serial::SECOND_PORT;
use core::fmt::Write;
pub fn dump_ipc_message(from: usize, dest: usize, buffer: &[u8]) {
let ipc_proto = u16::from_ne_bytes([buffer[0], buffer[1]]);
@ -36,31 +38,31 @@ pub fn dump_ipc_message(from: usize, dest: usize, buffer: &[u8]) {
let (file_rpc, rem_data) = FileRpcMessage::dissect(buffer, &msg);
let msg = msg.set_l2(file_rpc);
if rem_data.is_empty() {
println!("{msg}");
writeln!(&*SECOND_PORT, "{msg}").unwrap();
} else {
let msg = msg.set_l3(HexdumpLayer::new(&rem_data, 128));
println!("{msg}");
writeln!(&*SECOND_PORT, "{msg}").unwrap();
}
} else if msg.get_l1().proto == 5 {
let syslog_rpc = SyslogRpcMessage::dissect(buffer, &msg);
let msg = msg.set_l2(syslog_rpc);
println!("{msg}");
writeln!(&*SECOND_PORT, "{msg}").unwrap();
} else if msg.get_l1().proto == 8 {
let syslog_rpc = ProcManRpcMessage::dissect(buffer, &msg);
let msg = msg.set_l2(syslog_rpc);
println!("{msg}");
writeln!(&*SECOND_PORT, "{msg}").unwrap();
} else {
let msg = msg.set_l2(HexdumpLayer::new(buffer, 128));
println!("{msg}");
writeln!(&*SECOND_PORT, "{msg}").unwrap();
}
} else if ipc_proto == 1 {
let msg = msg.set_l1(SyslogIpc::dissect(buffer));
println!("{msg}");
writeln!(&*SECOND_PORT, "{msg}").unwrap();
} else if ipc_proto == 2 {
let msg = msg.set_l1(InterruptProto::dissect(buffer));
println!("{msg}");
writeln!(&*SECOND_PORT, "{msg}").unwrap();
} else {
let msg = msg.set_l1(HexdumpLayer::new(buffer, 128));
println!("{msg}");
writeln!(&*SECOND_PORT, "{msg}").unwrap();
}
}

View File

@ -74,6 +74,7 @@ extern crate alloc;
mod bootinfo;
mod gdt;
mod interrupts;
#[cfg(feature = "log-rpc-text")]
mod ipc_dump;
mod kernel_heap;
mod panic_handler;
@ -97,6 +98,7 @@ use elf::{
endian::AnyEndian,
ElfBytes,
};
use mutually_exclusive_features::none_or_one_of;
use physical_memory::PHYSICAL_MEMORY;
use spin::lazy::Lazy;
use tar_no_std::TarArchiveRef;
@ -110,11 +112,13 @@ use x86_64::{
use crate::virtual_memory::AddressSpace;
#[cfg(feature = "log-rpc")]
#[cfg(feature = "log-rpc-pcapng")]
use serial::SECOND_PORT;
// pub static INITRD: &[u8] = include_bytes!("../initrd.tar");
none_or_one_of!("log-rpc-text", "log-rpc-pcapng");
#[expect(
clippy::expect_used,
reason = "Nothing to do here but panic on errors, this is the top level"
@ -271,7 +275,7 @@ pub fn main() {
}
}
#[cfg(feature = "log-rpc")]
#[cfg(feature = "log-rpc-pcapng")]
// Before starting init, write the pcapng section header + interface description to the second serial port
SECOND_PORT.write_u32s(&[
0x0A0D_0D0A, // SHB type

View File

@ -11,7 +11,7 @@ pub static FIRST_PORT: Lazy<Wrapper> = Lazy::new(|| {
Wrapper(Mutex::new(port))
});
#[cfg(feature = "log-rpc")]
#[cfg(any(feature = "log-rpc-pcapng", feature = "log-rpc-text"))]
pub static SECOND_PORT: Lazy<Wrapper> = Lazy::new(|| {
// SAFETY:
// 0x2f8 is the defined address for the second serial port on x86_64,