How segmented stacks work

How do segmented stacks work? This question also applies Boost.Coroutine, so I also use the C ++ tag. The main doubt comes from this article . It seems that they occupy some space at the bottom of the stack and check if it is damaged by registering some signal processor with the memory allocated there (maybe through mmapand mprotect?). Then, when they discover that they have run out of free space, they continue to allocate more memory, and then continue from there. 3 questions about this

  • Isn't this a user space construct? How do they control where the new stack is located, and how do the instructions compiled by the program to find out about it?

    The push command basically just adds the value to the stack pointer, and then stores the value in a register on the stack, and then how the push command can know where the new stack starts, and accordingly, how the pop can know when it should move the stack pointer back to the old stack ?

  • They also say

    After we have a new stack segment, we restart goroutineby repeating the function that caused us to end the stack

    what does it mean? Do they restart all goroutine? Could this be the cause of non-deterministic behavior?

  • How do they detect a program overflowing the stack? If they save the memory area of ​​the canary area below, then what happens when the user program creates an array large enough to overflow this? Could this lead to a stack overflow and potential security vulnerabilities?

Go Boost , , 🙂

+6
1

.

-, , . , , , , . , 4k , 4k - 1 , .

. , , . , , . , , , - upcall - , UNIX.

( ) , , , , . , , , , . , , , , , . ( .)

, , -, , , . , , , . ( , . , , .)

, unchaining , , unchains . , , , - .

, . , , , , , .

, , Go . proog , , .

Go 1.3 , . , , . . , . .

. (, . . , .)

, - . Go , , . , , C , , , . ( , C , , .)

, , , . , . , Go, , , alloca , .

+5

All Articles