-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 297598 b: refs/heads/master c: b21d55e h: refs/heads/master v: v3
- Loading branch information
Rabin Vincent
authored and
Russell King
committed
Mar 24, 2012
1 parent
395d58c
commit c3674de
Showing
5 changed files
with
109 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: d82227cf8f0b42ff42c21ed47025fdf54cb1698d | ||
refs/heads/master: b21d55e98ac2bbcbbeec9a8cb091f717fd95b072 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <linux/kernel.h> | ||
#include <linux/kprobes.h> | ||
#include <linux/stop_machine.h> | ||
|
||
#include <asm/cacheflush.h> | ||
#include <asm/smp_plat.h> | ||
#include <asm/opcodes.h> | ||
|
||
#include "patch.h" | ||
|
||
struct patch { | ||
void *addr; | ||
unsigned int insn; | ||
}; | ||
|
||
void __kprobes __patch_text(void *addr, unsigned int insn) | ||
{ | ||
bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL); | ||
int size; | ||
|
||
if (thumb2 && __opcode_is_thumb16(insn)) { | ||
*(u16 *)addr = __opcode_to_mem_thumb16(insn); | ||
size = sizeof(u16); | ||
} else if (thumb2 && ((uintptr_t)addr & 2)) { | ||
u16 first = __opcode_thumb32_first(insn); | ||
u16 second = __opcode_thumb32_second(insn); | ||
u16 *addrh = addr; | ||
|
||
addrh[0] = __opcode_to_mem_thumb16(first); | ||
addrh[1] = __opcode_to_mem_thumb16(second); | ||
|
||
size = sizeof(u32); | ||
} else { | ||
if (thumb2) | ||
insn = __opcode_to_mem_thumb32(insn); | ||
else | ||
insn = __opcode_to_mem_arm(insn); | ||
|
||
*(u32 *)addr = insn; | ||
size = sizeof(u32); | ||
} | ||
|
||
flush_icache_range((uintptr_t)(addr), | ||
(uintptr_t)(addr) + size); | ||
} | ||
|
||
static int __kprobes patch_text_stop_machine(void *data) | ||
{ | ||
struct patch *patch = data; | ||
|
||
__patch_text(patch->addr, patch->insn); | ||
|
||
return 0; | ||
} | ||
|
||
void __kprobes patch_text(void *addr, unsigned int insn) | ||
{ | ||
struct patch patch = { | ||
.addr = addr, | ||
.insn = insn, | ||
}; | ||
|
||
if (cache_ops_need_broadcast()) { | ||
stop_machine(patch_text_stop_machine, &patch, cpu_online_mask); | ||
} else { | ||
bool straddles_word = IS_ENABLED(CONFIG_THUMB2_KERNEL) | ||
&& __opcode_is_thumb32(insn) | ||
&& ((uintptr_t)addr & 2); | ||
|
||
if (straddles_word) | ||
stop_machine(patch_text_stop_machine, &patch, NULL); | ||
else | ||
__patch_text(addr, insn); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef _ARM_KERNEL_PATCH_H | ||
#define _ARM_KERNEL_PATCH_H | ||
|
||
void patch_text(void *addr, unsigned int insn); | ||
void __patch_text(void *addr, unsigned int insn); | ||
|
||
#endif |