bootstrap: Pass proc auth FdGuard by-value
This commit is contained in:
+24
-19
@@ -52,11 +52,12 @@ pub fn main() -> ! {
|
||||
FdGuard::new(*(base_ptr as *const usize))
|
||||
};
|
||||
|
||||
let kernel_schemes = KernelSchemeMap::new(kernel_scheme_infos);
|
||||
let mut kernel_schemes = KernelSchemeMap::new(kernel_scheme_infos);
|
||||
|
||||
let auth = FdGuard::new(
|
||||
*kernel_schemes
|
||||
.get(GlobalSchemes::Proc)
|
||||
kernel_schemes
|
||||
.0
|
||||
.remove(&GlobalSchemes::Proc)
|
||||
.expect("failed to get proc fd"),
|
||||
);
|
||||
let pipe_fd = *kernel_schemes
|
||||
@@ -125,13 +126,13 @@ pub fn main() -> ! {
|
||||
(*(core::ptr::addr_of!(__initfs_header) as *const redox_initfs::types::Header)).initfs_size
|
||||
};
|
||||
|
||||
let (scheme_creation_cap, initfs_fd) = spawn(
|
||||
let (scheme_creation_cap, auth, initfs_fd) = spawn(
|
||||
"initfs daemon",
|
||||
&auth,
|
||||
auth,
|
||||
&this_thr_fd,
|
||||
scheme_creation_cap,
|
||||
pipe_fd,
|
||||
|write_fd, scheme_creation_cap| unsafe {
|
||||
|write_fd, scheme_creation_cap, _| unsafe {
|
||||
// Creating a reference to NULL is UB. Mask the UB for now using black_box.
|
||||
// FIXME use a raw pointer and inline asm for reading instead for the initfs header.
|
||||
let initfs_start = core::ptr::addr_of!(__initfs_header);
|
||||
@@ -146,24 +147,24 @@ pub fn main() -> ! {
|
||||
},
|
||||
);
|
||||
|
||||
let (scheme_creation_cap, proc_fd) = spawn(
|
||||
let (scheme_creation_cap, auth, proc_fd) = spawn(
|
||||
"process manager",
|
||||
&auth,
|
||||
auth,
|
||||
&this_thr_fd,
|
||||
scheme_creation_cap,
|
||||
pipe_fd,
|
||||
|write_fd, scheme_creation_cap| {
|
||||
crate::procmgr::run(write_fd, &auth, &kernel_schemes, scheme_creation_cap)
|
||||
|write_fd, scheme_creation_cap, auth| {
|
||||
crate::procmgr::run(write_fd, auth, &kernel_schemes, scheme_creation_cap)
|
||||
},
|
||||
);
|
||||
|
||||
let (_, initns_fd) = spawn(
|
||||
let (_, _, initns_fd) = spawn(
|
||||
"init namespace manager",
|
||||
&auth,
|
||||
auth,
|
||||
&this_thr_fd,
|
||||
scheme_creation_cap,
|
||||
pipe_fd,
|
||||
|write_fd, scheme_creation_cap| {
|
||||
|write_fd, scheme_creation_cap, _| {
|
||||
let mut schemes = HashMap::default();
|
||||
for (scheme, fd) in kernel_schemes.0.into_iter() {
|
||||
schemes.insert(scheme.as_str().to_string(), Arc::new(FdGuard::new(fd)));
|
||||
@@ -259,12 +260,12 @@ pub fn main() -> ! {
|
||||
|
||||
pub(crate) fn spawn(
|
||||
name: &str,
|
||||
auth: &FdGuard,
|
||||
auth: FdGuard,
|
||||
this_thr_fd: &FdGuardUpper,
|
||||
scheme_creation_cap: FdGuard,
|
||||
pipe_fd: usize,
|
||||
inner: impl FnOnce(FdGuard, FdGuard) -> !,
|
||||
) -> (FdGuard, FdGuard) {
|
||||
inner: impl FnOnce(FdGuard, FdGuard, FdGuard) -> !,
|
||||
) -> (FdGuard, FdGuard, FdGuard) {
|
||||
let read = FdGuard::new(
|
||||
syscall::openat(pipe_fd, "", O_CLOEXEC, 0).expect("failed to open sync read pipe"),
|
||||
);
|
||||
@@ -274,13 +275,18 @@ pub(crate) fn spawn(
|
||||
syscall::dup(read.as_raw_fd(), b"write").expect("failed to open sync write pipe"),
|
||||
);
|
||||
|
||||
match fork_impl(&ForkArgs::Init { this_thr_fd, auth }) {
|
||||
match fork_impl(&ForkArgs::Init {
|
||||
this_thr_fd,
|
||||
auth: &auth,
|
||||
}) {
|
||||
Err(err) => {
|
||||
panic!("Failed to fork in order to start {name}: {err}");
|
||||
}
|
||||
// Continue serving the scheme as the child.
|
||||
Ok(0) => {
|
||||
drop(read);
|
||||
|
||||
inner(write, scheme_creation_cap, auth)
|
||||
}
|
||||
// Return in order to execute init, as the parent.
|
||||
Ok(_) => {
|
||||
@@ -305,8 +311,7 @@ pub(crate) fn spawn(
|
||||
}
|
||||
}
|
||||
|
||||
return (scheme_creation_cap, FdGuard::new(new_fd));
|
||||
(scheme_creation_cap, auth, FdGuard::new(new_fd))
|
||||
}
|
||||
}
|
||||
inner(write, scheme_creation_cap)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ enum VirtualId {
|
||||
|
||||
pub fn run(
|
||||
write_fd: FdGuard,
|
||||
auth: &FdGuard,
|
||||
auth: FdGuard,
|
||||
kernel_schemes: &KernelSchemeMap,
|
||||
scheme_creation_cap: FdGuard,
|
||||
) -> ! {
|
||||
@@ -67,10 +67,7 @@ pub fn run(
|
||||
.expect("failed to get event fd"),
|
||||
)
|
||||
.expect("failed to create event queue");
|
||||
for (scheme, fd) in kernel_schemes.0.iter() {
|
||||
if *scheme == GlobalSchemes::Proc {
|
||||
continue;
|
||||
}
|
||||
for fd in kernel_schemes.0.values() {
|
||||
let _ = syscall::close(*fd);
|
||||
}
|
||||
|
||||
@@ -520,7 +517,7 @@ struct ProcScheme<'a> {
|
||||
next_id: ProcessId,
|
||||
|
||||
queue: &'a RawEventQueue,
|
||||
auth: &'a FdGuard,
|
||||
auth: FdGuard,
|
||||
}
|
||||
#[derive(Debug, Default)]
|
||||
struct Pgrp {
|
||||
@@ -598,7 +595,7 @@ impl RawEventQueue {
|
||||
}
|
||||
|
||||
impl<'a> ProcScheme<'a> {
|
||||
pub fn new(auth: &'a FdGuard, queue: &'a RawEventQueue) -> ProcScheme<'a> {
|
||||
pub fn new(auth: FdGuard, queue: &'a RawEventQueue) -> ProcScheme<'a> {
|
||||
ProcScheme {
|
||||
processes: HashMap::new(),
|
||||
groups: HashMap::new(),
|
||||
@@ -745,7 +742,7 @@ impl<'a> ProcScheme<'a> {
|
||||
}));
|
||||
if let Err(err) = new_process
|
||||
.borrow_mut()
|
||||
.sync_kernel_attrs(child_pid, self.auth)
|
||||
.sync_kernel_attrs(child_pid, &self.auth)
|
||||
{
|
||||
log::warn!("Failed to set kernel attrs when forking: {err}");
|
||||
}
|
||||
@@ -1611,7 +1608,7 @@ impl<'a> ProcScheme<'a> {
|
||||
if let Some(new_sgid) = new_sgid {
|
||||
proc.sgid = new_sgid;
|
||||
}
|
||||
if let Err(err) = proc.sync_kernel_attrs(pid, self.auth) {
|
||||
if let Err(err) = proc.sync_kernel_attrs(pid, &self.auth) {
|
||||
log::warn!("Failed to sync proc attrs in setresugid: {err}");
|
||||
}
|
||||
Ok(())
|
||||
@@ -2393,7 +2390,7 @@ impl<'a> ProcScheme<'a> {
|
||||
.borrow_mut();
|
||||
|
||||
proc.name = ArrayString::from_str(&new_name[..new_name.len().min(NAME_CAPAC)]).unwrap();
|
||||
if let Err(err) = proc.sync_kernel_attrs(pid, self.auth) {
|
||||
if let Err(err) = proc.sync_kernel_attrs(pid, &self.auth) {
|
||||
log::warn!("Failed to set kernel attrs when renaming proc: {err}");
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user