]> git.lizzy.rs Git - rust.git/blob - library/std/src/panicking.rs
Auto merge of #78472 - hermitcore:builtins, r=Mark-Simulacrum
[rust.git] / library / std / src / panicking.rs
1 //! Implementation of various bits and pieces of the `panic!` macro and
2 //! associated runtime pieces.
3 //!
4 //! Specifically, this module contains the implementation of:
5 //!
6 //! * Panic hooks
7 //! * Executing a panic up to doing the actual implementation
8 //! * Shims around "try"
9
10 #![deny(unsafe_op_in_unsafe_fn)]
11
12 use core::panic::{BoxMeUp, Location, PanicInfo};
13
14 use crate::any::Any;
15 use crate::fmt;
16 use crate::intrinsics;
17 use crate::mem::{self, ManuallyDrop};
18 use crate::process;
19 use crate::sync::atomic::{AtomicBool, Ordering};
20 use crate::sys::stdio::panic_output;
21 use crate::sys_common::backtrace::{self, RustBacktrace};
22 use crate::sys_common::rwlock::RWLock;
23 use crate::sys_common::{thread_info, util};
24 use crate::thread;
25
26 #[cfg(not(test))]
27 use crate::io::set_panic;
28 // make sure to use the stderr output configured
29 // by libtest in the real copy of std
30 #[cfg(test)]
31 use realstd::io::set_panic;
32
33 // Binary interface to the panic runtime that the standard library depends on.
34 //
35 // The standard library is tagged with `#![needs_panic_runtime]` (introduced in
36 // RFC 1513) to indicate that it requires some other crate tagged with
37 // `#![panic_runtime]` to exist somewhere. Each panic runtime is intended to
38 // implement these symbols (with the same signatures) so we can get matched up
39 // to them.
40 //
41 // One day this may look a little less ad-hoc with the compiler helping out to
42 // hook up these functions, but it is not this day!
43 #[allow(improper_ctypes)]
44 extern "C" {
45     fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static);
46
47     /// `payload` is actually a `*mut &mut dyn BoxMeUp` but that would cause FFI warnings.
48     /// It cannot be `Box<dyn BoxMeUp>` because the other end of this call does not depend
49     /// on liballoc, and thus cannot use `Box`.
50     #[unwind(allowed)]
51     fn __rust_start_panic(payload: usize) -> u32;
52 }
53
54 /// This function is called by the panic runtime if FFI code catches a Rust
55 /// panic but doesn't rethrow it. We don't support this case since it messes
56 /// with our panic count.
57 #[cfg(not(test))]
58 #[rustc_std_internal_symbol]
59 extern "C" fn __rust_drop_panic() -> ! {
60     rtabort!("Rust panics must be rethrown");
61 }
62
63 /// This function is called by the panic runtime if it catches an exception
64 /// object which does not correspond to a Rust panic.
65 #[cfg(not(test))]
66 #[rustc_std_internal_symbol]
67 extern "C" fn __rust_foreign_exception() -> ! {
68     rtabort!("Rust cannot catch foreign exceptions");
69 }
70
71 #[derive(Copy, Clone)]
72 enum Hook {
73     Default,
74     Custom(*mut (dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send)),
75 }
76
77 static HOOK_LOCK: RWLock = RWLock::new();
78 static mut HOOK: Hook = Hook::Default;
79
80 /// Registers a custom panic hook, replacing any that was previously registered.
81 ///
82 /// The panic hook is invoked when a thread panics, but before the panic runtime
83 /// is invoked. As such, the hook will run with both the aborting and unwinding
84 /// runtimes. The default hook prints a message to standard error and generates
85 /// a backtrace if requested, but this behavior can be customized with the
86 /// `set_hook` and [`take_hook`] functions.
87 ///
88 /// [`take_hook`]: ./fn.take_hook.html
89 ///
90 /// The hook is provided with a `PanicInfo` struct which contains information
91 /// about the origin of the panic, including the payload passed to `panic!` and
92 /// the source code location from which the panic originated.
93 ///
94 /// The panic hook is a global resource.
95 ///
96 /// # Panics
97 ///
98 /// Panics if called from a panicking thread.
99 ///
100 /// # Examples
101 ///
102 /// The following will print "Custom panic hook":
103 ///
104 /// ```should_panic
105 /// use std::panic;
106 ///
107 /// panic::set_hook(Box::new(|_| {
108 ///     println!("Custom panic hook");
109 /// }));
110 ///
111 /// panic!("Normal panic");
112 /// ```
113 #[stable(feature = "panic_hooks", since = "1.10.0")]
114 pub fn set_hook(hook: Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>) {
115     if thread::panicking() {
116         panic!("cannot modify the panic hook from a panicking thread");
117     }
118
119     unsafe {
120         HOOK_LOCK.write();
121         let old_hook = HOOK;
122         HOOK = Hook::Custom(Box::into_raw(hook));
123         HOOK_LOCK.write_unlock();
124
125         if let Hook::Custom(ptr) = old_hook {
126             #[allow(unused_must_use)]
127             {
128                 Box::from_raw(ptr);
129             }
130         }
131     }
132 }
133
134 /// Unregisters the current panic hook, returning it.
135 ///
136 /// *See also the function [`set_hook`].*
137 ///
138 /// [`set_hook`]: ./fn.set_hook.html
139 ///
140 /// If no custom hook is registered, the default hook will be returned.
141 ///
142 /// # Panics
143 ///
144 /// Panics if called from a panicking thread.
145 ///
146 /// # Examples
147 ///
148 /// The following will print "Normal panic":
149 ///
150 /// ```should_panic
151 /// use std::panic;
152 ///
153 /// panic::set_hook(Box::new(|_| {
154 ///     println!("Custom panic hook");
155 /// }));
156 ///
157 /// let _ = panic::take_hook();
158 ///
159 /// panic!("Normal panic");
160 /// ```
161 #[stable(feature = "panic_hooks", since = "1.10.0")]
162 pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
163     if thread::panicking() {
164         panic!("cannot modify the panic hook from a panicking thread");
165     }
166
167     unsafe {
168         HOOK_LOCK.write();
169         let hook = HOOK;
170         HOOK = Hook::Default;
171         HOOK_LOCK.write_unlock();
172
173         match hook {
174             Hook::Default => Box::new(default_hook),
175             Hook::Custom(ptr) => Box::from_raw(ptr),
176         }
177     }
178 }
179
180 fn default_hook(info: &PanicInfo<'_>) {
181     // If this is a double panic, make sure that we print a backtrace
182     // for this panic. Otherwise only print it if logging is enabled.
183     let backtrace_env = if panic_count::get() >= 2 {
184         RustBacktrace::Print(crate::backtrace_rs::PrintFmt::Full)
185     } else {
186         backtrace::rust_backtrace_env()
187     };
188
189     // The current implementation always returns `Some`.
190     let location = info.location().unwrap();
191
192     let msg = match info.payload().downcast_ref::<&'static str>() {
193         Some(s) => *s,
194         None => match info.payload().downcast_ref::<String>() {
195             Some(s) => &s[..],
196             None => "Box<Any>",
197         },
198     };
199     let thread = thread_info::current_thread();
200     let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>");
201
202     let write = |err: &mut dyn crate::io::Write| {
203         let _ = writeln!(err, "thread '{}' panicked at '{}', {}", name, msg, location);
204
205         static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
206
207         match backtrace_env {
208             RustBacktrace::Print(format) => drop(backtrace::print(err, format)),
209             RustBacktrace::Disabled => {}
210             RustBacktrace::RuntimeDisabled => {
211                 if FIRST_PANIC.swap(false, Ordering::SeqCst) {
212                     let _ = writeln!(
213                         err,
214                         "note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"
215                     );
216                 }
217             }
218         }
219     };
220
221     if let Some(mut local) = set_panic(None) {
222         // NB. In `cfg(test)` this uses the forwarding impl
223         // for `dyn ::realstd::io::LocalOutput`.
224         write(&mut local);
225         set_panic(Some(local));
226     } else if let Some(mut out) = panic_output() {
227         write(&mut out);
228     }
229 }
230
231 #[cfg(not(test))]
232 #[doc(hidden)]
233 #[unstable(feature = "update_panic_count", issue = "none")]
234 pub mod panic_count {
235     use crate::cell::Cell;
236     use crate::sync::atomic::{AtomicUsize, Ordering};
237
238     // Panic count for the current thread.
239     thread_local! { static LOCAL_PANIC_COUNT: Cell<usize> = Cell::new(0) }
240
241     // Sum of panic counts from all threads. The purpose of this is to have
242     // a fast path in `is_zero` (which is used by `panicking`). In any particular
243     // thread, if that thread currently views `GLOBAL_PANIC_COUNT` as being zero,
244     // then `LOCAL_PANIC_COUNT` in that thread is zero. This invariant holds before
245     // and after increase and decrease, but not necessarily during their execution.
246     static GLOBAL_PANIC_COUNT: AtomicUsize = AtomicUsize::new(0);
247
248     pub fn increase() -> usize {
249         GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed);
250         LOCAL_PANIC_COUNT.with(|c| {
251             let next = c.get() + 1;
252             c.set(next);
253             next
254         })
255     }
256
257     pub fn decrease() -> usize {
258         GLOBAL_PANIC_COUNT.fetch_sub(1, Ordering::Relaxed);
259         LOCAL_PANIC_COUNT.with(|c| {
260             let next = c.get() - 1;
261             c.set(next);
262             next
263         })
264     }
265
266     pub fn get() -> usize {
267         LOCAL_PANIC_COUNT.with(|c| c.get())
268     }
269
270     #[inline]
271     pub fn is_zero() -> bool {
272         if GLOBAL_PANIC_COUNT.load(Ordering::Relaxed) == 0 {
273             // Fast path: if `GLOBAL_PANIC_COUNT` is zero, all threads
274             // (including the current one) will have `LOCAL_PANIC_COUNT`
275             // equal to zero, so TLS access can be avoided.
276             //
277             // In terms of performance, a relaxed atomic load is similar to a normal
278             // aligned memory read (e.g., a mov instruction in x86), but with some
279             // compiler optimization restrictions. On the other hand, a TLS access
280             // might require calling a non-inlinable function (such as `__tls_get_addr`
281             // when using the GD TLS model).
282             true
283         } else {
284             is_zero_slow_path()
285         }
286     }
287
288     // Slow path is in a separate function to reduce the amount of code
289     // inlined from `is_zero`.
290     #[inline(never)]
291     #[cold]
292     fn is_zero_slow_path() -> bool {
293         LOCAL_PANIC_COUNT.with(|c| c.get() == 0)
294     }
295 }
296
297 #[cfg(test)]
298 pub use realstd::rt::panic_count;
299
300 /// Invoke a closure, capturing the cause of an unwinding panic if one occurs.
301 pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> {
302     union Data<F, R> {
303         f: ManuallyDrop<F>,
304         r: ManuallyDrop<R>,
305         p: ManuallyDrop<Box<dyn Any + Send>>,
306     }
307
308     // We do some sketchy operations with ownership here for the sake of
309     // performance. We can only pass pointers down to `do_call` (can't pass
310     // objects by value), so we do all the ownership tracking here manually
311     // using a union.
312     //
313     // We go through a transition where:
314     //
315     // * First, we set the data field `f` to be the argumentless closure that we're going to call.
316     // * When we make the function call, the `do_call` function below, we take
317     //   ownership of the function pointer. At this point the `data` union is
318     //   entirely uninitialized.
319     // * If the closure successfully returns, we write the return value into the
320     //   data's return slot (field `r`).
321     // * If the closure panics (`do_catch` below), we write the panic payload into field `p`.
322     // * Finally, when we come back out of the `try` intrinsic we're
323     //   in one of two states:
324     //
325     //      1. The closure didn't panic, in which case the return value was
326     //         filled in. We move it out of `data.r` and return it.
327     //      2. The closure panicked, in which case the panic payload was
328     //         filled in. We move it out of `data.p` and return it.
329     //
330     // Once we stack all that together we should have the "most efficient'
331     // method of calling a catch panic whilst juggling ownership.
332     let mut data = Data { f: ManuallyDrop::new(f) };
333
334     let data_ptr = &mut data as *mut _ as *mut u8;
335     // SAFETY:
336     //
337     // Access to the union's fields: this is `std` and we know that the `r#try`
338     // intrinsic fills in the `r` or `p` union field based on its return value.
339     //
340     // The call to `intrinsics::r#try` is made safe by:
341     // - `do_call`, the first argument, can be called with the initial `data_ptr`.
342     // - `do_catch`, the second argument, can be called with the `data_ptr` as well.
343     // See their safety preconditions for more informations
344     unsafe {
345         return if intrinsics::r#try(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
346             Ok(ManuallyDrop::into_inner(data.r))
347         } else {
348             Err(ManuallyDrop::into_inner(data.p))
349         };
350     }
351
352     // We consider unwinding to be rare, so mark this function as cold. However,
353     // do not mark it no-inline -- that decision is best to leave to the
354     // optimizer (in most cases this function is not inlined even as a normal,
355     // non-cold function, though, as of the writing of this comment).
356     #[cold]
357     unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send + 'static> {
358         // SAFETY: The whole unsafe block hinges on a correct implementation of
359         // the panic handler `__rust_panic_cleanup`. As such we can only
360         // assume it returns the correct thing for `Box::from_raw` to work
361         // without undefined behavior.
362         let obj = unsafe { Box::from_raw(__rust_panic_cleanup(payload)) };
363         panic_count::decrease();
364         obj
365     }
366
367     // SAFETY:
368     // data must be non-NUL, correctly aligned, and a pointer to a `Data<F, R>`
369     // Its must contains a valid `f` (type: F) value that can be use to fill
370     // `data.r`.
371     //
372     // This function cannot be marked as `unsafe` because `intrinsics::r#try`
373     // expects normal function pointers.
374     #[inline]
375     fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
376         // SAFETY: this is the responsibilty of the caller, see above.
377         unsafe {
378             let data = data as *mut Data<F, R>;
379             let data = &mut (*data);
380             let f = ManuallyDrop::take(&mut data.f);
381             data.r = ManuallyDrop::new(f());
382         }
383     }
384
385     // We *do* want this part of the catch to be inlined: this allows the
386     // compiler to properly track accesses to the Data union and optimize it
387     // away most of the time.
388     //
389     // SAFETY:
390     // data must be non-NUL, correctly aligned, and a pointer to a `Data<F, R>`
391     // Since this uses `cleanup` it also hinges on a correct implementation of
392     // `__rustc_panic_cleanup`.
393     //
394     // This function cannot be marked as `unsafe` because `intrinsics::r#try`
395     // expects normal function pointers.
396     #[inline]
397     fn do_catch<F: FnOnce() -> R, R>(data: *mut u8, payload: *mut u8) {
398         // SAFETY: this is the responsibilty of the caller, see above.
399         //
400         // When `__rustc_panic_cleaner` is correctly implemented we can rely
401         // on `obj` being the correct thing to pass to `data.p` (after wrapping
402         // in `ManuallyDrop`).
403         unsafe {
404             let data = data as *mut Data<F, R>;
405             let data = &mut (*data);
406             let obj = cleanup(payload);
407             data.p = ManuallyDrop::new(obj);
408         }
409     }
410 }
411
412 /// Determines whether the current thread is unwinding because of panic.
413 #[inline]
414 pub fn panicking() -> bool {
415     !panic_count::is_zero()
416 }
417
418 /// The entry point for panicking with a formatted message.
419 ///
420 /// This is designed to reduce the amount of code required at the call
421 /// site as much as possible (so that `panic!()` has as low an impact
422 /// on (e.g.) the inlining of other functions as possible), by moving
423 /// the actual formatting into this shared place.
424 #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")]
425 #[cold]
426 // If panic_immediate_abort, inline the abort call,
427 // otherwise avoid inlining because of it is cold path.
428 #[cfg_attr(not(feature = "panic_immediate_abort"), track_caller)]
429 #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
430 #[cfg_attr(feature = "panic_immediate_abort", inline)]
431 pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! {
432     if cfg!(feature = "panic_immediate_abort") {
433         intrinsics::abort()
434     }
435
436     let info = PanicInfo::internal_constructor(Some(msg), Location::caller());
437     begin_panic_handler(&info)
438 }
439
440 /// Entry point of panics from the libcore crate (`panic_impl` lang item).
441 #[cfg_attr(not(test), panic_handler)]
442 #[unwind(allowed)]
443 pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
444     struct PanicPayload<'a> {
445         inner: &'a fmt::Arguments<'a>,
446         string: Option<String>,
447     }
448
449     impl<'a> PanicPayload<'a> {
450         fn new(inner: &'a fmt::Arguments<'a>) -> PanicPayload<'a> {
451             PanicPayload { inner, string: None }
452         }
453
454         fn fill(&mut self) -> &mut String {
455             use crate::fmt::Write;
456
457             let inner = self.inner;
458             // Lazily, the first time this gets called, run the actual string formatting.
459             self.string.get_or_insert_with(|| {
460                 let mut s = String::new();
461                 drop(s.write_fmt(*inner));
462                 s
463             })
464         }
465     }
466
467     unsafe impl<'a> BoxMeUp for PanicPayload<'a> {
468         fn take_box(&mut self) -> *mut (dyn Any + Send) {
469             // We do two allocations here, unfortunately. But (a) they're required with the current
470             // scheme, and (b) we don't handle panic + OOM properly anyway (see comment in
471             // begin_panic below).
472             let contents = mem::take(self.fill());
473             Box::into_raw(Box::new(contents))
474         }
475
476         fn get(&mut self) -> &(dyn Any + Send) {
477             self.fill()
478         }
479     }
480
481     struct StrPanicPayload(&'static str);
482
483     unsafe impl BoxMeUp for StrPanicPayload {
484         fn take_box(&mut self) -> *mut (dyn Any + Send) {
485             Box::into_raw(Box::new(self.0))
486         }
487
488         fn get(&mut self) -> &(dyn Any + Send) {
489             &self.0
490         }
491     }
492
493     let loc = info.location().unwrap(); // The current implementation always returns Some
494     let msg = info.message().unwrap(); // The current implementation always returns Some
495     crate::sys_common::backtrace::__rust_end_short_backtrace(move || {
496         if let Some(msg) = msg.as_str() {
497             rust_panic_with_hook(&mut StrPanicPayload(msg), info.message(), loc);
498         } else {
499             rust_panic_with_hook(&mut PanicPayload::new(msg), info.message(), loc);
500         }
501     })
502 }
503
504 /// This is the entry point of panicking for the non-format-string variants of
505 /// panic!() and assert!(). In particular, this is the only entry point that supports
506 /// arbitrary payloads, not just format strings.
507 #[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")]
508 #[cfg_attr(not(test), lang = "begin_panic")]
509 // lang item for CTFE panic support
510 // never inline unless panic_immediate_abort to avoid code
511 // bloat at the call sites as much as possible
512 #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
513 #[cold]
514 #[track_caller]
515 pub fn begin_panic<M: Any + Send>(msg: M) -> ! {
516     if cfg!(feature = "panic_immediate_abort") {
517         intrinsics::abort()
518     }
519
520     let loc = Location::caller();
521     return crate::sys_common::backtrace::__rust_end_short_backtrace(move || {
522         rust_panic_with_hook(&mut PanicPayload::new(msg), None, loc)
523     });
524
525     struct PanicPayload<A> {
526         inner: Option<A>,
527     }
528
529     impl<A: Send + 'static> PanicPayload<A> {
530         fn new(inner: A) -> PanicPayload<A> {
531             PanicPayload { inner: Some(inner) }
532         }
533     }
534
535     unsafe impl<A: Send + 'static> BoxMeUp for PanicPayload<A> {
536         fn take_box(&mut self) -> *mut (dyn Any + Send) {
537             // Note that this should be the only allocation performed in this code path. Currently
538             // this means that panic!() on OOM will invoke this code path, but then again we're not
539             // really ready for panic on OOM anyway. If we do start doing this, then we should
540             // propagate this allocation to be performed in the parent of this thread instead of the
541             // thread that's panicking.
542             let data = match self.inner.take() {
543                 Some(a) => Box::new(a) as Box<dyn Any + Send>,
544                 None => process::abort(),
545             };
546             Box::into_raw(data)
547         }
548
549         fn get(&mut self) -> &(dyn Any + Send) {
550             match self.inner {
551                 Some(ref a) => a,
552                 None => process::abort(),
553             }
554         }
555     }
556 }
557
558 /// Central point for dispatching panics.
559 ///
560 /// Executes the primary logic for a panic, including checking for recursive
561 /// panics, panic hooks, and finally dispatching to the panic runtime to either
562 /// abort or unwind.
563 fn rust_panic_with_hook(
564     payload: &mut dyn BoxMeUp,
565     message: Option<&fmt::Arguments<'_>>,
566     location: &Location<'_>,
567 ) -> ! {
568     let panics = panic_count::increase();
569
570     // If this is the third nested call (e.g., panics == 2, this is 0-indexed),
571     // the panic hook probably triggered the last panic, otherwise the
572     // double-panic check would have aborted the process. In this case abort the
573     // process real quickly as we don't want to try calling it again as it'll
574     // probably just panic again.
575     if panics > 2 {
576         util::dumb_print(format_args!("thread panicked while processing panic. aborting.\n"));
577         intrinsics::abort()
578     }
579
580     unsafe {
581         let mut info = PanicInfo::internal_constructor(message, location);
582         HOOK_LOCK.read();
583         match HOOK {
584             // Some platforms (like wasm) know that printing to stderr won't ever actually
585             // print anything, and if that's the case we can skip the default
586             // hook. Since string formatting happens lazily when calling `payload`
587             // methods, this means we avoid formatting the string at all!
588             // (The panic runtime might still call `payload.take_box()` though and trigger
589             // formatting.)
590             Hook::Default if panic_output().is_none() => {}
591             Hook::Default => {
592                 info.set_payload(payload.get());
593                 default_hook(&info);
594             }
595             Hook::Custom(ptr) => {
596                 info.set_payload(payload.get());
597                 (*ptr)(&info);
598             }
599         };
600         HOOK_LOCK.read_unlock();
601     }
602
603     if panics > 1 {
604         // If a thread panics while it's already unwinding then we
605         // have limited options. Currently our preference is to
606         // just abort. In the future we may consider resuming
607         // unwinding or otherwise exiting the thread cleanly.
608         util::dumb_print(format_args!("thread panicked while panicking. aborting.\n"));
609         intrinsics::abort()
610     }
611
612     rust_panic(payload)
613 }
614
615 /// This is the entry point for `resume_unwind`.
616 /// It just forwards the payload to the panic runtime.
617 pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
618     panic_count::increase();
619
620     struct RewrapBox(Box<dyn Any + Send>);
621
622     unsafe impl BoxMeUp for RewrapBox {
623         fn take_box(&mut self) -> *mut (dyn Any + Send) {
624             Box::into_raw(mem::replace(&mut self.0, Box::new(())))
625         }
626
627         fn get(&mut self) -> &(dyn Any + Send) {
628             &*self.0
629         }
630     }
631
632     rust_panic(&mut RewrapBox(payload))
633 }
634
635 /// An unmangled function (through `rustc_std_internal_symbol`) on which to slap
636 /// yer breakpoints.
637 #[inline(never)]
638 #[cfg_attr(not(test), rustc_std_internal_symbol)]
639 fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! {
640     let code = unsafe {
641         let obj = &mut msg as *mut &mut dyn BoxMeUp;
642         __rust_start_panic(obj as usize)
643     };
644     rtabort!("failed to initiate panic, error {}", code)
645 }