library: Compute Rust exception class from its string repr · qinheping/verify-rust-std@085baa2 (original) (raw)

Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ struct Exception {
61 61 pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
62 62 let exception = Box::new(Exception {
63 63 _uwe: uw::_Unwind_Exception {
64 -exception_class: rust_exception_class(),
64 +exception_class: RUST_EXCEPTION_CLASS,
65 65 exception_cleanup: Some(exception_cleanup),
66 66 private: [core::ptr::null(); uw::unwinder_private_data_size],
67 67 },
@@ -84,7 +84,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
84 84
85 85 pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
86 86 let exception = ptr as *mut uw::_Unwind_Exception;
87 -if (*exception).exception_class != rust_exception_class() {
87 +if (*exception).exception_class != RUST_EXCEPTION_CLASS {
88 88 uw::_Unwind_DeleteException(exception);
89 89 super::__rust_foreign_exception();
90 90 }
@@ -107,7 +107,4 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
107 107
108 108 // Rust's exception class identifier. This is used by personality routines to
109 109 // determine whether the exception was thrown by their own runtime.
110 -fn rust_exception_class() -> uw::_Unwind_Exception_Class {
111 -// M O Z \0 R U S T -- vendor, language
112 -0x4d4f5a_00_52555354
113 -}
110 +const RUST_EXCEPTION_CLASS: uw::_Unwind_Exception_Class = u64::from_be_bytes(*b"MOZ\0RUST");