What is the window nesting limit?

Date:December 18, 2003 / year-entry #167
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20031218-00/?p=41453
Comments:    10
Summary:In the old days, Windows didn't bother enforcing a nesting limit because, well, if you want to nest windows 200 deep, that's your decision. Many window operations are recursive, but since everything happened on the application's stack, it was your own responsibility to make your stack big enough so it didn't overflow. But Windows NT...

In the old days, Windows didn't bother enforcing a nesting limit because, well, if you want to nest windows 200 deep, that's your decision. Many window operations are recursive, but since everything happened on the application's stack, it was your own responsibility to make your stack big enough so it didn't overflow.

But Windows NT moved the window manager off the application stack (first into a separate process, then into kernel mode). So now the OS needs to watch out for stack overflow attacks from people creating too many nested windows.

The window nesting limit was set to 100 for the early days of Windows NT. For Windows XP, it dropped to 50 because increased stack usage in some internal functions caused us to overflow at around 75. Dropping to 50 created some breathing room.

Disclaimer: I was not personally involved in this issue. I'm just reporting what I was able to figure out from reading checkin logs.


Comments (10)
  1. Ian Hanschen says:

    I wish *some* checkin logs(e.g. wmgr) were public, would make an interesting read.

  2. joe says:

    Check in to where? Are you using SourceSafe?

  3. Ian Ringrose. says:

    I have only know of one, did other people hit this problem?

    ianr at bigfoot dot com

  4. Jeroen-bart Engelen says:

    AFAIK Microsoft doesn’t use SourceSafe for OS development. They have their own special software.

  5. (6) says:

    Last I heard Microsoft used a Perforce derivative. I suppose the problem with publishing some checkin notes is it provides information about the Windows internals which Microsoft may not wish to divulge (particularly mid-development when anything can change, or be dropped)

  6. asdf says:

    I can’t imagine any apps needing more than 10 nested windows (and I’m being generous there). Ian, what kind of app ran into this problem so I can stay far, far away from that company?

  7. Mike Dimmick says:

    You can find some (limited) information about MS’ source control system (SourceDepot) in a talk that Mark Lucovsky gave at Usenix’s 4th Windows Systems Symposium. You can find the slides at http://www.usenix.org/events/usenix-win2000/invitedtalks/lucovsky.ppt.

    Apparently some teams do use SourceSafe, but the OS team is not one of them.

  8. Ian Hanschen says:

    Raymond,

    As a test(I’m interested in oditties concerning the window manager, it’s an obsession..) I wrote an app to test the recursion limit. When creating the 48th window, the cardinal checking for DCBAABCD in callwindowproc from keusermodecallback failed. I would guess the top parent could be considered a child of the desktop itself, but the stack is still being eaten before 50 windows are hit(and it seems to be the temp stack put together by keusermodecallback). That’s with the uxtheme hooks enabled though, so it’s possible that the extra stack overhead there is the cause.

  9. Jordan Russell says:

    Windows 2000 (SP4) also appears to have a limit of 50.

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index