Skip to content

Commit

Permalink
improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yjhmelody committed Dec 11, 2023
1 parent cdcbd3d commit 81f12af
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
14 changes: 1 addition & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions substrate/primitives/allocator-v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
lol_alloc = { version = "0.4", optional = true }
dlmalloc = { version = "0.2.4", optional = true, features = ["global"] }

sp-io = { path = "../io", default-features = false }
sp-std = { path = "../std", default-features = false }
Expand All @@ -31,7 +31,7 @@ std = [
improved_panic_error_reporting = []

allocator-v1 = [
"dep:lol_alloc",
"dep:dlmalloc",
"sp-io/disable_allocator",
"sp-io/disable_panic_handler",
"sp-io/disable_oom",
Expand Down
3 changes: 3 additions & 0 deletions substrate/primitives/allocator-v1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Spec about runtime allocator

License: Apache-2.0
12 changes: 7 additions & 5 deletions substrate/primitives/allocator-v1/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
// limitations under the License.

use core::alloc::GlobalAlloc;
use lol_alloc::{AssumeSingleThreaded, FreeListAllocator};
use dlmalloc::GlobalDlmalloc;

#[global_allocator]
pub static ALLOCATOR: AssumeSingleThreaded<FreeListAllocator> =
unsafe { AssumeSingleThreaded::new(FreeListAllocator::new()) };
pub static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc;

#[no_mangle]
unsafe fn alloc(size: usize) -> *mut u8 {
Expand Down Expand Up @@ -61,7 +60,6 @@ pub fn panic(info: &core::panic::PanicInfo) -> ! {
}
}


/// A default OOM handler for WASM environment.
#[cfg(all(not(feature = "disable_oom"), enable_alloc_error_handler))]
#[alloc_error_handler]
Expand All @@ -72,7 +70,11 @@ pub fn oom(_layout: core::alloc::Layout) -> ! {
}
#[cfg(not(feature = "improved_panic_error_reporting"))]
{
sp_io::logging::log(sp_core::LogLevel::Error, "runtime", b"Runtime memory exhausted. Aborting");
sp_io::logging::log(
sp_core::LogLevel::Error,
"runtime",
b"Runtime memory exhausted. Aborting",
);
core::arch::wasm32::unreachable();
}
}
4 changes: 2 additions & 2 deletions substrate/primitives/allocator-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! # V1 spec about runtime abi
//! # Spec about runtime allocator
//!
//! Export the `alloc`/`dealloc`/`realloc` primitive functions inside the runtime to host.
//!
//! In runtime crate, must use the following sp-io features:
//! When enable this crate, the following features will be set:
//! - disable_allocator
//! - disable_panic_handler
//! - disable_oom
Expand Down

0 comments on commit 81f12af

Please sign in to comment.