linux-0.11,任务1的用户态堆栈,copy-on-write之后的堆栈!

下面是copy-on-write之和之的内存页,copy-on-write之前0x401ee50位于user_stack[]数组内user_stack地址:0x1de6c。0x1ee5c处的地址0x5412既head.s中L6的地址:$L6。

copy-on-write后位于0xffd000-0xffe000对应的内存页中。

linux-0.11,任务1的用户态堆栈,copy-on-write之后的堆栈!_第1张图片


下面是copy-on-write之前和之后页表项的变化:

linux-0.11,任务1的用户态堆栈,copy-on-write之后的堆栈!_第2张图片



看来Linus Torvalds的main.c中注释是不正确的。

/*
 *  linux/init/main.c
 *
 *  (C) 1991  Linus Torvalds
 */

#define __LIBRARY__
#include <unistd.h>
#include <time.h>

/*
 * we need this inline - forking from kernel space will result
 * in NO COPY ON WRITE (!!!), until an execve is executed. This
 * is no problem, but for the stack. This is handled by not letting
 * main() use the stack at all after fork(). Thus, no function
 * calls - which means inline code for fork too, as otherwise we
 * would use the stack upon exit from 'fork()'.
 *
 * Actually only pause and fork are needed inline, so that there
 * won't be any messing with the stack from main(), but we define
 * some others too.
 */

你可能感兴趣的:(linux-0.11,任务1的用户态堆栈,copy-on-write之后的堆栈!)