diff --git a/source/module/monitor_kallsyms.c b/source/module/monitor_kallsyms.c index 81dec2e..9815f79 100644 --- a/source/module/monitor_kallsyms.c +++ b/source/module/monitor_kallsyms.c @@ -1,5 +1,22 @@ #include "monitor_kallsyms.h" +unsigned long (*diag_kallsyms_lookup_name)(const char *name); +struct kprobe kprobe_kallsyms_lookup_name = {.symbol_name = + "kallsyms_lookup_name"}; + +unsigned int (*orig_stack_trace_save_tsk)(struct task_struct *task, + unsigned long *store, + unsigned int size, + unsigned int skipnr); +void (*orig_show_stack)(struct task_struct *task, unsigned long *sp, + const char *loglvl); + +struct sched_class *orig_idle_sched_class; +int (*orig_get_task_type)(struct sched_entity *se); +int (*orig_kernfs_name)(struct kernfs_node *kn, char *buf, size_t buflen); +int (*orig_access_remote_vm)(struct mm_struct *mm, unsigned long addr, + void *buf, int len, unsigned int gup_flags); + /// @brief init kallsyms_lookup_name /// @param /// @return 0 is success @@ -26,4 +43,5 @@ int init_orig_fun(void) { LOOKUP_SYMS_NORET(get_task_type); // get_task_type LOOKUP_SYMS_NORET(kernfs_name); // kernfs_name + return 0; } diff --git a/source/module/monitor_kallsyms.h b/source/module/monitor_kallsyms.h index 92cbc24..d127e4a 100644 --- a/source/module/monitor_kallsyms.h +++ b/source/module/monitor_kallsyms.h @@ -1,9 +1,8 @@ #include // for diag_kallsyms_lookup_name -unsigned long (*diag_kallsyms_lookup_name)(const char *name); -struct kprobe kprobe_kallsyms_lookup_name = {.symbol_name = - "kallsyms_lookup_name"}; +extern unsigned long (*diag_kallsyms_lookup_name)(const char *name); +extern struct kprobe kprobe_kallsyms_lookup_name; // int fn_kallsyms_lookup_name_init(void); // init kallsyms_lookup_name @@ -30,15 +29,16 @@ int init_orig_fun(void); // All the function with prefix "orig_X" are // LOOKUP_SYMS(X); -unsigned int (*orig_stack_trace_save_tsk)(struct task_struct *task, - unsigned long *store, - unsigned int size, - unsigned int skipnr); -void (*orig_show_stack)(struct task_struct *task, unsigned long *sp, - const char *loglvl); +extern unsigned int (*orig_stack_trace_save_tsk)(struct task_struct *task, + unsigned long *store, + unsigned int size, + unsigned int skipnr); +extern void (*orig_show_stack)(struct task_struct *task, unsigned long *sp, + const char *loglvl); -struct sched_class *orig_idle_sched_class; -int (*orig_get_task_type)(struct sched_entity *se); -int (*orig_kernfs_name)(struct kernfs_node *kn, char *buf, size_t buflen); -int (*orig_access_remote_vm)(struct mm_struct *mm, unsigned long addr, - void *buf, int len, unsigned int gup_flags); \ No newline at end of file +extern struct sched_class *orig_idle_sched_class; +extern int (*orig_get_task_type)(struct sched_entity *se); +extern int (*orig_kernfs_name)(struct kernfs_node *kn, char *buf, + size_t buflen); +extern int (*orig_access_remote_vm)(struct mm_struct *mm, unsigned long addr, + void *buf, int len, unsigned int gup_flags); \ No newline at end of file diff --git a/source/module/monitor_timer.c b/source/module/monitor_timer.c index ef40d94..96152a3 100644 --- a/source/module/monitor_timer.c +++ b/source/module/monitor_timer.c @@ -1,5 +1,14 @@ #include "monitor_timer.h" +// Global variable +kernel_watch_timer kernel_wtimer_list[MAX_TIMER_NUM] = { + 0}; // all kernel_watch_timer +int kernel_wtimer_num = 0; // current kernel_watch_timer number + +EXPORT_SYMBOL(kernel_wtimer_list); // export kernel_watch_timer_list +EXPORT_SYMBOL(kernel_wtimer_num); // export kernel_watch_timer_num + + #define TIMER_FILLED(timer) ((timer)->sentinel >= TIMER_MAX_WATCH_NUM) #define TIMER_EMPTY(timer) (!((timer)->time_ns | (timer)->sentinel)) #define TIMER_NO_KWARG(timer) ((timer)->sentinel == 0) @@ -113,23 +122,23 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) { int i = 0, j = 0; int buffer[TIMER_MAX_WATCH_NUM]; // Buffer to store the messages - // check all watched kernel_watch_arg - for (i = 0; i < k_watch_timer->sentinel; i++) { - if (read_and_compare(&k_watch_timer->k_watch_args[i])) { - // snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), " - // name: %s, threshold: %lld, pid: %d\n", - // k_watch_timer->k_watch_args[i].name, - // k_watch_timer->k_watch_args[i].threshold, - // k_watch_timer->k_watch_args[i].task_id); - buffer[j] = i; - j++; + // // check all watched kernel_watch_arg + // for (i = 0; i < k_watch_timer->sentinel; i++) { + // if (read_and_compare(&k_watch_timer->k_watch_args[i])) { + // // snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), " + // // name: %s, threshold: %lld, pid: %d\n", + // // k_watch_timer->k_watch_args[i].name, + // // k_watch_timer->k_watch_args[i].threshold, + // // k_watch_timer->k_watch_args[i].task_id); + // buffer[j] = i; + // j++; - // printk(KERN_INFO "j: name %s, threshold: %lld\n", - // k_watch_timer->k_watch_args[i].name, - // k_watch_timer->k_watch_args[i].threshold); - // printk(KERN_INFO "j: %d\n", j); - } - } + // // printk(KERN_INFO "j: name %s, threshold: %lld\n", + // // k_watch_timer->k_watch_args[i].name, + // // k_watch_timer->k_watch_args[i].threshold); + // // printk(KERN_INFO "j: %d\n", j); + // } + // } if (j > 0) // if any threshold reached { printk("-------------------------------------\n"); @@ -142,7 +151,7 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) { k_watch_timer->k_watch_args[buffer[i]].threshold, k_watch_timer->k_watch_args[buffer[i]].task_id); } - print_task_stack(); + // print_task_stack(); // restart timer after 1s hrtimer_forward(timer, timer->base->get_time(), ktime_set(1, 0)); //! todo printk("-------------------------------------\n"); diff --git a/source/module/monitor_timer.h b/source/module/monitor_timer.h index e5b4fa2..605514b 100644 --- a/source/module/monitor_timer.h +++ b/source/module/monitor_timer.h @@ -49,12 +49,12 @@ typedef struct { } kernel_watch_timer; // Global variable -kernel_watch_timer kernel_wtimer_list[MAX_TIMER_NUM] = { - 0}; // all kernel_watch_timer -int kernel_wtimer_num = 0; // current kernel_watch_timer number +extern kernel_watch_timer + kernel_wtimer_list[MAX_TIMER_NUM]; // all kernel_watch_timer +extern int kernel_wtimer_num; // current kernel_watch_timer number -EXPORT_SYMBOL(kernel_wtimer_list); // export kernel_watch_timer_list -EXPORT_SYMBOL(kernel_wtimer_num); // export kernel_watch_timer_num +// EXPORT_SYMBOL(kernel_wtimer_list); // export kernel_watch_timer_list +// EXPORT_SYMBOL(kernel_wtimer_num); // export kernel_watch_timer_num unsigned char del_all_kwarg_by_pid(pid_t pid); diff --git a/source/module/monitor_trace.c b/source/module/monitor_trace.c index 153cefe..b91c301 100644 --- a/source/module/monitor_trace.c +++ b/source/module/monitor_trace.c @@ -7,6 +7,9 @@ #include #include +mm_tree mm_tree_struct; +struct diag_variant_buffer load_monitor_variant_buffer; + typedef struct { struct rcu_head rcu_head; pid_t pid; diff --git a/source/module/monitor_trace.h b/source/module/monitor_trace.h index bfcd117..56eb36a 100644 --- a/source/module/monitor_trace.h +++ b/source/module/monitor_trace.h @@ -68,8 +68,8 @@ typedef struct { spinlock_t mm_tree_lock; } mm_tree; -mm_tree mm_tree_struct; -struct diag_variant_buffer load_monitor_variant_buffer; // Global buffer +extern mm_tree mm_tree_struct; +extern struct diag_variant_buffer load_monitor_variant_buffer; // Global buffer void diag_task_brief(struct task_struct *tsk, task_detail *detail); // get task brief