スタックサイズの制限に達すると、プロセッサがオペレーティングシステムにTRAPを引き起こしません(したがって、スタックオーバーフローを防止する:P)プログラムスタックが本当にオーバーフローしますか?
2
A
答えて
1
私は、Windowsにスタックが伸びていると思います。
Visual Studioコンパイラでは、これを担当するコードはchkstk.objモジュールにあります。
このコードはオープンソースですので、私はそれをここに投稿することができます:どのようなプロセッサ上で
;***
;_chkstk - check stack upon procedure entry
;
;Purpose:
; Provide stack checking on procedure entry. Method is to simply probe
; each page of memory required for the stack in descending order. This
; causes the necessary pages of memory to be allocated via the guard
; page scheme, if possible. In the event of failure, the OS raises the
; _XCPT_UNABLE_TO_GROW_STACK exception.
;
; NOTE: Currently, the (EAX < _PAGESIZE_) code path falls through
; to the "lastpage" label of the (EAX >= _PAGESIZE_) code path. This
; is small; a minor speed optimization would be to special case
; this up top. This would avoid the painful save/restore of
; ecx and would shorten the code path by 4-6 instructions.
;
;Entry:
; EAX = size of local frame
;
;Exit:
; ESP = new stackframe, if successful
;
;Uses:
; EAX
;
;Exceptions:
; _XCPT_GUARD_PAGE_VIOLATION - May be raised on a page probe. NEVER TRAP
; THIS!!!! It is used by the OS to grow the
; stack on demand.
; _XCPT_UNABLE_TO_GROW_STACK - The stack cannot be grown. More precisely,
; the attempt by the OS memory manager to
; allocate another guard page in response
; to a _XCPT_GUARD_PAGE_VIOLATION has
; failed.
;
;*******************************************************************************
public _alloca_probe
_chkstk proc
_alloca_probe = _chkstk
push ecx
; Calculate new TOS.
lea ecx, [esp] + 8 - 4 ; TOS before entering function + size for ret value
sub ecx, eax ; new TOS
; Handle allocation size that results in wraparound.
; Wraparound will result in StackOverflow exception.
sbb eax, eax ; 0 if CF==0, ~0 if CF==1
not eax ; ~0 if TOS did not wrapped around, 0 otherwise
and ecx, eax ; set to 0 if wraparound
mov eax, esp ; current TOS
and eax, not (_PAGESIZE_ - 1) ; Round down to current page boundary
cs10:
cmp ecx, eax ; Is new TOS
jb short cs20 ; in probed page?
mov eax, ecx ; yes.
pop ecx
xchg esp, eax ; update esp
mov eax, dword ptr [eax] ; get return address
mov dword ptr [esp], eax ; and put it at new TOS
ret
; Find next lower page and probe
cs20:
sub eax, _PAGESIZE_ ; decrease by PAGESIZE
test dword ptr [eax],eax ; probe page.
jmp short cs10
_chkstk endp
end
+0
ありがとうございます。ガードページは、スタックのオーバーフロー時にSPが流入すると思いますか? OSはこれを検出し、さらにページを割り当てますか?また、スタックに必要なメモリの各ページを降順で調べます。うーん...何の降順で? –
関連する問題
- 1. HTMLとCSSを使用して本文にオーバーフローしますか?
- 2. 本当にモーダルウィンドウが可能ですか?
- 3. 本当にlibgccが必要ですか?
- 4. Iphoneいつ操作キュースレッドが本当に開始しますか?
- 5. スウィフトNSURLSession本当に本当に遅い
- 6. 何かが本当であれば通知しますか?
- 7. レイトレーシングについては本当に良い本がありますか?
- 8. スプリングツールスイートが本当に遅く
- 9. ここに本当に必要なバンパターンがありますか?
- 10. Googleアナリティクススパマーには本当に危険がありますか?
- 11. は本当に
- 12. JavaScript []は本当にどのように機能しますか?
- 13. font-sizeは本当に何に対応していますか?
- 14. 私のサービスオブジェクトは本当にエンティティパッケージに属していますか?
- 15. IDEは本当に価値がありますか?
- 16. DataReaderと比較してDataSetが本当に遅いですか?
- 17. 本当の理由がないのにRailsテストが失敗しますか?
- 18. function(){}は本当ですか?
- 19. が本当に遅いです(PostgreSQLの)
- 20. このテストは本当に価値を追加しますか?
- 21. ネイティブは本当にAndroidフラグメントをサポートしていますか?
- 22. 本当にC#で 'using'ブロックを使用していますか?
- 23. data-ajax = "false"は本当に何をしますか?
- 24. Railsは本当にデータベースクエリをキャッシュしますか?
- 25. Bluetooth HDP android 4.0は本当に機能しますか?
- 26. OAuth 2クライアントは本当にTLSを必要としますか?
- 27. GRASP Creatorは本当に切り離していますか?
- 28. MemoryBarrierは本当にリフレッシュ値を保証しますか?
- 29. React.js tic-tac-toe。 `キー`は本当に機能しますか?
- 30. SparkのAPI newHadoopRDDは本当に何をしていますか?
を?そのOSで? OSがあっても?このような一般的な質問では、答えは可能です。はい、スタックがオーバーフローする可能性があります。 – Ernstsson