• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef HIEBPF_COMMON_H
17 #define HIEBPF_COMMON_H
18 
19 #include "hiebpf_macros.h"
20 
21 constexpr int ARGS_ARRAY_SIZE = 4;
22 constexpr int  COMMAND_LINE_MAX = 127;
23 const int MAX_BUFFER_SIZE = 256 * 1024 * 1024;
24 
25 enum ITEM_TYPE {
26     itemEventMaps,
27     itemSymbolInfo,
28     itemEventFs,
29     itemEventMem,
30 };
31 
32 enum CLOCK_TYPE {
33     RealTime,
34     BootTime,
35     Monotonic,
36     MonotonicRaw,
37 };
38 
39 // event type
40 enum EVENT_TYPE {
41     EBPF_OPEN,
42     EBPF_CLOSE,
43     EBPF_READ,
44     EBPF_WRITE,
45 };
46 
47 struct EBPFHead {
48     int type;
49     int size;
50 };
51 
52 struct ArgStr {
53     uint16_t argStrLen;
54     char* argStr;
55 };
56 
57 struct EbpfHeader {
58     static constexpr uint32_t HEADER_SIZE = 1024;
59     static constexpr uint32_t STR_SIZE = 127;
60     struct HeaderData {
61         char magic[8] = {'E', 'B', 'P', 'F', 'F', 'I', 'L', 'E'};
62         uint32_t headSize = 1024;
63         uint32_t version = 0;
64         uint32_t clock = CLOCK_TYPE::BootTime;
65         uint32_t cmdLineLen = 0;
66         char cmdline[COMMAND_LINE_MAX] = { 0 };
67     };
68     HeaderData data_ = {};
69     char padding[HEADER_SIZE - sizeof(data_)] = {};
70 };
71 
72 struct SysOpenArgs {
73     char fileName[];
74 };
75 
76 struct SysCloseArgs {
77     uint64_t fd;
78 };
79 
80 struct SysReadWriteArgs {
81     uint64_t fd;
82     uint64_t size;
83 };
84 
85 struct ItemEventFs {
86     uint32_t tag;
87     uint32_t len;
88     uint32_t pid;
89     uint32_t tid;
90     uint64_t start;
91     uint64_t end;
92     int ret;
93     uint16_t nrUserIPs;
94     uint16_t type;
95     uint64_t args[ARGS_ARRAY_SIZE] = {0};
96     uint64_t* userIPs;
97     uint16_t commLen;
98     char* comm;
99     uint16_t argStrTotalLen;
100 };
101 
102 struct ItemEventMem {
103     uint32_t tag;
104     uint32_t len;
105     uint32_t pid;
106     uint32_t tid;
107     char tagName[MAX_TRACER_NAME_LEN];
108     uint64_t start;
109     uint64_t end;
110     char typeName[MAX_TYPE_NAME_LEN];
111     uint64_t addr;
112     uint32_t size;
113     uint16_t nIPs;
114     uint16_t type;
115     char comm[MAX_COMM_LEN];
116     uint64_t* userIPs;
117 };
118 #endif