(The following refers to GCC/Linux/32Bit)
I'm currently taking an OS course.
I'm asked to write a User-Level Thread Library.
I'm given the following C method by the school,
alongside with a demo on how to use it:
//A translation required when using an address of a variable
//Use this as a black box in your code.
unsigned int translate_address(unsigned int addr)
unsigned int tmp;}
asm volatile("mov %%gs, %0\n"
printf ("%%gs=%u\n", tmp);
unsigned int ret;
asm volatile("xor %%gs:0x18,%0\n"
"rol $0x9,%0\n"printf("ret=%u\n", ret);
: "=g" (ret)
: "0" (addr));
I anyone can explain to me how this works, this would be useful.
Most of all I'm interested in the cryptic %gs:0x18.
What happens at the GS data segment? What's so special about the 24 bits (=0x18) bits offset?
Attached is the demo file using the above method.