mirror of https://github.com/dynup/kpatch
livepatch-patch-hook: clean up version checks
Clean up the kernel version checks a little bit. Use 'HAVE_*' naming everywhere for consistency. Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
This commit is contained in:
parent
7d99acf6ad
commit
d44a4b9df5
|
@ -35,8 +35,18 @@
|
|||
#define UTS_UBUNTU_RELEASE_ABI 0
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
|
||||
#define NEED_KLP_RELOCS
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
|
||||
#define HAVE_ELF_RELOCS
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) || \
|
||||
(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \
|
||||
UTS_UBUNTU_RELEASE_ABI >= 7)
|
||||
#define HAVE_SYMPOS
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
|
||||
#define HAVE_IMMEDIATE
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -87,7 +97,7 @@ static struct patch_object *patch_alloc_new_object(const char *name)
|
|||
if (!object)
|
||||
return NULL;
|
||||
INIT_LIST_HEAD(&object->funcs);
|
||||
#ifdef NEED_KLP_RELOCS
|
||||
#ifndef HAVE_ELF_RELOCS
|
||||
INIT_LIST_HEAD(&object->relocs);
|
||||
#endif
|
||||
if (strcmp(name, "vmlinux"))
|
||||
|
@ -129,7 +139,7 @@ static int patch_add_func_to_object(struct kpatch_patch_func *kfunc)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef NEED_KLP_RELOCS
|
||||
#ifndef HAVE_ELF_RELOCS
|
||||
static int patch_add_reloc_to_object(struct kpatch_patch_dynrela *kdynrela)
|
||||
{
|
||||
struct patch_reloc *reloc;
|
||||
|
@ -155,7 +165,7 @@ static int patch_add_reloc_to_object(struct kpatch_patch_dynrela *kdynrela)
|
|||
static void patch_free_scaffold(void) {
|
||||
struct patch_func *func, *safefunc;
|
||||
struct patch_object *object, *safeobject;
|
||||
#ifdef NEED_KLP_RELOCS
|
||||
#ifndef HAVE_ELF_RELOCS
|
||||
struct patch_reloc *reloc, *safereloc;
|
||||
#endif
|
||||
|
||||
|
@ -165,7 +175,7 @@ static void patch_free_scaffold(void) {
|
|||
list_del(&func->list);
|
||||
kfree(func);
|
||||
}
|
||||
#ifdef NEED_KLP_RELOCS
|
||||
#ifndef HAVE_ELF_RELOCS
|
||||
list_for_each_entry_safe(reloc, safereloc,
|
||||
&object->relocs, list) {
|
||||
list_del(&reloc->list);
|
||||
|
@ -185,7 +195,7 @@ static void patch_free_livepatch(struct klp_patch *patch)
|
|||
for (object = patch->objs; object && object->funcs; object++) {
|
||||
if (object->funcs)
|
||||
kfree(object->funcs);
|
||||
#ifdef NEED_KLP_RELOCS
|
||||
#ifndef HAVE_ELF_RELOCS
|
||||
if (object->relocs)
|
||||
kfree(object->relocs);
|
||||
#endif
|
||||
|
@ -197,7 +207,7 @@ static void patch_free_livepatch(struct klp_patch *patch)
|
|||
}
|
||||
|
||||
extern struct kpatch_patch_func __kpatch_funcs[], __kpatch_funcs_end[];
|
||||
#ifdef NEED_KLP_RELOCS
|
||||
#ifndef HAVE_ELF_RELOCS
|
||||
extern struct kpatch_patch_dynrela __kpatch_dynrelas[], __kpatch_dynrelas_end[];
|
||||
#endif
|
||||
|
||||
|
@ -209,7 +219,7 @@ static int __init patch_init(void)
|
|||
struct patch_object *object;
|
||||
struct patch_func *func;
|
||||
int ret = 0, i, j;
|
||||
#ifdef NEED_KLP_RELOCS
|
||||
#ifndef HAVE_ELF_RELOCS
|
||||
struct kpatch_patch_dynrela *kdynrela;
|
||||
struct patch_reloc *reloc;
|
||||
struct klp_reloc *lrelocs, *lreloc;
|
||||
|
@ -224,7 +234,7 @@ static int __init patch_init(void)
|
|||
goto out;
|
||||
}
|
||||
|
||||
#ifdef NEED_KLP_RELOCS
|
||||
#ifndef HAVE_ELF_RELOCS
|
||||
for (kdynrela = __kpatch_dynrelas;
|
||||
kdynrela != __kpatch_dynrelas_end;
|
||||
kdynrela++) {
|
||||
|
@ -248,10 +258,8 @@ static int __init patch_init(void)
|
|||
goto out;
|
||||
lpatch->mod = THIS_MODULE;
|
||||
lpatch->objs = lobjects;
|
||||
#if __powerpc__
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
|
||||
#if defined(__powerpc__) && defined(HAVE_IMMEDIATE)
|
||||
lpatch->immediate = true;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
i = 0;
|
||||
|
@ -268,10 +276,7 @@ static int __init patch_init(void)
|
|||
lfunc = &lfuncs[j];
|
||||
lfunc->old_name = func->kfunc->name;
|
||||
lfunc->new_func = (void *)func->kfunc->new_addr;
|
||||
#if (( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) ) || \
|
||||
( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \
|
||||
UTS_UBUNTU_RELEASE_ABI >= 7 ) \
|
||||
)
|
||||
#ifdef HAVE_SYMPOS
|
||||
lfunc->old_sympos = func->kfunc->sympos;
|
||||
#else
|
||||
lfunc->old_addr = func->kfunc->old_addr;
|
||||
|
@ -279,7 +284,7 @@ static int __init patch_init(void)
|
|||
j++;
|
||||
}
|
||||
|
||||
#ifdef NEED_KLP_RELOCS
|
||||
#ifndef HAVE_ELF_RELOCS
|
||||
lrelocs = kzalloc(sizeof(struct klp_reloc) *
|
||||
(object->relocs_nr+1), GFP_KERNEL);
|
||||
if (!lrelocs)
|
||||
|
@ -289,21 +294,18 @@ static int __init patch_init(void)
|
|||
list_for_each_entry(reloc, &object->relocs, list) {
|
||||
lreloc = &lrelocs[j];
|
||||
lreloc->loc = reloc->kdynrela->dest;
|
||||
#if (( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) ) || \
|
||||
( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \
|
||||
UTS_UBUNTU_RELEASE_ABI >= 7 ) \
|
||||
)
|
||||
#ifdef HAVE_SYMPOS
|
||||
lreloc->sympos = reloc->kdynrela->sympos;
|
||||
#else
|
||||
lreloc->val = reloc->kdynrela->src;
|
||||
#endif /* 4.5.0 */
|
||||
#endif /* HAVE_SYMPOS */
|
||||
lreloc->type = reloc->kdynrela->type;
|
||||
lreloc->name = reloc->kdynrela->name;
|
||||
lreloc->addend = reloc->kdynrela->addend;
|
||||
lreloc->external = reloc->kdynrela->external;
|
||||
j++;
|
||||
}
|
||||
#endif /* 4.7.0 */
|
||||
#endif /* HAVE_ELF_RELOCS */
|
||||
|
||||
i++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue