Show argv[0] when printing process memory usage
This commit is contained in:
parent
3b2cf8bbb5
commit
07393d8c71
@ -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,
|
||||
};
|
||||
@ -64,17 +65,17 @@ extern "C" fn switch_to_asm_exit(next_stack: *mut usize) {
|
||||
extern "C" fn task_init() {
|
||||
unsafe {
|
||||
asm!(
|
||||
"pop rcx", // Get the user stack pointer
|
||||
"pop rbx", // Get the entry point
|
||||
"push 43", // Push the stack segment selector - same as data
|
||||
"pop rcx", // Get the user stack pointer
|
||||
"pop rbx", // Get the entry point
|
||||
"push 43", // Push the stack segment selector - same as data
|
||||
"push rcx", // Push the stack pointer
|
||||
"pushfq", // Get the flags into RAX
|
||||
"pushfq", // Get the flags into RAX
|
||||
"pop rax",
|
||||
"or rax, 0x200", // Enable interrupts in the stored copy
|
||||
"push rax", // Push the flags
|
||||
"push 51", // Push the code selector
|
||||
"push rbx", // Push the entry point
|
||||
"iretq", // Return from the fake interrupt and enter user mode
|
||||
"push rax", // Push the flags
|
||||
"push 51", // Push the code selector
|
||||
"push rbx", // Push the entry point
|
||||
"iretq", // Return from the fake interrupt and enter user mode
|
||||
options(noreturn)
|
||||
)
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user