堆栈指针在几个进程中是如何工作的? [英] How does the stack pointer work in several processes?

查看:39
本文介绍了堆栈指针在几个进程中是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我之前所理解的,每个进程都有自己的地址空间,称为虚拟地址空间或程序存储器,每个进程都有一个称为堆栈的位置,用于存储函数的局部变量和参数.

As I understood before, each process has its own address space called vitual address space or program memory, and every process has a location called stack which is used to store local variables and parameters of a function.

此外,当发生异常时,处理器(比如 ARM cortex-A)会切换到特权模式,然后分支到异常处理程序.

Also, when an exception occurs the processor (say an ARM cortex-A) switches to privileged mode and then branches to the exception handler.

据我了解,大多数应用程序运行在非特权用户模式下,这种模式有一个特殊的寄存器叫做栈指针,用来保存栈顶地址;但这是一个单独的寄存器,实际上不能同时保存多个进程的栈顶地址.你能解释一下实际发生的情况吗?

According to what I understood, most applications run in non-privileged user mode, and this mode has a special register called stack pointer to hold the address of top of the stack; but this is a single register and can't actually hold the address of top of the stack of several processes at the same time. Would you please explain what actually happens?

推荐答案

至于所有寄存器,一旦操作系统决定是另一个进程运行的时间(上下文切换");就好像它拍摄了当前处理器状态的快照.

As for all registers, it's saved and put away in a data structure associated to the process once the OS decides it's time for another process to run ("context switch"); it's as if it took a snapshot of the current processor state.

当进程再次被调度时,所有的寄存器(包括指令指针)都被恢复,并像什么也没发生一样继续执行.

When the process is scheduled again, all registers are restored (including the instruction pointer) and execution resumes as if nothing happened.

据我了解,大多数应用程序运行在非特权用户模式下,这种模式有一个特殊的寄存器叫做栈指针,用来保存栈顶地址

According to what I understood, most applications run in non-privileged user mode, and this mode has a special register called stack pointer to hold the address of top of the stack

堆栈指针不是特定于用户模式的,处理器总是拥有(并且可以使用)它,而不管模式如何.

The stack pointer is not specific of user mode, the processor always has (and can use) it, regardless of the mode.

这篇关于堆栈指针在几个进程中是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆