This commit is contained in:
bjorn3
2025-12-03 22:02:20 +01:00
parent f1057b6750
commit 7aa0776abd
11 changed files with 75 additions and 32 deletions
+2 -1
View File
@@ -60,7 +60,8 @@ fn daemon(daemon: Daemon) -> anyhow::Result<()> {
let ns = libredox::call::mkns(&[
//IoSlice::new(b"memory"), TODO: already included, uncommenting gives EEXIST
IoSlice::new(b"rand"), // for HashMap
]).context("failed to make namespace")?;
])
.context("failed to make namespace")?;
libredox::call::setrens(ns, ns).context("failed to set namespace")?;
// Spawn a thread to mix and send audio data
+5 -2
View File
@@ -262,7 +262,8 @@ impl AmlSymbols {
let handler = AmlPhysMemHandler::new(Arc::clone(&self.page_cache));
//TODO: use these parsed tables for the rest of acpid
let rsdp_address = usize::from_str_radix(&std::env::var("RSDP_ADDR")?, 16)?;
let tables = unsafe { AcpiTables::from_rsdp(handler.clone(), rsdp_address).map_err(format_err)? };
let tables =
unsafe { AcpiTables::from_rsdp(handler.clone(), rsdp_address).map_err(format_err)? };
let platform = AcpiPlatform::new(tables, handler).map_err(format_err)?;
let interpreter = Interpreter::new_from_platform(&platform).map_err(format_err)?;
self.aml_context = Some(interpreter);
@@ -279,7 +280,9 @@ impl AmlSymbols {
}
}
}
self.aml_context.as_mut().expect("AML context not initialized")
self.aml_context
.as_mut()
.expect("AML context not initialized")
}
pub fn symbols_cache(&self) -> &FxHashMap<String, String> {
+14 -11
View File
@@ -152,14 +152,14 @@ impl AmlPhysMemHandler {
match libredox::Fd::open(
"/scheme/pci/access",
libredox::flag::O_RDWR | libredox::flag::O_CLOEXEC,
0
0,
) {
Ok(fd) => Some(fd),
Err(err) => {
log::error!("failed to open /scheme/pci/access: {}", err);
None
}
}
},
);
Self { page_cache, pci_fd }
}
@@ -172,11 +172,11 @@ impl AmlPhysMemHandler {
// Offset: u16, 12 bits, 4096 total, at 0 bits
[
kind.into(),
(u64::from(addr.segment()) << 28) |
(u64::from(addr.bus()) << 20) |
(u64::from(addr.device()) << 15) |
(u64::from(addr.function()) << 12) |
u64::from(off)
(u64::from(addr.segment()) << 28)
| (u64::from(addr.bus()) << 20)
| (u64::from(addr.device()) << 15)
| (u64::from(addr.function()) << 12)
| u64::from(off),
]
}
@@ -184,13 +184,16 @@ impl AmlPhysMemHandler {
let metadata = Self::pci_call_metadata(1, addr, off);
match &*self.pci_fd {
Some(pci_fd) => match pci_fd.call_ro(value, syscall::CallFlags::empty(), &metadata) {
Ok(_) => {},
Ok(_) => {}
Err(err) => {
log::error!("read pci {addr}@{off:04X}:{:02X}: {}", value.len(), err);
}
},
None => {
log::error!("read pci {addr}@{off:04X}:{:02X}: pci access not available", value.len());
log::error!(
"read pci {addr}@{off:04X}:{:02X}: pci access not available",
value.len()
);
}
}
}
@@ -199,11 +202,11 @@ impl AmlPhysMemHandler {
let metadata = Self::pci_call_metadata(2, addr, off);
match &*self.pci_fd {
Some(pci_fd) => match pci_fd.call_wo(value, syscall::CallFlags::empty(), &metadata) {
Ok(_) => {},
Ok(_) => {}
Err(err) => {
log::error!("write pci {addr}@{off:04X}={value:02X?}: {}", err);
}
}
},
None => {
log::error!("write pci {addr}@{off:04X}={value:02X?}: pci access not available");
}
+1 -1
View File
@@ -19,7 +19,7 @@ pub mod sgl;
/// Low latency timeout for driver loops
pub mod timeout;
pub use logger::{output_level, file_level, setup_logging};
pub use logger::{file_level, output_level, setup_logging};
/// Specifies the write behavior for a specific region of memory
///
+1 -1
View File
@@ -23,7 +23,7 @@ fn main() {
"fbcond",
"fbcond",
common::output_level(),
common::file_level()
common::file_level(),
);
daemon::Daemon::new(|daemon| inner(daemon, &vt_ids));
+5 -3
View File
@@ -39,9 +39,11 @@ fn daemon(daemon: daemon::Daemon) -> ! {
// Must launch after acpid but before probe calls /scheme/acpi/symbols
match process::Command::new("pcid").spawn() {
Ok(mut child) => match child.wait() {
Ok(status) => if !status.success() {
log::error!("pcid exited with status {}", status);
},
Ok(status) => {
if !status.success() {
log::error!("pcid exited with status {}", status);
}
}
Err(err) => {
log::error!("failed to wait for pcid: {}", err);
}
+1 -1
View File
@@ -182,7 +182,7 @@ fn main() {
.expect(USAGE)
.parse::<u8>()
.expect("Expected integer as input of interface");
let name = format!("{}_{}_{}_hid", scheme, port, interface_num);
common::setup_logging(
"usb",
+5 -3
View File
@@ -134,7 +134,7 @@ impl SchemeSync for PciScheme {
addr: _,
ref mut st,
} => Self::read_channel(st, buf),
_ => Err(Error::new(EBADF))
_ => Err(Error::new(EBADF)),
}
}
fn getdents<'buf>(
@@ -232,7 +232,7 @@ impl SchemeSync for PciScheme {
((value >> 15) & 0x1F) as u8,
((value >> 12) & 0x7) as u8,
),
(value & 0xFFF) as u16
(value & 0xFFF) as u16,
)
}
None => return Err(Error::new(EINVAL)),
@@ -259,7 +259,9 @@ impl SchemeSync for PciScheme {
}
if write {
let value = u32::from_le_bytes(bytes);
unsafe { self.pcie.write(addr, start + i, value); }
unsafe {
self.pcie.write(addr, start + i, value);
}
}
}
Ok(payload.len())
+14 -4
View File
@@ -4,8 +4,8 @@ use libredox::error::Error;
use libredox::{flag, Fd};
use redox_scheme::{CallRequest, RequestKind, Response, SignalBehavior, Socket};
use syscall::EINTR;
use syscall::data::TimeSpec;
use syscall::EINTR;
mod controlterm;
mod pgrp;
@@ -106,7 +106,10 @@ fn scan_requests(
match request.kind() {
RequestKind::Cancellation(req) => {
if let Some(idx) = todo.iter().position(|t| t.request.request().request_id() == req.id) {
if let Some(idx) = todo
.iter()
.position(|t| t.request.request().request_id() == req.id)
{
todo[idx].cancelling = true;
}
}
@@ -116,7 +119,10 @@ fn scan_requests(
.write_response(response, SignalBehavior::Restart)
.expect("pty: failed to write responses to pty scheme");
} else {
todo.push(Todo { request, cancelling: false });
todo.push(Todo {
request,
cancelling: false,
});
}
}
_ => (),
@@ -134,7 +140,11 @@ fn do_todos(socket: &Socket, scheme: &mut PtyScheme, todo: &mut Vec<Todo>) {
.write_response(response, SignalBehavior::Restart)
.expect("pty: failed to write responses to pty scheme");
} else if todo[i].cancelling {
socket.write_response(Response::new(&todo[i].request, Err(Error::new(EINTR).into())), SignalBehavior::Restart)
socket
.write_response(
Response::new(&todo[i].request, Err(Error::new(EINTR).into())),
SignalBehavior::Restart,
)
.expect("pty: failed to write responses to pty scheme");
todo.remove(i);
} else {
+9 -2
View File
@@ -44,7 +44,10 @@ impl Resource for PtyPgrp {
let pty = pty_lock.borrow();
//println!("READ PGRP {}: {}", pty.id, pty.pgrp);
let dst_buf = buf.get_mut(..4).and_then(|b| <&mut [u8; 4]>::try_from(b).ok()).ok_or(Error::new(EBADF))?;
let dst_buf = buf
.get_mut(..4)
.and_then(|b| <&mut [u8; 4]>::try_from(b).ok())
.ok_or(Error::new(EBADF))?;
*dst_buf = (pty.pgrp as u32).to_ne_bytes();
Ok(Some(4))
@@ -57,7 +60,11 @@ impl Resource for PtyPgrp {
if let Some(pty_lock) = self.pty.upgrade() {
let mut pty = pty_lock.borrow_mut();
let new_pgrp = u32::from_ne_bytes(buf.get(..4).and_then(|b| <[u8; 4]>::try_from(b).ok()).ok_or(Error::new(EBADF))?);
let new_pgrp = u32::from_ne_bytes(
buf.get(..4)
.and_then(|b| <[u8; 4]>::try_from(b).ok())
.ok_or(Error::new(EBADF))?,
);
pty.pgrp = new_pgrp as usize;
//println!("WRITE PGRP {}: {} => {}", pty.id, pty.pgrp, new_pgrp);
+18 -3
View File
@@ -46,7 +46,10 @@ impl SchemeBlock for PtyScheme {
} else {
let control_term_id = path.parse::<usize>().or(Err(Error::new(EINVAL)))?;
let pty = {
let handle = self.handles.get(&control_term_id).ok_or(Error::new(ENOENT))?;
let handle = self
.handles
.get(&control_term_id)
.ok_or(Error::new(ENOENT))?;
handle.pty()
};
@@ -82,12 +85,24 @@ impl SchemeBlock for PtyScheme {
Ok(Some(id))
}
fn read(&mut self, id: usize, buf: &mut [u8], _offset: u64, _fcntl_flags: u32) -> Result<Option<usize>> {
fn read(
&mut self,
id: usize,
buf: &mut [u8],
_offset: u64,
_fcntl_flags: u32,
) -> Result<Option<usize>> {
let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?;
handle.read(buf)
}
fn write(&mut self, id: usize, buf: &[u8], _offset: u64, _fcntl_flags: u32) -> Result<Option<usize>> {
fn write(
&mut self,
id: usize,
buf: &[u8],
_offset: u64,
_fcntl_flags: u32,
) -> Result<Option<usize>> {
let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?;
handle.write(buf)
}