aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2000-09-07 16:10:38 +0000
committerGerd Moellmann2000-09-07 16:10:38 +0000
commit24f76fbf714f6031ec4eccf1b8b914fa17282492 (patch)
treeb6ed2875a0afef71696d6efc597ecfb3cd4a2344
parentf46f845b3f32f50a973b382f500711e7ce78137e (diff)
downloademacs-24f76fbf714f6031ec4eccf1b8b914fa17282492.tar.gz
emacs-24f76fbf714f6031ec4eccf1b8b914fa17282492.zip
(mmap_find): Fix overlap computation.
(mmap_enlarge): Compute nbytes before trying to find an overlapping region.
-rw-r--r--src/ChangeLog4
-rw-r--r--src/ralloc.c22
2 files changed, 18 insertions, 8 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d1cf3aaa514..59d91667461 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
12000-09-07 Gerd Moellmann <gerd@gnu.org> 12000-09-07 Gerd Moellmann <gerd@gnu.org>
2 2
3 * ralloc.c (mmap_find): Fix overlap computation.
4 (mmap_enlarge): Compute nbytes before trying to find an
5 overlapping region.
6
3 * xfaces.c (smaller_face): Compare font heights with `<' and `>' 7 * xfaces.c (smaller_face): Compare font heights with `<' and `>'
4 instead of `!='. 8 instead of `!='.
5 9
diff --git a/src/ralloc.c b/src/ralloc.c
index 7caffa4a8da..ae2d70ee709 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -1303,8 +1303,9 @@ POINTER_TYPE *r_re_alloc P_ ((POINTER_TYPE **, size_t));
1303void r_alloc_free P_ ((POINTER_TYPE **ptr)); 1303void r_alloc_free P_ ((POINTER_TYPE **ptr));
1304 1304
1305 1305
1306/* Return a region overlapping with the address range START...END, or 1306/* Return a region overlapping address range START...END, or null if
1307 null if none. */ 1307 none. END is not including, i.e. the last byte in the range
1308 is at END - 1. */
1308 1309
1309static struct mmap_region * 1310static struct mmap_region *
1310mmap_find (start, end) 1311mmap_find (start, end)
@@ -1318,10 +1319,14 @@ mmap_find (start, end)
1318 char *rstart = (char *) r; 1319 char *rstart = (char *) r;
1319 char *rend = rstart + r->nbytes_mapped; 1320 char *rend = rstart + r->nbytes_mapped;
1320 1321
1321 if ((s >= rstart && s < rend) 1322 if (/* First byte of range, i.e. START, in this region? */
1322 || (e >= rstart && e < rend) 1323 (s >= rstart && s < rend)
1324 /* Last byte of range, i.e. END - 1, in this region? */
1325 || (e > rstart && e <= rend)
1326 /* First byte of this region in the range? */
1323 || (rstart >= s && rstart < e) 1327 || (rstart >= s && rstart < e)
1324 || (rend >= s && rend < e)) 1328 /* Last byte of this region in the range? */
1329 || (rend > s && rend <= e))
1325 break; 1330 break;
1326 } 1331 }
1327 1332
@@ -1348,7 +1353,7 @@ mmap_free (r)
1348 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); 1353 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno));
1349 return 0; 1354 return 0;
1350 } 1355 }
1351 1356
1352 return 1; 1357 return 1;
1353} 1358}
1354 1359
@@ -1379,6 +1384,8 @@ mmap_enlarge (r, npages)
1379 } 1384 }
1380 else if (npages > 0) 1385 else if (npages > 0)
1381 { 1386 {
1387 nbytes = npages * page_size;
1388
1382 /* Try to map additional pages at the end of the region. We 1389 /* Try to map additional pages at the end of the region. We
1383 cannot do this if the address range is already occupied by 1390 cannot do this if the address range is already occupied by
1384 something else because mmap deletes any previous mapping. 1391 something else because mmap deletes any previous mapping.
@@ -1389,7 +1396,6 @@ mmap_enlarge (r, npages)
1389 { 1396 {
1390 POINTER_TYPE *p; 1397 POINTER_TYPE *p;
1391 1398
1392 nbytes = npages * page_size;
1393 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE, 1399 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE,
1394 MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); 1400 MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0);
1395 if (p == MAP_FAILED) 1401 if (p == MAP_FAILED)
@@ -1547,7 +1553,7 @@ r_re_alloc (var, nbytes)
1547 /* Try to map additional pages at the end of the region. 1553 /* Try to map additional pages at the end of the region.
1548 If that fails, allocate a new region, copy data 1554 If that fails, allocate a new region, copy data
1549 from the old region, then free it. */ 1555 from the old region, then free it. */
1550 if (mmap_enlarge (r, ROUND (nbytes - room, page_size))) 1556 if (mmap_enlarge (r, ROUND (nbytes - room, page_size) / page_size))
1551 { 1557 {
1552 r->nbytes_specified = nbytes; 1558 r->nbytes_specified = nbytes;
1553 *var = result = old_ptr; 1559 *var = result = old_ptr;