File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -156,3 +156,36 @@ fn test_mremap_dontunmap() {
156156 std:: slice:: from_raw_parts_mut ( mem. cast ( ) . as_ptr ( ) , 10 * ONE_K )
157157 } ;
158158}
159+
160+ #[ test]
161+ #[ cfg( target_os = "linux" ) ]
162+ fn test_madv_wipeonfork ( ) {
163+ use nix:: libc:: size_t;
164+ use nix:: sys:: mman:: { madvise, MmapAdvise } ;
165+ use nix:: unistd:: { fork, ForkResult } ;
166+ use std:: num:: NonZeroUsize ;
167+
168+ const ONE_K : size_t = 1024 ;
169+ let ten_one_k = NonZeroUsize :: new ( 10 * ONE_K ) . unwrap ( ) ;
170+ let slice: & mut [ u8 ] = unsafe {
171+ let mem = mmap_anonymous (
172+ None ,
173+ ten_one_k,
174+ ProtFlags :: PROT_READ | ProtFlags :: PROT_WRITE ,
175+ MapFlags :: MAP_PRIVATE ,
176+ )
177+ . unwrap ( ) ;
178+ madvise ( mem, ONE_K , MmapAdvise :: MADV_WIPEONFORK )
179+ . expect ( "madvise failed" ) ;
180+ std:: slice:: from_raw_parts_mut ( mem. as_ptr ( ) . cast ( ) , ONE_K )
181+ } ;
182+ slice[ ONE_K - 1 ] = 0xFF ;
183+ let _m = crate :: FORK_MTX . lock ( ) ;
184+
185+ unsafe {
186+ if let ForkResult :: Child = fork ( ) . expect ( "fork failed" ) {
187+ // that s the while point of MADV_WIPEONFORK
188+ assert_eq ! ( slice[ ONE_K - 1 ] , 0x00 ) ;
189+ }
190+ }
191+ }
You can’t perform that action at this time.
0 commit comments