问题
I am currently dealing with a problem relating to some kernel-mode code referencing %gs. Here’s what’s going on:
I have a fairly large structure which is stored in the %gs register. I am trying to get/set the cpu_active_thread value from that structure, which happens to be at offset 0x8 inside that structure. In other words, I am trying to get/set %gs:0x8. The problem is, when I get the value, the result is the literal value 0x8. (As this is not a valid address, I am crashing later on.) How can I change this so that I am getting the value eight bytes into the structure based in %gs?
If you need to know how I am getting the data out of the structure, I am using these macros. Thanks!
Edit: I am using clang. The macros above are used as such:
static inline thread_t
get_active_thread(void)
{
CPU_DATA_GET(cpu_active_thread,thread_t)
}
来源:https://stackoverflow.com/questions/25294924/address-versus-value-at-address