Re: Help with very persistent scheduler bug
Posted: Sun Apr 30, 2017 9:29 am
OK so I have created an ASM function "set_stack_ptr", (2 parameters: new stack ptr, and new instruction pointer) which is defined like this (nasm format, with Intel syntax):
the function changes esp, then pushes the old ebp to the new stack (which corresponds to the new ebp of this particular function), and then pushes eip to the new stack. After doing this, it copies the previous stack's values and pushes them into the new thread stack.
it is called from the scheduler function at the end (after the register restoring memcpy), like this:
It "kind of" works, but gets stuck on the first thread. So my question is, what values do I need to push to the new stack so that the program can continue seamlessly through the esp transition?
Code: Select all
global set_stack_ptr
set_stack_ptr:
mov eax, [esp + 4]
mov ebx, esp
mov esp, eax
push ebp ; continue the linked list of ebp's
mov eax, [esp + 8]
push eax ; push second param for "ret" to work
mov ecx, 4
loop_stack:
mov edx, [ebx + 4*ecx]
push edx
dec ecx
loop_bottom:
cmp ecx, 1
jne loop_stack
ret
it is called from the scheduler function at the end (after the register restoring memcpy), like this:
Code: Select all
// set the registers from the current thread's saved state
memcpy(r, &(thread_running->state_reg), sizeof(registers));
set_stack_ptr(r->esp, r->eip);
}