Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,26 @@ bool retro_load_game(const struct retro_game_info *info)
JaguarLoadFile((uint8_t*)info->data, info->size);
JaguarReset();

/* Advertise the Jaguar memory map to the frontend so features like
* RetroAchievements (rcheevos) can resolve emulated addresses to
* the host buffers backing them. */
{
struct retro_memory_descriptor descs[1];
struct retro_memory_map memmap;

memset(descs, 0, sizeof(descs));
descs[0].flags = RETRO_MEMDESC_SYSTEM_RAM | RETRO_MEMDESC_BIGENDIAN;
descs[0].ptr = jaguarMainRAM;
descs[0].start = 0x000000;
descs[0].len = 0x200000;
Comment on lines +1007 to +1008
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are magic constants for the main RAM mapping. To reduce the chance of future mismatches, prefer using a named constant (e.g., JAGUAR_MAIN_RAM_SIZE) or sizeof (if jaguarMainRAM is a real array in this translation unit) for len.

Copilot uses AI. Check for mistakes.
descs[0].addrspace = "RAM";

memmap.descriptors = descs;
memmap.num_descriptors = sizeof(descs) / sizeof(descs[0]);
if (!environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &memmap))
fprintf(stderr, "[virtualjaguar-libretro] Frontend rejected RETRO_ENVIRONMENT_SET_MEMORY_MAPS.\n");
}
Comment on lines +1000 to +1015
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The descs array (and memmap) are stack-allocated and go out of scope when retro_load_game returns, but frontends may keep and query the memory map later. This can leave the frontend with dangling pointers for memmap.descriptors, causing incorrect reads or crashes. Make the descriptors and the retro_memory_map storage persist for the lifetime of the loaded game (e.g., static/global storage, or heap-allocate and free on retro_unload_game).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback


/* The frontend will load .srm data into our save buffer (returned by
* retro_get_memory_data) after this function returns but before the
* first retro_run(). We unpack it on the first frame. */
Expand Down
Loading