This is the mail archive of the
cygwin-developers
mailing list for the Cygwin project.
Re: stack overflow bug in ofstream::operator<<
On Jun 30 13:15, Corinna Vinschen wrote:
> inline bool
> check_alloca (size_t size)
> {
> extern unsigned long _size_of_stack_reserve__;
> register char *_curstack __asm__ ("%esp");
> register size_t stacksize = pthread_self ()->attr.stacksize
> ?: (size_t) &_size_of_stack_reserve__;
> return (size_t) ((_curstack - (_tlsbase - stacksize)) / 65536) * 65536 > size;
> }
No, that's incorrect since pthread_self ()->attr.stacksize doesn't
determine the stacksize of the current thread.
However, on reading MSDN again, I found that it's simpler than that.
We can savely assume that the thread's stack is *at least* as big as
__size_of_stack_reserve__. See
http://msdn.microsoft.com/library/en-us/dllproc/base/thread_stack_size.asp
So the function can be simplified like this:
inline bool
check_alloca (size_t size)
{
extern unsigned long _size_of_stack_reserve__;
register char *_curstack __asm__ ("%esp");
return (size_t) ((_curstack - (_tlsbase - (size_t) &_size_of_stack_reserve__))
/ 65536) * 65536 > size;
}
Unfortunately SetThreadStackGuarantee() only exists beginning with 2K3 SP1.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader mailto:cygwin@cygwin.com
Red Hat, Inc.