From: kosmirror <kos...@us...> - 2025-08-14 20:18:18
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via e655808a8d4b52640f0524210985f3978901d8c6 (commit) via 03df46db210ee53614bfb31b7c576177d02409c4 (commit) from 1e6a1b3041ee8aebe2845c07b9ac3436b9f5fd81 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit e655808a8d4b52640f0524210985f3978901d8c6 Author: QuzarDC <qu...@co...> Date: Mon Aug 11 23:59:22 2025 -0400 examples: More stable exec example The changes made in #1112 to make the romdisk vfs dynamically allocate file handles had a side effect of being more likely to break this exec example. This happens because the example was using `fs_mmap` with a hidden assumption that the memory allocated for the open rd file would persist through the `arch_shutdown` that happens during `arch_exec`. This only ever worked because of the specifics of how the example were being crafted: having the subelf in a static romdisk built into the loaded parent binary and could have failed before #1112 with any mildly different use like loading a romdisk from a disc first. commit 03df46db210ee53614bfb31b7c576177d02409c4 Author: QuzarDC <qu...@co...> Date: Tue Aug 12 01:15:59 2025 -0400 fs_romdisk: Correct `fs_romdisk_shutdown` The changes in #1112 broke `fs_romdisk_shutdown` when any files were left open (found via exec example). The problem was that the functionality to free dangling file handles would deadlock with the already open mutex. ----------------------------------------------------------------------- Summary of changes: examples/dreamcast/basic/exec/exec.c | 30 ++++++++++++++++++++++++------ kernel/fs/fs_romdisk.c | 8 ++++---- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/examples/dreamcast/basic/exec/exec.c b/examples/dreamcast/basic/exec/exec.c index edcb201d..0fd34be6 100644 --- a/examples/dreamcast/basic/exec/exec.c +++ b/examples/dreamcast/basic/exec/exec.c @@ -9,20 +9,38 @@ int main(int argc, char **argv) { file_t f; - void *subelf; + size_t s; + ssize_t rv; + void *subbin; /* Print a hello */ printf("\n\nHello world from the exec.elf process\n"); - /* Map the sub-elf */ + /* Open the sub-bin. Note normally this wouldn't be from a + romdisk as that means that you'd already have it loaded + in memory. + */ f = fs_open("/rd/sub.bin", O_RDONLY); assert(f); - subelf = fs_mmap(f); - assert(subelf); + + /* Get the size of sub.bin */ + s = fs_total(f); + assert(s); + + /* Allocate space for it */ + subbin = malloc(s); + assert(subbin); + + /* Copy in the sub.bin */ + rv = fs_read(f, subbin, s); + assert(rv == s); + + /* Lets be nice and tidy up after ourselves */ + fs_close(f); /* Tell exec to replace us */ - printf("sub.bin mapped at %08x, jumping to it!\n\n\n", (unsigned int)subelf); - arch_exec(subelf, fs_total(f)); + printf("sub.bin loaded at %08x, jumping to it!\n\n\n", (uintptr_t)subbin); + arch_exec(subbin, s); /* Shouldn't get here */ assert_msg(false, "exec call failed"); diff --git a/kernel/fs/fs_romdisk.c b/kernel/fs/fs_romdisk.c index b2bc3784..39de9e4b 100644 --- a/kernel/fs/fs_romdisk.c +++ b/kernel/fs/fs_romdisk.c @@ -672,6 +672,8 @@ void fs_romdisk_shutdown(void) { if(!initted) return; + initted = 0; + mutex_lock(&fh_mutex); /* Go through and free all the romdisk mount entries */ @@ -679,17 +681,15 @@ void fs_romdisk_shutdown(void) { fs_romdisk_list_remove(c); } + mutex_unlock(&fh_mutex); + /* Iterate through any dangling files and clean them */ TAILQ_FOREACH_SAFE(i, &rd_fd_queue, next, j) { romdisk_close(i); } - mutex_unlock(&fh_mutex); - /* Free mutex */ mutex_destroy(&fh_mutex); - - initted = 0; } /* Mount a romdisk image; must have called fs_romdisk_init() earlier. hooks/post-receive -- A pseudo Operating System for the Dreamcast. |