-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kprobes: Make kprobe register via symbol name #135
base: master
Are you sure you want to change the base?
kprobes: Make kprobe register via symbol name #135
Conversation
CI fails because of incorrect linkage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll need to make a script to check this kind of hard find coding style problem......
{ | ||
int i; | ||
|
||
for (i = 0; i < __ksym_count; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use C99 style initializer. That is, for (int i = 0; i < __ksym_count; ++i) {
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll need to make a script to check this kind of hard find coding style problem......
@@ -78,3 +78,21 @@ void *ksym_id2addr(int symid) | |||
{ | |||
return __ksym_tbl[symid].addr; | |||
} | |||
|
|||
static inline int strcmp(const char *l, const char *r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_name
in struct kprobe.help function
kprobe_addr
,kprobe_addr
will return correctfunction address. Also,
kprobe_addr
will failed when it cannotmatch the symbol name in symtab, or address and symbol name are
used in the same time.
Example usage:
or