Linux 内核堆栈

发布于 2024-10-12 08:12:32 字数 64 浏览 8 评论 0原文

进程的内核模式堆栈中存储什么样的数据?进程的“用户模式”调用链是否存储在内核堆栈中?

谢谢, 维杰

What kind of data is stored in the Kernel mode stack of a process ? Is a processes "user mode" call chain stored in the kernel stack ?

Thanks,
vIjay

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぇ气 2024-10-19 08:12:32

你的内核调用链,和“不”


Linux内核本身就是一个线程程序,它通过切换堆栈来工作。

因此,假设您执行了 read(0, space, 100); ,或者只是执行了 c = getchar(); ,这最终会变成 read ()。

当linux获得控制权时,它将开始进行函数调用,自然地使用内核堆栈。它将在内核中进行越来越低的调用,直到最终到达 tty 或网络层。

但您还没有输入任何内容!

因此,它只是切换到另一个进程,一个真正可运行的进程,并将所有这些函数调用激活帧留在堆栈上。最终,您输入一些内容,内核发现您的进程现在可以运行,当它切换回来时,再次切换堆栈,所有这些实现 read(2) 的函数调用现在都可以展开并最终返回到用户模式。

Your kernel call chain, and "no"


The linux kernel is itself a threaded program which works by switching stacks.

So, let's say you do read(0, space, 100);, or perhaps just c = getchar();, which will eventually turn into a read().

When linux gets control it will start making function calls, naturally using the kernel stack. It will make calls lower and lower in the kernel until it finally gets to a tty or network layer.

But you haven't typed anything yet!

So it simply switches to another process, one that really is runnable, and it leaves all those function call activation frames on the stack. Eventually you type something and the kernel figures out that your process is now runnable, and when it switches back, again switching stacks, all of those function calls implementing your read(2) can now unwind and eventually return to user mode.

故事还在继续 2024-10-19 08:12:32

当进程进入内核模式时[由于系统调用或故障等异常,或者由于硬件中断],将使用进程的内核模式堆栈。进程从进入内核模式到离开内核模式所执行的步骤序列称为内核控制路径。内核控制路径的状态信息存储在进程的内核模式堆栈中。另外,由于时间片过期,如果发生上下文切换,进程-CPU 寄存器的状态将存储在内核模式堆栈上,以便在 CPU 上重新调度进程时可以检索它们。

由于内核模式堆栈仅在进入内核模式时使用,因此“用户模式”调用链不存储在该堆栈中。

The kernel mode stack of a process is used when the process enters the kernel mode [because of an exception such as system call or fault, or because of a hardware interrupt]. The sequence of steps which the process executes when it enters the kernel mode until it leaves it, is called the kernel control path. State information for the kernel control path is stored in the kernel mode stack of the process. Also, say due to expired time slice, if a context switch occurs, the state of the process-cpu registers are stored on the kernel mode stack so that they can be retrieved when the process is rescheduled on the cpu.

Since the kernel mode stack is only used upon entering the kernel mode, the "user mode" call chain is not stored in this stack.

孤千羽 2024-10-19 08:12:32

这个问题显示了当进程从用户态到内核态

This question shows values that are stored in kernel stack when process transits from user mode to kernel mode

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文