This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathExecute.cpp
100 lines (83 loc) · 2.95 KB
/
Execute.cpp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (c) 2017 Trail of Bits, Inc.
*
* 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.
*/
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <cerrno>
#include <csignal>
#include <cstdlib>
#include <ctime>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/ManagedStatic.h>
#include "remill/Arch/Arch.h"
#include "remill/Arch/Name.h"
#include "remill/BC/Util.h"
#include "remill/OS/FileSystem.h"
#include "remill/OS/OS.h"
#include "vmill/BC/Lifter.h"
#include "vmill/BC/Util.h"
#include "vmill/Executor/CodeCache.h"
#include "vmill/Executor/Executor.h"
#include "vmill/Program/AddressSpace.h"
#include "vmill/Program/Snapshot.h"
#include "vmill/Workspace/Workspace.h"
DECLARE_string(arch);
DECLARE_string(os);
DEFINE_uint64(max_num_execs, 1,
"Maximum number of times to execute the program.");
DEFINE_bool(verbose, false, "Enable verbose logging?");
int main(int argc, char **argv) {
std::stringstream ss;
ss << std::endl << std::endl
<< " " << argv[0] << " \\" << std::endl
<< " [--tool TOOL_NAME_OR_PATH] \\" << std::endl
<< " [--workspace WORKSPACE_DIR]" << std::endl
<< " [--runtime RUNTIME_PATH]" << std::endl;
google::InitGoogleLogging(argv[0]);
google::SetUsageMessage(ss.str());
google::ParseCommandLineFlags(&argc, &argv, true);
FLAGS_logtostderr = true;
CHECK(0 < FLAGS_max_num_execs)
<< "Must specific a positive value for `--max_num_execs`.";
auto snapshot = vmill::LoadSnapshotFromFile(vmill::Workspace::SnapshotPath());
// Take the target architecture from the snapshot file.
FLAGS_arch = snapshot->arch();
const auto arch_name = remill::GetArchName(FLAGS_arch);
CHECK(remill::kArchInvalid != arch_name)
<< "Snapshot file corrupted; invalid architecture " << FLAGS_arch;
// Take the target OS from the snapshot file.
FLAGS_os = snapshot->os();
const auto os_name = remill::GetOSName(FLAGS_os);
CHECK(remill::kOSInvalid != os_name)
<< "Snapshot file corrupted; invalid OS " << FLAGS_os;
vmill::Executor executor;
vmill::Workspace::LoadSnapshotIntoExecutor(snapshot, executor);
for (uint64_t i = 0; i < FLAGS_max_num_execs; ++i) {
executor.Run();
}
llvm::llvm_shutdown();
google::ShutDownCommandLineFlags();
google::ShutdownGoogleLogging();
return EXIT_SUCCESS;
}