-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 初步实现clone系统调用 * 实现了线程,初步实现futex机制,添加了几个小的系统调用 * 更改pcb引用计数问题 * 解决死锁bug --------- Co-authored-by: LoGin <[email protected]>
- Loading branch information
Showing
25 changed files
with
1,641 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,38 @@ | ||
use core::arch::x86_64::_rdtsc; | ||
|
||
use alloc::vec::Vec; | ||
|
||
use crate::{ | ||
libs::rand::GRandFlags, | ||
syscall::{user_access::UserBufferWriter, Syscall, SystemError}, | ||
}; | ||
|
||
pub fn rand() -> usize { | ||
return unsafe { (_rdtsc() * _rdtsc() + 998244353_u64 * _rdtsc()) as usize }; | ||
} | ||
|
||
impl Syscall { | ||
/// ## 将随机字节填入buf | ||
/// | ||
/// ### 该系统调用与linux不一致,因为目前没有其他随机源 | ||
pub fn get_random(buf: *mut u8, len: usize, flags: GRandFlags) -> Result<usize, SystemError> { | ||
if flags.bits() == (GRandFlags::GRND_INSECURE.bits() | GRandFlags::GRND_RANDOM.bits()) { | ||
return Err(SystemError::EINVAL); | ||
} | ||
|
||
let mut writer = UserBufferWriter::new(buf, len, true)?; | ||
|
||
let mut ret = Vec::new(); | ||
let mut count = 0; | ||
while count < len { | ||
let rand = rand(); | ||
for offset in 0..4 { | ||
ret.push((rand >> offset * 2) as u8); | ||
count += 1; | ||
} | ||
} | ||
|
||
writer.copy_to_user(&ret, 0)?; | ||
Ok(len) | ||
} | ||
} |
Oops, something went wrong.