f9-kernel icon indicating copy to clipboard operation
f9-kernel copied to clipboard

kprobes: Make kprobe register via symbol name

Open louisom opened this issue 9 years ago • 3 comments

In Linux kernel, kprobe can choose to register by address or symbol name, but currently F9 microkernel can only register by address.

In F9 microkernel, it can include ksymbols when compiling kernel with CONFIG_SYMMAP, which means F9 microkernel can support regiser kprobe via symbol name, too.

This commit change two parts in F9 microkernel, ksym and kprobes.

  • ksym
    • Adding ksym_lookup_name to search function address via symbol name.
  • kprobes
    • Adding new field symbol_name in struct kprobe.
    • When kprobe is registering, it will get the correct address via help function kprobe_addr, kprobe_addr will return correct function address. Also, kprobe_addr will failed when it cannot match the symbol name in symtab, or address and symbol name are used in the same time.

Example usage:

static struct kprobe kp = {
    .symbol_name = "ktimer_handler"
};

or

extern void ktimer_handler(void);
static struct kprobe kp = {
    .addr = ktimer_handler
};

louisom avatar Oct 20 '16 08:10 louisom

CI fails because of incorrect linkage.

jserv avatar Oct 20 '16 08:10 jserv

@jserv How could I prevent kernel / user function multiple define?

l4test and kernel all define the name strcmp

build/discoveryf4/user/apps/l4test/string.o: In function `strcmp':
/home/travis/build/f9micro/f9-kernel/user/apps/l4test/string.c:21: multiple definition of `strcmp'
build/discoveryf4/kernel/lib/strcmp.o:/home/travis/build/f9micro/f9-kernel/kernel/lib/strcmp.c:12: first defined here
make: *** [build/discoveryf4/f9_nosym.elf] Error 1

louisom avatar Jan 30 '17 13:01 louisom

@grapherd, there should be only one implementation providing strcmp: kernel/lib/strcmp.c. You would need appropriate declarations where user applications include include/lib/string.h

jserv avatar Feb 01 '17 09:02 jserv