ARM: replace values types 08/111108/3
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 8 Jul 2016 14:46:36 +0000 (17:46 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 30 Jan 2017 16:43:21 +0000 (19:43 +0300)
unsigned short -> u16
 unsigned long -> u32
          long -> s32

Change-Id: I19d5ffab2178862d83727cfa35849c26d1f4dc36
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
arch/arm/probes/decode_thumb.c
arch/arm/probes/decode_thumb.h
arch/arm/probes/probes_arm.c
arch/arm/probes/probes_arm.h
arch/arm/probes/probes_thumb.c
arch/arm/probes/probes_thumb.h
kprobe/arch/arm/swap-asm/swap_kprobes.c
uprobe/arch/arm/swap-asm/swap_uprobes.c
uprobe/arch/arm/swap-asm/swap_uprobes.h

index 3fe96c7..b922bbc 100644 (file)
 
 
 typedef union thumb_insn {
-       unsigned long val;
+       u32 val;
        struct {
-               unsigned short hw1;
-               unsigned short hw2;
+               u16 hw1;
+               u16 hw2;
        } __packed;
 } thumb_insn_t;
 
 typedef int (*decode_handler_t)(thumb_insn_t insn, struct decode_info *info);
 
 
-static void make_def(void *tramp, unsigned long insn,
-                    unsigned long vaddr, bool t2)
+static void make_def(void *tramp, u32 insn, u32 vaddr, bool t2)
 {
-       const unsigned long URET_BP = 0xdeff;   /* breakpoint for uretprobe */
-       unsigned long ret_addr;
-       unsigned short *tr = tramp;
+       const u32 URET_BP = 0xdeff;     /* breakpoint for uretprobe */
+       u32 ret_addr;
+       u16 *tr = tramp;
 
        /*
         * thumb  - +2
@@ -67,18 +66,16 @@ static void make_def(void *tramp, unsigned long insn,
        tr[17] = ret_addr >> 16;
 }
 
-static void tt_make_common(void *tramp, unsigned long insn,
-                          unsigned long vaddr, bool t2)
+static void tt_make_common(void *tramp, u32 insn, u32 vaddr, bool t2)
 {
        memcpy(tramp, gen_insn_execbuf_thumb, 4 * UPROBES_TRAMP_LEN);
        make_def(tramp, insn, vaddr, t2);
 }
 
-static void tt_make_pc_deps(void *tramp, unsigned long mod_insn,
-                    unsigned long vaddr, bool t2)
+static void tt_make_pc_deps(void *tramp, u32 mod_insn, u32 vaddr, bool t2)
 {
-       unsigned long pc_val = vaddr + 4;
-       unsigned short *tr = tramp;
+       u32 pc_val = vaddr + 4;
+       u16 *tr = tramp;
 
        memcpy(tramp, pc_dep_insn_execbuf_thumb, 4 * UPROBES_TRAMP_LEN);
        make_def(tramp, mod_insn, vaddr, t2);
@@ -157,14 +154,13 @@ static int t32_b1110_100(thumb_insn_t insn, struct decode_info *info)
        return thumb_not_implement(insn, info);
 }
 
-static void t32_simulate_branch(unsigned long insn,
-                               struct arch_insn *ainsn,
+static void t32_simulate_branch(u32 insn, struct arch_insn *ainsn,
                                struct pt_regs *regs)
 {
-       unsigned long pc = regs->ARM_pc;
+       u32 pc = regs->ARM_pc;
        thumb_insn_t i = { .val = insn };
 
-       long offset = GET_FIELD(i.hw2, 0, 11);          /* imm11 */
+       s32 offset = GET_FIELD(i.hw2, 0, 11);           /* imm11 */
        offset += GET_FIELD(i.hw1, 0, 10) << 11;        /* imm10 */
        offset += GET_BIT(i.hw2, 13) << 21;             /* J1 */
        offset += GET_BIT(i.hw2, 11) << 22;             /* J2 */
@@ -213,9 +209,9 @@ static decode_handler_t table_branches[8] = {
 static int t32_b1111_0xxx_xxxx_xxxx_1(thumb_insn_t insn,
                                      struct decode_info *info)
 {
-       unsigned long s = GET_BIT(insn.hw2, 14) << 2 |
-                         GET_BIT(insn.hw2, 12) << 1 |
-                         GET_BIT(insn.hw2, 0);
+       u32 s = GET_BIT(insn.hw2, 14) << 2 |
+               GET_BIT(insn.hw2, 12) << 1 |
+               GET_BIT(insn.hw2, 0);
 
        return table_branches[s](insn, info);
 }
@@ -248,7 +244,7 @@ decode_handler_t table_xxx[8] = {
 };
 
 
-int decode_thumb(unsigned long insn, struct decode_info *info)
+int decode_thumb(u32 insn, struct decode_info *info)
 {
        thumb_insn_t tinsn = { .val = insn };
 
index b33c305..2aedf0f 100644 (file)
 
 
 struct decode_info {
-       unsigned long vaddr;
+       u32 vaddr;
        void *tramp;
        uprobe_handler_t handeler;
 };
 
 
-int decode_thumb(unsigned long insn, struct decode_info *info);
+int decode_thumb(u32 insn, struct decode_info *info);
 
 
 #endif /* _ARM_DECODE_THUMB_H */
index d310ddb..ca35091 100644 (file)
 #define branch_displacement(insn) sign_extend(((insn) & 0xffffff) << 2, 25)
 
 
-static unsigned long get_addr_b(unsigned long insn, unsigned long addr)
+static u32 get_addr_b(u32 insn, u32 addr)
 {
        /* real position less then PC by 8 */
-       return ((long)addr + 8 + branch_displacement(insn));
+       return ((s32)addr + 8 + branch_displacement(insn));
 }
 
-static int prep_pc_dep_insn_execbuf(unsigned long *insns,
-                                   unsigned long insn, int uregs)
+static int prep_pc_dep_insn_execbuf(u32 *insns, u32 insn, int uregs)
 {
        int i;
 
@@ -67,7 +66,7 @@ static int prep_pc_dep_insn_execbuf(unsigned long *insns,
        }
 
        if (i == 13) {
-               pr_err("there are no free register %x in insn %lx!",
+               pr_err("there are no free register %x in insn %x!",
                       uregs, insn);
                return -EINVAL;
        }
@@ -98,7 +97,7 @@ static int prep_pc_dep_insn_execbuf(unsigned long *insns,
        return 0;
 }
 
-static int arch_check_insn_arm(unsigned long insn)
+static int arch_check_insn_arm(u32 insn)
 {
        /* check instructions that can change PC by nature */
        if (
@@ -133,8 +132,7 @@ bad_insn:
        return -EFAULT;
 }
 
-static int make_branch_tarmpoline(unsigned long addr, unsigned long insn,
-                                 unsigned long *tramp)
+static int make_branch_tarmpoline(u32 addr, u32 insn, u32 *tramp)
 {
        int ok = 0;
 
@@ -188,8 +186,7 @@ static int make_branch_tarmpoline(unsigned long addr, unsigned long insn,
  * @param tramp Pointer to memory for trampoline.
  * @return 0 on success, error code on error.
  */
-int make_trampoline_arm(unsigned long addr, unsigned long insn,
-                       unsigned long *tramp)
+int make_trampoline_arm(u32 addr, u32 insn, u32 *tramp)
 {
        int ret, uregs, pc_dep;
 
@@ -257,7 +254,7 @@ int make_trampoline_arm(unsigned long addr, unsigned long insn,
                memcpy(tramp, pc_dep_insn_execbuf, KPROBES_TRAMP_LEN);
                if (prep_pc_dep_insn_execbuf(tramp, insn, uregs) != 0) {
                        pr_err("Error in %s at %d: failed "
-                              "to prepare exec buffer for insn %lx!",
+                              "to prepare exec buffer for insn %x!",
                               __FILE__, __LINE__, insn);
                        return -EINVAL;
                }
index 19f74df..c324985 100644 (file)
@@ -24,9 +24,7 @@
 #define _SWAP_ASM_PROBES_ARM_H
 
 
-int make_trampoline_arm(unsigned long addr, unsigned long insn,
-                       unsigned long *tramp);
-
+int make_trampoline_arm(u32 addr, u32 insn, u32 *tramp);
 int noret_arm(u32 opcode);
 
 
index b6cd77c..9a05a3b 100644 (file)
 #include "decode_thumb_old.h"
 
 
-static inline long branch_t16_dest(unsigned long insn, unsigned int insn_addr)
+static inline s32 branch_t16_dest(u32 insn, unsigned int insn_addr)
 {
-       long offset = insn & 0x3ff;
+       s32 offset = insn & 0x3ff;
        offset -= insn & 0x400;
        return insn_addr + 4 + offset * 2;
 }
 
-static inline long branch_cond_t16_dest(unsigned long insn,
-                                       unsigned int insn_addr)
+static inline s32 branch_cond_t16_dest(u32 insn, unsigned int insn_addr)
 {
-       long offset = insn & 0x7f;
+       s32 offset = insn & 0x7f;
        offset -= insn & 0x80;
        return insn_addr + 4 + offset * 2;
 }
 
-static inline long branch_t32_dest(unsigned long insn, unsigned int insn_addr)
+static inline s32 branch_t32_dest(u32 insn, unsigned int insn_addr)
 {
        unsigned int poff = insn & 0x3ff;
        unsigned int offset = (insn & 0x07fe0000) >> 17;
@@ -53,7 +52,7 @@ static inline long branch_t32_dest(unsigned long insn, unsigned int insn_addr)
        return (insn_addr + 4 + (poff << 12) + offset * 4) & ~3;
 }
 
-static inline long cbz_t16_dest(unsigned long insn, unsigned int insn_addr)
+static inline s32 cbz_t16_dest(u32 insn, unsigned int insn_addr)
 {
        unsigned int i = (insn & 0x200) >> 3;
        unsigned int offset = (insn & 0xf8) >> 2;
@@ -61,15 +60,14 @@ static inline long cbz_t16_dest(unsigned long insn, unsigned int insn_addr)
 }
 
 /* is instruction Thumb2 and NOT a branch, etc... */
-static int is_thumb2(unsigned long insn)
+static int is_thumb2(u32 insn)
 {
        return ((insn & 0xf800) == 0xe800 ||
                (insn & 0xf800) == 0xf000 ||
                (insn & 0xf800) == 0xf800);
 }
 
-static int prep_pc_dep_insn_execbuf_thumb(unsigned long *insns,
-                                         unsigned long insn, int uregs)
+static int prep_pc_dep_insn_execbuf_thumb(u32 *insns, u32 insn, int uregs)
 {
        unsigned char mreg = 0;
        unsigned char reg = 0;
@@ -141,39 +139,36 @@ static int prep_pc_dep_insn_execbuf_thumb(unsigned long *insns,
        }
 
        if (reg == 6 || reg == 7) {
-               *((unsigned short *)insns + 0) =
-                       (*((unsigned short *)insns + 0) & 0x00ff) |
+               *((u16 *)insns + 0) =
+                       (*((u16 *)insns + 0) & 0x00ff) |
                        ((1 << mreg) | (1 << (mreg + 1)));
-               *((unsigned short *)insns + 1) =
-                       (*((unsigned short *)insns + 1) & 0xf8ff) | (mreg << 8);
-               *((unsigned short *)insns + 2) =
-                       (*((unsigned short *)insns + 2) & 0xfff8) | (mreg + 1);
-               *((unsigned short *)insns + 3) =
-                       (*((unsigned short *)insns + 3) & 0xffc7) | (mreg << 3);
-               *((unsigned short *)insns + 7) =
-                       (*((unsigned short *)insns + 7) & 0xf8ff) | (mreg << 8);
-               *((unsigned short *)insns + 8) =
-                       (*((unsigned short *)insns + 8) & 0xffc7) | (mreg << 3);
-               *((unsigned short *)insns + 9) =
-                       (*((unsigned short *)insns + 9) & 0xffc7) |
-                       ((mreg + 1) << 3);
-               *((unsigned short *)insns + 10) =
-                       (*((unsigned short *)insns + 10) & 0x00ff) |
+               *((u16 *)insns + 1) =
+                       (*((u16 *)insns + 1) & 0xf8ff) | (mreg << 8);
+               *((u16 *)insns + 2) =
+                       (*((u16 *)insns + 2) & 0xfff8) | (mreg + 1);
+               *((u16 *)insns + 3) =
+                       (*((u16 *)insns + 3) & 0xffc7) | (mreg << 3);
+               *((u16 *)insns + 7) =
+                       (*((u16 *)insns + 7) & 0xf8ff) | (mreg << 8);
+               *((u16 *)insns + 8) =
+                       (*((u16 *)insns + 8) & 0xffc7) | (mreg << 3);
+               *((u16 *)insns + 9) =
+                       (*((u16 *)insns + 9) & 0xffc7) | ((mreg + 1) << 3);
+               *((u16 *)insns + 10) =
+                       (*((u16 *)insns + 10) & 0x00ff) |
                        ((1 << mreg) | (1 << (mreg + 1)));
        }
 
        if (THUMB_INSN_MATCH(APC, insn)) {
                /* ADD Rd, PC, #immed_8*4 -> ADD Rd, SP, #immed_8*4 */
-               *((unsigned short *)insns + 4) = ((insn & 0xffff) | 0x800);
+               *((u16 *)insns + 4) = ((insn & 0xffff) | 0x800);
        } else if (THUMB_INSN_MATCH(LRO3, insn)) {
                /* LDR Rd, [PC, #immed_8*4] ->
                 * LDR Rd, [SP, #immed_8*4] */
-               *((unsigned short *)insns + 4) =
-                       ((insn & 0xffff) + 0x5000);
+               *((u16 *)insns + 4) = ((insn & 0xffff) + 0x5000);
        } else if (THUMB_INSN_MATCH(MOV3, insn)) {
                /* MOV Rd, PC -> MOV Rd, SP */
-               *((unsigned short *)insns + 4) =
-                       ((insn & 0xffff) ^ 0x10);
+               *((u16 *)insns + 4) = ((insn & 0xffff) ^ 0x10);
        } else if (THUMB2_INSN_MATCH(ADR, insn)) {
                /* ADDW Rd,PC,#imm -> ADDW Rd,SP,#imm */
                insns[2] = (insn & 0xfffffff0) | 0x0d;
@@ -288,7 +283,7 @@ static int prep_pc_dep_insn_execbuf_thumb(unsigned long *insns,
        return 0;
 }
 
-static int arch_check_insn_thumb(unsigned long insn)
+static int arch_check_insn_thumb(u32 insn)
 {
        int ret = 0;
 
@@ -350,8 +345,8 @@ static int arch_check_insn_thumb(unsigned long insn)
        return ret;
 }
 
-static int do_make_trampoline_thumb(unsigned long vaddr, unsigned long insn,
-                                   unsigned long *tramp, size_t tramp_len)
+static int do_make_trampoline_thumb(u32 vaddr, u32 insn,
+                                   u32 *tramp, size_t tramp_len)
 {
        int ret;
        int uregs = 0;
@@ -453,88 +448,83 @@ static int do_make_trampoline_thumb(unsigned long vaddr, unsigned long insn,
                prep_pc_dep_insn_execbuf_thumb(tramp, insn, uregs);
 
                addr = vaddr + 4;
-               *((unsigned short *)tramp + 13) = 0xdeff;
-               *((unsigned short *)tramp + 14) = addr & 0x0000ffff;
-               *((unsigned short *)tramp + 15) = addr >> 16;
+               *((u16 *)tramp + 13) = 0xdeff;
+               *((u16 *)tramp + 14) = addr & 0x0000ffff;
+               *((u16 *)tramp + 15) = addr >> 16;
                if (!is_thumb2(insn)) {
                        addr = vaddr + 2;
-                       *((unsigned short *)tramp + 16) =
-                               (addr & 0x0000ffff) | 0x1;
-                       *((unsigned short *)tramp + 17) = addr >> 16;
+                       *((u16 *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
+                       *((u16 *)tramp + 17) = addr >> 16;
                } else {
                        addr = vaddr + 4;
-                       *((unsigned short *)tramp + 16) =
-                               (addr & 0x0000ffff) | 0x1;
-                       *((unsigned short *)tramp + 17) = addr >> 16;
+                       *((u16 *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
+                       *((u16 *)tramp + 17) = addr >> 16;
                }
        } else {
                memcpy(tramp, gen_insn_execbuf_thumb, tramp_len);
-               *((unsigned short *)tramp + 13) = 0xdeff;
+               *((u16 *)tramp + 13) = 0xdeff;
                if (!is_thumb2(insn)) {
                        addr = vaddr + 2;
-                       *((unsigned short *)tramp + 2) = insn;
-                       *((unsigned short *)tramp + 16) =
-                               (addr & 0x0000ffff) | 0x1;
-                       *((unsigned short *)tramp + 17) = addr >> 16;
+                       *((u16 *)tramp + 2) = insn;
+                       *((u16 *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
+                       *((u16 *)tramp + 17) = addr >> 16;
                } else {
                        addr = vaddr + 4;
                        tramp[1] = insn;
-                       *((unsigned short *)tramp + 16) =
-                               (addr & 0x0000ffff) | 0x1;
-                       *((unsigned short *)tramp + 17) = addr >> 16;
+                       *((u16 *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
+                       *((u16 *)tramp + 17) = addr >> 16;
                }
        }
 
        if (THUMB_INSN_MATCH(B2, insn)) {
                memcpy(tramp, b_off_insn_execbuf_thumb, tramp_len);
-               *((unsigned short *)tramp + 13) = 0xdeff;
+               *((u16 *)tramp + 13) = 0xdeff;
                addr = branch_t16_dest(insn, vaddr);
-               *((unsigned short *)tramp + 14) = (addr & 0x0000ffff) | 0x1;
-               *((unsigned short *)tramp + 15) = addr >> 16;
-               *((unsigned short *)tramp + 16) = 0;
-               *((unsigned short *)tramp + 17) = 0;
+               *((u16 *)tramp + 14) = (addr & 0x0000ffff) | 0x1;
+               *((u16 *)tramp + 15) = addr >> 16;
+               *((u16 *)tramp + 16) = 0;
+               *((u16 *)tramp + 17) = 0;
 
        } else if (THUMB_INSN_MATCH(B1, insn)) {
                memcpy(tramp, b_cond_insn_execbuf_thumb, tramp_len);
-               *((unsigned short *)tramp + 13) = 0xdeff;
-               *((unsigned short *)tramp + 0) |= (insn & 0xf00);
+               *((u16 *)tramp + 13) = 0xdeff;
+               *((u16 *)tramp + 0) |= (insn & 0xf00);
                addr = branch_cond_t16_dest(insn, vaddr);
-               *((unsigned short *)tramp + 14) = (addr & 0x0000ffff) | 0x1;
-               *((unsigned short *)tramp + 15) = addr >> 16;
+               *((u16 *)tramp + 14) = (addr & 0x0000ffff) | 0x1;
+               *((u16 *)tramp + 15) = addr >> 16;
                addr = vaddr + 2;
-               *((unsigned short *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
-               *((unsigned short *)tramp + 17) = addr >> 16;
+               *((u16 *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
+               *((u16 *)tramp + 17) = addr >> 16;
 
        } else if (THUMB_INSN_MATCH(BLX2, insn) ||
                   THUMB_INSN_MATCH(BX, insn)) {
                memcpy(tramp, b_r_insn_execbuf_thumb, tramp_len);
-               *((unsigned short *)tramp + 13) = 0xdeff;
-               *((unsigned short *)tramp + 4) = insn;
+               *((u16 *)tramp + 13) = 0xdeff;
+               *((u16 *)tramp + 4) = insn;
                addr = vaddr + 2;
-               *((unsigned short *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
-               *((unsigned short *)tramp + 17) = addr >> 16;
+               *((u16 *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
+               *((u16 *)tramp + 17) = addr >> 16;
 
        } else if (THUMB_INSN_MATCH(CBZ, insn)) {
                memcpy(tramp, cbz_insn_execbuf_thumb, tramp_len);
-               *((unsigned short *)tramp + 13) = 0xdeff;
+               *((u16 *)tramp + 13) = 0xdeff;
                /* zero out original branch displacement (imm5 = 0; i = 0) */
-               *((unsigned short *)tramp + 0) = insn & (~0x2f8);
+               *((u16 *)tramp + 0) = insn & (~0x2f8);
                /* replace it with 8 bytes offset in execbuf (imm5 = 0b00010) */
-               *((unsigned short *)tramp + 0) |= 0x20;
+               *((u16 *)tramp + 0) |= 0x20;
                addr = cbz_t16_dest(insn, vaddr);
-               *((unsigned short *)tramp + 14) = (addr & 0x0000ffff) | 0x1;
-               *((unsigned short *)tramp + 15) = addr >> 16;
+               *((u16 *)tramp + 14) = (addr & 0x0000ffff) | 0x1;
+               *((u16 *)tramp + 15) = addr >> 16;
                addr = vaddr + 2;
-               *((unsigned short *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
-               *((unsigned short *)tramp + 17) = addr >> 16;
+               *((u16 *)tramp + 16) = (addr & 0x0000ffff) | 0x1;
+               *((u16 *)tramp + 17) = addr >> 16;
        }
 
        return 0;
 }
 
 int make_trampoline_thumb(struct uprobe *p,
-                         unsigned long vaddr, unsigned long insn,
-                         unsigned long *tramp, size_t tramp_len)
+                         u32 vaddr, u32 insn, u32 *tramp, size_t tramp_len)
 {
        int ret;
 
@@ -548,7 +538,7 @@ int make_trampoline_thumb(struct uprobe *p,
 
                ret = decode_thumb(insn, &info);
                if (info.handeler) {
-                       unsigned short *tr = (unsigned short *)tramp;
+                       u16 *tr = (u16 *)tramp;
                        tr[13] = 0xdeff; /* breakpoint for uretprobe */
                        p->ainsn.handler = info.handeler;
                }
index a8d2f97..5a33085 100644 (file)
 #define _SWAP_ASM_PROBES_THUMB_H
 
 
-int make_trampoline_thumb(struct uprobe *p,
-                         unsigned long vaddr, unsigned long insn,
-                         unsigned long *tramp, size_t tramp_len);
-
+int make_trampoline_thumb(struct uprobe *p, u32 vaddr, u32 insn,
+                         u32 *tramp, size_t tramp_len);
 int noret_thumb(u32 opcode);
 
 
index 7f438c4..7aad063 100644 (file)
@@ -62,7 +62,7 @@ static void (*__swap_unregister_undef_hook)(struct undef_hook *hook);
  */
 int arch_kp_core_prepare(struct kp_core *p, struct slot_manager *sm)
 {
-       unsigned long *tramp;
+       u32 *tramp;
        int ret;
 
        tramp = swap_slot_alloc(sm);
@@ -79,7 +79,7 @@ int arch_kp_core_prepare(struct kp_core *p, struct slot_manager *sm)
        flush_icache_range((unsigned long)tramp,
                           (unsigned long)tramp + KPROBES_TRAMP_LEN);
 
-       p->ainsn.insn = tramp;
+       p->ainsn.insn = (unsigned long *)tramp;
 
        return 0;
 }
index 2b9be2e..61b81cc 100644 (file)
@@ -71,7 +71,7 @@ int arch_prepare_uprobe(struct uprobe *p)
        unsigned long vaddr = (unsigned long)p->addr & ~((unsigned long)1);
        unsigned long insn;
        int thumb_mode = (unsigned long)p->addr & 1;
-       unsigned long tramp[UPROBES_TRAMP_LEN];
+       u32 tramp[UPROBES_TRAMP_LEN];
        unsigned long __user *utramp;
        enum { tramp_len = sizeof(tramp) };
 
index 5077261..3375005 100644 (file)
@@ -46,8 +46,8 @@ struct uretprobe;
 struct uretprobe_instance;
 
 typedef unsigned long uprobe_opcode_t;
-typedef void (*uprobe_handler_t)(unsigned long insn,
-                                struct arch_insn *, struct pt_regs *);
+typedef void (*uprobe_handler_t)(u32 insn, struct arch_insn *,
+                                struct pt_regs *);