@@ -24,7 +24,7 @@ const SYS_read: u8 = 63;
24
24
/// You need to use this with snapshot module!
25
25
#[ derive( Debug , Default ) ]
26
26
pub struct RedirectStdinModule {
27
- input_addr : GuestAddr ,
27
+ input_addr : Option < GuestAddr > ,
28
28
read : usize ,
29
29
total : usize ,
30
30
}
@@ -33,12 +33,12 @@ impl RedirectStdinModule {
33
33
#[ must_use]
34
34
/// constuctor
35
35
pub fn new ( ) -> Self {
36
- Self :: with_input_addr ( 0 )
36
+ Self :: with_input_addr ( None )
37
37
}
38
38
39
39
#[ must_use]
40
40
/// Create with specified input address
41
- pub fn with_input_addr ( addr : GuestAddr ) -> Self {
41
+ pub fn with_input_addr ( addr : Option < GuestAddr > ) -> Self {
42
42
Self {
43
43
input_addr : addr,
44
44
read : 0 ,
@@ -47,7 +47,7 @@ impl RedirectStdinModule {
47
47
}
48
48
49
49
/// Tell this module where to look for the input addr
50
- pub fn set_input_addr ( & mut self , addr : GuestAddr ) {
50
+ pub fn set_input_addr ( & mut self , addr : Option < GuestAddr > ) {
51
51
self . input_addr = addr;
52
52
}
53
53
}
57
57
I : Unpin + HasLen + Debug ,
58
58
S : Unpin ,
59
59
{
60
- fn post_qemu_init < ET > ( & mut self , _qemu : Qemu , emulator_modules : & mut EmulatorModules < ET , I , S > )
61
- where
60
+ fn first_exec < ET > (
61
+ & mut self ,
62
+ _qemu : Qemu ,
63
+ emulator_modules : & mut EmulatorModules < ET , I , S > ,
64
+ _state : & mut S ,
65
+ ) where
62
66
ET : EmulatorModuleTuple < I , S > ,
63
67
{
64
68
emulator_modules. pre_syscalls ( Hook :: Function ( syscall_read_hook :: < ET , I , S > ) ) ;
73
77
) where
74
78
ET : EmulatorModuleTuple < I , S > ,
75
79
{
76
- assert ! ( self . input_addr != 0 ) ;
80
+ assert ! ( self . input_addr. is_some ( ) ) ;
77
81
self . total = input. len ( ) ;
78
82
self . read = 0 ;
79
83
}
@@ -100,7 +104,10 @@ where
100
104
S : Unpin ,
101
105
{
102
106
let h = emulator_modules. get_mut :: < RedirectStdinModule > ( ) . unwrap ( ) ;
103
-
107
+ let addr = match h. input_addr {
108
+ Some ( addr) => addr,
109
+ None => return SyscallHookResult :: new ( None ) ,
110
+ } ;
104
111
if syscall == SYS_read as i32 && x0 == 0 {
105
112
/*
106
113
println!(
@@ -109,7 +116,7 @@ where
109
116
);
110
117
*/
111
118
let size = unsafe {
112
- let mut src = h . input_addr as * const u8 ;
119
+ let mut src = addr as * const u8 ;
113
120
src = src. wrapping_add ( h. read ) ;
114
121
let dst = x1 as * mut u8 ;
115
122
if h. total >= h. read {
0 commit comments