MemArena: report mapping failures instead of returning success

Horizon's CreateView printed 'Fatal error creating the view' and then returned base
anyway, so the caller recorded an unmapped address as a live view. Posix's
ftruncate failure was logged with a '// Should this be a failure?' - it is: the
mmaps afterwards succeed against a short file and the first touch past its end
raises SIGBUS, which is only hooked under __APPLE__.
This commit is contained in:
Henrik Rydgård committed 2026-09-02 18:06:47 +02:00
1 parent 67b4b68005
commit 91f08424fd
2 files changed
+10 -4

No files matched your search

+5 -3
View File
@@ -50,11 +50,13 @@ void *MemArena::CreateView(s64 offset, size_t size, void *base) {
if (R_FAILED(rc)) {
printf("Fatal error creating the view... base: %p offset: %p size: %p src: %p err: %d\n",
(void *)base, (void *)offset, (void *)size, (void *)(memoryCodeBase + offset), rc);
} else {
printf("Created the view... base: %p offset: %p size: %p src: %p err: %d\n",
(void *)base, (void *)offset, (void *)size, (void *)(memoryCodeBase + offset), rc);
// Returning base here reports success, so the caller happily uses an unmapped address
// and we take a fault later with nothing pointing back at this.
return nullptr;
}
printf("Created the view... base: %p offset: %p size: %p src: %p err: %d\n",
(void *)base, (void *)offset, (void *)size, (void *)(memoryCodeBase + offset), rc);
return base;
}
+5 -1
View File
@@ -97,7 +97,11 @@ bool MemArena::GrabMemSpace(size_t size) {
}
if (ftruncate(fd, size) != 0) {
ERROR_LOG(Log::MemMap, "Failed to ftruncate %d (%s) to size %08x", (int)fd, ram_temp_file.c_str(), (int)size);
// Should this be a failure?
// This is a failure: the mmaps below succeed against a short file, and touching a page past
// its end raises SIGBUS - which is only hooked on __APPLE__, so elsewhere it's a bare crash.
close(fd);
fd = -1;
return false;
}
#endif
return true;