Merge pull request #662 from libretro/dynarec

Fix alternate bios name loading, better mmap errors
This commit is contained in:
hizzlekizzle 2020-05-24 19:23:05 -05:00 committed by GitHub
commit 4f1de91bb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,6 +73,8 @@ static int frame_width = 0;
static int frame_height = 0;
static bool gui_inited = false;
static bool gui_show = false;
static char bios_path[4096];
static bool firmware_found = false;
unsigned cd_2x_speedup = 1;
bool cd_async = false;
@ -139,7 +141,6 @@ enum
static bool firmware_is_present(unsigned region)
{
char bios_path[4096];
static const size_t list_size = 10;
const char *bios_name_list[list_size];
const char *bios_sha1 = NULL;
@ -191,7 +192,6 @@ static bool firmware_is_present(unsigned region)
bios_sha1 = "F6BC2D1F5EB6593DE7D089C425AC681D6FFFD3F0";
}
bool found = false;
size_t i;
for (i = 0; i < list_size; ++i)
{
@ -207,12 +207,12 @@ static bool firmware_is_present(unsigned region)
if (filestream_exists(bios_path))
{
found = true;
firmware_found = true;
break;
}
}
if (!found)
if (!firmware_found)
{
char s[4096];
@ -1659,7 +1659,7 @@ static const uintptr_t supported_io_bases[] = {
int lightrec_init_mmap()
{
int r = 0, i, j, err;
int r = 0, i, j;
uintptr_t base;
void *bios, *scratch, *map;
@ -1668,8 +1668,7 @@ int lightrec_init_mmap()
memfd = open("/dev/ashmem", O_RDWR);
if (memfd < 0) {
err = -errno;
log_cb(RETRO_LOG_ERROR, "Failed to open ASHMEM fd: %d\n", err);
log_cb(RETRO_LOG_ERROR, "Failed to create ASHMEM: %s\n", strerror(errno));
return 0;
}
@ -1684,17 +1683,16 @@ int lightrec_init_mmap()
S_IRUSR | S_IWUSR);
if (memfd < 0) {
err = -errno;
log_cb(RETRO_LOG_ERROR, "Failed to open SHM fd: %d\n", err);
log_cb(RETRO_LOG_ERROR, "Failed to create SHM: %s\n", strerror(errno));
return 0;
}
err = ftruncate(memfd, RAM_SIZE+BIOS_SIZE+SCRATCH_SIZE);
/* unlink ASAP to prevent leaving a file in shared memory if we crash */
shm_unlink(shm_name);
if (err < 0) {
err = -errno;
log_cb(RETRO_LOG_ERROR, "Could not set SHM size: %d\n", err);
goto shm_unlink_return;
if (ftruncate(memfd, RAM_SIZE+BIOS_SIZE+SCRATCH_SIZE) < 0) {
log_cb(RETRO_LOG_ERROR, "Could not truncate SHM size: %s\n", strerror(errno));
goto close_return;
}
#endif
#ifdef HAVE_WIN_SHM
@ -1704,8 +1702,7 @@ int lightrec_init_mmap()
RAM_SIZE+BIOS_SIZE+SCRATCH_SIZE, NULL);
if (memfd == NULL) {
err = GetLastError();
log_cb(RETRO_LOG_ERROR, "Failed to open WIN_SHM: %d\n", err);
log_cb(RETRO_LOG_ERROR, "Failed to create WIN_SHM: %s (%d)\n", strerror(errno), GetLastError());
return 0;
}
#endif
@ -1757,7 +1754,7 @@ int lightrec_init_mmap()
r = NUM_MEM;
goto shm_unlink_return;
goto close_return;
}
err_unmap_scratch:
@ -1782,9 +1779,8 @@ err_unmap:
log_cb(RETRO_LOG_WARN, "Unable to mmap on any base address, dynarec will be slower\n");
}
shm_unlink_return:
close_return:
#ifdef HAVE_SHM
shm_unlink(shm_name);
close(memfd);
#endif
#ifdef HAVE_WIN_SHM
@ -1968,30 +1964,40 @@ static void InitCommon(std::vector<CDIF *> *_CDInterfaces, const bool EmulateMem
MDFNMP_AddRAM(1024, 0x1F800000, ScratchRAM.data8);
#endif
const char *biospath_sname;
if(region == REGION_JP)
biospath_sname = "psx.bios_jp";
else if(region == REGION_EU)
biospath_sname = "psx.bios_eu";
else if(region == REGION_NA)
biospath_sname = "psx.bios_na";
else
abort();
RFILE *BIOSFile;
if(firmware_is_present(region))
{
const char *biospath = MDFN_MakeFName(MDFNMKF_FIRMWARE,
0, MDFN_GetSettingS(biospath_sname).c_str());
RFILE *BIOSFile = filestream_open(biospath,
BIOSFile = filestream_open(bios_path,
RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
}
else
{
const char *biospath_sname;
if(region == REGION_JP)
biospath_sname = "psx.bios_jp";
else if(region == REGION_EU)
biospath_sname = "psx.bios_eu";
else if(region == REGION_NA)
biospath_sname = "psx.bios_na";
else
abort();
const char *biospath = MDFN_MakeFName(MDFNMKF_FIRMWARE,
0, MDFN_GetSettingS(biospath_sname).c_str());
BIOSFile = filestream_open(biospath,
RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
}
if (BIOSFile)
{
filestream_read(BIOSFile, BIOSROM->data8, 512 * 1024);
filestream_close(BIOSFile);
}
}
i = 0;
@ -4063,7 +4069,7 @@ bool retro_load_game(const struct retro_game_info *info)
// MDFNI_LoadGame() has been called and surface has been allocated,
// we can now perform firmware check
bool force_software_renderer = false;
if (!firmware_is_present(disc_region))
if (!firmware_found)
{
log_cb(RETRO_LOG_ERROR, "Content cannot be loaded\n");