• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <elf.h>
20 #include <sys/mman.h>
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include <fuzzer/FuzzedDataProvider.h>
27 #include <unwindstack/DexFiles.h>
28 #include <unwindstack/Maps.h>
29 #include <unwindstack/Regs.h>
30 #include <unwindstack/RegsArm.h>
31 #include <unwindstack/RegsArm64.h>
32 #include <unwindstack/RegsMips.h>
33 #include <unwindstack/RegsMips64.h>
34 #include <unwindstack/RegsX86.h>
35 #include <unwindstack/RegsX86_64.h>
36 
37 #include "../ElfFake.h"
38 #include "utils/MemoryFake.h"
39 
40 #include "fuzzer/FuzzedDataProvider.h"
41 
42 using unwindstack::ArchEnum;
43 using unwindstack::DexFiles;
44 using unwindstack::Elf;
45 using unwindstack::ElfFake;
46 using unwindstack::ElfInterfaceFake;
47 using unwindstack::FunctionData;
48 using unwindstack::Maps;
49 using unwindstack::Memory;
50 using unwindstack::MemoryFake;
51 using unwindstack::Regs;
52 using unwindstack::StepData;
53 
54 static constexpr uint8_t kArchCount = 6;
55 
56 static constexpr uint8_t kMaxSoNameLen = 150;
57 
58 static constexpr uint8_t kMaxFuncNameLen = 50;
59 static constexpr uint8_t kMaxFuncCount = 100;
60 
61 static constexpr uint8_t kMaxJitElfFiles = 20;
62 static constexpr uint8_t kJitElfPadding = 32;
63 
64 static constexpr uint8_t kMaxStepCount = 100;
65 static constexpr uint8_t kMaxMapEntryCount = 50;
66 static constexpr uint8_t kMaxBuildIdLen = 100;
67 static constexpr uint8_t kMaxMapInfoNameLen = 150;
68 
69 std::unique_ptr<unwindstack::Regs> GetRegisters(unwindstack::ArchEnum arch);
70 std::unique_ptr<unwindstack::Maps> GetMaps(FuzzedDataProvider* data_provider);
71 std::vector<std::string> GetStringList(FuzzedDataProvider* data_provider, uint max_str_len,
72                                        uint max_strings);
73 unwindstack::ArchEnum GetArch(FuzzedDataProvider* data_provider);
74 
75 void AddMapInfo(uint64_t start, uint64_t end, uint64_t offset, uint64_t flags, const char* name,
76                 Elf* elf = nullptr);
77 void PutElfFilesInMemory(MemoryFake* memory, FuzzedDataProvider* data_provider);
78 
79 std::unique_ptr<unwindstack::DexFiles> GetDexFiles(FuzzedDataProvider* data_provider,
80                                                    std::shared_ptr<unwindstack::Memory> memory,
81                                                    uint max_libraries, uint max_library_length,
82                                                    unwindstack::ArchEnum arch);
83