summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerd Moellmann <gerd@gnu.org>2000-09-07 16:10:38 +0000
committerGerd Moellmann <gerd@gnu.org>2000-09-07 16:10:38 +0000
commit24f76fbf714f6031ec4eccf1b8b914fa17282492 (patch)
treeb6ed2875a0afef71696d6efc597ecfb3cd4a2344
parentf46f845b3f32f50a973b382f500711e7ce78137e (diff)
downloademacs-24f76fbf714f6031ec4eccf1b8b914fa17282492.tar.gz
(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 @@
2000-09-07 Gerd Moellmann <gerd@gnu.org>
+ * ralloc.c (mmap_find): Fix overlap computation.
+ (mmap_enlarge): Compute nbytes before trying to find an
+ overlapping region.
+
* xfaces.c (smaller_face): Compare font heights with `<' and `>'
instead of `!='.
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));
void r_alloc_free P_ ((POINTER_TYPE **ptr));
-/* Return a region overlapping with the address range START...END, or
- null if none. */
+/* Return a region overlapping address range START...END, or null if
+ none. END is not including, i.e. the last byte in the range
+ is at END - 1. */
static struct mmap_region *
mmap_find (start, end)
@@ -1318,10 +1319,14 @@ mmap_find (start, end)
char *rstart = (char *) r;
char *rend = rstart + r->nbytes_mapped;
- if ((s >= rstart && s < rend)
- || (e >= rstart && e < rend)
+ if (/* First byte of range, i.e. START, in this region? */
+ (s >= rstart && s < rend)
+ /* Last byte of range, i.e. END - 1, in this region? */
+ || (e > rstart && e <= rend)
+ /* First byte of this region in the range? */
|| (rstart >= s && rstart < e)
- || (rend >= s && rend < e))
+ /* Last byte of this region in the range? */
+ || (rend > s && rend <= e))
break;
}
@@ -1348,7 +1353,7 @@ mmap_free (r)
fprintf (stderr, "munmap: %s\n", emacs_strerror (errno));
return 0;
}
-
+
return 1;
}
@@ -1379,6 +1384,8 @@ mmap_enlarge (r, npages)
}
else if (npages > 0)
{
+ nbytes = npages * page_size;
+
/* Try to map additional pages at the end of the region. We
cannot do this if the address range is already occupied by
something else because mmap deletes any previous mapping.
@@ -1389,7 +1396,6 @@ mmap_enlarge (r, npages)
{
POINTER_TYPE *p;
- nbytes = npages * page_size;
p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0);
if (p == MAP_FAILED)
@@ -1547,7 +1553,7 @@ r_re_alloc (var, nbytes)
/* Try to map additional pages at the end of the region.
If that fails, allocate a new region, copy data
from the old region, then free it. */
- if (mmap_enlarge (r, ROUND (nbytes - room, page_size)))
+ if (mmap_enlarge (r, ROUND (nbytes - room, page_size) / page_size))
{
r->nbytes_specified = nbytes;
*var = result = old_ptr;