aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog26
-rw-r--r--src/gmalloc.c62
-rw-r--r--src/unexcw.c5
-rw-r--r--src/xdisp.c10
4 files changed, 97 insertions, 6 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index b16606ce121..ac9864f9f95 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,29 @@
12011-08-16 Ken Brown <kbrown@cornell.edu>
2
3 * gmalloc.c: Expand comment.
4
52011-08-16 Eli Zaretskii <eliz@gnu.org>
6
7 * xdisp.c (set_cursor_from_row): Don't accept a previous candidate
8 if it fails the cursor_row_p test. Fixes cursor positioning at ZV.
9
102011-08-16 Ken Brown <kbrown@cornell.edu>
11
12 Fix memory allocation problems in Cygwin build (Bug#9273).
13
14 * unexcw.c ( __malloc_initialized): Declare external variable.
15 (fixup_executable): Force the dumped emacs to reinitialize malloc.
16
17 * gmalloc.c [CYGWIN] (bss_sbrk_heapbase, bss_sbrk_heapinfo): New
18 variables.
19 (malloc_initialize_1) [CYGWIN]: Prepare for reinitializing the
20 dumped emacs.
21 (_free_internal_nolock) [CYGWIN]: Ignore requests to free storage
22 in the static heap.
23 [CYGWIN] (special_realloc): New function.
24 (_realloc_internal_nolock) [CYGWIN]: Use the new function on
25 requests to realloc storage in the static heap.
26
12011-08-15 Paul Eggert <eggert@cs.ucla.edu> 272011-08-15 Paul Eggert <eggert@cs.ucla.edu>
2 28
3 * bidi.c (bidi_initialize): Remove unused local. 29 * bidi.c (bidi_initialize): Remove unused local.
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 916bb300fe1..d49259b8ed7 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -351,10 +351,21 @@ Fifth Floor, Boston, MA 02110-1301, USA.
351#endif 351#endif
352#include <errno.h> 352#include <errno.h>
353 353
354/* How to really get more memory. */ 354/* On Cygwin there are two heaps. temacs uses the static heap
355#if defined(CYGWIN) 355 (defined in sheap.c and managed with bss_sbrk), and the dumped
356 emacs uses the Cygwin heap (managed with sbrk). When emacs starts
357 on Cygwin, it reinitializes malloc, and we save the old info for
358 use by free and realloc if they're called with a pointer into the
359 static heap.
360
361 Currently (2011-08-16) the Cygwin build doesn't use ralloc.c; if
362 this is changed in the future, we'll have to similarly deal with
363 reinitializing ralloc. */
364#ifdef CYGWIN
356extern __ptr_t bss_sbrk PP ((ptrdiff_t __size)); 365extern __ptr_t bss_sbrk PP ((ptrdiff_t __size));
357extern int bss_sbrk_did_unexec; 366extern int bss_sbrk_did_unexec;
367char *bss_sbrk_heapbase; /* _heapbase for static heap */
368malloc_info *bss_sbrk_heapinfo; /* _heapinfo for static heap */
358#endif 369#endif
359__ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size)) = __default_morecore; 370__ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size)) = __default_morecore;
360 371
@@ -584,6 +595,16 @@ malloc_initialize_1 ()
584 mcheck (NULL); 595 mcheck (NULL);
585#endif 596#endif
586 597
598#ifdef CYGWIN
599 if (bss_sbrk_did_unexec)
600 /* we're reinitializing the dumped emacs */
601 {
602 bss_sbrk_heapbase = _heapbase;
603 bss_sbrk_heapinfo = _heapinfo;
604 memset (_fraghead, 0, BLOCKLOG * sizeof (struct list));
605 }
606#endif
607
587 if (__malloc_initialize_hook) 608 if (__malloc_initialize_hook)
588 (*__malloc_initialize_hook) (); 609 (*__malloc_initialize_hook) ();
589 610
@@ -1054,6 +1075,12 @@ _free_internal_nolock (ptr)
1054 if (ptr == NULL) 1075 if (ptr == NULL)
1055 return; 1076 return;
1056 1077
1078#ifdef CYGWIN
1079 if (ptr < _heapbase)
1080 /* We're being asked to free something in the static heap. */
1081 return;
1082#endif
1083
1057 PROTECT_MALLOC_STATE (0); 1084 PROTECT_MALLOC_STATE (0);
1058 1085
1059 LOCK_ALIGNED_BLOCKS (); 1086 LOCK_ALIGNED_BLOCKS ();
@@ -1349,6 +1376,31 @@ Fifth Floor, Boston, MA 02110-1301, USA.
1349 1376
1350#define min(A, B) ((A) < (B) ? (A) : (B)) 1377#define min(A, B) ((A) < (B) ? (A) : (B))
1351 1378
1379/* On Cygwin the dumped emacs may try to realloc storage allocated in
1380 the static heap. We just malloc space in the new heap and copy the
1381 data. */
1382#ifdef CYGWIN
1383__ptr_t
1384special_realloc (ptr, size)
1385 __ptr_t ptr;
1386 __malloc_size_t size;
1387{
1388 __ptr_t result;
1389 int type;
1390 __malloc_size_t block, oldsize;
1391
1392 block = ((char *) ptr - bss_sbrk_heapbase) / BLOCKSIZE + 1;
1393 type = bss_sbrk_heapinfo[block].busy.type;
1394 oldsize =
1395 type == 0 ? bss_sbrk_heapinfo[block].busy.info.size * BLOCKSIZE
1396 : (__malloc_size_t) 1 << type;
1397 result = _malloc_internal_nolock (size);
1398 if (result != NULL)
1399 memcpy (result, ptr, min (oldsize, size));
1400 return result;
1401}
1402#endif
1403
1352/* Debugging hook for realloc. */ 1404/* Debugging hook for realloc. */
1353__ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size)); 1405__ptr_t (*__realloc_hook) PP ((__ptr_t __ptr, __malloc_size_t __size));
1354 1406
@@ -1375,6 +1427,12 @@ _realloc_internal_nolock (ptr, size)
1375 else if (ptr == NULL) 1427 else if (ptr == NULL)
1376 return _malloc_internal_nolock (size); 1428 return _malloc_internal_nolock (size);
1377 1429
1430#ifdef CYGWIN
1431 if (ptr < _heapbase)
1432 /* ptr points into the static heap */
1433 return special_realloc (ptr, size);
1434#endif
1435
1378 block = BLOCK (ptr); 1436 block = BLOCK (ptr);
1379 1437
1380 PROTECT_MALLOC_STATE (0); 1438 PROTECT_MALLOC_STATE (0);
diff --git a/src/unexcw.c b/src/unexcw.c
index f643c196de0..62df82ec3bc 100644
--- a/src/unexcw.c
+++ b/src/unexcw.c
@@ -33,6 +33,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33 33
34extern int bss_sbrk_did_unexec; 34extern int bss_sbrk_did_unexec;
35 35
36extern int __malloc_initialized;
37
36/* emacs symbols that indicate where bss and data end for emacs internals */ 38/* emacs symbols that indicate where bss and data end for emacs internals */
37extern char my_endbss[]; 39extern char my_endbss[];
38extern char my_edata[]; 40extern char my_edata[];
@@ -210,9 +212,12 @@ fixup_executable (int fd)
210 lseek (fd, (long) (exe_header->section_header[i].s_scnptr), 212 lseek (fd, (long) (exe_header->section_header[i].s_scnptr),
211 SEEK_SET); 213 SEEK_SET);
212 assert (ret != -1); 214 assert (ret != -1);
215 /* force the dumped emacs to reinitialize malloc */
216 __malloc_initialized = 0;
213 ret = 217 ret =
214 write (fd, (char *) start_address, 218 write (fd, (char *) start_address,
215 my_endbss - (char *) start_address); 219 my_endbss - (char *) start_address);
220 __malloc_initialized = 1;
216 assert (ret == (my_endbss - (char *) start_address)); 221 assert (ret == (my_endbss - (char *) start_address));
217 if (debug_unexcw) 222 if (debug_unexcw)
218 printf (" .bss, mem start 0x%08x mem length %d\n", 223 printf (" .bss, mem start 0x%08x mem length %d\n",
diff --git a/src/xdisp.c b/src/xdisp.c
index 79cab8c558c..b26d844cdf2 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -13812,11 +13812,13 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13812 /* that candidate is not the row we are processing */ 13812 /* that candidate is not the row we are processing */
13813 && MATRIX_ROW (matrix, w->cursor.vpos) != row 13813 && MATRIX_ROW (matrix, w->cursor.vpos) != row
13814 /* Make sure cursor.vpos specifies a row whose start and end 13814 /* Make sure cursor.vpos specifies a row whose start and end
13815 charpos occlude point. This is because some callers of this 13815 charpos occlude point, and it is valid candidate for being a
13816 function leave cursor.vpos at the row where the cursor was 13816 cursor-row. This is because some callers of this function
13817 displayed during the last redisplay cycle. */ 13817 leave cursor.vpos at the row where the cursor was displayed
13818 during the last redisplay cycle. */
13818 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix, w->cursor.vpos)) <= pt_old 13819 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix, w->cursor.vpos)) <= pt_old
13819 && pt_old <= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix, w->cursor.vpos))) 13820 && pt_old <= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix, w->cursor.vpos))
13821 && cursor_row_p (MATRIX_ROW (matrix, w->cursor.vpos)))
13820 { 13822 {
13821 struct glyph *g1 = 13823 struct glyph *g1 =
13822 MATRIX_ROW_GLYPH_START (matrix, w->cursor.vpos) + w->cursor.hpos; 13824 MATRIX_ROW_GLYPH_START (matrix, w->cursor.vpos) + w->cursor.hpos;