Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(rust): Support new alloc panic handling (#2582)" #2590

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
294 changes: 146 additions & 148 deletions Cargo.lock

Large diffs are not rendered by default.

212 changes: 106 additions & 106 deletions Cargo.toml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/binaries/async-tester/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Decode, Encode};

Expand Down
1 change: 1 addition & 0 deletions examples/binaries/exit-handle-sender/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode};
Expand Down
1 change: 1 addition & 0 deletions examples/binaries/exit-handle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
Expand Down
1 change: 1 addition & 0 deletions examples/binaries/exit-init/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
Expand Down
1 change: 1 addition & 0 deletions examples/binaries/gas-burned/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
Expand Down
1 change: 1 addition & 0 deletions examples/binaries/init-fail-sender/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
Expand Down
1 change: 1 addition & 0 deletions examples/binaries/init-wait-reply-exit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
Expand Down
1 change: 1 addition & 0 deletions examples/binaries/init-wait/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
Expand Down
1 change: 1 addition & 0 deletions examples/binaries/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
7 changes: 7 additions & 0 deletions examples/ping/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_std]
#![feature(alloc_error_handler)]

#[cfg(target_arch = "wasm32")]
extern crate galloc;
Expand All @@ -19,6 +20,12 @@ extern "C" fn handle() {
}
}

#[cfg(target_arch = "wasm32")]
#[alloc_error_handler]
pub fn oom(_: core::alloc::Layout) -> ! {
core::arch::wasm32::unreachable()
}

#[cfg(target_arch = "wasm32")]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
Expand Down
1 change: 1 addition & 0 deletions gcli/res/messager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]
#![cfg_attr(not(feature = "std"), feature(const_btree_new))]
#![cfg_attr(not(feature = "std"), no_std)]

Expand Down
7 changes: 7 additions & 0 deletions gcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
//!
//! ```
//! #![no_std]
//! #![feature(alloc_error_handler)]
//!
//! extern crate galloc;
//!
Expand All @@ -48,6 +49,12 @@
//! }
//!
//! # #[cfg(target = "wasm32")]
//! #[alloc_error_handler]
//! pub fn oom(_: core::alloc::Layout) -> ! {
//! core::arch::wasm32::unreachable()
//! }
//!
//! # #[cfg(target = "wasm32")]
//! #[panic_handler]
//! fn panic(_: &core::panic::PanicInfo) -> ! {
//! core::arch::wasm32::unreachable()
Expand Down
8 changes: 7 additions & 1 deletion gcore/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ pub mod ext {
///
/// ```rust,ignore
/// #![no_std]
/// #![feature(alloc_error_handler)]
/// #![feature(allocator_api)]
///
/// extern crate alloc;
///
/// use alloc::alloc::{Global, Allocator};
/// use alloc::alloc::{Global, Layout, Allocator};
/// use gcore::ext;
///
/// #[alloc_error_handler]
/// fn oom(_layout: Layout) -> ! {
/// ext::oom_panic()
/// }
///
/// #[no_mangle]
/// extern "C" fn handle() {
/// let layout = Layout::new::<[u8; 64 * 1024]>();
Expand Down
30 changes: 8 additions & 22 deletions gstd/src/common/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,19 @@
//! For `debug` mode it provides more extensive logging.

#[cfg(target_arch = "wasm32")]
use {crate::ext, alloc::alloc::AllocErrorPanicPayload, core::panic::PanicInfo};
use {crate::ext, core::alloc::Layout, core::panic::PanicInfo};

#[cfg(target_arch = "wasm32")]
#[alloc_error_handler]
pub fn oom(_: Layout) -> ! {
ext::oom_panic()
}

#[cfg(not(feature = "debug"))]
#[cfg(not(debug_assertions))]
#[cfg(target_arch = "wasm32")]
#[panic_handler]
pub fn panic(panic_info: &PanicInfo) -> ! {
// Alloc error handling through panic message.
if panic_info
.payload()
.downcast_ref::<AllocErrorPanicPayload>()
.is_some()
{
ext::oom_panic()
}

// Common panic handling.
pub fn panic(_: &PanicInfo) -> ! {
ext::panic("no info")
}

Expand All @@ -52,16 +48,6 @@ pub fn panic(panic_info: &PanicInfo) -> ! {
pub fn panic(panic_info: &PanicInfo) -> ! {
use crate::prelude::format;

// Alloc error handling through panic message.
if panic_info
.payload()
.downcast_ref::<AllocErrorPanicPayload>()
.is_some()
{
ext::oom_panic()
}

// Common panic handling.
let msg = match (panic_info.message(), panic_info.location()) {
(Some(msg), Some(loc)) => format!(
"'{:?}', {}:{}:{}",
Expand Down
3 changes: 1 addition & 2 deletions gstd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@
all(target_arch = "wasm32", any(feature = "debug", debug_assertions)),
feature(panic_info_message)
)]
#![cfg_attr(target_arch = "wasm32", feature(panic_oom_payload))]
#![cfg_attr(target_arch = "wasm32", feature(alloc_error_handler))]
#![cfg_attr(feature = "strict", deny(warnings))]
#![doc(html_logo_url = "https://docs.gear.rs/logo.svg")]

extern crate alloc;
#[cfg(target_arch = "wasm32")]
extern crate galloc;

Expand Down
2 changes: 2 additions & 0 deletions gstd/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
//! The `gstd` default prelude. Re-imports default `std` modules and traits.
//! `std` can be safely replaced to `gstd` in the Rust programs.

extern crate alloc;

pub use core::prelude::v1::*;

// Public module re-exports
Expand Down