77// compile-flags:-C panic=abort
88// aux-build:helper.rs
99
10- #![ feature( start , rustc_private, new_uninit , panic_info_message , lang_items) ]
10+ #![ feature( rustc_private, lang_items) ]
1111#![ feature( alloc_error_handler) ]
1212#![ no_std]
13+ #![ no_main]
1314
1415extern crate alloc;
1516extern crate libc;
@@ -21,35 +22,30 @@ pub fn __aeabi_unwind_cpp_pr0() {}
2122#[ no_mangle]
2223pub fn __aeabi_unwind_cpp_pr1 ( ) { }
2324
24- use core:: ptr:: null_mut;
25- use core:: alloc:: { GlobalAlloc , Layout } ;
2625use alloc:: boxed:: Box ;
26+ use alloc:: string:: ToString ;
27+ use core:: alloc:: { GlobalAlloc , Layout } ;
28+ use core:: ptr:: null_mut;
2729
2830extern crate helper;
2931
3032struct MyAllocator ;
3133
3234#[ alloc_error_handler]
33- fn my_oom ( layout : Layout ) -> !
34- {
35+ fn my_oom ( layout : Layout ) -> ! {
3536 use alloc:: fmt:: write;
3637 unsafe {
3738 let size = layout. size ( ) ;
3839 let mut s = alloc:: string:: String :: new ( ) ;
3940 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 ( ) ) ;
4242 libc:: exit ( 0 )
4343 }
4444}
4545
4646unsafe impl GlobalAlloc for MyAllocator {
4747 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 ( ) }
5349 }
5450 unsafe fn dealloc ( & self , _ptr : * mut u8 , _layout : Layout ) { }
5551}
@@ -60,26 +56,12 @@ static A: MyAllocator = MyAllocator;
6056#[ panic_handler]
6157fn panic ( panic_info : & core:: panic:: PanicInfo ) -> ! {
6258 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 ( ) ) ;
8365 libc:: exit ( 1 )
8466 }
8567}
@@ -89,15 +71,14 @@ fn panic(panic_info: &core::panic::PanicInfo) -> ! {
8971// in these libraries will refer to `rust_eh_personality` if LLVM can not *prove* the contents won't
9072// unwind. So, for this test case we will define the symbol.
9173#[ lang = "eh_personality" ]
92- extern fn rust_eh_personality ( ) { }
74+ extern "C" fn rust_eh_personality ( ) { }
9375
94- #[ derive( Debug ) ]
76+ #[ derive( Default , Debug ) ]
9577struct Page ( #[ allow( unused_tuple_struct_fields) ] [ [ u64 ; 32 ] ; 16 ] ) ;
9678
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 ( ) ) ;
10182 helper:: work_with ( & zero) ;
10283 1
10384}
0 commit comments