emach hang problem: sbrk weirdness in cygwin 1.5.20?

Sean M. Paus spaus@pobox.com
Wed Sep 27 23:30:00 GMT 2006


I recently upgraded to cygwin 1.5.21-1.  Once doing so I noticed that I
could no longer run emacs.  emacs would hang and take up around 90-99%
of the cpu.  Attaching a debugger, I noticed that one of the threads
appeared to be in an infinite loop.

I downloaded the emacs source, rebuilt it (debug) and noticed that the
same problem would occur during the build process when
bootstrap-emacs.exe was run.

At this point I attached gdb, finding that one of the threads was in an
infinite loop in morecore.  Apparently, the call to align returned a
result that was smaller than the base of the heap.

I further tracked this down to the result of __sbrk in __default_morecore.

Prior to running bootstrap_emacs.exe, another emacs executable
(temacs.exe) ran without error.  This confused me until I determined
that __default_morecore was invoking bss_sbrk instead of __sbrk.

Now, it's still confusing that bss_sbrk is working while __sbrk is not,
but at least it narrows down the result of the problem.

For example, __sbrk would return a result of 0x642000 while _heapbase
had a value of 0x203f4000.

Here's essentiall what the loop in morecore does to compute newsize:

  newsize = heapsize;
  do
    newsize *= 2;
  while ( BLOCK( result + size ) > newsize);

where result is returned by (ultimately) __sbrk, size is the extra space
requested, newsize is the actual amount to grow, and BLOCK calculates
the block number relative to _heapbase.  heapsize usually starts around
1024.

The problem is, if result < _heapbase, BLOCK returns a huge number
(~4gig in my case).  If new size starts at 1024, it will continue to
double until it's greater than BLOCK(result+size).  If at some point
newsize is slightly less than BLOCK(result+size) doubling new size
causes an overflow and set's newsize to zero.  Infinite loop.

Anybody got a clue as to why __sbrk might be returning a value that is
so clearly wrong?

I've attached my sysinfo if that will help.

Sean
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sysinfo.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20060927/ce7cc6a2/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20060927/ce7cc6a2/attachment.sig>


More information about the Cygwin mailing list