aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/ftrace.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kernel/ftrace.c')
-rw-r--r--arch/x86/kernel/ftrace.c84
1 files changed, 7 insertions, 77 deletions
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 944e9820b4b5..309689245431 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -9,6 +9,8 @@
9 * the dangers of modifying code on the run. 9 * the dangers of modifying code on the run.
10 */ 10 */
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
12#include <linux/spinlock.h> 14#include <linux/spinlock.h>
13#include <linux/hardirq.h> 15#include <linux/hardirq.h>
14#include <linux/uaccess.h> 16#include <linux/uaccess.h>
@@ -353,15 +355,15 @@ int __init ftrace_dyn_arch_init(void *data)
353 355
354 switch (faulted) { 356 switch (faulted) {
355 case 0: 357 case 0:
356 pr_info("ftrace: converting mcount calls to 0f 1f 44 00 00\n"); 358 pr_info("converting mcount calls to 0f 1f 44 00 00\n");
357 memcpy(ftrace_nop, ftrace_test_p6nop, MCOUNT_INSN_SIZE); 359 memcpy(ftrace_nop, ftrace_test_p6nop, MCOUNT_INSN_SIZE);
358 break; 360 break;
359 case 1: 361 case 1:
360 pr_info("ftrace: converting mcount calls to 66 66 66 66 90\n"); 362 pr_info("converting mcount calls to 66 66 66 66 90\n");
361 memcpy(ftrace_nop, ftrace_test_nop5, MCOUNT_INSN_SIZE); 363 memcpy(ftrace_nop, ftrace_test_nop5, MCOUNT_INSN_SIZE);
362 break; 364 break;
363 case 2: 365 case 2:
364 pr_info("ftrace: converting mcount calls to jmp . + 5\n"); 366 pr_info("converting mcount calls to jmp . + 5\n");
365 memcpy(ftrace_nop, ftrace_test_jmp, MCOUNT_INSN_SIZE); 367 memcpy(ftrace_nop, ftrace_test_jmp, MCOUNT_INSN_SIZE);
366 break; 368 break;
367 } 369 }
@@ -485,82 +487,10 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
485 487
486#ifdef CONFIG_FTRACE_SYSCALLS 488#ifdef CONFIG_FTRACE_SYSCALLS
487 489
488extern unsigned long __start_syscalls_metadata[];
489extern unsigned long __stop_syscalls_metadata[];
490extern unsigned long *sys_call_table; 490extern unsigned long *sys_call_table;
491 491
492static struct syscall_metadata **syscalls_metadata; 492unsigned long __init arch_syscall_addr(int nr)
493
494static struct syscall_metadata *find_syscall_meta(unsigned long *syscall)
495{
496 struct syscall_metadata *start;
497 struct syscall_metadata *stop;
498 char str[KSYM_SYMBOL_LEN];
499
500
501 start = (struct syscall_metadata *)__start_syscalls_metadata;
502 stop = (struct syscall_metadata *)__stop_syscalls_metadata;
503 kallsyms_lookup((unsigned long) syscall, NULL, NULL, NULL, str);
504
505 for ( ; start < stop; start++) {
506 if (start->name && !strcmp(start->name, str))
507 return start;
508 }
509 return NULL;
510}
511
512struct syscall_metadata *syscall_nr_to_meta(int nr)
513{
514 if (!syscalls_metadata || nr >= NR_syscalls || nr < 0)
515 return NULL;
516
517 return syscalls_metadata[nr];
518}
519
520int syscall_name_to_nr(char *name)
521{ 493{
522 int i; 494 return (unsigned long)(&sys_call_table)[nr];
523
524 if (!syscalls_metadata)
525 return -1;
526
527 for (i = 0; i < NR_syscalls; i++) {
528 if (syscalls_metadata[i]) {
529 if (!strcmp(syscalls_metadata[i]->name, name))
530 return i;
531 }
532 }
533 return -1;
534}
535
536void set_syscall_enter_id(int num, int id)
537{
538 syscalls_metadata[num]->enter_id = id;
539}
540
541void set_syscall_exit_id(int num, int id)
542{
543 syscalls_metadata[num]->exit_id = id;
544}
545
546static int __init arch_init_ftrace_syscalls(void)
547{
548 int i;
549 struct syscall_metadata *meta;
550 unsigned long **psys_syscall_table = &sys_call_table;
551
552 syscalls_metadata = kzalloc(sizeof(*syscalls_metadata) *
553 NR_syscalls, GFP_KERNEL);
554 if (!syscalls_metadata) {
555 WARN_ON(1);
556 return -ENOMEM;
557 }
558
559 for (i = 0; i < NR_syscalls; i++) {
560 meta = find_syscall_meta(psys_syscall_table[i]);
561 syscalls_metadata[i] = meta;
562 }
563 return 0;
564} 495}
565arch_initcall(arch_init_ftrace_syscalls);
566#endif 496#endif