3 ms·
Good to know about that gcc extension, that's cool :) Ok, I think I understand what's going on now. To write it down in a bit of a different way for anyone els
by gpm 6y ago
Good to know about that gcc extension, that's cool :)
Ok, I think I understand what's going on now. To write it down in a bit of a different way for anyone else who is confused
Start with some user written code like this
... usercode(...) {
...
static_call(x86_pmu_add)(args..);
...
}
That code is expanded to (desugaring the gcc extension as well)
... usercode(...) {
...
__ADDRESSABLE(__SCK__x86_pmu_add); // Just making sure the compiler doesn't think this is unused
(&__SCT__x86_pmu_add_tramp)(args...);
...
}
__SCT__x86_pmu_add_tramp is where we've "jitted" the function address to jump to. If we've written a function pointer, that assembly is just a "jmp" instruction to the function we wrote (note that one function jumping to another is just a tail call), and in the other case it's just a "ret" instruction because we don't want to do anything.
Thanks woodruffw! This is some really Interesting (and intricate) code
- woodruffw 6y agoYou're welcome, and thanks for breaking it out like that! The kernel developers, of course, deserve the majority of the praise -- I just summarized my understanding as I read through it :-)