Skip to content

Commit

Permalink
Clean up code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
hunhoffe committed Nov 23, 2023
1 parent 78fe4fa commit bed929d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 79 deletions.
2 changes: 1 addition & 1 deletion kernel/src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub mod tlb;
mod tls;
pub mod vspace;

pub(crate) const MAX_NUMA_NODES: usize = 6;
pub(crate) const MAX_NUMA_NODES: usize = 12;
pub(crate) const MAX_CORES: usize = 192;
pub(crate) const MAX_MACHINES: usize = 16;

Expand Down
48 changes: 14 additions & 34 deletions kernel/src/arch/x86_64/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use crate::round_up;

use super::gdt::GdtTable;
use super::vspace::*;
//use super::Module;
use super::MAX_NUMA_NODES;

const INVALID_EXECUTOR_START: VAddr = VAddr(0xdeadffff);
Expand Down Expand Up @@ -110,7 +109,7 @@ lazy_static! {
let mut process_logs = Box::try_new(ArrayVec::new()).expect("Can't initialize process log vector.");
for _pid in 0..MAX_PROCESSES {
let log = Arc::try_new(
Log::<<NrProcess<Ring3Process> as Dispatch>::WriteOperation>::new(BASE_PAGE_SIZE),
Log::<<NrProcess<Ring3Process> as Dispatch>::WriteOperation>::new(LARGE_PAGE_SIZE),
)
.expect("Can't initialize process logs, out of memory.");
process_logs.push(log);
Expand Down Expand Up @@ -225,7 +224,6 @@ fn create_process_table(
KernelAllocator::try_refill_tcache(0, MAX_PROCESSES * 5 * numa_nodes, MemType::Mem)
.expect("Trying to refill the tcache with shmem caused an error");

log::info!("process table 1");
let allocator = ShmemAlloc::new(local_shmem_affinity());
for pid in 0..MAX_PROCESSES {
for node in 0..numa_nodes {
Expand All @@ -237,19 +235,13 @@ fn create_process_table(
)
.expect("Not enough memory to initialize processes");

log::info!("process table 2");

let nrp = NrProcess::new(p, Box::new(allocator.clone()));

log::info!("process table 3");

numa_cache[node].push(Replica::<NrProcess<Ring3Process>>::with_data(
&PROCESS_LOGS[pid],
nrp,
));

log::info!("process table 4");

debug_assert_eq!(
*crate::environment::NODE_ID,
0,
Expand Down Expand Up @@ -679,7 +671,7 @@ impl Ring3Resumer {
// `sysretq` expectations are:
// %rcx Program entry point in Ring 3
// %r11 RFlags
log::info!("Jumping to {:#x}", self.entry_point);
trace!("Jumping to {:#x}", self.entry_point);

asm!("
// rax: contains stack pointer
Expand Down Expand Up @@ -1356,44 +1348,32 @@ impl Process for Ring3Process {
self.writeable_sections.try_push(sec)?;
}

let mut maybemodule = None;
let module = if let Some(modules) = crate::KERNEL_ARGS.get().map(|args| &args.modules) {
for m in modules {
if m.name() == module_name {
maybemodule = Some(m);
}
}
if maybemodule.is_none() {
panic!("Cannot find module for proccess?");
// Get module from module name
let modules = crate::KERNEL_ARGS
.get()
.map(|args| &args.modules)
.expect("No modules found for process");
let mut module = None;
for m in modules {
if m.name() == module_name {
module = Some(m);
break;
}
maybemodule.unwrap()
} else {
panic!("Cannot find module for proccess?");
};
}
let module = module.expect("Failed to find process module");

// Load the Module into the process address-space
// This needs mostly sanitation work on elfloader and
// ElfLoad trait impl for process to be safe
log::info!("Before elfbinary 2");

unsafe {
log::info!(
"ELF ADDR: vaddr={:?} paddr={:?}",
module.binary_vaddr,
module.binary_paddr
);
log::info!("ELF HEADER2: {:?}", &module.as_slice()[..128]);
let e = elfloader::ElfBinary::new(module.as_slice())?;
if !e.is_pie() {
// We don't have an offset for non-pie applications (rump apps)
self.offset = VAddr::zero();
}
self.entry_point = VAddr::from(e.entry_point());
log::info!("after new, before load");
e.load(self)?;
log::info!("after load");
}
log::info!("After elfbinary 2");

// Install the kernel mappings
// TODO(efficiency): These should probably be global mappings
Expand Down
36 changes: 0 additions & 36 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,42 +114,6 @@ pub(crate) enum ExitReason {
/// This function is executed from each core (which is
/// different from a traditional main routine).
pub(crate) fn main() {
use alloc::vec::Vec;
use fallible_collections::FallibleVecGlobal;

log::info!("Checking modules...");
if let Some(modules) = crate::KERNEL_ARGS.get().map(|args| &args.modules) {
for module in modules {
if module.name() == "init" {
log::info!("{:?}", module);
unsafe {
let e = elfloader::ElfBinary::new(module.as_slice())
.expect("Failed to create new elf file");
log::info!("{:?}", e);
}
log::info!(
"vaddr=0x{:x}, paddr=0x{:x}, size=0x{:x}",
module.binary_vaddr,
module.binary_paddr,
module.binary_size
);

let mut elf_cpy = Vec::try_with_capacity(module.binary_size)
.expect("Failed to allocate copy for elf data");
let elf_mem = unsafe {
core::slice::from_raw_parts(
(module.binary_vaddr.as_u64()) as *mut u8,
module.binary_size as usize,
)
};
elf_cpy.extend_from_slice(elf_mem);
log::info!("Copied elf.");
}
}
} else {
log::warn!("Found no modules");
}

#[cfg(feature = "rackscale")]
if CMDLINE
.get()
Expand Down
9 changes: 1 addition & 8 deletions kernel/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) type Pid = usize;
pub(crate) type Eid = usize;

/// How many (concurrent) processes the systems supports.
pub(crate) const MAX_PROCESSES: usize = 10;
pub(crate) const MAX_PROCESSES: usize = 12;

/// How many registered "named" frames a process can have.
pub(crate) const MAX_FRAMES_PER_PROCESS: usize = MAX_CORES;
Expand Down Expand Up @@ -518,17 +518,10 @@ pub(crate) fn make_process<P: Process>(binary: &'static str) -> Result<Pid, KErr
.init_args,
mod_file
);
log::info!(
"ELF ADDR: vaddr={:?} paddr={:?}",
mod_file.binary_vaddr,
mod_file.binary_paddr
);

log::info!("Loading the binary");
let elf_module = unsafe {
elfloader::ElfBinary::new(mod_file.as_slice()).map_err(|_e| KError::UnableToParseElf)?
};
log::info!("After loading the binary");

// We don't have an offset for non-pie applications (i.e., rump apps)
let offset = if !elf_module.is_pie() {
Expand Down

0 comments on commit bed929d

Please sign in to comment.