Question

I am trying to create user level thread library. I have a function called void switch_thread(tcb* currSp,tcb* newSp) which is implemented in C. tcb* currSp,tcb* newSp are stack pointers of current thread and new thread. switch_thread function should be implemented in x86 assembly. My problem is how should I change stack pointer current thread to new thread in x86 assembly.

    .text
    .global switch_thread
   switch_thread:
        mov 0x4(%esp), %eax #current thread
        mov 0x8(%esp), %ecx #new thread
            //no idea how to implement rest of it.

No correct solution

OTHER TIPS

The functions in <ucontext.h> do exactly this, and setcontext() is what you want in particular. This function is implemented in GLIBC, and the source file for it can be found in various places on the internet.

Casually looking over the assembly, it basically recovers the floating point context, and then recovers all the other registers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top