mirror of
https://github.com/reswitched/Mephisto.git
synced 2024-05-11 09:14:54 -04:00
add --initialize-memory option to help catch uninitialized memory errors
This commit is contained in:
parent
5632e77ed4
commit
86e61651db
9
Cpu.cpp
9
Cpu.cpp
|
@ -120,7 +120,14 @@ void Cpu::stop() {
|
|||
bool Cpu::map(gptr addr, guint size) {
|
||||
CHECKED(uc_mem_map(uc, addr, size, UC_PROT_ALL));
|
||||
auto temp = new uint8_t[size];
|
||||
memset(temp, 0, size);
|
||||
if(ctu->initializeMemory) {
|
||||
uint8_t val[] = "badmem!!";
|
||||
for(size_t sz = 0; sz < size; sz++) {
|
||||
temp[sz] = val[sz % sizeof(val)];
|
||||
}
|
||||
} else {
|
||||
memset(temp, 0, size);
|
||||
}
|
||||
writemem(addr, temp, size);
|
||||
delete[] temp;
|
||||
return true;
|
||||
|
|
3
Ctu.h
3
Ctu.h
|
@ -214,7 +214,8 @@ public:
|
|||
gptr loadbase, loadsize;
|
||||
|
||||
bool socketsEnabled;
|
||||
|
||||
bool initializeMemory = false;
|
||||
|
||||
private:
|
||||
ghandle handleId;
|
||||
unordered_map<ghandle, shared_ptr<KObject>> handles;
|
||||
|
|
5
main.cpp
5
main.cpp
|
@ -38,7 +38,7 @@ struct Arg: public option::Arg
|
|||
}
|
||||
};
|
||||
|
||||
enum optionIndex { UNKNOWN, HELP, ENABLE_GDB, PORT, NSO, NRO, KIP, ENABLE_SOCKETS, RELOCATE };
|
||||
enum optionIndex { UNKNOWN, HELP, ENABLE_GDB, PORT, NSO, NRO, KIP, ENABLE_SOCKETS, RELOCATE, INITIALIZE_MEMORY };
|
||||
const option::Descriptor usage[] =
|
||||
{
|
||||
{UNKNOWN, 0, "", "",Arg::None, "USAGE: ctu [options] <load-directory>\n\n"
|
||||
|
@ -51,6 +51,7 @@ const option::Descriptor usage[] =
|
|||
{KIP, 0,"","load-kip",Arg::NonEmpty, " --load-kip \tLoad a KIP without load directory"},
|
||||
{ENABLE_SOCKETS, 0, "b","enable-sockets",Arg::None, " --enable-sockets, -b \tEnable BSD socket passthrough." },
|
||||
{RELOCATE, 0, "r","relocate",Arg::None, " --relocate, -r \tRelocate loaded NRO files" },
|
||||
{INITIALIZE_MEMORY, 0, "m", "initialize-memory", Arg::None, " --initialize-memory, -m \tInitialize memory to help catch uninitialized memory bugs" },
|
||||
{0,0,nullptr,nullptr,nullptr,nullptr}
|
||||
};
|
||||
|
||||
|
@ -172,6 +173,8 @@ int main(int argc, char **argv) {
|
|||
ctu.socketsEnabled = false;
|
||||
}
|
||||
|
||||
ctu.initializeMemory = options[INITIALIZE_MEMORY].count() > 0;
|
||||
|
||||
bool relocate = false;
|
||||
if(options[RELOCATE].count()) {
|
||||
relocate = true;
|
||||
|
|
Loading…
Reference in a new issue