From c5c7dd35bef6f4f68076c99526716159b95735b5 Mon Sep 17 00:00:00 2001 From: Jeffrey Brian Arnold Date: Mon, 14 Jul 2008 00:31:41 -0400 Subject: [PATCH] Include ksplice.h from userspace to avoid code duplication. Signed-off-by: Jeffrey Brian Arnold --- Makefile.in | 2 +- kmodsrc/ksplice.h | 58 +++++++++++++++++++++++++++++-------------------------- objmanip.c | 1 + objmanip.h | 29 ---------------------------- 4 files changed, 33 insertions(+), 57 deletions(-) diff --git a/Makefile.in b/Makefile.in index b1281ca..1e6aaf1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -48,7 +48,7 @@ $(perl_primary): %: %.in Makefile $(perl_man): %.8: % pod2man --center="Ksplice" --release="Ksplice v$(PACKAGE_VERSION)" --section=8 $< $@ -objdiff objmanip: %: %.c objcommon.c objcommon.h +objdiff objmanip: %: %.c objcommon.c objcommon.h kmodsrc/ksplice.h $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< $(srcdir)/objcommon.c $(LIBS) -o $@ install: default install-objmanip install-objdiff diff --git a/kmodsrc/ksplice.h b/kmodsrc/ksplice.h index a9ca575..0c300ae 100644 --- a/kmodsrc/ksplice.h +++ b/kmodsrc/ksplice.h @@ -1,30 +1,3 @@ -#include -#include -#include -#include - -#if BITS_PER_LONG == 32 -#define ADDR "08lx" -#elif BITS_PER_LONG == 64 -#define ADDR "016lx" -#endif -#ifdef KSPLICE_STANDALONE -#if defined(CONFIG_PARAVIRT) && defined(CONFIG_X86_64) && \ - LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) && \ - LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) -/* Linux 2.6.25 and 2.6.26 apply paravirt replacements to the core - * kernel but not modules on x86-64. If we are patching the core - * kernel, we need to apply the same replacements to our update - * modules in order for run-pre matching to succeed. - */ -#define KSPLICE_NEED_PARAINSTRUCTIONS 1 -#endif -#endif - -enum ksplice_state_enum { - KSPLICE_PREPARING, KSPLICE_APPLIED, KSPLICE_REVERSED -}; - struct ksplice_reloc { char *sym_name; unsigned long blank_addr; @@ -54,6 +27,35 @@ struct ksplice_patch { char *saved; }; +#ifdef __KERNEL__ + +#include +#include +#include +#include + +#if BITS_PER_LONG == 32 +#define ADDR "08lx" +#elif BITS_PER_LONG == 64 +#define ADDR "016lx" +#endif +#ifdef KSPLICE_STANDALONE +#if defined(CONFIG_PARAVIRT) && defined(CONFIG_X86_64) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) && \ + LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +/* Linux 2.6.25 and 2.6.26 apply paravirt replacements to the core + * kernel but not modules on x86-64. If we are patching the core + * kernel, we need to apply the same replacements to our update + * modules in order for run-pre matching to succeed. + */ +#define KSPLICE_NEED_PARAINSTRUCTIONS 1 +#endif +#endif + +enum ksplice_state_enum { + KSPLICE_PREPARING, KSPLICE_APPLIED, KSPLICE_REVERSED +}; + struct module_pack { const char *name; const char *target; @@ -188,3 +190,5 @@ static inline void print_abort(const char *str) int init_ksplice_module(struct module_pack *pack); void cleanup_ksplice_module(struct module_pack *pack); + +#endif /* __KERNEL__ */ diff --git a/objmanip.c b/objmanip.c index 832a251..69e48e6 100644 --- a/objmanip.c +++ b/objmanip.c @@ -97,6 +97,7 @@ #define _GNU_SOURCE #include "objcommon.h" #include "objmanip.h" +#include "kmodsrc/ksplice.h" #include #include #include diff --git a/objmanip.h b/objmanip.h index 85f70b7..2140172 100644 --- a/objmanip.h +++ b/objmanip.h @@ -10,35 +10,6 @@ struct specsect { int entry_size; }; -struct ksplice_reloc { - char *sym_name; - unsigned long blank_addr; - long blank_offset; - unsigned long num_sym_addrs; - unsigned long *sym_addrs; - int pcrel; - long addend; - int size; - unsigned long dst_mask; - unsigned int rightshift; -}; - -struct ksplice_size { - char *name; - unsigned long size; - unsigned long thismod_addr; - unsigned long num_sym_addrs; - unsigned long *sym_addrs; -}; - -struct ksplice_patch { - char *oldstr; - char *replstr; - unsigned long oldaddr; - unsigned long repladdr; - char *saved; -}; - int main(int argc, char **argv); void rm_some_relocs(bfd *ibfd, asection *isection); void write_ksplice_reloc(bfd *ibfd, asection *isection, arelent *orig_reloc, -- 2.11.4.GIT