For a user-lever thread library, I need to figure out jumping to a function by modifying PC value stored in jmp_buf.
This is what I have written:
jmp_buf env;
void print (void) {
 printf("\nHello World!");
}
 static int ptr_mangle(int p) {
        unsigned int ret;
        asm(" movl %1, %%eax;\n"
            " xorl %%gs:0x18, %%eax;"
            " roll $0x9, %%eax;"
            " movl %%eax, %0;"
        : "=r"(ret)
        : "r"(p)
        : "%eax"
        );
        return ret;
    }
int main() {
 int i = setjmp(env);
    env[0].__jmpbuf[5] = ptr_mangle(print);
 longjmp(env, 2);
    return 0;
}
I am trying to modify PC in jmp_buf by setting it to the address of the function I am trying to jump to. I am getting a segmentation fault. I am unable to figure out what exactly needs to be done. Do I need to modify SP as well?
Any help would be very much appreciated.