1800b99b8Sopenharmony_ci/*
2800b99b8Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License.
5800b99b8Sopenharmony_ci * You may obtain a copy of the License at
6800b99b8Sopenharmony_ci *
7800b99b8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8800b99b8Sopenharmony_ci *
9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and
13800b99b8Sopenharmony_ci * limitations under the License.
14800b99b8Sopenharmony_ci */
15800b99b8Sopenharmony_ci#ifndef DFX_ELF_DEFINE_H
16800b99b8Sopenharmony_ci#define DFX_ELF_DEFINE_H
17800b99b8Sopenharmony_ci
18800b99b8Sopenharmony_ci#include <cinttypes>
19800b99b8Sopenharmony_ci#include <string>
20800b99b8Sopenharmony_ci#if !is_mingw
21800b99b8Sopenharmony_ci#include <elf.h>
22800b99b8Sopenharmony_ci#include <link.h>
23800b99b8Sopenharmony_ci#endif
24800b99b8Sopenharmony_ci
25800b99b8Sopenharmony_cinamespace OHOS {
26800b99b8Sopenharmony_cinamespace HiviewDFX {
27800b99b8Sopenharmony_cistatic const std::string NOTE_GNU_BUILD_ID = ".note.gnu.build-id";
28800b99b8Sopenharmony_cistatic const std::string NOTES = ".notes";
29800b99b8Sopenharmony_cistatic const std::string GNU_DEBUGDATA = ".gnu_debugdata";
30800b99b8Sopenharmony_cistatic const std::string EH_FRAME_HDR = ".eh_frame_hdr";
31800b99b8Sopenharmony_cistatic const std::string EH_FRAME = ".eh_frame";
32800b99b8Sopenharmony_cistatic const std::string ARM_EXIDX = ".ARM.exidx";
33800b99b8Sopenharmony_cistatic const std::string ARM_EXTAB = ".ARM.extab";
34800b99b8Sopenharmony_cistatic const std::string SHSTRTAB = ".shstrtab";
35800b99b8Sopenharmony_cistatic const std::string STRTAB = ".strtab";
36800b99b8Sopenharmony_cistatic const std::string SYMTAB = ".symtab";
37800b99b8Sopenharmony_cistatic const std::string DYNSYM = ".dynsym";
38800b99b8Sopenharmony_cistatic const std::string DYNSTR = ".dynstr";
39800b99b8Sopenharmony_cistatic const std::string PLT = ".plt";
40800b99b8Sopenharmony_ci
41800b99b8Sopenharmony_cistruct ElfLoadInfo {
42800b99b8Sopenharmony_ci    uint64_t offset = 0;
43800b99b8Sopenharmony_ci    uint64_t tableVaddr = 0;
44800b99b8Sopenharmony_ci    size_t tableSize = 0;
45800b99b8Sopenharmony_ci    uint64_t align = 0;
46800b99b8Sopenharmony_ci    uint64_t mmapLen = 0;
47800b99b8Sopenharmony_ci};
48800b99b8Sopenharmony_ci
49800b99b8Sopenharmony_cistruct ElfSymbol {
50800b99b8Sopenharmony_ci    std::string nameStr = "";
51800b99b8Sopenharmony_ci    uint32_t name = 0;
52800b99b8Sopenharmony_ci    unsigned char info = 0;
53800b99b8Sopenharmony_ci    unsigned char other = 0;
54800b99b8Sopenharmony_ci    uint16_t shndx = 0;
55800b99b8Sopenharmony_ci    uint64_t value = 0;
56800b99b8Sopenharmony_ci    uint64_t size = 0;
57800b99b8Sopenharmony_ci};
58800b99b8Sopenharmony_ci
59800b99b8Sopenharmony_cistruct ElfShdr {
60800b99b8Sopenharmony_ci    uint32_t	name = 0;       // Section name (string tbl index)
61800b99b8Sopenharmony_ci    uint32_t	type = 0;       // Section type
62800b99b8Sopenharmony_ci    uint64_t	flags = 0;      // Section flags
63800b99b8Sopenharmony_ci    uint64_t	addr = 0;       // Section virtual addr at execution
64800b99b8Sopenharmony_ci    uint64_t	offset = 0;     // Section file offset
65800b99b8Sopenharmony_ci    uint64_t	size = 0;       // Section size in bytes
66800b99b8Sopenharmony_ci    uint32_t	link = 0;       // Link to another section
67800b99b8Sopenharmony_ci    uint32_t	info = 0;       // Additional section information
68800b99b8Sopenharmony_ci    uint64_t	addrAlign = 0;  // Section alignment
69800b99b8Sopenharmony_ci    uint64_t	entSize = 0;    // Entry size if section holds table
70800b99b8Sopenharmony_ci};
71800b99b8Sopenharmony_ci
72800b99b8Sopenharmony_cistruct ShdrInfo {
73800b99b8Sopenharmony_ci    uint64_t addr = 0;
74800b99b8Sopenharmony_ci    uint64_t entSize = 0;
75800b99b8Sopenharmony_ci    uint64_t offset = 0;
76800b99b8Sopenharmony_ci    uint64_t size = 0;
77800b99b8Sopenharmony_ci};
78800b99b8Sopenharmony_ci
79800b99b8Sopenharmony_cistruct __attribute__((packed)) DwarfEhFrameHdr {
80800b99b8Sopenharmony_ci    unsigned char version = 0;
81800b99b8Sopenharmony_ci    unsigned char ehFramePtrEnc = 0;
82800b99b8Sopenharmony_ci    unsigned char fdeCountEnc = 0;
83800b99b8Sopenharmony_ci    unsigned char tableEnc = 0;
84800b99b8Sopenharmony_ci    ElfW(Addr) ehFrame;
85800b99b8Sopenharmony_ci};
86800b99b8Sopenharmony_ci
87800b99b8Sopenharmony_cistruct MiniDebugInfo {
88800b99b8Sopenharmony_ci    uint64_t offset = 0;
89800b99b8Sopenharmony_ci    uintptr_t size = 0;
90800b99b8Sopenharmony_ci};
91800b99b8Sopenharmony_ci
92800b99b8Sopenharmony_ci} // namespace HiviewDFX
93800b99b8Sopenharmony_ci} // namespace OHOS
94800b99b8Sopenharmony_ci#endif
95