From 36abc43dbe08d9d73acb615e33aef93d1e0cc9d5 Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Wed, 30 Mar 2016 13:47:11 -0600 Subject: [PATCH] patcher/linux: code cleanup Signed-off-by: Nathan Hjelm --- opal/mca/patcher/linux/patcher_linux_module.c | 74 ++----------------- 1 file changed, 6 insertions(+), 68 deletions(-) diff --git a/opal/mca/patcher/linux/patcher_linux_module.c b/opal/mca/patcher/linux/patcher_linux_module.c index cc8c4a3fb65..4abb651c36e 100644 --- a/opal/mca/patcher/linux/patcher_linux_module.c +++ b/opal/mca/patcher/linux/patcher_linux_module.c @@ -76,8 +76,6 @@ OBJ_CLASS_INSTANCE(mca_patcher_linux_patch_t, mca_patcher_base_patch_t, mca_patc mca_patcher_linux_patch_destruct); /* List of patches to be applied to additional libraries */ -static bool mca_patcher_linux_dlopen_installed; -static mca_patcher_linux_patch_t *mca_patcher_linux_dlopen_patch; static void *(*orig_dlopen) (const char *, int); static const ElfW(Phdr) * @@ -401,39 +399,6 @@ static intptr_t mca_patcher_linux_get_orig (const char *symbol, void *replacemen return (intptr_t) func_ptr; } -/* called with lock held */ -static int mca_patcher_linux_install_dlopen (void) -{ - int rc; - - if (mca_patcher_linux_dlopen_installed) { - return OPAL_SUCCESS; - } - - orig_dlopen = (void *(*) (const char *, int)) mca_patcher_linux_get_orig (mca_patcher_linux_dlopen_patch->super.patch_symbol, - (void *) mca_patcher_linux_dlopen_patch->super.patch_value); - - rc = mca_patcher_base_patch_hook (&mca_patcher_linux_module, mca_patcher_linux_dlopen_patch->super.patch_value); - if (OPAL_SUCCESS != rc) { - return rc; - } - - rc = mca_patcher_linux_apply_patch (mca_patcher_linux_dlopen_patch); - if (OPAL_SUCCESS != rc) { - return rc; - } - - mca_patcher_linux_dlopen_installed = true; - - return OPAL_SUCCESS; -} - -static int mca_patcher_linux_remove_dlopen (void) -{ - mca_patcher_linux_dlopen_installed = false; - return mca_patcher_linux_remove_patch (mca_patcher_linux_dlopen_patch); -} - static int mca_patcher_linux_patch_symbol (const char *symbol_name, uintptr_t replacement, uintptr_t *orig) { 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 return rc; } -static int mca_patcher_linux_init (void) +/* called with lock held */ +static int mca_patcher_linux_install_dlopen (void) { - int rc; - - mca_patcher_linux_dlopen_patch = OBJ_NEW(mca_patcher_linux_patch_t); - if (NULL == mca_patcher_linux_dlopen_patch) { - return OPAL_ERR_OUT_OF_RESOURCE; - } - - mca_patcher_linux_dlopen_patch->super.patch_symbol = strdup ("dlopen"); - if (NULL == mca_patcher_linux_dlopen_patch->super.patch_symbol) { - OBJ_RELEASE(mca_patcher_linux_dlopen_patch); - return OPAL_ERR_OUT_OF_RESOURCE; - } - - mca_patcher_linux_dlopen_patch->super.patch_value = mca_patcher_base_addr_text ((intptr_t) mca_patcher_linux_dlopen); - mca_patcher_linux_dlopen_patch->super.patch_restore = (mca_patcher_base_restore_fn_t) mca_patcher_linux_remove_patch; - - rc = mca_patcher_linux_install_dlopen (); - if (OPAL_SUCCESS != rc) { - OBJ_RELEASE(mca_patcher_linux_dlopen_patch); - } - - return rc; + return mca_patcher_linux_patch_symbol ("dlopen", (uintptr_t) mca_patcher_linux_dlopen, + (uintptr_t *) &orig_dlopen); } -static int mca_patcher_linux_fini (void) +static int mca_patcher_linux_init (void) { - int rc = OPAL_SUCCESS; - - if (mca_patcher_linux_dlopen_patch) { - rc = mca_patcher_linux_remove_dlopen (); - OBJ_RELEASE(mca_patcher_linux_dlopen_patch); - } - - return rc; + return mca_patcher_linux_install_dlopen (); } mca_patcher_base_module_t mca_patcher_linux_module = { .patch_init = mca_patcher_linux_init, - .patch_fini = mca_patcher_linux_fini, .patch_symbol = mca_patcher_linux_patch_symbol, };