Show argv[0] when printing process memory usage

This commit is contained in:
pjht 2024-09-06 10:45:48 -05:00
parent 3b2cf8bbb5
commit 07393d8c71
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -2,7 +2,9 @@ use crate::{
gdt, println, qemu_exit,
virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE},
};
use alloc::{borrow::ToOwned, boxed::Box, collections::VecDeque, ffi::CString, vec::Vec};
use alloc::{
borrow::ToOwned, boxed::Box, collections::VecDeque, ffi::CString, string::ToString, vec::Vec,
};
use core::{
alloc::Layout,
arch::asm,
@ -14,7 +16,6 @@ use humansize::{SizeFormatter, BINARY};
use slab::Slab;
use spin::{Lazy, Mutex, RwLock};
use x86_64::{
instructions::interrupts,
structures::paging::{Page, PageTableFlags},
VirtAddr,
};
@ -168,8 +169,9 @@ impl Tasking {
)]
args_layout.align_to(4096).unwrap().pad_to_align()
};
let user_arg_mem =
address_space.map_free(args_layout.size() / 4096, PageTableFlags::USER_ACCESSIBLE)?;
let user_arg_mem = KERNEL_SPACE
.lock()
.map_free(args_layout.size() / 4096, PageTableFlags::USER_ACCESSIBLE)?;
address_space.run(|| unsafe {
let mut ptr_ptr: *mut *const u8 = user_arg_mem.cast();
for (&offset, argument) in arg_offsets.iter().zip(arguments.iter()) {
@ -391,7 +393,19 @@ impl Tasking {
|space| space.get_bytes_allocated(),
);
total += bytes_used;
println!("[TASKING] PID {} used {}", i, SizeFormatter::new(bytes_used, BINARY),);
let name = if process.arguments.1 > 0 {
unsafe { CStr::from_ptr(process.arguments.0.read().cast()) }
.to_string_lossy()
.into_owned()
} else {
"UNKNOWN".to_string()
};
println!(
"[TASKING] PID {} ({}) used {}",
i,
name,
SizeFormatter::new(bytes_used, BINARY),
);
}
println!("[TASKING] Total used {} ({})", SizeFormatter::new(total, BINARY), total / 4096);
}