106f6ba60Sopenharmony_ci/*
206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License.
506f6ba60Sopenharmony_ci * You may obtain a copy of the License at
606f6ba60Sopenharmony_ci *
706f6ba60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
806f6ba60Sopenharmony_ci *
906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and
1306f6ba60Sopenharmony_ci * limitations under the License.
1406f6ba60Sopenharmony_ci */
1506f6ba60Sopenharmony_ci
1606f6ba60Sopenharmony_ci#include "type_headers.h"
1706f6ba60Sopenharmony_ci
1806f6ba60Sopenharmony_cistatic constexpr int ARGS_POINT_ZERO = 0;
1906f6ba60Sopenharmony_cistatic constexpr int ARGS_POINT_ONE = 1;
2006f6ba60Sopenharmony_cistatic constexpr int ARGS_POINT_TWO = 2;
2106f6ba60Sopenharmony_cistatic constexpr int ARGS_POINT_THREE = 3;
2206f6ba60Sopenharmony_ci
2306f6ba60Sopenharmony_cistatic int Openat2ArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
2406f6ba60Sopenharmony_ci{
2506f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->openat2_args.dfd;
2606f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->openat2_args.filename;
2706f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = (__u64) startEvent->openat2_args.how;
2806f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
2906f6ba60Sopenharmony_ci    return 0;
3006f6ba60Sopenharmony_ci}
3106f6ba60Sopenharmony_ci
3206f6ba60Sopenharmony_cistatic int ReadArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
3306f6ba60Sopenharmony_ci{
3406f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->read_args.fd;
3506f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->read_args.buf;
3606f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = (__u64) startEvent->read_args.count;
3706f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
3806f6ba60Sopenharmony_ci    return 0;
3906f6ba60Sopenharmony_ci}
4006f6ba60Sopenharmony_ci
4106f6ba60Sopenharmony_cistatic int WriteArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
4206f6ba60Sopenharmony_ci{
4306f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->write_args.fd;
4406f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->write_args.buf;
4506f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = (__u64) startEvent->write_args.count;
4606f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
4706f6ba60Sopenharmony_ci    return 0;
4806f6ba60Sopenharmony_ci}
4906f6ba60Sopenharmony_ci
5006f6ba60Sopenharmony_cistatic int Pread64ArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
5106f6ba60Sopenharmony_ci{
5206f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->pread64_args.fd;
5306f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->pread64_args.buf;
5406f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = (__u64) startEvent->pread64_args.count;
5506f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = (__u64) startEvent->pread64_args.pos;
5606f6ba60Sopenharmony_ci    return 0;
5706f6ba60Sopenharmony_ci}
5806f6ba60Sopenharmony_ci
5906f6ba60Sopenharmony_cistatic int Pwrite64ArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
6006f6ba60Sopenharmony_ci{
6106f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->pwrite64_args.fd;
6206f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->pwrite64_args.buf;
6306f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = (__u64) startEvent->pwrite64_args.count;
6406f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = (__u64) startEvent->pwrite64_args.pos;
6506f6ba60Sopenharmony_ci    return 0;
6606f6ba60Sopenharmony_ci}
6706f6ba60Sopenharmony_ci
6806f6ba60Sopenharmony_cistatic int ReadvArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
6906f6ba60Sopenharmony_ci{
7006f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->readv_args.fd;
7106f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->readv_args.vec;
7206f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = (__u64) startEvent->readv_args.vlen;
7306f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = (__u64) startEvent->readv_args.flags;
7406f6ba60Sopenharmony_ci    return 0;
7506f6ba60Sopenharmony_ci}
7606f6ba60Sopenharmony_ci
7706f6ba60Sopenharmony_cistatic int WritevArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
7806f6ba60Sopenharmony_ci{
7906f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->writev_args.fd;
8006f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->writev_args.vec;
8106f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = (__u64) startEvent->writev_args.vlen;
8206f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = (__u64) startEvent->writev_args.flags;
8306f6ba60Sopenharmony_ci    return 0;
8406f6ba60Sopenharmony_ci}
8506f6ba60Sopenharmony_ci
8606f6ba60Sopenharmony_cistatic int PreadvArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
8706f6ba60Sopenharmony_ci{
8806f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->preadv_args.fd;
8906f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->preadv_args.vec;
9006f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = (__u64) startEvent->preadv_args.vlen;
9106f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = (__u64) startEvent->preadv_args.pos;
9206f6ba60Sopenharmony_ci    return 0;
9306f6ba60Sopenharmony_ci}
9406f6ba60Sopenharmony_ci
9506f6ba60Sopenharmony_cistatic int PwritevArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
9606f6ba60Sopenharmony_ci{
9706f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->pwritev_args.fd;
9806f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->pwritev_args.vec;
9906f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = (__u64) startEvent->pwritev_args.vlen;
10006f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = (__u64) startEvent->pwritev_args.pos;
10106f6ba60Sopenharmony_ci    return 0;
10206f6ba60Sopenharmony_ci}
10306f6ba60Sopenharmony_ci
10406f6ba60Sopenharmony_cistatic int CloseArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
10506f6ba60Sopenharmony_ci{
10606f6ba60Sopenharmony_ci    args[ARGS_POINT_ZERO] = (__u64) startEvent->close_args.files;
10706f6ba60Sopenharmony_ci    args[ARGS_POINT_ONE] = (__u64) startEvent->close_args.fd;
10806f6ba60Sopenharmony_ci    args[ARGS_POINT_TWO] = 0xFFFFFFFFFFFFFFFF;
10906f6ba60Sopenharmony_ci    args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
11006f6ba60Sopenharmony_ci    return 0;
11106f6ba60Sopenharmony_ci}
11206f6ba60Sopenharmony_ci
11306f6ba60Sopenharmony_ciusing ConverterType = int (*) (__u64*, const struct fstrace_start_event_t *);
11406f6ba60Sopenharmony_ciConverterType g_argsConverterTable[11] = {
11506f6ba60Sopenharmony_ci    nullptr,
11606f6ba60Sopenharmony_ci    &Openat2ArgsConverter,
11706f6ba60Sopenharmony_ci    &ReadArgsConverter,
11806f6ba60Sopenharmony_ci    &WriteArgsConverter,
11906f6ba60Sopenharmony_ci    &Pread64ArgsConverter,
12006f6ba60Sopenharmony_ci    &Pwrite64ArgsConverter,
12106f6ba60Sopenharmony_ci    &ReadvArgsConverter,
12206f6ba60Sopenharmony_ci    &WritevArgsConverter,
12306f6ba60Sopenharmony_ci    &PreadvArgsConverter,
12406f6ba60Sopenharmony_ci    &PwritevArgsConverter,
12506f6ba60Sopenharmony_ci    &CloseArgsConverter
12606f6ba60Sopenharmony_ci};
127