Skip to content

Commit 36abc43

Browse files
committed
patcher/linux: code cleanup
Signed-off-by: Nathan Hjelm <[email protected]>
1 parent e401a03 commit 36abc43

File tree

1 file changed

+6
-68
lines changed

1 file changed

+6
-68
lines changed

opal/mca/patcher/linux/patcher_linux_module.c

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ OBJ_CLASS_INSTANCE(mca_patcher_linux_patch_t, mca_patcher_base_patch_t, mca_patc
7676
mca_patcher_linux_patch_destruct);
7777

7878
/* List of patches to be applied to additional libraries */
79-
static bool mca_patcher_linux_dlopen_installed;
80-
static mca_patcher_linux_patch_t *mca_patcher_linux_dlopen_patch;
8179
static void *(*orig_dlopen) (const char *, int);
8280

8381
static const ElfW(Phdr) *
@@ -401,39 +399,6 @@ static intptr_t mca_patcher_linux_get_orig (const char *symbol, void *replacemen
401399
return (intptr_t) func_ptr;
402400
}
403401

404-
/* called with lock held */
405-
static int mca_patcher_linux_install_dlopen (void)
406-
{
407-
int rc;
408-
409-
if (mca_patcher_linux_dlopen_installed) {
410-
return OPAL_SUCCESS;
411-
}
412-
413-
orig_dlopen = (void *(*) (const char *, int)) mca_patcher_linux_get_orig (mca_patcher_linux_dlopen_patch->super.patch_symbol,
414-
(void *) mca_patcher_linux_dlopen_patch->super.patch_value);
415-
416-
rc = mca_patcher_base_patch_hook (&mca_patcher_linux_module, mca_patcher_linux_dlopen_patch->super.patch_value);
417-
if (OPAL_SUCCESS != rc) {
418-
return rc;
419-
}
420-
421-
rc = mca_patcher_linux_apply_patch (mca_patcher_linux_dlopen_patch);
422-
if (OPAL_SUCCESS != rc) {
423-
return rc;
424-
}
425-
426-
mca_patcher_linux_dlopen_installed = true;
427-
428-
return OPAL_SUCCESS;
429-
}
430-
431-
static int mca_patcher_linux_remove_dlopen (void)
432-
{
433-
mca_patcher_linux_dlopen_installed = false;
434-
return mca_patcher_linux_remove_patch (mca_patcher_linux_dlopen_patch);
435-
}
436-
437402
static int mca_patcher_linux_patch_symbol (const char *symbol_name, uintptr_t replacement, uintptr_t *orig)
438403
{
439404
mca_patcher_linux_patch_t *patch = OBJ_NEW(mca_patcher_linux_patch_t);
@@ -478,46 +443,19 @@ static int mca_patcher_linux_patch_symbol (const char *symbol_name, uintptr_t re
478443
return rc;
479444
}
480445

481-
static int mca_patcher_linux_init (void)
446+
/* called with lock held */
447+
static int mca_patcher_linux_install_dlopen (void)
482448
{
483-
int rc;
484-
485-
mca_patcher_linux_dlopen_patch = OBJ_NEW(mca_patcher_linux_patch_t);
486-
if (NULL == mca_patcher_linux_dlopen_patch) {
487-
return OPAL_ERR_OUT_OF_RESOURCE;
488-
}
489-
490-
mca_patcher_linux_dlopen_patch->super.patch_symbol = strdup ("dlopen");
491-
if (NULL == mca_patcher_linux_dlopen_patch->super.patch_symbol) {
492-
OBJ_RELEASE(mca_patcher_linux_dlopen_patch);
493-
return OPAL_ERR_OUT_OF_RESOURCE;
494-
}
495-
496-
mca_patcher_linux_dlopen_patch->super.patch_value = mca_patcher_base_addr_text ((intptr_t) mca_patcher_linux_dlopen);
497-
mca_patcher_linux_dlopen_patch->super.patch_restore = (mca_patcher_base_restore_fn_t) mca_patcher_linux_remove_patch;
498-
499-
rc = mca_patcher_linux_install_dlopen ();
500-
if (OPAL_SUCCESS != rc) {
501-
OBJ_RELEASE(mca_patcher_linux_dlopen_patch);
502-
}
503-
504-
return rc;
449+
return mca_patcher_linux_patch_symbol ("dlopen", (uintptr_t) mca_patcher_linux_dlopen,
450+
(uintptr_t *) &orig_dlopen);
505451
}
506452

507-
static int mca_patcher_linux_fini (void)
453+
static int mca_patcher_linux_init (void)
508454
{
509-
int rc = OPAL_SUCCESS;
510-
511-
if (mca_patcher_linux_dlopen_patch) {
512-
rc = mca_patcher_linux_remove_dlopen ();
513-
OBJ_RELEASE(mca_patcher_linux_dlopen_patch);
514-
}
515-
516-
return rc;
455+
return mca_patcher_linux_install_dlopen ();
517456
}
518457

519458
mca_patcher_base_module_t mca_patcher_linux_module = {
520459
.patch_init = mca_patcher_linux_init,
521-
.patch_fini = mca_patcher_linux_fini,
522460
.patch_symbol = mca_patcher_linux_patch_symbol,
523461
};

0 commit comments

Comments
 (0)