7
7
// compile-flags:-C panic=abort
8
8
// aux-build:helper.rs
9
9
10
- #![ feature( start , rustc_private, new_uninit , panic_info_message , lang_items) ]
10
+ #![ feature( rustc_private, lang_items) ]
11
11
#![ feature( alloc_error_handler) ]
12
12
#![ no_std]
13
+ #![ no_main]
13
14
14
15
extern crate alloc;
15
16
extern crate libc;
@@ -21,35 +22,30 @@ pub fn __aeabi_unwind_cpp_pr0() {}
21
22
#[ no_mangle]
22
23
pub fn __aeabi_unwind_cpp_pr1 ( ) { }
23
24
24
- use core:: ptr:: null_mut;
25
- use core:: alloc:: { GlobalAlloc , Layout } ;
26
25
use alloc:: boxed:: Box ;
26
+ use alloc:: string:: ToString ;
27
+ use core:: alloc:: { GlobalAlloc , Layout } ;
28
+ use core:: ptr:: null_mut;
27
29
28
30
extern crate helper;
29
31
30
32
struct MyAllocator ;
31
33
32
34
#[ alloc_error_handler]
33
- fn my_oom ( layout : Layout ) -> !
34
- {
35
+ fn my_oom ( layout : Layout ) -> ! {
35
36
use alloc:: fmt:: write;
36
37
unsafe {
37
38
let size = layout. size ( ) ;
38
39
let mut s = alloc:: string:: String :: new ( ) ;
39
40
write ( & mut s, format_args ! ( "My OOM: failed to allocate {} bytes!\n " , size) ) . unwrap ( ) ;
40
- let s = s. as_str ( ) ;
41
- libc:: write ( libc:: STDERR_FILENO , s as * const _ as _ , s. len ( ) ) ;
41
+ libc:: write ( libc:: STDERR_FILENO , s. as_ptr ( ) as * const _ , s. len ( ) ) ;
42
42
libc:: exit ( 0 )
43
43
}
44
44
}
45
45
46
46
unsafe impl GlobalAlloc for MyAllocator {
47
47
unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
48
- if layout. size ( ) < 4096 {
49
- libc:: malloc ( layout. size ( ) ) as _
50
- } else {
51
- null_mut ( )
52
- }
48
+ if layout. size ( ) < 4096 { libc:: malloc ( layout. size ( ) ) as _ } else { null_mut ( ) }
53
49
}
54
50
unsafe fn dealloc ( & self , _ptr : * mut u8 , _layout : Layout ) { }
55
51
}
@@ -60,26 +56,12 @@ static A: MyAllocator = MyAllocator;
60
56
#[ panic_handler]
61
57
fn panic ( panic_info : & core:: panic:: PanicInfo ) -> ! {
62
58
unsafe {
63
- if let Some ( s) = panic_info. payload ( ) . downcast_ref :: < & str > ( ) {
64
- const PSTR : & str = "panic occurred: " ;
65
- const CR : & str = "\n " ;
66
- libc:: write ( libc:: STDERR_FILENO , PSTR as * const _ as _ , PSTR . len ( ) ) ;
67
- libc:: write ( libc:: STDERR_FILENO , s as * const _ as _ , s. len ( ) ) ;
68
- libc:: write ( libc:: STDERR_FILENO , CR as * const _ as _ , CR . len ( ) ) ;
69
- }
70
- if let Some ( args) = panic_info. message ( ) {
71
- let mut s = alloc:: string:: String :: new ( ) ;
72
- alloc:: fmt:: write ( & mut s, * args) . unwrap ( ) ;
73
- let s = s. as_str ( ) ;
74
- const PSTR : & str = "panic occurred: " ;
75
- const CR : & str = "\n " ;
76
- libc:: write ( libc:: STDERR_FILENO , PSTR as * const _ as _ , PSTR . len ( ) ) ;
77
- libc:: write ( libc:: STDERR_FILENO , s as * const _ as _ , s. len ( ) ) ;
78
- libc:: write ( libc:: STDERR_FILENO , CR as * const _ as _ , CR . len ( ) ) ;
79
- } else {
80
- const PSTR : & str = "panic occurred\n " ;
81
- libc:: write ( libc:: STDERR_FILENO , PSTR as * const _ as _ , PSTR . len ( ) ) ;
82
- }
59
+ let s = panic_info. to_string ( ) ;
60
+ const PSTR : & str = "panic occurred: " ;
61
+ const CR : & str = "\n " ;
62
+ libc:: write ( libc:: STDERR_FILENO , PSTR . as_ptr ( ) as * const _ , PSTR . len ( ) ) ;
63
+ libc:: write ( libc:: STDERR_FILENO , s. as_ptr ( ) as * const _ , s. len ( ) ) ;
64
+ libc:: write ( libc:: STDERR_FILENO , CR . as_ptr ( ) as * const _ , CR . len ( ) ) ;
83
65
libc:: exit ( 1 )
84
66
}
85
67
}
@@ -89,15 +71,14 @@ fn panic(panic_info: &core::panic::PanicInfo) -> ! {
89
71
// in these libraries will refer to `rust_eh_personality` if LLVM can not *prove* the contents won't
90
72
// unwind. So, for this test case we will define the symbol.
91
73
#[ lang = "eh_personality" ]
92
- extern fn rust_eh_personality ( ) { }
74
+ extern "C" fn rust_eh_personality ( ) { }
93
75
94
- #[ derive( Debug ) ]
76
+ #[ derive( Default , Debug ) ]
95
77
struct Page ( #[ allow( unused_tuple_struct_fields) ] [ [ u64 ; 32 ] ; 16 ] ) ;
96
78
97
- #[ start]
98
- pub fn main ( _argc : isize , _argv : * const * const u8 ) -> isize {
99
- let zero = Box :: < Page > :: new_zeroed ( ) ;
100
- let zero = unsafe { zero. assume_init ( ) } ;
79
+ #[ no_mangle]
80
+ fn main ( _argc : i32 , _argv : * const * const u8 ) -> isize {
81
+ let zero = Box :: < Page > :: new ( Default :: default ( ) ) ;
101
82
helper:: work_with ( & zero) ;
102
83
1
103
84
}
0 commit comments