+ // #6 Create kernel stack
+ // tThread->KernelStack is the top
+ // There is 1 guard page below the stack
+ kstackbase = Proc_GetCurThread()->KernelStack - KERNEL_STACK_SIZE;
+
+// Log("MM_Clone: kstackbase = %p", kstackbase);
+
+ TMPMAPLVL4(MM_KSTACK_BASE >> PML4_SHIFT) = 0;
+ for( i = 1; i < KERNEL_STACK_SIZE/0x1000; i ++ )
+ {
+ tPAddr phys = MM_AllocPhys();
+ tVAddr tmpmapping;
+ MM_MapEx(kstackbase+i*0x1000, phys, 1, 0);
+
+ Log_Debug("MM", "MM_Clone: Cloning stack page %p from %P to %P",
+ kstackbase+i*0x1000, MM_GetPhysAddr( kstackbase+i*0x1000 ), phys
+ );
+ tmpmapping = MM_MapTemp(phys);
+ if( MM_GetPhysAddr( kstackbase+i*0x1000 ) )
+ memcpy((void*)tmpmapping, (void*)(kstackbase+i*0x1000), 0x1000);
+ else
+ memset((void*)tmpmapping, 0, 0x1000);
+// if( i == 0xF )
+// Debug_HexDump("MM_Clone: *tmpmapping = ", (void*)tmpmapping, 0x1000);
+ MM_FreeTemp(tmpmapping);
+ }
+
+// MAGIC_BREAK();
+
+ // #7 Return