• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
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 
16 /**
17  * @addtogroup TeeTrusted
18  * @{
19  *
20  * @brief TEE(Trusted Excution Environment) API.
21  * Provides security capability APIs such as trusted storage, encryption and decryption,
22  * and trusted time for trusted application development.
23  *
24  * @since 20
25  */
26 
27 /**
28  * @file tee_sharemem_ops.h
29  *
30  * @brief Provides  APIs for developers to apply for shared memory.
31  *
32  * @library NA
33  * @kit TEEKit
34  * @syscap SystemCapability.Tee.TeeClient
35  * @since 20
36  */
37 
38 #ifndef TEE_SHAREMEM_OPS_H
39 #define TEE_SHAREMEM_OPS_H
40 
41 #include <stdint.h>
42 #include <tee_defines.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * @brief Alloc shared memory in TEE.
50  *
51  * @param uuid Indicates the UUID of TA.
52  * @param size Indicates the size of the requested shared memory.
53  *
54  * @return Returns a pointer to the newly allocated space if the operation is successful.
55  *         Returns a <b>NULL</b> pointer if the allocation fails.
56  *
57  * @since 20
58  */
59 void *tee_alloc_sharemem_aux(const struct tee_uuid *uuid, uint32_t size);
60 
61 /**
62  * @brief Alloc continuous shared memory in TEE.
63  *
64  * @param uuid Indicates the UUID of TA.
65  * @param size Indicates the size of the requested shared memory.
66  *
67  * @return Returns a pointer to the newly allocated space if the operation is successful.
68  *         Returns a <b>NULL</b> pointer if the allocation fails.
69  *
70  * @since 20
71  */
72 void *tee_alloc_coherent_sharemem_aux(const struct tee_uuid *uuid, uint32_t size);
73 
74 /**
75  * @brief Free the shared memory in TEE.
76  *
77  * @param addr Indicates the shared memory address that will be freed.
78  * @param size Indicates the size of the shared memory.
79  *
80  * @return Returns <b>0</b> if the operation is successful.
81  *         Returns others if the operation is failed.
82  *
83  * @since 20
84  */
85 uint32_t tee_free_sharemem(void *addr, uint32_t size);
86 
87 /**
88  * @brief Copy shared memory from source task.
89  *
90  * @param src_task Indicates the pid of the source task.
91  * @param src Indicates the address of the source buffer.
92  * @param src_size Indicates the size of the source buffer.
93  * @param dst Indicates the address of the destination buffer.
94  * @param dst_size Indicates the size of the destination buffer.
95  *
96  * @return Returns <b>0</b> if the operation is successful.
97  *         Returns <b>-1</b> if the operation is failed.
98  *
99  * @since 20
100  */
101 int32_t copy_from_sharemem(uint32_t src_task, uint64_t src, uint32_t src_size, uintptr_t dst, uint32_t dst_size);
102 
103 /**
104  * @brief Copy shared memory to destination task.
105  *
106  * @param src Indicates the address of the source buffer.
107  * @param src_size Indicates the size of the source buffer.
108  * @param dst_task Indicates the pid of the destination task.
109  * @param dst Indicates the address of the destination buffer.
110  * @param dst_size Indicates the size of the destination buffer.
111  *
112  * @return Returns <b>0</b> if the operation is successful.
113  *         Returns <b>-1</b> if the operation is failed.
114  *
115  * @since 20
116  */
117 int32_t copy_to_sharemem(uintptr_t src, uint32_t src_size, uint32_t dst_task, uint64_t dst, uint32_t dst_size);
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif
123 /** @} */