Commit ee0d75ef by Ian Lance Taylor Committed by Ian Lance Taylor

ggc-common.c (gt_pch_restore): Don't unmap addr unless we are going to call mmap again.

	* ggc-common.c (gt_pch_restore): Don't unmap addr unless we are
	going to call mmap again.  Read the file into the right place.
	Give a fatal error if we have to relocate.

From-SVN: r78957
parent 6e5ff6e7
2004-03-04 Ian Lance Taylor <ian@wasabisystems.com>
* ggc-common.c (gt_pch_restore): Don't unmap addr unless we are
going to call mmap again. Read the file into the right place.
Give a fatal error if we have to relocate.
2004-03-04 Bob Wilson <bob.wilson@acm.org> 2004-03-04 Bob Wilson <bob.wilson@acm.org>
* config/xtensa/xtensa.c (xtensa_return_in_msb): New function. * config/xtensa/xtensa.c (xtensa_return_in_msb): New function.
......
...@@ -607,23 +607,20 @@ gt_pch_restore (FILE *f) ...@@ -607,23 +607,20 @@ gt_pch_restore (FILE *f)
addr = mmap (mmi.preferred_base, mmi.size, addr = mmap (mmi.preferred_base, mmi.size,
PROT_READ | PROT_WRITE, MAP_PRIVATE, PROT_READ | PROT_WRITE, MAP_PRIVATE,
fileno (f), mmi.offset); fileno (f), mmi.offset);
#if HAVE_MINCORE #if HAVE_MINCORE
if (addr != mmi.preferred_base) if (addr != mmi.preferred_base)
{ {
size_t page_size = getpagesize(); size_t page_size = getpagesize();
char one_byte; char one_byte;
if (addr != (void *) MAP_FAILED)
munmap (addr, mmi.size);
/* We really want to be mapped at mmi.preferred_base /* We really want to be mapped at mmi.preferred_base
so we're going to resort to MAP_FIXED. But before, so we're going to resort to MAP_FIXED. But before,
make sure that we can do so without destroying a make sure that we can do so without destroying a
previously mapped area, by looping over all pages previously mapped area, by looping over all pages
that would be affected by the fixed mapping. */ that would be affected by the fixed mapping. */
errno = 0; errno = 0;
for (i = 0; i < mmi.size; i+= page_size) for (i = 0; i < mmi.size; i+= page_size)
if (mincore ((char *)mmi.preferred_base + i, page_size, if (mincore ((char *)mmi.preferred_base + i, page_size,
(void *)&one_byte) == -1 (void *)&one_byte) == -1
...@@ -631,14 +628,19 @@ gt_pch_restore (FILE *f) ...@@ -631,14 +628,19 @@ gt_pch_restore (FILE *f)
continue; /* The page is not mapped. */ continue; /* The page is not mapped. */
else else
break; break;
if (i >= mmi.size) if (i >= mmi.size)
addr = mmap (mmi.preferred_base, mmi.size, {
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, if (addr != (void *) MAP_FAILED)
fileno (f), mmi.offset); munmap (addr, mmi.size);
addr = mmap (mmi.preferred_base, mmi.size,
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
fileno (f), mmi.offset);
}
} }
#endif /* HAVE_MINCORE */ #endif /* HAVE_MINCORE */
needs_read = addr == (void *) MAP_FAILED; needs_read = addr == (void *) MAP_FAILED;
#else /* HAVE_MMAP_FILE */ #else /* HAVE_MMAP_FILE */
...@@ -651,7 +653,7 @@ gt_pch_restore (FILE *f) ...@@ -651,7 +653,7 @@ gt_pch_restore (FILE *f)
if (needs_read) if (needs_read)
{ {
if (fseek (f, mmi.offset, SEEK_SET) != 0 if (fseek (f, mmi.offset, SEEK_SET) != 0
|| fread (&mmi, mmi.size, 1, f) != 1) || fread (addr, mmi.size, 1, f) != 1)
fatal_error ("can't read PCH file: %m"); fatal_error ("can't read PCH file: %m");
} }
else if (fseek (f, mmi.offset + mmi.size, SEEK_SET) != 0) else if (fseek (f, mmi.offset + mmi.size, SEEK_SET) != 0)
...@@ -679,7 +681,7 @@ gt_pch_restore (FILE *f) ...@@ -679,7 +681,7 @@ gt_pch_restore (FILE *f)
*ptr += (size_t)addr - (size_t)mmi.preferred_base; *ptr += (size_t)addr - (size_t)mmi.preferred_base;
} }
sorry ("had to relocate PCH"); fatal_error ("had to relocate PCH");
} }
gt_pch_restore_stringpool (); gt_pch_restore_stringpool ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment