Skip to content

Commit

Permalink
A null check and a locking simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 30, 2024
1 parent 0576caf commit fae1f4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
20 changes: 11 additions & 9 deletions Core/ELF/ElfReader.cpp
Expand Up @@ -533,17 +533,19 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
u32 srcSize = p->p_filesz;
u32 dstSize = p->p_memsz;
u8 *dst = Memory::GetPointerWriteRange(writeAddr, dstSize);
if (dst) {
if (srcSize < dstSize) {
memset(dst + srcSize, 0, dstSize - srcSize); //zero out bss
NotifyMemInfo(MemBlockFlags::WRITE, writeAddr + srcSize, dstSize - srcSize, "ELFZero");
}

if (srcSize < dstSize)
{
memset(dst + srcSize, 0, dstSize - srcSize); //zero out bss
NotifyMemInfo(MemBlockFlags::WRITE, writeAddr + srcSize, dstSize - srcSize, "ELFZero");
memcpy(dst, src, srcSize);
std::string tag = StringFromFormat("ELFLoad/%08x", writeAddr);
NotifyMemInfo(MemBlockFlags::WRITE, writeAddr, srcSize, tag.c_str(), tag.size());
DEBUG_LOG(LOADER, "Loadable Segment Copied to %08x, size %08x", writeAddr, (u32)p->p_memsz);
} else {
ERROR_LOG(LOADER, "Bad ELF segment. Trying to write %d bytes to %08x", dstSize, writeAddr);
}

memcpy(dst, src, srcSize);
std::string tag = StringFromFormat("ELFLoad/%08x", writeAddr);
NotifyMemInfo(MemBlockFlags::WRITE, writeAddr, srcSize, tag.c_str(), tag.size());
DEBUG_LOG(LOADER,"Loadable Segment Copied to %08x, size %08x", writeAddr, (u32)p->p_memsz);
}
}
memblock.ListBlocks();
Expand Down
10 changes: 5 additions & 5 deletions Core/HW/Display.cpp
Expand Up @@ -243,12 +243,12 @@ void DisplayFireVblankStart() {
}

void DisplayFireVblankEnd() {
std::vector<VblankCallback> toCall = [] {
std::lock_guard<std::mutex> guard(listenersLock);
return vblankListeners;
}();

isVblank = 0;
std::vector<VblankCallback> toCall;
{
std::lock_guard<std::mutex> guard(listenersLock);
toCall = vblankListeners;
}

for (VblankCallback cb : toCall) {
cb();
Expand Down

0 comments on commit fae1f4a

Please sign in to comment.