GNU bug report logs - #9273
23.3; malloc initialization should (sometimes) happen at runtime

Previous Next

Package: emacs;

Reported by: Ken Brown <kbrown <at> cornell.edu>

Date: Tue, 9 Aug 2011 20:12:02 UTC

Severity: normal

Found in version 23.3

Done: Ken Brown <kbrown <at> cornell.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Ken Brown <kbrown <at> cornell.edu>
Subject: bug#9273: closed (Re: bug#9273: 23.3;	malloc initialization
 should (sometimes) happen at runtime)
Date: Tue, 16 Aug 2011 13:33:04 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#9273: 23.3; malloc initialization should (sometimes) happen at runtime

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 9273 <at> debbugs.gnu.org.

-- 
9273: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9273
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Ken Brown <kbrown <at> cornell.edu>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 9273-done <at> debbugs.gnu.org
Subject: Re: bug#9273: 23.3;	malloc initialization should (sometimes) happen
	at runtime
Date: Tue, 16 Aug 2011 09:30:31 -0400
I've committed the changes and am closing the bug.

Ken

[Message part 3 (message/rfc822, inline)]
From: Ken Brown <kbrown <at> cornell.edu>
To: bug-gnu-emacs <at> gnu.org
Subject: 23.3; malloc initialization should (sometimes) happen at runtime
Date: Tue, 09 Aug 2011 16:09:48 -0400
The code in src/gmalloc.c makes assumptions about how a system maintains 
its memory that are not necessarily valid.  In particular, they will not 
be valid on Cygwin starting with version 1.7.10 (which will almost 
certainly be released before emacs 24.1).  The problem is that malloc 
initialization is done by temacs, and the results are dumped into emacs. 
 This includes the setting __malloc_initialized = 1, so no malloc 
initialization is done when emacs is run.  But the dumped value of 
_heapbase, while appropriate for temacs, may not point to the beginning 
of the runtime heap for emacs.  This causes all code that uses the BLOCK 
and ADDRESS macros to be invalid.

Here's what happens on Cygwin.  temacs (on Cygwin) uses a static buffer 
as its heap and a function bss_sbrk that simulates sbrk.  (See 
src/sheap.c.)  The data in this buffer, including malloc information, 
are then dumped into emacs.exe as initialized data.  But when the dumped 
emacs is run, it uses Cygwin's sbrk, which allocates memory on a heap 
that won't (as of Cygwin 1.7.10) be contiguous with the static heap. 
The saved value of _heapbase, which points into the static heap, is 
never changed, but it will mess up later calculations as soon as sbrk is 
called for the first time.

All of this is described in detail on the Cygwin mailing list in the 
thread starting at

  http://cygwin.com/ml/cygwin/2011-08/msg00153.html

See especially

  http://cygwin.com/ml/cygwin/2011-08/msg00193.html

which contains a gdb session illustrating the problem.  The context for 
that session is that, as a result of the problem I'm reporting, 
morecore_nolock went into an infinite loop.  I attached gdb to that 
looping process.

Maybe the solution is for emacs to do malloc initialization, including 
the assignment of _heapbase, every time it starts, at least on systems 
that use gmalloc.c.  I made one naive attempt to do this, but it didn't 
work (and it was Cygwin specific).  Namely, I made unexec (for Cygwin) 
set _malloc_initialized = 0 before dumping.  The resulting emacs aborted 
as soon as it was started.  I haven't figured out what went wrong, but 
I'm not sure that's the right answer anyway.

Ken



This bug report was last modified 14 years and 1 day ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.