ko/kprobe_trace.c

89 lines
1.6 KiB
C
Raw Permalink Normal View History

#include <linux/kobject.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include <linux/module.h>
#include <linux/init.h>
struct test_struct {
int val;
int arr[3];
int *parr;
char name[8];
char *pname;
};
void test_func1(struct test_struct *p);
void test_func2(struct test_struct p);
void test_func1(struct test_struct *p)
{
printk("%d\n", p->val);
printk("%s\n", p->name);
printk("%s\n", p->pname);
printk("%d\n", p->arr[1]);
printk("%d\n", p->parr[1]);
}
void test_func2(struct test_struct p)
{
printk("%d\n", p.val);
printk("%s\n", p.name);
printk("%s\n", p.pname);
printk("%d\n", p.arr[1]);
printk("%d\n", p.parr[1]);
}
static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{
struct test_struct a;
a.val = 10;
sprintf(a.name, "hwc");
a.pname="njit";
for (int i = 0; i < 3; i++)
a.arr[i] = i;
a.parr = a.arr;
test_func1(&a);
test_func2(a);
return 0;
}
static struct kobj_attribute foo_attribute =
__ATTR(foo, 0444, foo_show, NULL);
static struct attribute *attrs[] = {
&foo_attribute.attr,
NULL,
};
static struct attribute_group attr_group = {
.attrs = attrs,
};
static struct kobject *example_kobj;
static int __init example_init(void)
{
int retval;
example_kobj = kobject_create_and_add("kprobe_ftrace", kernel_kobj);
if (!example_kobj)
return -ENOMEM;
retval = sysfs_create_group(example_kobj, &attr_group);
if (retval)
kobject_put(example_kobj);
return retval;
}
static void __exit example_exit(void)
{
kobject_put(example_kobj);
}
module_init(example_init);
module_exit(example_exit);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Greg Kroah-Hartman <greg@kroah.com>");