Is it possible for one thread to corrupt the stack of another thread by directly modifying the stack address ? How are thread local variables implemented to provide access safety ?
But the child threads stack is different from main thread.
Child Threads' statck consists of the VMA got from mmap. And the it's protected by mprotect(NONE) when segmentfault
main thread's stack is protected by kernel when segmentfault.
Nope, all threads share a common heap, however, each thread has a private stack, and a red zone is appended for each stack
Since each thread has individual stack space, it is not possible to modify another thread's stack variable. Each stack is protected by a boundary and it also stores the start address, current stack pointer and few other information-variables location at the edge. which protects the another thread's stackoverflow modifying stack variables.
Yes, a thread can modify the stack contents of another thread if they are in the same process. Stack is simply a region of memory in the process's address space and all threads of that process have same access rights to all its memory regions.
For TLS, the compiler places all TLS variables in .tdata section. For each thread, the .tdata is copied to a new memory location. When threads switch, the .tdata is also switched.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.