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 #ifndef _LIBUNWINDSTACK_UNWINDERCOMPONENTCREATOR_H 18 #define _LIBUNWINDSTACK_UNWINDERCOMPONENTCREATOR_H 19 20 #include <elf.h> 21 #include <sys/mman.h> 22 23 #include <memory> 24 #include <string> 25 #include <vector> 26 27 #include <fuzzer/FuzzedDataProvider.h> 28 #include <unwindstack/DexFiles.h> 29 #include <unwindstack/Maps.h> 30 #include <unwindstack/Regs.h> 31 #include <unwindstack/RegsArm.h> 32 #include <unwindstack/RegsArm64.h> 33 #include <unwindstack/RegsMips.h> 34 #include <unwindstack/RegsMips64.h> 35 #include <unwindstack/RegsX86.h> 36 #include <unwindstack/RegsX86_64.h> 37 38 #include "../ElfFake.h" 39 #include "../MemoryFake.h" 40 41 #include "fuzzer/FuzzedDataProvider.h" 42 43 using unwindstack::ArchEnum; 44 using unwindstack::DexFiles; 45 using unwindstack::Elf; 46 using unwindstack::ElfFake; 47 using unwindstack::ElfInterfaceFake; 48 using unwindstack::FunctionData; 49 using unwindstack::Maps; 50 using unwindstack::Memory; 51 using unwindstack::MemoryFake; 52 using unwindstack::Regs; 53 using unwindstack::StepData; 54 55 static constexpr uint8_t kArchCount = 6; 56 57 static constexpr uint8_t kMaxSoNameLen = 150; 58 59 static constexpr uint8_t kMaxFuncNameLen = 50; 60 static constexpr uint8_t kMaxFuncCount = 100; 61 62 static constexpr uint8_t kMaxJitElfFiles = 20; 63 static constexpr uint8_t kJitElfPadding = 32; 64 65 static constexpr uint8_t kMaxStepCount = 100; 66 static constexpr uint8_t kMaxMapEntryCount = 50; 67 static constexpr uint8_t kMaxBuildIdLen = 100; 68 static constexpr uint8_t kMaxMapInfoNameLen = 150; 69 70 std::unique_ptr<unwindstack::Regs> GetRegisters(unwindstack::ArchEnum arch); 71 std::unique_ptr<unwindstack::Maps> GetMaps(FuzzedDataProvider* data_provider); 72 std::vector<std::string> GetStringList(FuzzedDataProvider* data_provider, uint max_str_len, 73 uint max_strings); 74 unwindstack::ArchEnum GetArch(FuzzedDataProvider* data_provider); 75 76 void AddMapInfo(uint64_t start, uint64_t end, uint64_t offset, uint64_t flags, const char* name, 77 Elf* elf = nullptr); 78 void PutElfFilesInMemory(MemoryFake* memory, FuzzedDataProvider* data_provider); 79 80 std::unique_ptr<unwindstack::DexFiles> GetDexFiles(FuzzedDataProvider* data_provider, 81 std::shared_ptr<unwindstack::Memory> memory, 82 uint max_libraries, uint max_library_length, 83 unwindstack::ArchEnum arch); 84 #endif // _LIBUNWINDSTACK_UNWINDERCOMPONENTCREATOR_H 85