main()
调用函数时。这意味着我实际上正在移动 sp,不是吗?(ps.env是jmp_buf的一种类型)
类似这样的:
if (setjmp(current_thread->env)==0){
longjmp(current_thread->env,*((int*)current_thread->stack_p));
}
结构线程:
struct thread {
void (*fp)(void *arg);
void *arg;
void *stack;
void *stack_p;
jmp_buf env; // for thread function
int buf_set; // 1: indicate jmp_buf (env) has been set, 0: indicate jmp_buf (env) not set
int ID;
struct thread *previous;
struct thread *next;
};
看看 swtch.S
extern void thread_switch(uint64 old, uint64 new);
thread_switch((uint64) ¤t_thread->previous->ctx, (uint64) ¤t_thread->ctx);