相关疑难解决方法(0)

进程虚拟地址空间中其他线程的堆栈在哪里?

下图显示了进程的各个部分在进程的虚拟地址空间中的布局(在Linux中):

在此处输入图片说明

您会看到只有一个堆栈部分(因为我假设该进程只有一个线程)。

但是,如果该进程有另一个线程,该第二个线程的堆栈将位于哪里呢?它会位于第一个堆栈的正下方吗?

linux x86 assembly process

4
推荐指数
1
解决办法
2066
查看次数

Analyzing memory mapping of a process with pmap. [stack]

I'm trying to understand how stack works in Linux. I read AMD64 ABI sections about stack and process initialization and it is not clear how the stack should be mapped. Here is the relevant quote (3.4.1):

Stack State

This section describes the machine state that exec (BA_OS) creates for new processes.

and

It is unspecified whether the data and stack segments are initially mapped with execute permissions or not. Applications which need to execute code on the stack or data …

c linux stack mmap linux-kernel

3
推荐指数
1
解决办法
2892
查看次数

使用“推”或“子” x86指令时如何分配堆栈内存?

我浏览了一段时间,试图例如在执行操作时了解如何将内存分配给堆栈:

push rax
Run Code Online (Sandbox Code Playgroud)

或者移动堆栈指针为子例程的局部变量分配空间:

sub rsp, X    ;Move stack pointer down by X bytes 
Run Code Online (Sandbox Code Playgroud)

据我了解,堆栈段在虚拟内存空间中是匿名的,即不是文件支持的。

我还了解的是,内核不会真正将匿名虚拟内存段映射到物理内存,直到程序对该内存段进行实际操作(即写入数据)为止。因此,尝试在写入该段之前先读取该段可能会导致错误。

在第一个示例中,如果需要,内核将在物理内存中分配一个帧页。在第二个示例中,我假设内核不会在程序实际将数据写入堆栈堆栈段中的地址之前将任何物理内存分配给堆栈段。

我在正确的轨道上吗?

linux memory memory-management x86-64

2
推荐指数
1
解决办法
452
查看次数

标签 统计

linux ×3

assembly ×1

c ×1

linux-kernel ×1

memory ×1

memory-management ×1

mmap ×1

process ×1

stack ×1

x86 ×1

x86-64 ×1