mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-23 18:06:20 +04:00
Remove talloc and tfree, instead we will use Rusts built-in Box
This commit is contained in:
parent
b1ae1e3a4f
commit
c1c8f2876b
@ -3,7 +3,7 @@
|
||||
// Stephen Marz
|
||||
// 10 March 2020
|
||||
|
||||
use crate::{kmem::{kfree, kmalloc, talloc, tfree},
|
||||
use crate::{kmem::{kfree, kmalloc},
|
||||
page::{zalloc, PAGE_SIZE},
|
||||
process::{add_kernel_process_args,
|
||||
get_by_pid,
|
||||
@ -16,6 +16,7 @@ use crate::{kmem::{kfree, kmalloc, talloc, tfree},
|
||||
StatusField,
|
||||
VIRTIO_RING_SIZE}};
|
||||
use core::mem::size_of;
|
||||
use alloc::boxed::Box;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Geometry {
|
||||
@ -461,8 +462,7 @@ struct ProcArgs {
|
||||
|
||||
/// This will be a
|
||||
fn read_proc(args_addr: usize) {
|
||||
let args_ptr = args_addr as *mut ProcArgs;
|
||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
||||
let args = unsafe { Box::from_raw(args_addr as *mut ProcArgs) };
|
||||
let _ = block_op(
|
||||
args.dev,
|
||||
args.buffer,
|
||||
@ -471,7 +471,6 @@ fn read_proc(args_addr: usize) {
|
||||
false,
|
||||
args.pid,
|
||||
);
|
||||
tfree(args_ptr);
|
||||
// This should be handled by the RA now.
|
||||
// syscall_exit();
|
||||
}
|
||||
@ -484,22 +483,23 @@ pub fn process_read(pid: u16,
|
||||
{
|
||||
// println!("Block read {}, {}, 0x{:x}, {}, {}", pid, dev, buffer as
|
||||
// usize, size, offset);
|
||||
let args = talloc::<ProcArgs>().unwrap();
|
||||
args.pid = pid;
|
||||
args.dev = dev;
|
||||
args.buffer = buffer;
|
||||
args.size = size;
|
||||
args.offset = offset;
|
||||
let args = ProcArgs {
|
||||
pid,
|
||||
dev,
|
||||
buffer,
|
||||
size,
|
||||
offset,
|
||||
};
|
||||
let boxed_args = Box::new(args);
|
||||
set_waiting(pid);
|
||||
let _ = add_kernel_process_args(
|
||||
read_proc,
|
||||
args as *mut ProcArgs as usize,
|
||||
Box::into_raw(boxed_args) as usize,
|
||||
);
|
||||
}
|
||||
|
||||
fn write_proc(args_addr: usize) {
|
||||
let args_ptr = args_addr as *mut ProcArgs;
|
||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
||||
let args = unsafe { Box::from_raw(args_addr as *mut ProcArgs) };
|
||||
|
||||
let _ = block_op(
|
||||
args.dev,
|
||||
@ -509,7 +509,6 @@ fn write_proc(args_addr: usize) {
|
||||
true,
|
||||
args.pid,
|
||||
);
|
||||
tfree(args_ptr);
|
||||
// syscall_exit();
|
||||
}
|
||||
|
||||
@ -519,15 +518,17 @@ pub fn process_write(pid: u16,
|
||||
size: u32,
|
||||
offset: u64)
|
||||
{
|
||||
let args = talloc::<ProcArgs>().unwrap();
|
||||
args.pid = pid;
|
||||
args.dev = dev;
|
||||
args.buffer = buffer;
|
||||
args.size = size;
|
||||
args.offset = offset;
|
||||
let args = ProcArgs {
|
||||
pid,
|
||||
dev,
|
||||
buffer,
|
||||
size,
|
||||
offset,
|
||||
};
|
||||
let boxed_args = Box::new(args);
|
||||
set_waiting(pid);
|
||||
let _ = add_kernel_process_args(
|
||||
write_proc,
|
||||
args as *mut ProcArgs as usize,
|
||||
Box::into_raw(boxed_args) as usize,
|
||||
);
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
// 16 March 2020
|
||||
|
||||
use crate::{cpu::Registers,
|
||||
kmem::{talloc, tfree},
|
||||
process::{add_kernel_process_args,
|
||||
get_by_pid,
|
||||
set_running,
|
||||
@ -12,7 +11,7 @@ use crate::{cpu::Registers,
|
||||
syscall::syscall_block_read};
|
||||
|
||||
use crate::{buffer::Buffer, cpu::memcpy};
|
||||
use alloc::{collections::BTreeMap, string::String};
|
||||
use alloc::{collections::BTreeMap, string::String, boxed::Box};
|
||||
use core::mem::size_of;
|
||||
|
||||
pub const MAGIC: u16 = 0x4d5a;
|
||||
@ -563,8 +562,7 @@ struct ProcArgs {
|
||||
|
||||
// This is the actual code ran inside of the read process.
|
||||
fn read_proc(args_addr: usize) {
|
||||
let args_ptr = args_addr as *mut ProcArgs;
|
||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
||||
let args = unsafe { Box::from_raw(args_addr as *mut ProcArgs) };
|
||||
|
||||
// Start the read! Since we're in a kernel process, we can block by putting this
|
||||
// process into a waiting state and wait until the block driver returns.
|
||||
@ -589,9 +587,6 @@ fn read_proc(args_addr: usize) {
|
||||
// the process and get it ready to go. The only thing this process needs to clean up is the
|
||||
// tfree(), but the user process doesn't care about that.
|
||||
set_running(args.pid);
|
||||
|
||||
// tfree() is used to free a pointer created by talloc.
|
||||
tfree(args_ptr);
|
||||
}
|
||||
|
||||
/// System calls will call process_read, which will spawn off a kernel process to read
|
||||
@ -604,17 +599,19 @@ pub fn process_read(pid: u16,
|
||||
offset: u32)
|
||||
{
|
||||
// println!("FS read {}, {}, 0x{:x}, {}, {}", pid, dev, buffer as usize, size, offset);
|
||||
let args = talloc::<ProcArgs>().unwrap();
|
||||
args.pid = pid;
|
||||
args.dev = dev;
|
||||
args.buffer = buffer;
|
||||
args.size = size;
|
||||
args.offset = offset;
|
||||
args.node = node;
|
||||
let args = ProcArgs {
|
||||
pid,
|
||||
dev,
|
||||
buffer,
|
||||
size,
|
||||
offset,
|
||||
node,
|
||||
};
|
||||
let boxed_args = Box::new(args);
|
||||
set_waiting(pid);
|
||||
let _ = add_kernel_process_args(
|
||||
read_proc,
|
||||
args as *mut ProcArgs as usize
|
||||
Box::into_raw(boxed_args) as usize
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -89,18 +89,6 @@ pub fn init() {
|
||||
}
|
||||
}
|
||||
|
||||
/// talloc and tfree will allocate a reference to a given type
|
||||
/// This helps when creating structures.
|
||||
pub fn talloc<T>() -> Option<&'static mut T> {
|
||||
unsafe {
|
||||
(kzmalloc(size_of::<T>()) as *mut T).as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tfree<T>(p: *mut T) {
|
||||
kfree(p as *mut u8);
|
||||
}
|
||||
|
||||
/// Allocate sub-page level allocation based on bytes and zero the memory
|
||||
pub fn kzmalloc(sz: usize) -> *mut u8 {
|
||||
let size = align_val(sz, 3);
|
||||
|
Loading…
Reference in New Issue
Block a user