Date: Tue, 11 Feb 2003 08:01:52 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: djgpp-workers AT delorie DOT com Subject: Re: Checking for stack overflow In-Reply-To: <3E47CDCC.9330D67E@yahoo.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Mon, 10 Feb 2003, CBFalconer wrote: > > Assuming that esp > > has already decremented to point to the newly allocated space, > > the possible overflow is detected thus: > > I don't believe you should make any such assumption. You cannot > assume that anything called has stack checking code. I think you misunderstood what Esa was saying (or else I misunderstood it ;-). As I understand it, his code assumes to be called by GCC _after_ each change in ESP. There's no assumption that the calling code was compiled with stack checking. > So I > consider you should ONLY check at function entry, when stack space > is being allocated for locals. If I understand correctly, here you assume that the code generated by the compiler allocates space for locals only in the function prologue. This is not true for latest versions of GCC, especially under -On optimization options. Take a look at the code it emits, search for "esp", and you will see how many stack adjustments are done during a function's life.