Skip to content

Commit d32fedc

Browse files
author
Luca Toniolo
committed
rtapi: Refuse to load uspace components missing rtapi_app_exit
rtapi_app.h mandates that every component exports both rtapi_app_main and rtapi_app_exit, but do_load_cmd() only checked for main and do_unload_cmd() silently skipped the exit call when it was absent. That let enum.c slip into the tree without rtapi_app_exit for years (Fixes #3191), visible only once lld 17+'s default --no-undefined-version made it a hard link error. Check for rtapi_app_exit in do_load_cmd() alongside rtapi_app_main and refuse to load the component otherwise, so future omissions surface immediately at load time with a clear error message. While here, also correct the dlsym cast for rtapi_app_exit in both do_load_cmd() and do_unload_cmd() from int(*)(void) to void(*)(void) to match the component's actual declaration. The int version was copy-pasted from the rtapi_app_main lookup and while harmless in practice (the return value was never read) it misrepresents the function signature.
1 parent 387ccce commit d32fedc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/rtapi/uspace_rtapi_app.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ static int do_load_cmd(const string& name, const vector<string>& args) {
289289
modules.erase(name);
290290
return -1;
291291
}
292+
if(!DLSYM<void(*)(void)>(module, "rtapi_app_exit")) {
293+
rtapi_print_msg(RTAPI_MSG_ERR, "%s: component is missing rtapi_app_exit\n", name.c_str());
294+
dlclose(module);
295+
modules.erase(name);
296+
return -1;
297+
}
292298
int result;
293299

294300
result = do_comp_args(module, args);
@@ -320,7 +326,7 @@ static int do_unload_cmd(const string& name) {
320326
rtapi_print_msg(RTAPI_MSG_ERR, "%s: not loaded\n", name.c_str());
321327
return -1;
322328
} else {
323-
int (*stop)(void) = DLSYM<int(*)(void)>(w, "rtapi_app_exit");
329+
void (*stop)(void) = DLSYM<void(*)(void)>(w, "rtapi_app_exit");
324330
if(stop) stop();
325331
modules.erase(modules.find(name));
326332
dlclose(w);

0 commit comments

Comments
 (0)