summaryrefslogtreecommitdiff
path: root/libunwindstack/tests/fuzz/UnwinderComponentCreator.h
blob: 392219f26288727031b8c6beb074ca64e5e0c573 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _LIBUNWINDSTACK_UNWINDERCOMPONENTCREATOR_H
#define _LIBUNWINDSTACK_UNWINDERCOMPONENTCREATOR_H

#include <elf.h>
#include <sys/mman.h>

#include <memory>
#include <string>
#include <vector>

#include <fuzzer/FuzzedDataProvider.h>
#include <unwindstack/DexFiles.h>
#include <unwindstack/Maps.h>
#include <unwindstack/Regs.h>
#include <unwindstack/RegsArm.h>
#include <unwindstack/RegsArm64.h>
#include <unwindstack/RegsMips.h>
#include <unwindstack/RegsMips64.h>
#include <unwindstack/RegsX86.h>
#include <unwindstack/RegsX86_64.h>

#include "../ElfFake.h"
#include "utils/MemoryFake.h"

#include "fuzzer/FuzzedDataProvider.h"

using unwindstack::ArchEnum;
using unwindstack::DexFiles;
using unwindstack::Elf;
using unwindstack::ElfFake;
using unwindstack::ElfInterfaceFake;
using unwindstack::FunctionData;
using unwindstack::Maps;
using unwindstack::Memory;
using unwindstack::MemoryFake;
using unwindstack::Regs;
using unwindstack::StepData;

static constexpr uint8_t kArchCount = 6;

static constexpr uint8_t kMaxSoNameLen = 150;

static constexpr uint8_t kMaxFuncNameLen = 50;
static constexpr uint8_t kMaxFuncCount = 100;

static constexpr uint8_t kMaxJitElfFiles = 20;
static constexpr uint8_t kJitElfPadding = 32;

static constexpr uint8_t kMaxStepCount = 100;
static constexpr uint8_t kMaxMapEntryCount = 50;
static constexpr uint8_t kMaxBuildIdLen = 100;
static constexpr uint8_t kMaxMapInfoNameLen = 150;

std::unique_ptr<unwindstack::Regs> GetRegisters(unwindstack::ArchEnum arch);
std::unique_ptr<unwindstack::Maps> GetMaps(FuzzedDataProvider* data_provider);
std::vector<std::string> GetStringList(FuzzedDataProvider* data_provider, uint max_str_len,
                                       uint max_strings);
unwindstack::ArchEnum GetArch(FuzzedDataProvider* data_provider);

void AddMapInfo(uint64_t start, uint64_t end, uint64_t offset, uint64_t flags, const char* name,
                Elf* elf = nullptr);
void PutElfFilesInMemory(MemoryFake* memory, FuzzedDataProvider* data_provider);

std::unique_ptr<unwindstack::DexFiles> GetDexFiles(FuzzedDataProvider* data_provider,
                                                   std::shared_ptr<unwindstack::Memory> memory,
                                                   uint max_libraries, uint max_library_length,
                                                   unwindstack::ArchEnum arch);
#endif  // _LIBUNWINDSTACK_UNWINDERCOMPONENTCREATOR_H