下面是copy-on-write之后和之前的内存页,copy-on-write之前0x401ee50位于user_stack[]数组内。user_stack地址:0x1de6c。0x1ee5c处的地址0x5412既head.s中L6的地址:$L6。
copy-on-write之后位于0xffd000-0xffe000对应的内存页中。
下面是copy-on-write之前和之后页表项的变化:
看来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.
*/