Re: [PATCH 2/3] x86: Macrofy resuable code

2008-01-27 Thread Abhishek Sagar
Sam Ravnborg wrote:

> Small static functions are preferred over macros.
> Any particular reason to use a macro here?
> 
>   Sam

These macros have very limited(two) instantiations. But here's an alternative 
patch inlined.

Signed-off-by: Abhishek Sagar <[EMAIL PROTECTED]>
---

diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
index a99e764..b7c2d20 100644
--- a/arch/x86/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes.c
@@ -159,6 +159,16 @@ struct kretprobe_blackpoint kretprobe_blacklist[] = {
 };
 const int kretprobe_blacklist_size = ARRAY_SIZE(kretprobe_blacklist);
 
+static inline unsigned long kprobe_bkpt_addr(struct pt_regs *regs)
+{
+   return (instruction_pointer(regs) - sizeof(kprobe_opcode_t));
+}
+
+static inline int is_jprobe_bkpt(u8 *ptr)
+{
+   return (ptr > (u8 *)jprobe_return) && (ptr < (u8 *)jprobe_return_end);
+}
+
 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
 static void __kprobes set_jmp_op(void *from, void *to)
 {
@@ -519,7 +529,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
struct kprobe *p;
struct kprobe_ctlblk *kcb;
 
-   addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
+   addr = (kprobe_opcode_t *)kprobe_bkpt_addr(regs);
if (*addr != BREAKPOINT_INSTRUCTION) {
/*
 * The breakpoint instruction was removed right
@@ -1032,8 +1042,7 @@ int __kprobes longjmp_break_handler(struct kprobe *p, 
struct pt_regs *regs)
u8 *addr = (u8 *) (regs->ip - 1);
struct jprobe *jp = container_of(p, struct jprobe, kp);
 
-   if ((addr > (u8 *) jprobe_return) &&
-   (addr < (u8 *) jprobe_return_end)) {
+   if (is_jprobe_bkpt(addr)) {
if (stack_addr(regs) != kcb->jprobe_saved_sp) {
struct pt_regs *saved_regs = &kcb->jprobe_saved_regs;
printk(KERN_ERR
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] x86: Macrofy resuable code

2008-01-27 Thread Sam Ravnborg
On Sun, Jan 27, 2008 at 02:39:22PM +0530, Abhishek Sagar wrote:
> Encapsulate reusable code .
> 
> Signed-off-by: Abhishek Sagar <[EMAIL PROTECTED]>
> ---
> 
> diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
> index a99e764..45f2949 100644
> --- a/arch/x86/kernel/kprobes.c
> +++ b/arch/x86/kernel/kprobes.c
> @@ -74,6 +74,13 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
>  #define stack_addr(regs) ((unsigned long *)®s->sp)
>  #endif
>  
> +#define kprobe_bkpt_addr(regs) \
> + ((unsigned long)(regs->ip - sizeof(kprobe_opcode_t)))
> +
> +#define is_jprobe_bkpt(ptr) \
> + ((ptr > (u8 *)jprobe_return) && (ptr < (u8 *)jprobe_return_end))
> +
> +
Small static functions are preferred over macros.
Any particular reason to use a macro here?

Sam
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3] x86: Macrofy resuable code

2008-01-27 Thread Abhishek Sagar
Encapsulate reusable code .

Signed-off-by: Abhishek Sagar <[EMAIL PROTECTED]>
---

diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
index a99e764..45f2949 100644
--- a/arch/x86/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes.c
@@ -74,6 +74,13 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
 #define stack_addr(regs) ((unsigned long *)®s->sp)
 #endif
 
+#define kprobe_bkpt_addr(regs) \
+   ((unsigned long)(regs->ip - sizeof(kprobe_opcode_t)))
+
+#define is_jprobe_bkpt(ptr) \
+   ((ptr > (u8 *)jprobe_return) && (ptr < (u8 *)jprobe_return_end))
+
+
 #define W(row, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf)\
(((b0##UL << 0x0)|(b1##UL << 0x1)|(b2##UL << 0x2)|(b3##UL << 0x3) |   \
  (b4##UL << 0x4)|(b5##UL << 0x5)|(b6##UL << 0x6)|(b7##UL << 0x7) |   \
@@ -519,7 +526,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
struct kprobe *p;
struct kprobe_ctlblk *kcb;
 
-   addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
+   addr = (kprobe_opcode_t *)kprobe_bkpt_addr(regs);
if (*addr != BREAKPOINT_INSTRUCTION) {
/*
 * The breakpoint instruction was removed right
@@ -1032,8 +1039,7 @@ int __kprobes longjmp_break_handler(struct kprobe *p, 
struct pt_regs *regs)
u8 *addr = (u8 *) (regs->ip - 1);
struct jprobe *jp = container_of(p, struct jprobe, kp);
 
-   if ((addr > (u8 *) jprobe_return) &&
-   (addr < (u8 *) jprobe_return_end)) {
+   if (is_jprobe_bkpt(addr)) {
if (stack_addr(regs) != kcb->jprobe_saved_sp) {
struct pt_regs *saved_regs = &kcb->jprobe_saved_regs;
printk(KERN_ERR
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/