进程地址空间和线性区 。进程最多能访问4GB的线性地址空间 ·但进程在访问某个线性空间之前,必须获得该线性空间的许可 。因此,一个进程的地址空间是由允许该进程访问的全部线性地 址组成 ·内核使用线性区资源来表示线性地址空间 。每个线性区由起始线性地址、长度和一些存取权限描述 口40是42在月0C 陈香兰(x1 anchenoustc,edu.cn)(计算丸应L1nux操作看统分析Chapter9 Linux中的选权: November 4.2014 5/27
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 进程地址空间和线性区 进程最多能访问4GB的线性地址空间 但进程在访问某个线性空间之前,必须获得该线性空间的许可 因此,一个进程的地址空间是由允许该进程访问的全部线性地 址组成 内核使用线性区资源来表示线性地址空间 每个线性区由起始线性地址、长度和一些存取权限描述 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 Linux中的进程地址空间 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 5 / 27
与进程地址空间相关的描述符 Figure 8-2.Descriptors related to the address space of a process Linear Address Space Memory Regions mmap mmap_cache →vmstart ---→vm_end >vm next Memory Descriptor 1口t4四1是42刀00 陈香兰(x1 anchenoustc,edu,cn)(计算丸应Linux操作看统分所Chapter9 Linux中的边权: November-4,20146/23
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 与进程地址空间相关的描述符 Figure 8-2. Descriptors related to the address space of a process Linear Address Space Memory Regions Memory Descriptor mmap mmap_cache vm_next vm_end vm_start 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 Linux中的进程地址空间 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 6 / 27
与进程地址空间相关的描述符 ●线性区的开始和结束都必须4KB对齐 ©进程获得新线性区的一些典型情况: ●刚刚创建的新进程 。使用exec系统调用装载一个新的程序运行 。将一个文件(或部分)映射到进程地址空间中 。当用户堆栈不够用的时候,扩展堆栈对应的线性区 ●… 1口4四是42,刀00 陈香兰(x1 anchenoustc,edu,cn)(计算丸应L1nux操作看统分所Chapter9 Linux中的过权: None0er4,20146/29
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 与进程地址空间相关的描述符 线性区的开始和结束都必须4KB对齐 进程获得新线性区的一些典型情况: 刚刚创建的新进程 使用exec系统调用装载一个新的程序运行 将一个文件(或部分)映射到进程地址空间中 当用户堆栈不够用的时候,扩展堆栈对应的线性区 …… 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 Linux中的进程地址空间 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 6 / 27
与创建、删除线性区相关的系统调用 brk() 改变进程堆的大小 execve() Loads a new executable file,thus changing the process address space exit() Terminates the current process and destroys its address space fork() Creates a new process,and thus a new address space mmap() Creates a memory mapping for a file,thus mmap2() enlarging the process address space mremap() 扩大或缩小线性区 remap file pages( Creates a non-linear mapping for a file munmap() Destroys a memory mapping for a file,thus contracting the process address space shmat() Attaches a shared memory region shmdt() Detaches a shared memory region 1口4四是14P定刀00 陈香兰(xianchenoustc,edu,cn)(计算丸应L1nux操作系统分析Chapter9 Linux中的边权. November 4.2014 7/27
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 与创建、删除线性区相关的系统调用 brk( ) 改变进程堆的大小 execve( ) Loads a new executable file, thus changing the process address space _exit( ) Terminates the current process and destroys its address space fork( ) Creates a new process, and thus a new address space mmap( ) Creates a memory mapping for a file, thus mmap2( ) enlarging the process address space mremap( ) 扩大或缩小线性区 remap_file_pages( ) Creates a non-linear mapping for a file munmap( ) Destroys a memory mapping for a file, thus contracting the process address space shmat( ) Attaches a shared memory region shmdt( ) Detaches a shared memory region 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 Linux中的进程地址空间 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 7 / 27
线性区(memory area) 。比如0x08048000一0x0804C000这段线性地址空间被分配给了 一个进程,进程就可以访问这段地址空间 ●进程只能访问某个有效的memory area。进一步讲,这个area 可以被标志为只读或者不可执行(nonexecutable) ●如果进程试图访问一个有效的area之外的地址或者用不正确的 方式访问一个有效的area,内核将通过段异常(segmentation fault)杀死这个进程 1口+4四1是4P在刀0C 陈香兰(x1 anchenoustc,edu,cn)(计算丸应L1nux操作看统分析Chapter9 Linux中的达权: November 4.2014 8 /27
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 线性区(memory area) 比如0x08048000–0x0804C000这段线性地址空间被分配给了 一个进程,进程就可以访问这段地址空间 进程只能访问某个有效的memory area。进一步讲,这个area 可以被标志为只读或者不可执行(nonexecutable) 如果进程试图访问一个有效的area之外的地址或者用不正确的 方式访问一个有效的area,内核将通过段异常(segmentation fault)杀死这个进程 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 Linux中的进程地址空间 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) November 4, 2014 8 / 27