all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#9273: 23.3; malloc initialization should (sometimes) happen at runtime
@ 2011-08-09 20:09 Ken Brown
  2011-08-10  0:24 ` Richard Stallman
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Ken Brown @ 2011-08-09 20:09 UTC (permalink / raw)
  To: 9273

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





^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2011-08-16 13:30 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-09 20:09 bug#9273: 23.3; malloc initialization should (sometimes) happen at runtime Ken Brown
2011-08-10  0:24 ` Richard Stallman
2011-08-10 15:56 ` Eli Zaretskii
2011-08-10 17:52   ` Ken Brown
2011-08-10 18:10     ` Eli Zaretskii
2011-08-10 18:49       ` Ken Brown
2011-08-11 21:45   ` Ken Brown
2011-08-12  6:54     ` Eli Zaretskii
2011-08-12 10:10       ` Ken Brown
2011-08-12 11:33         ` Eli Zaretskii
2011-08-12 12:18           ` Ken Brown
2011-08-12 20:24             ` Ken Brown
2011-08-13  8:05               ` Eli Zaretskii
2011-08-13 13:48                 ` Ken Brown
2011-08-13 14:41                   ` Eli Zaretskii
2011-08-13 14:53                     ` Ken Brown
2011-08-13 15:07                       ` Stefan Monnier
2011-08-13 15:33                         ` Ken Brown
2011-08-13 19:19                           ` Stefan Monnier
2011-08-14  3:13                             ` Ken Brown
2011-08-16 13:30                               ` Ken Brown
2011-08-12 23:51 ` grischka

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.