Skip to main content

optee_utee/
lib.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#![cfg_attr(not(feature = "std"), no_std)]
19#![cfg_attr(doc, doc = concat!(
20    env!("CARGO_PKG_DESCRIPTION"),
21    "\n",
22    "## Feature flags\n",
23    document_features::document_features!(),
24))]
25
26// Requires `alloc`.
27#[macro_use]
28extern crate alloc;
29
30#[cfg(not(feature = "std"))]
31use libc_alloc::LibcAlloc;
32
33#[cfg(not(feature = "std"))]
34#[global_allocator]
35static ALLOCATOR: LibcAlloc = LibcAlloc;
36
37#[cfg(all(not(feature = "std"), not(feature = "no_panic_handler")))]
38#[panic_handler]
39fn panic(_info: &core::panic::PanicInfo) -> ! {
40    unsafe {
41        optee_utee_sys::TEE_Panic(0);
42    }
43    loop {}
44}
45
46// Stubs for unwinding symbols required by the precompiled sysroot when not using
47// `-Z build-std`. These are never actually called because we compile with
48// `-C panic=abort`, but the linker requires the symbols to be present.
49#[cfg(all(not(feature = "std"), feature = "unwind_stubs"))]
50mod unwind_stubs {
51    #[unsafe(no_mangle)]
52    extern "C" fn _Unwind_Resume() -> ! {
53        loop {}
54    }
55
56    #[unsafe(no_mangle)]
57    extern "C" fn rust_eh_personality() {}
58}
59
60pub use arithmetical::*;
61pub use crypto_op::*;
62pub use error::{Error, ErrorKind, Result};
63pub(crate) use error::{tee_check, tee_check_with_origin};
64pub use extension::*;
65pub use identity::{Identity, LoginType};
66pub use object::*;
67pub use optee_utee_macros::{
68    ta_close_session, ta_create, ta_destroy, ta_invoke_command, ta_open_session,
69};
70pub use parameter::{
71    FromRawParameter, FromRawParameters, ParamType, ParameterAny, ParametersAny, ParametersNone,
72    RawParamType, RawParamTypes, RawParams, deprecated,
73    memref::{
74        ParameterMemref, ParameterMemrefInout, ParameterMemrefInput, ParameterMemrefOutput,
75        ParameterMemrefRead, ParameterMemrefWrite,
76    },
77    none::ParameterNone,
78    value::{
79        ParameterValueInout, ParameterValueInput, ParameterValueOutput, ParameterValueRead,
80        ParameterValueWrite,
81    },
82};
83pub use ta_session::{TaSession, TaSessionBuilder};
84pub use tee_parameter::{ParamIndex, TeeParams};
85pub use time::*;
86pub use uuid::*;
87
88pub mod trace;
89#[macro_use]
90mod macros;
91pub mod arithmetical;
92pub mod crypto_op;
93mod error;
94pub mod extension;
95pub mod identity;
96pub mod net;
97pub mod object;
98mod parameter;
99pub mod property;
100mod ta_session;
101mod tee_parameter;
102pub mod time;
103pub mod uuid;
104
105// Re-export optee_utee_sys so developers don't have to add it to their cargo
106// dependencies.
107pub use optee_utee_sys as raw;
108
109pub mod prelude {
110    pub use crate::{
111        FromRawParameter, FromRawParameters, ParameterAny, ParameterMemref, ParameterMemrefInout,
112        ParameterMemrefInput, ParameterMemrefOutput, ParameterMemrefRead, ParameterMemrefWrite,
113        ParameterNone, ParameterValueInout, ParameterValueInput, ParameterValueOutput,
114        ParameterValueRead, ParameterValueWrite, ParametersAny, ParametersNone, ta_close_session,
115        ta_create, ta_destroy, ta_invoke_command, ta_open_session, trace_print, trace_println,
116    };
117}