mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 16:26:31 +00:00
新增http server (#265)
* 1.修复了当传入ahci驱动的缓冲区地址为用户缓冲区时,产生的内存越界问题.(采用分配内核缓冲区的方式临时解决) 2.新增http server * 把libssl-dev添加到bootstrap.sh * http_server增加对父级相对路径的安全检查,防止访问系统内的其他文件 * 检查空指针情况 * 解决由于链接时,crt*.o未按照升序排列导致init段链接错误的问题
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
use super::{_port, hba::HbaCmdTable, virt_2_phys};
|
||||
use crate::driver::disk::ahci::HBA_PxIS_TFES;
|
||||
use crate::filesystem::mbr::MbrDiskPartionTable;
|
||||
use crate::include::bindings::bindings::verify_area;
|
||||
use crate::io::{device::BlockDevice, disk_info::Partition, SeekFrom};
|
||||
|
||||
use crate::libs::{spinlock::SpinLock, vec_cursor::VecCursor};
|
||||
@ -95,6 +96,29 @@ impl AhciDisk {
|
||||
|
||||
// 设置数据存放地址
|
||||
let mut buf_ptr = buf as *mut [u8] as *mut usize as usize;
|
||||
|
||||
// 由于目前的内存管理机制无法把用户空间的内存地址转换为物理地址,所以只能先把数据拷贝到内核空间
|
||||
// TODO:在内存管理重构后,可以直接使用用户空间的内存地址
|
||||
let user_buf = if unsafe { verify_area(buf_ptr as u64, buf.len() as u64) } {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let mut kbuf = if user_buf {
|
||||
let mut x: Vec<u8> = Vec::with_capacity(buf.len());
|
||||
unsafe {
|
||||
x.set_len(buf.len());
|
||||
}
|
||||
Some(x)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if kbuf.is_some() {
|
||||
buf_ptr = kbuf.as_mut().unwrap().as_mut_ptr() as usize;
|
||||
}
|
||||
|
||||
|
||||
#[allow(unused_unsafe)]
|
||||
let cmdtbl = unsafe {
|
||||
(phys_2_virt(volatile_read!(cmdheader.ctba) as usize) as *mut HbaCmdTable)
|
||||
@ -177,6 +201,10 @@ impl AhciDisk {
|
||||
}
|
||||
}
|
||||
|
||||
if kbuf.is_some() {
|
||||
buf.copy_from_slice(kbuf.as_ref().unwrap());
|
||||
}
|
||||
|
||||
compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
||||
// successfully read
|
||||
return Ok(count * 512);
|
||||
@ -231,6 +259,27 @@ impl AhciDisk {
|
||||
// 设置数据存放地址
|
||||
compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
||||
let mut buf_ptr = buf as *const [u8] as *mut usize as usize;
|
||||
|
||||
// 由于目前的内存管理机制无法把用户空间的内存地址转换为物理地址,所以只能先把数据拷贝到内核空间
|
||||
// TODO:在内存管理重构后,可以直接使用用户空间的内存地址
|
||||
let user_buf = if unsafe { verify_area(buf_ptr as u64, buf.len() as u64) } {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let mut kbuf = if user_buf {
|
||||
let mut x: Vec<u8> = Vec::with_capacity(buf.len());
|
||||
x.resize(buf.len(), 0);
|
||||
x.copy_from_slice(buf);
|
||||
Some(x)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if kbuf.is_some() {
|
||||
buf_ptr = kbuf.as_mut().unwrap().as_mut_ptr() as usize;
|
||||
}
|
||||
|
||||
#[allow(unused_unsafe)]
|
||||
let cmdtbl = unsafe {
|
||||
(phys_2_virt(volatile_read!(cmdheader.ctba) as usize) as *mut HbaCmdTable)
|
||||
|
Reference in New Issue
Block a user