File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use crate::{
5
5
arch:: {
6
6
interrupt:: TrapFrame ,
7
7
process:: table:: { USER_CS , USER_DS } ,
8
+ rand:: rand_bytes,
8
9
CurrentIrqArch ,
9
10
} ,
10
11
exception:: InterruptArch ,
@@ -74,7 +75,7 @@ impl Syscall {
74
75
75
76
// 生成16字节随机数
76
77
// TODO 暂时设为0
77
- param. init_info_mut ( ) . rand_num = [ 0u8 ; 16 ] ;
78
+ param. init_info_mut ( ) . rand_num = rand_bytes :: < 16 > ( ) ;
78
79
79
80
// 把proc_init_info写到用户栈上
80
81
let mut ustack_message = unsafe {
Original file line number Diff line number Diff line change @@ -3,3 +3,23 @@ use core::arch::x86_64::_rdtsc;
3
3
pub fn rand ( ) -> usize {
4
4
return unsafe { ( _rdtsc ( ) * _rdtsc ( ) + 998244353_u64 * _rdtsc ( ) ) as usize } ;
5
5
}
6
+
7
+ //TODO move it out from arch module
8
+ pub fn rand_bytes < const N : usize > ( ) -> [ u8 ; N ] {
9
+ let mut bytes = [ 0u8 ; N ] ;
10
+ let mut remaining = N ;
11
+ let mut index = 0 ;
12
+
13
+ while remaining > 0 {
14
+ let random_num = rand ( ) ;
15
+ let random_bytes = random_num. to_le_bytes ( ) ;
16
+
17
+ let to_copy = core:: cmp:: min ( remaining, size_of :: < usize > ( ) ) ;
18
+ bytes[ index..index + to_copy] . copy_from_slice ( & random_bytes[ ..to_copy] ) ;
19
+
20
+ index += to_copy;
21
+ remaining -= to_copy;
22
+ }
23
+
24
+ bytes
25
+ }
You can’t perform that action at this time.
0 commit comments