1 /*
2 * Copyright (c) 2022 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 #include "type_headers.h"
17
18 static constexpr int ARGS_POINT_ZERO = 0;
19 static constexpr int ARGS_POINT_ONE = 1;
20 static constexpr int ARGS_POINT_TWO = 2;
21 static constexpr int ARGS_POINT_THREE = 3;
22
Openat2ArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)23 static int Openat2ArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
24 {
25 args[ARGS_POINT_ZERO] = (__u64) startEvent->openat2_args.dfd;
26 args[ARGS_POINT_ONE] = (__u64) startEvent->openat2_args.filename;
27 args[ARGS_POINT_TWO] = (__u64) startEvent->openat2_args.how;
28 args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
29 return 0;
30 }
31
ReadArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)32 static int ReadArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
33 {
34 args[ARGS_POINT_ZERO] = (__u64) startEvent->read_args.fd;
35 args[ARGS_POINT_ONE] = (__u64) startEvent->read_args.buf;
36 args[ARGS_POINT_TWO] = (__u64) startEvent->read_args.count;
37 args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
38 return 0;
39 }
40
WriteArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)41 static int WriteArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
42 {
43 args[ARGS_POINT_ZERO] = (__u64) startEvent->write_args.fd;
44 args[ARGS_POINT_ONE] = (__u64) startEvent->write_args.buf;
45 args[ARGS_POINT_TWO] = (__u64) startEvent->write_args.count;
46 args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
47 return 0;
48 }
49
Pread64ArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)50 static int Pread64ArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
51 {
52 args[ARGS_POINT_ZERO] = (__u64) startEvent->pread64_args.fd;
53 args[ARGS_POINT_ONE] = (__u64) startEvent->pread64_args.buf;
54 args[ARGS_POINT_TWO] = (__u64) startEvent->pread64_args.count;
55 args[ARGS_POINT_THREE] = (__u64) startEvent->pread64_args.pos;
56 return 0;
57 }
58
Pwrite64ArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)59 static int Pwrite64ArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
60 {
61 args[ARGS_POINT_ZERO] = (__u64) startEvent->pwrite64_args.fd;
62 args[ARGS_POINT_ONE] = (__u64) startEvent->pwrite64_args.buf;
63 args[ARGS_POINT_TWO] = (__u64) startEvent->pwrite64_args.count;
64 args[ARGS_POINT_THREE] = (__u64) startEvent->pwrite64_args.pos;
65 return 0;
66 }
67
ReadvArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)68 static int ReadvArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
69 {
70 args[ARGS_POINT_ZERO] = (__u64) startEvent->readv_args.fd;
71 args[ARGS_POINT_ONE] = (__u64) startEvent->readv_args.vec;
72 args[ARGS_POINT_TWO] = (__u64) startEvent->readv_args.vlen;
73 args[ARGS_POINT_THREE] = (__u64) startEvent->readv_args.flags;
74 return 0;
75 }
76
WritevArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)77 static int WritevArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
78 {
79 args[ARGS_POINT_ZERO] = (__u64) startEvent->writev_args.fd;
80 args[ARGS_POINT_ONE] = (__u64) startEvent->writev_args.vec;
81 args[ARGS_POINT_TWO] = (__u64) startEvent->writev_args.vlen;
82 args[ARGS_POINT_THREE] = (__u64) startEvent->writev_args.flags;
83 return 0;
84 }
85
PreadvArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)86 static int PreadvArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
87 {
88 args[ARGS_POINT_ZERO] = (__u64) startEvent->preadv_args.fd;
89 args[ARGS_POINT_ONE] = (__u64) startEvent->preadv_args.vec;
90 args[ARGS_POINT_TWO] = (__u64) startEvent->preadv_args.vlen;
91 args[ARGS_POINT_THREE] = (__u64) startEvent->preadv_args.pos;
92 return 0;
93 }
94
PwritevArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)95 static int PwritevArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
96 {
97 args[ARGS_POINT_ZERO] = (__u64) startEvent->pwritev_args.fd;
98 args[ARGS_POINT_ONE] = (__u64) startEvent->pwritev_args.vec;
99 args[ARGS_POINT_TWO] = (__u64) startEvent->pwritev_args.vlen;
100 args[ARGS_POINT_THREE] = (__u64) startEvent->pwritev_args.pos;
101 return 0;
102 }
103
CloseArgsConverter(__u64 * args,const struct fstrace_start_event_t * startEvent)104 static int CloseArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
105 {
106 args[ARGS_POINT_ZERO] = (__u64) startEvent->close_args.files;
107 args[ARGS_POINT_ONE] = (__u64) startEvent->close_args.fd;
108 args[ARGS_POINT_TWO] = 0xFFFFFFFFFFFFFFFF;
109 args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
110 return 0;
111 }
112
113 using ConverterType = int (*) (__u64*, const struct fstrace_start_event_t *);
114 ConverterType g_argsConverterTable[11] = {
115 nullptr,
116 &Openat2ArgsConverter,
117 &ReadArgsConverter,
118 &WriteArgsConverter,
119 &Pread64ArgsConverter,
120 &Pwrite64ArgsConverter,
121 &ReadvArgsConverter,
122 &WritevArgsConverter,
123 &PreadvArgsConverter,
124 &PwritevArgsConverter,
125 &CloseArgsConverter
126 };
127