File tree 1 file changed +29
-1
lines changed
lib/runtime-core/src/sys/windows
1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,13 @@ impl Memory {
33
33
34
34
let protect = protection. to_protect_const ( ) ;
35
35
36
- let ptr = unsafe { VirtualAlloc ( ptr:: null_mut ( ) , size, MEM_RESERVE , protect) } ;
36
+ let flags = if protection == Protect :: None {
37
+ MEM_RESERVE
38
+ } else {
39
+ MEM_RESERVE | MEM_COMMIT
40
+ } ;
41
+
42
+ let ptr = unsafe { VirtualAlloc ( ptr:: null_mut ( ) , size, flags, protect) } ;
37
43
38
44
if ptr. is_null ( ) {
39
45
Err ( "unable to allocate memory" . to_string ( ) )
@@ -229,3 +235,25 @@ fn round_up_to_page_size(size: usize, page_size: usize) -> usize {
229
235
fn round_down_to_page_size ( size : usize , page_size : usize ) -> usize {
230
236
size & !( page_size - 1 )
231
237
}
238
+
239
+ #[ cfg( test) ]
240
+ mod tests {
241
+ use super :: * ;
242
+
243
+ #[ test]
244
+ fn clone ( ) {
245
+ // these should work
246
+ let _ = Memory :: with_size_protect ( 200_000 , Protect :: Read )
247
+ . unwrap ( )
248
+ . clone ( ) ;
249
+ let _ = Memory :: with_size_protect ( 200_000 , Protect :: ReadWrite )
250
+ . unwrap ( )
251
+ . clone ( ) ;
252
+ let _ = Memory :: with_size_protect ( 200_000 , Protect :: ReadExec )
253
+ . unwrap ( )
254
+ . clone ( ) ;
255
+
256
+ // this would cause segmentation fault as uncommited memory with no access
257
+ //let _ = Memory::with_size_protect(200_000, Protect::None).unwrap().clone();
258
+ }
259
+ }
You can’t perform that action at this time.
0 commit comments