From 02b2a83eb3c9c82a35d8196fce8bb7d244a81587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:07:41 -0300 Subject: [PATCH] make IOP skeleton showcase module unloading --- skeleton/iop/hello_main.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/skeleton/iop/hello_main.c b/skeleton/iop/hello_main.c index 88afbc50c30..53cc086be72 100644 --- a/skeleton/iop/hello_main.c +++ b/skeleton/iop/hello_main.c @@ -2,7 +2,7 @@ #include "irx_imports.h" #define MODNAME "hello" -IRX_ID("IOP skeleton", 1, 1); +IRX_ID("IOP_skeleton", 1, 1); extern struct irx_export_table _exp_hello; @@ -12,12 +12,38 @@ extern struct irx_export_table _exp_hello; // This is a bit like a "main" for IRX files. -int _start(int argc, char *argv[]) +int _start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi) { - if (RegisterLibraryEntries(&_exp_hello) != 0) + +#ifndef NO_MODULE_UNLOAD_SUPPORT + if (argc < 0) _stop(argc, argv, startaddr, mi); +#endif + if (RegisterLibraryEntries(&_exp_hello) != 0) { + printf("Failed to RegisterLibraryEntries()\n"); return MODULE_NO_RESIDENT_END; + } hello(); - return MODULE_RESIDENT_END; +#ifdef MODULE_UNLOAD_ORIGINAL_APPROACH + return MODULE_REMOVABLE_END; +#else +#ifndef NO_MODULE_UNLOAD_SUPPORT + if (mi && ((mi->newflags & 2) != 0)) + mi->newflags |= 0x10; +#endif + return MODULE_RESIDENT_END; +#endif } + +// Here you have to deinit devices, free memory, release exports, +// or whatever cleanup is required depending on what is your module doing +#ifndef NO_MODULE_UNLOAD_SUPPORT +int _stop(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi) +{ + printf("Unloading %s module\n", MODNAME); + ReleaseLibraryEntries(&_exp_hello); + + return MODULE_NO_RESIDENT_END; //if the deinit process fails for whatever reason. you should return MODULE_REMOVABLE_END +} +#endif