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 #define _GNU_SOURCE
14 #include "drv_param_ops.h"
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <drv_thread.h>
18 #include <tee_log.h>
19 #include <tee_sharemem_ops.h>
20
get_drv_caller_taskid(uint32_t * taskid)21 static int32_t get_drv_caller_taskid(uint32_t *taskid)
22 {
23 tid_t tid;
24 pid_t caller_pid;
25
26 tid = gettid();
27 if (tid < 0) {
28 tloge("get tid failed\n");
29 return -1;
30 }
31
32 int32_t ret = get_callerpid_by_tid(tid, &caller_pid);
33 if (ret != 0) {
34 tloge("get tid:0x%x caller pid failed\n", tid);
35 return -1;
36 }
37
38 *taskid = (uint32_t)caller_pid;
39 return 0;
40 }
41
copy_from_client(uint64_t src,uint32_t src_size,uintptr_t dst,uint32_t dst_size)42 int32_t copy_from_client(uint64_t src, uint32_t src_size, uintptr_t dst, uint32_t dst_size)
43 {
44 uint32_t taskid;
45 int32_t ret = get_drv_caller_taskid(&taskid);
46 if (ret != 0)
47 return -1;
48
49 /* Parameters are checked in copy_from_sharemem */
50 ret = copy_from_sharemem(taskid, src, src_size, dst, dst_size);
51 if (ret != 0) {
52 tloge("copy from task:0x%x failed\n", taskid);
53 return -1;
54 }
55
56 return 0;
57 }
58
copy_to_client(uintptr_t src,uint32_t src_size,uint64_t dst,uint32_t dst_size)59 int32_t copy_to_client(uintptr_t src, uint32_t src_size, uint64_t dst, uint32_t dst_size)
60 {
61 uint32_t taskid;
62 int32_t ret = get_drv_caller_taskid(&taskid);
63 if (ret != 0)
64 return -1;
65
66 /* Parameters are checked in copy_to_sharemem */
67 ret = copy_to_sharemem(src, src_size, taskid, dst, dst_size);
68 if (ret != 0) {
69 tloge("copy to task:0x%x failed\n", taskid);
70 return -1;
71 }
72
73 return 0;
74 }
75