3
3
// Run-time:
4
4
// status: 0
5
5
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
-
14
6
mod libc {
15
7
#[ link( name = "c" ) ]
16
8
extern "C" {
@@ -44,8 +36,7 @@ static mut COUNT: u32 = 0;
44
36
static mut STORAGE : * mut u8 = core:: ptr:: null_mut ( ) ;
45
37
const PAGE_SIZE : usize = 1 << 15 ;
46
38
47
- #[ start]
48
- fn main ( _argc : isize , _argv : * const * const u8 ) -> isize {
39
+ fn main ( ) {
49
40
unsafe {
50
41
// Register a segfault handler
51
42
libc:: sigaction (
@@ -67,8 +58,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
67
58
0 ,
68
59
) . cast ( ) ;
69
60
if STORAGE == libc:: MAP_FAILED {
70
- libc:: puts ( b"error: mmap failed\0 " . as_ptr ( ) ) ;
71
- return 1 ;
61
+ panic ! ( "error: mmap failed" ) ;
72
62
}
73
63
74
64
let p_count = ( & mut COUNT ) as * mut u32 ;
@@ -81,21 +71,25 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
81
71
STORAGE . add ( PAGE_SIZE ) . write_volatile ( 1 ) ;
82
72
STORAGE . add ( 0 ) . write_volatile ( 1 ) ;
83
73
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 ) ;
84
82
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.
89
86
//
90
87
// This `p_count` read is done by a volatile read. If the compiler
91
88
// ignores volatility, the compiler will speculate that `*p_count` is
92
89
// 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( ) ) ;
96
92
}
97
-
98
- 0
99
93
}
100
94
}
101
95
0 commit comments