From e8014f37a2661ba5c463f3f099418c7a7e1e4016 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 19 Jun 2008 21:33:59 -0400 Subject: [PATCH] Clean up run-pre matching loop structure. Signed-off-by: Anders Kaseorg --- kmodsrc/helper.c | 55 ++++++++++++++++++++++++------------------------------- kmodsrc/helper.h | 2 +- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/kmodsrc/helper.c b/kmodsrc/helper.c index 4c7bcb1..0167deb 100644 --- a/kmodsrc/helper.c +++ b/kmodsrc/helper.c @@ -212,15 +212,14 @@ try_addr(struct ksplice_size *s, long run_addr, long pre_addr, int run_pre_cmp(long run_addr, long pre_addr, int size, int rerun) { - int run_o, pre_o, lenient = 0, prev_c3 = 0, recent_5b = 0; + int run_o = 0, pre_o = 0, lenient = 0, prev_c3 = 0, recent_5b = 0; unsigned char run, pre; struct reloc_addrmap *map; if (size == 0) return 1; - for (run_o = 0, pre_o = 0; run_o < size && pre_o < size; - pre_o++, run_o++) { + while (run_o < size && pre_o < size) { if (lenient > 0) lenient--; if (prev_c3 > 0) @@ -230,6 +229,18 @@ int run_pre_cmp(long run_addr, long pre_addr, int size, int rerun) if (!virtual_address_mapped(run_addr + run_o)) return 1; + + if ((map = find_addrmap(pre_addr + pre_o)) != NULL) { + if (handle_myst_reloc + (pre_addr, &pre_o, run_addr, &run_o, map, + rerun) == 1) + return 1; + continue; + } + + if (match_nop(run_addr, &run_o) || match_nop(pre_addr, &pre_o)) + continue; + run = *(unsigned char *)(run_addr + run_o); pre = *(unsigned char *)(pre_addr + pre_o); @@ -237,44 +248,27 @@ int run_pre_cmp(long run_addr, long pre_addr, int size, int rerun) printk("%02x/%02x ", run, pre); if (run == pre) { - if ((map = find_addrmap(pre_addr + pre_o)) != NULL) { - if (handle_myst_reloc - (pre_addr, &pre_o, run_addr, &run_o, - map, rerun) == 1) - return 1; - continue; - } if (pre == 0xc3) prev_c3 = 1 + 1; if (pre == 0x5b) recent_5b = 10 + 1; if (jumplen[pre]) lenient = max(jumplen[pre] + 1, lenient); - if (match_nop(run_addr, &run_o, &pre_o) || - match_nop(pre_addr, &pre_o, &run_o)) - continue; + pre_o++, run_o++; continue; } - if ((map = find_addrmap(pre_addr + pre_o)) != NULL) { - if (handle_myst_reloc - (pre_addr, &pre_o, run_addr, &run_o, map, - rerun) == 1) - return 1; - continue; - } if (prev_c3 && recent_5b) return 0; - if (match_nop(run_addr, &run_o, &pre_o) || - match_nop(pre_addr, &pre_o, &run_o)) - continue; if (jumplen[run] && jumplen[pre]) { - run_o += jumplen[run]; - pre_o += jumplen[pre]; + run_o += 1 + jumplen[run]; + pre_o += 1 + jumplen[pre]; continue; } - if (lenient) + if (lenient) { + pre_o++, run_o++; continue; + } if (rerun) { printk("[p_o=%08x] ! %02x/%02x %02x/%02x", pre_o, @@ -331,14 +325,14 @@ handle_myst_reloc(long pre_addr, int *pre_o, long run_addr, } } - *pre_o += map->size - offset - 1; - *run_o += map->size - offset - 1; + *pre_o += map->size - offset; + *run_o += map->size - offset; return 0; } /* TODO: The recommended way to pad 64bit code is to use NOPs preceded by maximally four 0x66 prefixes. */ -int match_nop(long addr, int *o, int *other_o) +int match_nop(long addr, int *o) { int i, j; for (i = NUM_NOPS - 1; i >= 0; i--) { @@ -349,8 +343,7 @@ int match_nop(long addr, int *o, int *other_o) break; } if (j == i + 1) { - *o += i; - (*other_o)--; + *o += j; return 1; } diff --git a/kmodsrc/helper.h b/kmodsrc/helper.h index 4edaa45..0a6f956 100644 --- a/kmodsrc/helper.h +++ b/kmodsrc/helper.h @@ -11,7 +11,7 @@ int try_addr(struct ksplice_size *s, long run_addr, long pre_addr, int run_pre_cmp(long run_addr, long pre_addr, int size, int rerun); int handle_myst_reloc(long pre_addr, int *pre_z, long run_addr, int *run_z, struct reloc_addrmap *map, int rerun); -int match_nop(long addr, int *main_o, int *other_o); +int match_nop(long addr, int *main_o); void brute_search_all_mods(struct ksplice_size *s); static inline int virtual_address_mapped(long addr) -- 2.11.4.GIT