kprobes: Make kprobe register via symbol name#135
kprobes: Make kprobe register via symbol name#135louisom wants to merge 1 commit intof9micro:masterfrom louisom:feature/register_kprobes_with_symbols
Conversation
|
CI fails because of incorrect linkage. |
jserv
left a comment
There was a problem hiding this comment.
Follow consistent coding style.
| void *addr = kp->addr; | ||
|
|
||
| /* Cannot use address and symbol name at the same time */ | ||
| if ((kp->addr && kp->symbol_name) || |
There was a problem hiding this comment.
You can rewrite by following to comply with consistent coding style:
if ((kp->addr && kp->symbol_name) ||
(!kp->addr && !kp->symbol_name))There was a problem hiding this comment.
I think I'll need to make a script to check this kind of hard find coding style problem......
kernel/ksym.c
Outdated
| { | ||
| int i; | ||
|
|
||
| for (i = 0; i < __ksym_count; ++i) { |
There was a problem hiding this comment.
Use C99 style initializer. That is, for (int i = 0; i < __ksym_count; ++i) {.
louisom
left a comment
There was a problem hiding this comment.
I'm not sure how to resolve incorrect linkage problem. In kernel, there is a strcmp, and in l4test, there is another strcmp, too.
It seems we can't split out kernel space and user space here.
| void *addr = kp->addr; | ||
|
|
||
| /* Cannot use address and symbol name at the same time */ | ||
| if ((kp->addr && kp->symbol_name) || |
There was a problem hiding this comment.
I think I'll need to make a script to check this kind of hard find coding style problem......
kernel/ksym.c
Outdated
| return __ksym_tbl[symid].addr; | ||
| } | ||
|
|
||
| static inline int strcmp(const char *l, const char *r) |
There was a problem hiding this comment.
Remove it since we already have functional implementation in file kernel/lib/strcmp.c.
In Linux kernel, kprobe can register by function address or symbol name,
but currently in F9 microkernel, can only register by address.
9 microkernel already include ksymbols when compiling kernel with
CONFIG_SYMMAP, which means F9 microkernel have the ability to 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
};
|
@jserv How could I prevent kernel / user function multiple define? l4test and kernel all define the name 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 |
|
@grapherd, there should be only one implementation providing |
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.
symbol_namein struct kprobe.help function
kprobe_addr,kprobe_addrwill return correctfunction address. Also,
kprobe_addrwill failed when it cannotmatch the symbol name in symtab, or address and symbol name are
used in the same time.
Example usage:
or