1 // Copyright 2023, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 //! This is a compilation-only test to ensure that libgbl can build against
16 //! [no_std] code.
17 //!
18 //! This also provides a reference for the Rust hooks that a [no_std] user must
19 //! provide in order to build against libgbl.
20
21 #![no_main]
22 #![no_std]
23
24 // use core::panic::PanicInfo;
25
26 use gbl as _;
27
28 use buddy_system_allocator::LockedHeap;
29
30 // Providing allocator to satisfy AVB dependency
31 #[global_allocator]
32 static HEAP_ALLOCATOR: LockedHeap<32> = LockedHeap::<32>::new();
33
34 static mut HEAP: [u8; 65536] = [0; 65536];
35
36 // #[panic_handler]
37 // fn panic(_: &PanicInfo) -> ! {
38 // loop {}
39 // }
40
41 /// main() entry point replacement required by [no_std].
42 #[no_mangle]
main() -> !43 pub fn main() -> ! {
44 // SAFETY: Safe because `HEAP` is only used here and `entry` is only called once.
45 unsafe {
46 // Give the allocator some memory to allocate.
47 HEAP_ALLOCATOR.lock().init(HEAP.as_mut_ptr() as usize, HEAP.len());
48 }
49
50 panic!()
51 }
52