From fc12020ae384a1b27adbe587a249ff65ac1c86c0 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Fri, 18 Jan 2013 10:42:56 -0600 Subject: [PATCH] fix compiler warnings, add -o flag --- kmod/base.c | 9 +++++---- kpatch-create | 38 +++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/kmod/base.c b/kmod/base.c index 292265f..49f528e 100644 --- a/kmod/base.c +++ b/kmod/base.c @@ -144,7 +144,6 @@ int kpatch_register(struct module *mod, void *kpatch_relas, { int ret = 0; int ret2; - struct kpatch_func *f, *g; int num_relas; struct kpatch_rela *relas; int i; @@ -179,7 +178,7 @@ int kpatch_register(struct module *mod, void *kpatch_relas, ret = -EINVAL; goto out; } - printk("%p <- %lx\n", loc, val); + //printk("%p <- %lx\n", loc, val); //printk("%lx\n", (unsigned long)__va(__pa((unsigned long)loc))); //loc = __va(__pa((unsigned long)loc)); set_memory_rw((unsigned long)loc & PAGE_MASK, 1); @@ -290,6 +289,7 @@ out: } EXPORT_SYMBOL(kpatch_register); +#if 0 /* Called from stop_machine */ static int kpatch_remove_patch(void *data) { @@ -321,13 +321,14 @@ static int kpatch_remove_patch(void *data) out: return ret; } +#endif int kpatch_unregister(struct module *mod) { int ret = 0; +#if 0 struct kpatch_func *f; -#if 0 ret = stop_machine(kpatch_remove_patch, funcs, NULL); if (ret) goto out; @@ -350,9 +351,9 @@ int kpatch_unregister(struct module *mod) goto out; } } -#endif out: +#endif return ret; } EXPORT_SYMBOL(kpatch_unregister); diff --git a/kpatch-create b/kpatch-create index 4e54851..43ce294 100755 --- a/kpatch-create +++ b/kpatch-create @@ -4,6 +4,8 @@ set -o nounset set -o errexit set -o pipefail +# TODO: log output to a file instead of /dev/null + CUR_DIR="$PWD" SCRIPT="`basename $BASH_SOURCE`" SCRIPT_DIR="`dirname $BASH_SOURCE`" @@ -24,6 +26,13 @@ PROGRESS_FILE="kpatch-in-progress" PATCHED= PATCH= KERNEL_DIR= +OUTPUT_DIR= + +usage () +{ + echo "usage: $SCRIPT -p [PATCH] -k [KERNEL DIR] -o [OUTPUT DIR]" >&2 + exit 1 +} scriptecho () @@ -45,12 +54,12 @@ cleanup () cleanup_objs if [ $PATCHED ]; then cd "$KERNEL_DIR" - patch -p1 -R < "$PATCH" + patch -p1 -R < "$PATCH" > /dev/null export CROSS_COMPILE="$KPATCHGCC " $MAKE_CMD > /dev/null fi - #rm -rf "$TMPDIR" + rm -rf "$TMPDIR" } die () @@ -59,27 +68,24 @@ die () exit 1 } -usage () -{ - echo "usage: $SCRIPT -p [patch] -k [KERNEL_DIR]" >&2 - exit 1 -} - -while getopts "p:k:" arg; do +while getopts "p:k:o:" arg; do case "$arg" in p) PATCH="$OPTARG" ;; k) KERNEL_DIR="$OPTARG" ;; + o) OUTPUT_DIR="$OPTARG" ;; *) usage ;; esac done -[ ! "$PATCH" ] || [ ! "$KERNEL_DIR" ] && usage +[ ! "$PATCH" ] || [ ! "$KERNEL_DIR" ] || [ ! "$OUTPUT_DIR" ] && usage [ ! -f "$PATCH" ] && die "$PATCH doesn't exist" [ ! -d "$KERNEL_DIR" ] && die "$KERNEL_DIR doesn't exist" +mkdir -p "$OUTPUT_DIR" PATCH="`readlink -f \"$PATCH\"`" KERNEL_DIR="`readlink -f \"$KERNEL_DIR\"`" +OUTPUT_DIR="`readlink -f \"$OUTPUT_DIR\"`" TMPDIR="`mktemp -d`" trap cleanup exit @@ -92,7 +98,7 @@ $MAKE_CMD > /dev/null cp vmlinux vmlinux.orig_kpatch scriptecho "patching kernel" -patch -p1 < "$PATCH" +patch -p1 < "$PATCH" > /dev/null PATCHED=1 scriptecho "compiling patched kernel" @@ -115,12 +121,14 @@ done unset CROSS_COMPILE cp -a "$KMOD_DIR" "$TMPDIR/kmod" -make -C "$KERNEL_DIR" M="$TMPDIR/kmod" kpatch-patch-hook.o +make -C "$KERNEL_DIR" M="$TMPDIR/kmod" kpatch-patch-hook.o > /dev/null cd $TMPDIR/kmod find "$KERNEL_DIR" -name "*.kpatch_gen" -exec ld -m elf_x86_64 -r -o kpatch-patch-foo.o kpatch-patch-hook.o kpatch.lds {} + -make -C "$KERNEL_DIR" M="$TMPDIR/kmod" kpatch.ko -make -C "$KERNEL_DIR" M="$TMPDIR/kmod" kpatch-patch.ko +make -C "$KERNEL_DIR" M="$TMPDIR/kmod" kpatch.ko > /dev/null +make -C "$KERNEL_DIR" M="$TMPDIR/kmod" kpatch-patch.ko > /dev/null -scriptecho success +cp kpatch.ko kpatch-patch.ko "$OUTPUT_DIR" + +scriptecho Success!