From d6d21da8641b5c5c0dd89890cb5e9b7d0b2ee5d1 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 15 Jun 2008 22:05:16 -0400 Subject: [PATCH] Remove dependence on kmodsrc from userspace tools. Signed-off-by: Anders Kaseorg --- Makefile.in | 7 ++----- kmodsrc/allcommon.c | 2 +- kmodsrc/allcommon.h | 6 ------ objcommon.c | 42 ++++++++++++++++++++++++++++++++++++++++++ objcommon.h | 10 +++++++++- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Makefile.in b/Makefile.in index 12033d7..48fd963 100644 --- a/Makefile.in +++ b/Makefile.in @@ -49,11 +49,8 @@ $(perl_primary): %: %.in Makefile $(perl_man): %.8: % pod2man --center="Ksplice" --release="Ksplice v$(PACKAGE_VERSION)" --section=8 $< $@ -objdiff objmanip: %: %.c objcommon.c objcommon.h allcommon-user.o - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< $(srcdir)/objcommon.c allcommon-user.o $(LIBS) -o $@ - -allcommon-user.o: kmodsrc/allcommon.c kmodsrc/allcommon.h - $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ +objdiff objmanip: %: %.c objcommon.c objcommon.h + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< $(srcdir)/objcommon.c $(LIBS) -o $@ install: default install-objmanip install-objdiff install -m644 -D ksplice-create.8 $(DESTDIR)$(mandir)/man8/ksplice-create.8 diff --git a/kmodsrc/allcommon.c b/kmodsrc/allcommon.c index d1207eb..eb669f8 100644 --- a/kmodsrc/allcommon.c +++ b/kmodsrc/allcommon.c @@ -52,7 +52,7 @@ const char *dup_wolabel(const char *sym_name) entire_strlen = strlen(sym_name); new_strlen = entire_strlen - label_strlen; - newstr = malloc(new_strlen + 1); + newstr = kmalloc(new_strlen + 1, GFP_KERNEL); memcpy(newstr, sym_name, new_strlen); newstr[new_strlen] = 0; return newstr; diff --git a/kmodsrc/allcommon.h b/kmodsrc/allcommon.h index 61445b7..38a4566 100644 --- a/kmodsrc/allcommon.h +++ b/kmodsrc/allcommon.h @@ -1,11 +1,5 @@ -#ifdef __KERNEL__ #include #include -#define malloc(size) kmalloc(size, GFP_KERNEL) -#else -#include -#include -#endif #define starts_with(str, prefix) (!strncmp(str, prefix, strlen(prefix))) #define ends_with(str, suffix) (strlen(str) > strlen(suffix) && !strcmp(&str[strlen(str)-strlen(suffix)], suffix)) diff --git a/objcommon.c b/objcommon.c index 5170503..cc6d3ad 100644 --- a/objcommon.c +++ b/objcommon.c @@ -61,3 +61,45 @@ struct supersect *fetch_supersect(bfd *abfd, asection *sect, asymbol **sympp) return new; } + +int label_offset(const char *sym_name) +{ + int i; + for (i = 0; + sym_name[i] != 0 && sym_name[i + 1] != 0 && sym_name[i + 2] != 0 + && sym_name[i + 3] != 0; i++) { + if (sym_name[i] == '_' && sym_name[i + 1] == '_' + && sym_name[i + 2] == '_' && sym_name[i + 3] == '_') { + return i + 4; + } + } + return -1; +} + +const char *only_label(const char *sym_name) +{ + int offset = label_offset(sym_name); + if (offset == -1) + return NULL; + return &sym_name[offset]; +} + +const char *dup_wolabel(const char *sym_name) +{ + int offset, entire_strlen, label_strlen, new_strlen; + char *newstr; + + offset = label_offset(sym_name); + if (offset == -1) { + label_strlen = 0; + } else { + label_strlen = strlen(&sym_name[offset]) + strlen("____"); + } + + entire_strlen = strlen(sym_name); + new_strlen = entire_strlen - label_strlen; + newstr = malloc(new_strlen + 1); + memcpy(newstr, sym_name, new_strlen); + newstr[new_strlen] = 0; + return newstr; +} diff --git a/objcommon.h b/objcommon.h index def25f0..b7575a9 100644 --- a/objcommon.h +++ b/objcommon.h @@ -1,6 +1,7 @@ -#include "kmodsrc/allcommon.h" #include #include +#include +#include #define DIE do { printf("ksplice: died at line %d of %s\n", __LINE__, __FILE__); fflush(0); exit(1); } while(0) #define assert(x) do { if(!(x)) DIE; } while(0) @@ -22,3 +23,10 @@ struct supersect { long get_syms(bfd *abfd, asymbol ***syms_ptr); struct supersect *fetch_supersect(bfd *abfd, asection *sect, asymbol **sympp); + +#define starts_with(str, prefix) (!strncmp(str, prefix, strlen(prefix))) +#define ends_with(str, suffix) (strlen(str) > strlen(suffix) && !strcmp(&str[strlen(str)-strlen(suffix)], suffix)) + +int label_offset(const char *sym_name); +const char *only_label(const char *sym_name); +const char *dup_wolabel(const char *sym_name); -- 2.11.4.GIT