Skip to content

Commit

Permalink
Add 84455
Browse files Browse the repository at this point in the history
  • Loading branch information
fanninpm authored and JohnTitor committed Jun 21, 2021
1 parent 8eb1ac7 commit 179c09c
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions ices/84455.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash

cat > Cargo.toml <<'EOF'
[package]
name = "abc"
version = "0.0.1"
edition = "2018"
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
EOF

mkdir -p src

cat > src/lib.rs <<'EOF'
// ice_test
#![no_std]
#![feature(const_fn)]
use core::alloc::{GlobalAlloc, Layout};
pub static DEFAULT_ALLOCATOR: Allocator = Allocator::new(&DEFAULT_HEAP);
static DEFAULT_HEAP: GeneralAllocator = GeneralAllocator::new();
#[derive(Copy, Clone)]
pub struct Allocator {
allocator: &'static (dyn GlobalAlloc + 'static),
}
unsafe impl Sync for Allocator {}
impl Allocator {
const fn new(allocator: &'static dyn GlobalAlloc) -> Self {
Self { allocator }
}
}
unsafe impl GlobalAlloc for Allocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
self.allocator.alloc(layout)
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
self.allocator.dealloc(ptr, layout)
}
}
pub struct GeneralAllocator;
unsafe impl Sync for GeneralAllocator {}
impl GeneralAllocator {
pub const fn new() -> Self {
Self {}
}
}
unsafe impl GlobalAlloc for GeneralAllocator {
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
todo!()
}
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
todo!()
}
}
EOF

cat > src/test.rs <<'EOF'
#![feature(alloc_error_handler)]
#![no_std]
#![no_main]
use ice_test::{Allocator, DEFAULT_ALLOCATOR};
extern crate alloc;
#[global_allocator]
pub static GLOBAL_ALLOCATOR: Allocator = DEFAULT_ALLOCATOR;
#[no_mangle]
fn main() {
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[alloc_error_handler]
fn alloc_error_handler(layout: core::alloc::Layout) -> ! {
panic!(
"Error allocating {} bytes of memory with alignment {}",
layout.size(),
layout.align()
);
}
EOF

cargo test

0 comments on commit 179c09c

Please sign in to comment.