mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-22 19:33:26 +00:00
new:在fork时拷贝signal和sighand (#91)
* refcount初始化 * new: 实现copy_sighand del: 删除sighand_struct的wqh, 待将来有需要时,替换成rust版本的 * new: 拷贝signal bugfix: 解决拷贝sighand时的uaf问题
This commit is contained in:
@ -1,11 +1,26 @@
|
||||
use core::ptr::read_volatile;
|
||||
#![allow(dead_code)]
|
||||
use core::ptr::{read_volatile, write_volatile};
|
||||
|
||||
use crate::include::bindings::bindings::atomic_t;
|
||||
|
||||
/// @brief 原子的读取指定的原子变量的值
|
||||
#[inline]
|
||||
pub fn atomic_read(ato:*const atomic_t)-> i64{
|
||||
unsafe{
|
||||
pub fn atomic_read(ato: *const atomic_t) -> i64 {
|
||||
unsafe {
|
||||
return read_volatile(&(*ato).value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief 原子的设置原子变量的值
|
||||
#[inline]
|
||||
pub fn atomic_set(ato: *mut atomic_t, value:i64) {
|
||||
unsafe{
|
||||
write_volatile(&mut (*ato).value, value);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for atomic_t {
|
||||
fn default() -> Self {
|
||||
Self { value: 0 }
|
||||
}
|
||||
}
|
||||
|
15
kernel/src/libs/list.rs
Normal file
15
kernel/src/libs/list.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use crate::include::bindings::bindings::List;
|
||||
|
||||
/// @brief 初始化链表
|
||||
#[inline]
|
||||
pub fn list_init(list: *mut List) {
|
||||
unsafe{*list}.prev = list;
|
||||
unsafe{*list}.next = list;
|
||||
}
|
||||
|
||||
impl Default for List{
|
||||
fn default() -> Self {
|
||||
let x= Self { prev: 0 as *mut List, next: 0 as *mut List };
|
||||
return x;
|
||||
}
|
||||
}
|
@ -3,4 +3,6 @@ pub mod spinlock;
|
||||
pub mod ffi_convert;
|
||||
#[macro_use]
|
||||
pub mod refcount;
|
||||
pub mod atomic;
|
||||
pub mod atomic;
|
||||
pub mod wait_queue;
|
||||
pub mod list;
|
@ -7,6 +7,12 @@ pub struct RefCount {
|
||||
pub refs: atomic_t,
|
||||
}
|
||||
|
||||
impl Default for RefCount{
|
||||
fn default() -> Self {
|
||||
Self { refs: atomic_t { value: 1 }}
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief 将给定的来自bindgen的refcount_t解析为Rust的RefCount的引用
|
||||
impl FFIBind2Rust<crate::include::bindings::bindings::refcount_struct> for RefCount{
|
||||
fn convert_mut<'a>(
|
||||
@ -21,10 +27,11 @@ impl FFIBind2Rust<crate::include::bindings::bindings::refcount_struct> for RefCo
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief 以指定的值初始化refcount
|
||||
macro_rules! REFCOUNT_INIT {
|
||||
($x:expr) => {
|
||||
$crate::libs::refcount::RefCount {
|
||||
refs: atomic_t { value: 0 },
|
||||
refs: $crate::include::bindings::bindings::atomic_t { value: $x },
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -28,3 +28,9 @@ pub fn spin_is_locked(lock: &spinlock_t) -> bool {
|
||||
|
||||
return if val == 0 { true } else { false };
|
||||
}
|
||||
|
||||
impl Default for spinlock_t {
|
||||
fn default() -> Self {
|
||||
Self { lock: 1 }
|
||||
}
|
||||
}
|
12
kernel/src/libs/wait_queue.rs
Normal file
12
kernel/src/libs/wait_queue.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use crate::include::bindings::bindings::{wait_queue_head_t};
|
||||
|
||||
use super::{list::list_init};
|
||||
|
||||
|
||||
impl Default for wait_queue_head_t{
|
||||
fn default() -> Self {
|
||||
let mut x = Self { wait_list: Default::default(), lock: Default::default() };
|
||||
list_init(&mut x.wait_list);
|
||||
return x;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user