On Thu, 19 Mar 2020 16:53:32 +0800, ", Samuel" said:
movl $0xffffe000,%ecx or 0xfffff000 for 4KB stacks andl %esp,%ecx movl %ecx,p
Why is *"stack pointer(esp) & 0xffffe000"* equal to the process descriptor base address?
That means the base address of process descriptor is always *0xXYZ...000*, right? It is weird.
It's not at all weird if the kernel, when allocating the stack space to begin with, asked for 1 (or 2 contiguous) 4K chunks of memory, at a page-aligned address.... For example, see kernel/fork.c: 238 /* 239 * Allocated stacks are cached and later reused by new threads, 240 * so memcg accounting is performed manually on assigning/releasing 241 * stacks to tasks. Drop __GFP_ACCOUNT. 242 */ 243 stack = __vmalloc_node_range(THREAD_SIZE, THREAD_ALIGN, 244 VMALLOC_START, VMALLOC_END, 245 THREADINFO_GFP & ~__GFP_ACCOUNT, 246 PAGE_KERNEL, 247 0, node, __builtin_return_address(0)); I'll leave figuring out what THREAD_ALIGN is set to, as an exercise for the student. :)