Skip to content

Commit

Permalink
x86, mm, kprobes: fault.c, simplify notify_page_fault()
Browse files Browse the repository at this point in the history
Impact: cleanup

Remove an #ifdef from notify_page_fault(). The function still
compiles to nothing in the !CONFIG_KPROBES case.

Introduce kprobes_built_in() and kprobe_fault_handler() helpers
to allow this - they returns 0 if !CONFIG_KPROBES.

No code changed:

   text	   data	    bss	    dec	    hex	filename
   4618	     32	     24	   4674	   1242	fault.o.before
   4618	     32	     24	   4674	   1242	fault.o.after

Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Ingo Molnar committed Feb 20, 2009
1 parent b814d41 commit b180181
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 1 addition & 5 deletions arch/x86/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,17 @@ static inline int kmmio_fault(struct pt_regs *regs, unsigned long addr)

static inline int notify_page_fault(struct pt_regs *regs)
{
#ifdef CONFIG_KPROBES
int ret = 0;

/* kprobe_running() needs smp_processor_id() */
if (!user_mode_vm(regs)) {
if (kprobes_built_in() && !user_mode_vm(regs)) {
preempt_disable();
if (kprobe_running() && kprobe_fault_handler(regs, 14))
ret = 1;
preempt_enable();
}

return ret;
#else
return 0;
#endif
}

/*
Expand Down
22 changes: 19 additions & 3 deletions include/linux/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ struct kprobe_blackpoint {
DECLARE_PER_CPU(struct kprobe *, current_kprobe);
DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);

/*
* For #ifdef avoidance:
*/
static inline int kprobes_built_in(void)
{
return 1;
}

#ifdef CONFIG_KRETPROBES
extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
struct pt_regs *regs);
Expand Down Expand Up @@ -271,8 +279,16 @@ void unregister_kretprobes(struct kretprobe **rps, int num);
void kprobe_flush_task(struct task_struct *tk);
void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head);

#else /* CONFIG_KPROBES */
#else /* !CONFIG_KPROBES: */

static inline int kprobes_built_in(void)
{
return 0;
}
static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
{
return 0;
}
static inline struct kprobe *get_kprobe(void *addr)
{
return NULL;
Expand Down Expand Up @@ -329,5 +345,5 @@ static inline void unregister_kretprobes(struct kretprobe **rps, int num)
static inline void kprobe_flush_task(struct task_struct *tk)
{
}
#endif /* CONFIG_KPROBES */
#endif /* _LINUX_KPROBES_H */
#endif /* CONFIG_KPROBES */
#endif /* _LINUX_KPROBES_H */

0 comments on commit b180181

Please sign in to comment.