2

我想在目标 ARMV7 板上放置一个 uprobe,我有 uprobe_example.ko,它是针对内核 2.6.39 构建的。

insmod uprobe_example.ko vaddr=$vaddr pid=$!

Uprobes 处理被探测 + 进程生命周期中的有趣事件,例如 fork、clone、exec 和 exit。

# insmod uprobe_example.ko pid=1461 vaddr=0x000084ac
[15245.267358] up: Unknown parameterpid'`

我想用上面的参数插入这个模块,这是不允许的。

/*
* Usage: insmod uprobe_example.ko pid=<pid> vaddr=<address> [verbose=0]
* where <pid> identifies the probed process and <address> is the virtual
* address of the probed instruction.
*/

static int pid = 0;
module_param(pid, int, 0);
MODULE_PARM_DESC(pid, “pid”);

static int verbose = 1;
module_param(verbose, int, 0);
MODULE_PARM_DESC(verbose, “verbose”);

static long vaddr = 0;
module_param(vaddr, long, 0);
MODULE_PARM_DESC(vaddr, “vaddr”);

static int nhits;
static struct uprobe usp;

static void uprobe_handler(struct uprobe *u, struct pt_regs *regs)
{
nhits++;
if (verbose)
printk(KERN_INFO “Hit #%d on probepoint at %#lx\n”,
nhits, u->vaddr);
}

int __init init_module(void)
{
int ret;
usp.pid = pid;
usp.vaddr = vaddr;
usp.handler = uprobe_handler;
printk(KERN_INFO “Registering uprobe on pid %d, vaddr %#lx\n”,
usp.pid, usp.vaddr);
ret = register_uprobe(&usp);
if (ret != 0) {
printk(KERN_ERR “register_uprobe() failed, returned %d\n”, ret);
return -1;
}
return 0;
}

void __exit cleanup_module(void)
{
printk(KERN_INFO “Unregistering uprobe on pid %d, vaddr %#lx\n”,
usp.pid, usp.vaddr);
printk(KERN_INFO “Probepoint was hit %d times\n”, nhits);
unregister_uprobe(&usp);
}

制作文件

obj-m   := uprobe_example.o

KERNELDIR   ?= $(DLI_KERNEL)
PWD := $(shell pwd)

default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) EXTRA_CFLAGS=-I`pwd` modules
    #sync.sh up.ko

clean:
    rm -f *.o *.ko *.mod.c *.symvers
    rm -f trace/*.o arch/*.o
4

1 回答 1

0
obj-m += uprobe_example.o

KERNELDIR ?= $(DLI_KERNEL)

all:
    make -C $(KERNELDIR)  M=$(PWD) modules

clean: 
    make -C $(KERNELDIR)  M=$(PWD) clean

这个 Makefile 可以正常工作,没有任何错误

于 2013-03-27T10:47:04.943 回答