(or click "past" under the title, also helpful to check when you submit a link)
I say all of this in the past tesnse, since Meltdown makes it possible to read all that kernel memory. Kernels now keep most of the kernel memory unmapped when user mode is executing.
Can you elaborate on what you mean be x86 requires that the kernel stack always be mapped into a process address space in order for system calls?
The kernel always knows where a process's kernel stack is located as there is a pointer to it in the user process's task_struct. It is only in kernel mode that the kernel switches the CPU's stack pointer to use that that processes kernel stack.
>It is also possible to create an anonymous memory mapping that does not correspond to any files, being used instead for program data."
This isn't strictly true though is it? It was my understanding even mmap() MAP_ANONYMOUS used a file interface, and that the way the kernel creates anonymous maps is by creating an instance of /dev/zero in tmpfs. Although I believe the file descriptor might be ignored however.
You're totally right though, that threads complicated the traditional "stack grows down heap grows up" view of a Unix user address space.
- If a process has many threads, their stacks are all located within a single virtual address space corresponding to the user process?
- If one thread grows down and is about to overwrite the top of another thread's stack, does the OS detect this automatically and do some sort of reallocation procedure?
That's right there together with the city states of Greece and other ancient memories. Meltdown and Specter happened.