Goランタイムが管理するスタックの種類
This content is a draft and will not be included in production builds.
スタックはいくつか種類がある。ゴルーチンごとに管理するスタックはg.stackにセットされる。プロセッサ(P)もスタックを持っていて、これはシグナルハンドラ等で使われるらしい?分からない。
https://groups.google.com/g/golang-nuts/c/M74ufF_Ot0w
ユーザーのゴルーチンからm0を参照するときはruntime.mcallを呼ぶ https://github.com/golang/go/blob/master/src/runtime/asm_amd64.s#L443
このとき重要なレジスタを退避していて、使い終わったらruntime.gogoで元に戻る。 https://github.com/golang/go/blob/master/src/runtime/asm_amd64.s#L420
morestackでゴルーチン固有のスタックを拡張する。 https://github.com/golang/go/blob/master/src/runtime/asm_amd64.s#L595
実際はnewstackとcopystackが主要な関数 newstack https://github.com/golang/go/blob/master/src/runtime/stack.go#L1093 copystack https://github.com/golang/go/blob/master/src/runtime/stack.go#L1093
m0 は基本的に拡張しないが、ゴルーチン固有のスタックは必要に応じて伸縮する。