为什么要通过寄存器将参数传递给 `__switch_to` 函数?
Why passing parameters to `__switch_to` function through registers?
为什么函数 __switch_to
声明为通过寄存器获取参数(而不是按照惯例通过堆栈获取参数)?
extern void FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
这可能与我们 return 从它变成 ret_from_fork
而不是标记 1
的情况有关?怎么样?
源代码:
https://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/include/asm-i386/system.h
(是的,我知道它很旧,我想知道是什么原因)
简而言之,当您谈论 'the stack' 时,您实际上是在谈论 'the stack of the current process',并且在所有正常情况下,您不需要指定这一点。但是对于 __switch_to() 来说,没有 'the current process' 这样的东西,因为这个函数的目的是从一个进程切换到另一个进程。
在进入时有一个当前进程,在退出时有另一个进程但是(或者至少看起来是这样)但在两者之间它只是操作执行指令来保存旧进程的 CPU 上下文(在其堆栈上)并恢复新进程的 CPU 上下文(从其堆栈)。
使用堆栈只会带来麻烦。
现在看来,我觉得不是不行,就是没用。
为什么函数 __switch_to
声明为通过寄存器获取参数(而不是按照惯例通过堆栈获取参数)?
extern void FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
这可能与我们 return 从它变成 ret_from_fork
而不是标记 1
的情况有关?怎么样?
源代码: https://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/include/asm-i386/system.h
(是的,我知道它很旧,我想知道是什么原因)
简而言之,当您谈论 'the stack' 时,您实际上是在谈论 'the stack of the current process',并且在所有正常情况下,您不需要指定这一点。但是对于 __switch_to() 来说,没有 'the current process' 这样的东西,因为这个函数的目的是从一个进程切换到另一个进程。 在进入时有一个当前进程,在退出时有另一个进程但是(或者至少看起来是这样)但在两者之间它只是操作执行指令来保存旧进程的 CPU 上下文(在其堆栈上)并恢复新进程的 CPU 上下文(从其堆栈)。
使用堆栈只会带来麻烦。
现在看来,我觉得不是不行,就是没用。