• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #include "tee_file.h"
14 
15 #define TEE_FD_TAG 0xD005B00
tee_open(const char * pathname,int flags,mode_t mode)16 int tee_open(const char* pathname, int flags, mode_t mode)
17 {
18     if (pathname == NULL) {
19         return -1;
20     }
21     int fd = -1;
22     if (mode == 0) {
23         fd = open(pathname, flags);
24     } else {
25         fd = open(pathname, flags, mode);
26     }
27 #ifdef ENABLE_FDSAN_CHECK
28     if (fd >= 0) {
29         fdsan_exchange_owner_tag(fd, 0, TEE_FD_TAG);
30     }
31 #endif
32     return fd;
33 }
34 
tee_close(int * fd)35 void tee_close(int *fd)
36 {
37     if (fd == NULL || *fd < 0) {
38         return;
39     }
40 #ifdef ENABLE_FDSAN_CHECK
41     fdsan_close_with_tag(*fd, TEE_FD_TAG);
42 #else
43     close(*fd);
44 #endif
45     *fd = -1;
46     return;
47 }
48 
49