mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-24 02:16:19 +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
|
// Stephen Marz
|
||||||
// 10 March 2020
|
// 10 March 2020
|
||||||
|
|
||||||
use crate::{kmem::{kfree, kmalloc, talloc, tfree},
|
use crate::{kmem::{kfree, kmalloc},
|
||||||
page::{zalloc, PAGE_SIZE},
|
page::{zalloc, PAGE_SIZE},
|
||||||
process::{add_kernel_process_args,
|
process::{add_kernel_process_args,
|
||||||
get_by_pid,
|
get_by_pid,
|
||||||
@ -16,6 +16,7 @@ use crate::{kmem::{kfree, kmalloc, talloc, tfree},
|
|||||||
StatusField,
|
StatusField,
|
||||||
VIRTIO_RING_SIZE}};
|
VIRTIO_RING_SIZE}};
|
||||||
use core::mem::size_of;
|
use core::mem::size_of;
|
||||||
|
use alloc::boxed::Box;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Geometry {
|
pub struct Geometry {
|
||||||
@ -461,8 +462,7 @@ struct ProcArgs {
|
|||||||
|
|
||||||
/// This will be a
|
/// This will be a
|
||||||
fn read_proc(args_addr: usize) {
|
fn read_proc(args_addr: usize) {
|
||||||
let args_ptr = args_addr as *mut ProcArgs;
|
let args = unsafe { Box::from_raw(args_addr as *mut ProcArgs) };
|
||||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
|
||||||
let _ = block_op(
|
let _ = block_op(
|
||||||
args.dev,
|
args.dev,
|
||||||
args.buffer,
|
args.buffer,
|
||||||
@ -471,7 +471,6 @@ fn read_proc(args_addr: usize) {
|
|||||||
false,
|
false,
|
||||||
args.pid,
|
args.pid,
|
||||||
);
|
);
|
||||||
tfree(args_ptr);
|
|
||||||
// This should be handled by the RA now.
|
// This should be handled by the RA now.
|
||||||
// syscall_exit();
|
// syscall_exit();
|
||||||
}
|
}
|
||||||
@ -484,22 +483,23 @@ pub fn process_read(pid: u16,
|
|||||||
{
|
{
|
||||||
// println!("Block read {}, {}, 0x{:x}, {}, {}", pid, dev, buffer as
|
// println!("Block read {}, {}, 0x{:x}, {}, {}", pid, dev, buffer as
|
||||||
// usize, size, offset);
|
// usize, size, offset);
|
||||||
let args = talloc::<ProcArgs>().unwrap();
|
let args = ProcArgs {
|
||||||
args.pid = pid;
|
pid,
|
||||||
args.dev = dev;
|
dev,
|
||||||
args.buffer = buffer;
|
buffer,
|
||||||
args.size = size;
|
size,
|
||||||
args.offset = offset;
|
offset,
|
||||||
|
};
|
||||||
|
let boxed_args = Box::new(args);
|
||||||
set_waiting(pid);
|
set_waiting(pid);
|
||||||
let _ = add_kernel_process_args(
|
let _ = add_kernel_process_args(
|
||||||
read_proc,
|
read_proc,
|
||||||
args as *mut ProcArgs as usize,
|
Box::into_raw(boxed_args) as usize,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_proc(args_addr: usize) {
|
fn write_proc(args_addr: usize) {
|
||||||
let args_ptr = args_addr as *mut ProcArgs;
|
let args = unsafe { Box::from_raw(args_addr as *mut ProcArgs) };
|
||||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
|
||||||
|
|
||||||
let _ = block_op(
|
let _ = block_op(
|
||||||
args.dev,
|
args.dev,
|
||||||
@ -509,7 +509,6 @@ fn write_proc(args_addr: usize) {
|
|||||||
true,
|
true,
|
||||||
args.pid,
|
args.pid,
|
||||||
);
|
);
|
||||||
tfree(args_ptr);
|
|
||||||
// syscall_exit();
|
// syscall_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,15 +518,17 @@ pub fn process_write(pid: u16,
|
|||||||
size: u32,
|
size: u32,
|
||||||
offset: u64)
|
offset: u64)
|
||||||
{
|
{
|
||||||
let args = talloc::<ProcArgs>().unwrap();
|
let args = ProcArgs {
|
||||||
args.pid = pid;
|
pid,
|
||||||
args.dev = dev;
|
dev,
|
||||||
args.buffer = buffer;
|
buffer,
|
||||||
args.size = size;
|
size,
|
||||||
args.offset = offset;
|
offset,
|
||||||
|
};
|
||||||
|
let boxed_args = Box::new(args);
|
||||||
set_waiting(pid);
|
set_waiting(pid);
|
||||||
let _ = add_kernel_process_args(
|
let _ = add_kernel_process_args(
|
||||||
write_proc,
|
write_proc,
|
||||||
args as *mut ProcArgs as usize,
|
Box::into_raw(boxed_args) as usize,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// 16 March 2020
|
// 16 March 2020
|
||||||
|
|
||||||
use crate::{cpu::Registers,
|
use crate::{cpu::Registers,
|
||||||
kmem::{talloc, tfree},
|
|
||||||
process::{add_kernel_process_args,
|
process::{add_kernel_process_args,
|
||||||
get_by_pid,
|
get_by_pid,
|
||||||
set_running,
|
set_running,
|
||||||
@ -12,7 +11,7 @@ use crate::{cpu::Registers,
|
|||||||
syscall::syscall_block_read};
|
syscall::syscall_block_read};
|
||||||
|
|
||||||
use crate::{buffer::Buffer, cpu::memcpy};
|
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;
|
use core::mem::size_of;
|
||||||
|
|
||||||
pub const MAGIC: u16 = 0x4d5a;
|
pub const MAGIC: u16 = 0x4d5a;
|
||||||
@ -563,8 +562,7 @@ struct ProcArgs {
|
|||||||
|
|
||||||
// This is the actual code ran inside of the read process.
|
// This is the actual code ran inside of the read process.
|
||||||
fn read_proc(args_addr: usize) {
|
fn read_proc(args_addr: usize) {
|
||||||
let args_ptr = args_addr as *mut ProcArgs;
|
let args = unsafe { Box::from_raw(args_addr as *mut ProcArgs) };
|
||||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
|
||||||
|
|
||||||
// Start the read! Since we're in a kernel process, we can block by putting this
|
// 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.
|
// 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
|
// 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.
|
// tfree(), but the user process doesn't care about that.
|
||||||
set_running(args.pid);
|
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
|
/// 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)
|
offset: u32)
|
||||||
{
|
{
|
||||||
// println!("FS read {}, {}, 0x{:x}, {}, {}", pid, dev, buffer as usize, size, offset);
|
// println!("FS read {}, {}, 0x{:x}, {}, {}", pid, dev, buffer as usize, size, offset);
|
||||||
let args = talloc::<ProcArgs>().unwrap();
|
let args = ProcArgs {
|
||||||
args.pid = pid;
|
pid,
|
||||||
args.dev = dev;
|
dev,
|
||||||
args.buffer = buffer;
|
buffer,
|
||||||
args.size = size;
|
size,
|
||||||
args.offset = offset;
|
offset,
|
||||||
args.node = node;
|
node,
|
||||||
|
};
|
||||||
|
let boxed_args = Box::new(args);
|
||||||
set_waiting(pid);
|
set_waiting(pid);
|
||||||
let _ = add_kernel_process_args(
|
let _ = add_kernel_process_args(
|
||||||
read_proc,
|
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
|
/// Allocate sub-page level allocation based on bytes and zero the memory
|
||||||
pub fn kzmalloc(sz: usize) -> *mut u8 {
|
pub fn kzmalloc(sz: usize) -> *mut u8 {
|
||||||
let size = align_val(sz, 3);
|
let size = align_val(sz, 3);
|
||||||
|
Loading…
Reference in New Issue
Block a user