Skip to content

Commit

Permalink
patcher/linux: code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Hjelm <[email protected]>
  • Loading branch information
hjelmn committed Mar 30, 2016
1 parent e401a03 commit 36abc43
Showing 1 changed file with 6 additions and 68 deletions.
74 changes: 6 additions & 68 deletions opal/mca/patcher/linux/patcher_linux_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) *
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
};

0 comments on commit 36abc43

Please sign in to comment.