• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 //! Test for `no_std` Rust apps.
18 //!
19 //! This test app exists to verify that `no_std` Rust apps build, link, and run
20 //! correctly. It is also used to test various pieces of functionality that
21 //! should still work in a `no_std` environment, such as allocation.
22 
23 #![no_std]
24 #![feature(start)]
25 
26 use core::panic::PanicInfo;
27 use trusty_std::alloc::{FallibleVec, Vec};
28 
29 #[start]
start(_argc: isize, _argv: *const *const u8) -> isize30 fn start(_argc: isize, _argv: *const *const u8) -> isize {
31     Vec::<u8>::try_with_capacity(128).unwrap();
32 
33     let message = b"Hello from no_std Rust!\n";
34     unsafe {
35         libc::write(libc::STDOUT_FILENO, message.as_ptr().cast(), message.len());
36     }
37 
38     0
39 }
40 
41 #[panic_handler]
panic(_panic: &PanicInfo<'_>) -> !42 fn panic(_panic: &PanicInfo<'_>) -> ! {
43     // TODO: This should be `libc::abort`, however `abort` isn't defined in libc
44     // when building for Trusty. This should be updated once `abort` is added.
45     loop {}
46 }
47