optee_utee_sys/
user_ta_header.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
18use super::tee_api_types::*;
19use super::utee_syscalls::*;
20use super::utee_types::*;
21use core::ffi::*;
22
23pub const TA_FLAG_SINGLE_INSTANCE: u32 = 1 << 2;
24pub const TA_FLAG_MULTI_SESSION: u32 = 1 << 3;
25pub const TA_FLAG_INSTANCE_KEEP_ALIVE: u32 = 1 << 4;
26pub const TA_FLAG_SECURE_DATA_PATH: u32 = 1 << 5;
27pub const TA_FLAG_REMAP_SUPPORT: u32 = 1 << 6;
28pub const TA_FLAG_CACHE_MAINTENANCE: u32 = 1 << 7;
29pub const TA_FLAG_CONCURRENT: u32 = 1 << 8;
30pub const TA_FLAG_DEVICE_ENUM: u32 = 1 << 9;
31pub const TA_FLAG_DEVICE_ENUM_SUPP: u32 = 1 << 10;
32pub const TA_FLAG_DONT_CLOSE_HANDLE_ON_CORRUPT_OBJECT: u32 = 1 << 11;
33pub const TA_FLAG_DEVICE_ENUM_TEE_STORAGE_PRIVATE: u32 = 1 << 12;
34pub const TA_FLAG_INSTANCE_KEEP_CRASHED: u32 = 1 << 13;
35
36pub const TA_FLAG_EXEC_DDR: u32 = 0;
37pub const TA_FLAG_USER_MODE: u32 = 0;
38#[repr(C)]
39pub struct ta_head {
40    pub uuid: TEE_UUID,
41    pub stack_size: u32,
42    pub flags: u32,
43    pub depr_entry: u64,
44}
45
46unsafe extern "C" {
47    pub fn __utee_entry(
48        func: c_ulong,
49        session_id: c_ulong,
50        up: *mut utee_params,
51        cmd_id: c_ulong,
52    ) -> TEE_Result;
53}
54
55/// # Safety
56/// This function is the main entry point for a Trusted Application (TA) in OP-TEE.
57/// It must only be called by the OP-TEE OS with valid parameters. The `up` parameter
58/// is a raw pointer that must point to a valid `utee_params` structure initialized
59/// by the OP-TEE runtime environment. This function should never be called directly
60/// from user code - it is only exported for the OP-TEE OS loader.
61#[unsafe(no_mangle)]
62unsafe fn __ta_entry(
63    func: c_ulong,
64    session_id: c_ulong,
65    up: *mut utee_params,
66    cmd_id: c_ulong,
67) -> ! {
68    let res: u32 = unsafe { __utee_entry(func, session_id, up, cmd_id) };
69
70    unsafe { _utee_return(res.into()) };
71}
72
73unsafe impl Sync for ta_head {}
74
75pub const TA_PROP_STR_SINGLE_INSTANCE: *const c_char = c"gpd.ta.singleInstance".as_ptr();
76pub const TA_PROP_STR_MULTI_SESSION: *const c_char = c"gpd.ta.multiSession".as_ptr();
77pub const TA_PROP_STR_KEEP_ALIVE: *const c_char = c"gpd.ta.instanceKeepAlive".as_ptr();
78pub const TA_PROP_STR_KEEP_CRASHED: *const c_char = c"gpd.ta.instanceKeepCrashed".as_ptr();
79pub const TA_PROP_STR_DATA_SIZE: *const c_char = c"gpd.ta.dataSize".as_ptr();
80pub const TA_PROP_STR_STACK_SIZE: *const c_char = c"gpd.ta.stackSize".as_ptr();
81pub const TA_PROP_STR_VERSION: *const c_char = c"gpd.ta.version".as_ptr();
82pub const TA_PROP_STR_DESCRIPTION: *const c_char = c"gpd.ta.description".as_ptr();
83pub const TA_PROP_STR_ENDIAN: *const c_char = c"gpd.ta.endian".as_ptr();
84pub const TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT: *const c_char =
85    c"gpd.ta.doesNotCloseHandleOnCorruptObject".as_ptr();
86
87#[repr(C)]
88pub enum user_ta_prop_type {
89    USER_TA_PROP_TYPE_BOOL,
90    USER_TA_PROP_TYPE_U32,
91    USER_TA_PROP_TYPE_UUID,
92    USER_TA_PROP_TYPE_IDENTITY,
93    USER_TA_PROP_TYPE_STRING,
94    USER_TA_PROP_TYPE_BINARY_BLOCK,
95    USER_TA_PROP_TYPE_U64,
96    USER_TA_PROP_TYPE_INVALID,
97}
98
99#[repr(C)]
100pub struct user_ta_property {
101    pub name: *const c_char,
102    pub prop_type: user_ta_prop_type,
103    pub value: *const c_void,
104}
105
106unsafe impl Sync for user_ta_property {}