33// Run-time:
44// status: 0
55
6- #![ no_std]
7- #![ feature( core_intrinsics, start) ]
8-
9- #[ panic_handler]
10- fn panic_handler ( _: & core:: panic:: PanicInfo ) -> ! {
11- core:: intrinsics:: abort ( ) ;
12- }
13-
146mod libc {
157 #[ link( name = "c" ) ]
168 extern "C" {
@@ -44,8 +36,7 @@ static mut COUNT: u32 = 0;
4436static mut STORAGE : * mut u8 = core:: ptr:: null_mut ( ) ;
4537const PAGE_SIZE : usize = 1 << 15 ;
4638
47- #[ start]
48- fn main ( _argc : isize , _argv : * const * const u8 ) -> isize {
39+ fn main ( ) {
4940 unsafe {
5041 // Register a segfault handler
5142 libc:: sigaction (
@@ -67,8 +58,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
6758 0 ,
6859 ) . cast ( ) ;
6960 if STORAGE == libc:: MAP_FAILED {
70- libc:: puts ( b"error: mmap failed\0 " . as_ptr ( ) ) ;
71- return 1 ;
61+ panic ! ( "error: mmap failed" ) ;
7262 }
7363
7464 let p_count = ( & mut COUNT ) as * mut u32 ;
@@ -81,21 +71,25 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
8171 STORAGE . add ( PAGE_SIZE ) . write_volatile ( 1 ) ;
8272 STORAGE . add ( 0 ) . write_volatile ( 1 ) ;
8373 STORAGE . add ( PAGE_SIZE ) . write_volatile ( 1 ) ;
74+ STORAGE . add ( 0 ) . read_volatile ( ) ;
75+ STORAGE . add ( PAGE_SIZE ) . read_volatile ( ) ;
76+ STORAGE . add ( 0 ) . read_volatile ( ) ;
77+ STORAGE . add ( PAGE_SIZE ) . read_volatile ( ) ;
78+ STORAGE . add ( 0 ) . read_volatile ( ) ;
79+ STORAGE . add ( PAGE_SIZE ) . read_volatile ( ) ;
80+ STORAGE . add ( 0 ) . write_volatile ( 1 ) ;
81+ STORAGE . add ( PAGE_SIZE ) . write_volatile ( 1 ) ;
8482
85- // The segfault handler should have been called for every
86- // `write_volatile` in `STORAGE`. If the compiler ignores volatility,
87- // some of these writes will be combined, causing a different number of
88- // segfaults.
83+ // The segfault handler should have been called for every `write_volatile` and
84+ // `read_volatile` in `STORAGE`. If the compiler ignores volatility, some of these writes
85+ // will be combined, causing a different number of segfaults.
8986 //
9087 // This `p_count` read is done by a volatile read. If the compiler
9188 // ignores volatility, the compiler will speculate that `*p_count` is
9289 // unchanged and remove this check, failing the test.
93- if p_count. read_volatile ( ) != 6 {
94- libc:: puts ( b"error: segfault count mismatch\0 " . as_ptr ( ) ) ;
95- return 1 ;
90+ if p_count. read_volatile ( ) != 14 {
91+ panic ! ( "error: segfault count mismatch: {}" , p_count. read_volatile( ) ) ;
9692 }
97-
98- 0
9993 }
10094}
10195
0 commit comments