2
2
extern crate clap;
3
3
4
4
use clap:: Arg ;
5
+ use human_size:: { Byte , Size } ;
5
6
use lucet_runtime:: { self , DlModule , Limits , MmapRegion , Module , Region } ;
6
7
use lucet_wasi:: { hostcalls, WasiCtxBuilder } ;
7
8
use std:: fs:: File ;
@@ -12,6 +13,7 @@ struct Config<'a> {
12
13
guest_args : Vec < & ' a str > ,
13
14
entrypoint : & ' a str ,
14
15
preopen_dirs : Vec < ( File , & ' a str ) > ,
16
+ limits : Limits ,
15
17
}
16
18
17
19
fn main ( ) {
@@ -41,10 +43,10 @@ fn main() {
41
43
virtual filesystem. Each directory is specified as \
42
44
--dir `host_path:guest_path`, where `guest_path` specifies the path that will \
43
45
correspond to `host_path` for calls like `fopen` in the guest.\
44
- \
46
+ \n \n \
45
47
For example, `--dir /home/host_user/wasi_sandbox:/sandbox` will make \
46
48
`/home/host_user/wasi_sandbox` available within the guest as `/sandbox`.\
47
- \
49
+ \n \n \
48
50
Guests will be able to access any files and directories under the \
49
51
`host_path`, but will be unable to access other parts of the host \
50
52
filesystem through relative paths (e.g., `/sandbox/../some_other_file`) \
@@ -56,6 +58,39 @@ fn main() {
56
58
. required ( true )
57
59
. help ( "Path to the `lucetc`-compiled WASI module" ) ,
58
60
)
61
+ . arg (
62
+ Arg :: with_name ( "heap_memory_size" )
63
+ . long ( "max-heap-size" )
64
+ . takes_value ( true )
65
+ . default_value ( "1024 KiB" )
66
+ . help ( "Maximum heap size (must be a multiple of 4 KiB)" ) ,
67
+ )
68
+ . arg (
69
+ Arg :: with_name ( "heap_address_space_size" )
70
+ . long ( "heap-address-space" )
71
+ . takes_value ( true )
72
+ . default_value ( "8 GiB" )
73
+ . help ( "Maximum heap address space size (must be a multiple of 4 KiB)" )
74
+ . long_help (
75
+ "Maximum heap address space size. Must be a multiple of 4KiB, and \
76
+ must be least as large as `max-heap-size`, `stack-size`, and \
77
+ `globals-size`, combined.",
78
+ ) ,
79
+ )
80
+ . arg (
81
+ Arg :: with_name ( "stack_size" )
82
+ . long ( "stack-size" )
83
+ . takes_value ( true )
84
+ . default_value ( "128 KiB" )
85
+ . help ( "Maximum stack size (must be a multiple of 4 KiB)" ) ,
86
+ )
87
+ . arg (
88
+ Arg :: with_name ( "globals_size" )
89
+ . long ( "globals-size" )
90
+ . takes_value ( true )
91
+ . default_value ( "4 KiB" )
92
+ . help ( "Maximum globals size (must be a multiple of 4 KiB)" ) ,
93
+ )
59
94
. arg (
60
95
Arg :: with_name ( "guest_args" )
61
96
. required ( false )
@@ -65,7 +100,9 @@ fn main() {
65
100
. get_matches ( ) ;
66
101
67
102
let entrypoint = matches. value_of ( "entrypoint" ) . unwrap ( ) ;
103
+
68
104
let lucet_module = matches. value_of ( "lucet_module" ) . unwrap ( ) ;
105
+
69
106
let preopen_dirs = matches
70
107
. values_of ( "preopen_dirs" )
71
108
. map ( |vals| {
@@ -84,24 +121,52 @@ fn main() {
84
121
. collect ( )
85
122
} )
86
123
. unwrap_or ( vec ! [ ] ) ;
124
+
125
+ let heap_memory_size = value_t ! ( matches, "heap_memory_size" , Size )
126
+ . unwrap_or_else ( |e| e. exit ( ) )
127
+ . into :: < Byte > ( )
128
+ . value ( ) as usize ;
129
+ let heap_address_space_size = value_t ! ( matches, "heap_address_space_size" , Size )
130
+ . unwrap_or_else ( |e| e. exit ( ) )
131
+ . into :: < Byte > ( )
132
+ . value ( ) as usize ;
133
+ let stack_size = value_t ! ( matches, "stack_size" , Size )
134
+ . unwrap_or_else ( |e| e. exit ( ) )
135
+ . into :: < Byte > ( )
136
+ . value ( ) as usize ;
137
+ let globals_size = value_t ! ( matches, "globals_size" , Size )
138
+ . unwrap_or_else ( |e| e. exit ( ) )
139
+ . into :: < Byte > ( )
140
+ . value ( ) as usize ;
141
+
142
+ let limits = Limits {
143
+ heap_memory_size,
144
+ heap_address_space_size,
145
+ stack_size,
146
+ globals_size,
147
+ } ;
148
+
87
149
let guest_args = matches
88
150
. values_of ( "guest_args" )
89
151
. map ( |vals| vals. collect ( ) )
90
152
. unwrap_or ( vec ! [ ] ) ;
153
+
91
154
let config = Config {
92
155
lucet_module,
93
156
guest_args,
94
157
entrypoint,
95
158
preopen_dirs,
159
+ limits,
96
160
} ;
161
+
97
162
run ( config)
98
163
}
99
164
100
165
fn run ( config : Config ) {
101
166
lucet_wasi:: hostcalls:: ensure_linked ( ) ;
102
167
let exitcode = {
103
168
// doing all of this in a block makes sure everything gets dropped before exiting
104
- let region = MmapRegion :: create ( 1 , & Limits :: default ( ) ) . expect ( "region can be created" ) ;
169
+ let region = MmapRegion :: create ( 1 , & config . limits ) . expect ( "region can be created" ) ;
105
170
let module = DlModule :: load ( & config. lucet_module ) . expect ( "module can be loaded" ) ;
106
171
107
172
// put the path to the module on the front for argv[0]
0 commit comments