mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-09 19:00:08 +00:00
Clean up locarchive mmap reservation code.
This commit is contained in:
parent
5060422095
commit
110946e473
@ -1,5 +1,8 @@
|
|||||||
2011-10-08 Roland McGrath <roland@hack.frob.com>
|
2011-10-08 Roland McGrath <roland@hack.frob.com>
|
||||||
|
|
||||||
|
* locale/programs/locarchive.c (prepare_address_space): New function.
|
||||||
|
(create_archive, enlarge_archive, open_archive): Use it.
|
||||||
|
|
||||||
* sysdeps/unix/sysv/linux/x86_64/time.c: Move #include <dl-vdso.h>
|
* sysdeps/unix/sysv/linux/x86_64/time.c: Move #include <dl-vdso.h>
|
||||||
inside [SHARED], where it is used.
|
inside [SHARED], where it is used.
|
||||||
|
|
||||||
|
@ -74,6 +74,29 @@ static const char *locnames[] =
|
|||||||
/* Size of the reserved address space area. */
|
/* Size of the reserved address space area. */
|
||||||
#define RESERVE_MMAP_SIZE 512 * 1024 * 1024
|
#define RESERVE_MMAP_SIZE 512 * 1024 * 1024
|
||||||
|
|
||||||
|
/* To prepare for enlargements of the mmaped area reserve some address
|
||||||
|
space. On some machines, being a file mapping rather than an anonymous
|
||||||
|
mapping affects the address selection. So do this mapping from the
|
||||||
|
actual file, even though it's only a dummy to reserve address space. */
|
||||||
|
static void *
|
||||||
|
prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags)
|
||||||
|
{
|
||||||
|
if (total < RESERVE_MMAP_SIZE)
|
||||||
|
{
|
||||||
|
void *p = mmap64 (NULL, RESERVE_MMAP_SIZE, PROT_NONE, MAP_SHARED, fd, 0);
|
||||||
|
if (p != MAP_FAILED)
|
||||||
|
{
|
||||||
|
*reserved = RESERVE_MMAP_SIZE;
|
||||||
|
*xflags = MAP_FIXED;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*reserved = total;
|
||||||
|
*xflags = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
create_archive (const char *archivefname, struct locarhandle *ah)
|
create_archive (const char *archivefname, struct locarhandle *ah)
|
||||||
@ -81,7 +104,6 @@ create_archive (const char *archivefname, struct locarhandle *ah)
|
|||||||
int fd;
|
int fd;
|
||||||
char fname[strlen (archivefname) + sizeof (".XXXXXX")];
|
char fname[strlen (archivefname) + sizeof (".XXXXXX")];
|
||||||
struct locarhead head;
|
struct locarhead head;
|
||||||
void *p;
|
|
||||||
size_t total;
|
size_t total;
|
||||||
|
|
||||||
strcpy (stpcpy (fname, archivefname), ".XXXXXX");
|
strcpy (stpcpy (fname, archivefname), ".XXXXXX");
|
||||||
@ -129,19 +151,9 @@ create_archive (const char *archivefname, struct locarhandle *ah)
|
|||||||
error (EXIT_FAILURE, errval, _("cannot resize archive file"));
|
error (EXIT_FAILURE, errval, _("cannot resize archive file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* To prepare for enlargements of the mmaped area reserve some
|
size_t reserved;
|
||||||
address space. */
|
int xflags;
|
||||||
size_t reserved = RESERVE_MMAP_SIZE;
|
void *p = prepare_address_space (fd, total, &reserved, &xflags);
|
||||||
int xflags = 0;
|
|
||||||
if (total < reserved
|
|
||||||
&& ((p = mmap64 (NULL, reserved, PROT_NONE, MAP_PRIVATE | MAP_ANON,
|
|
||||||
-1, 0)) != MAP_FAILED))
|
|
||||||
xflags = MAP_FIXED;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p = NULL;
|
|
||||||
reserved = total;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Map the header and all the administration data structures. */
|
/* Map the header and all the administration data structures. */
|
||||||
p = mmap64 (p, total, PROT_READ | PROT_WRITE, MAP_SHARED | xflags, fd, 0);
|
p = mmap64 (p, total, PROT_READ | PROT_WRITE, MAP_SHARED | xflags, fd, 0);
|
||||||
@ -297,7 +309,6 @@ enlarge_archive (struct locarhandle *ah, const struct locarhead *head)
|
|||||||
int fd;
|
int fd;
|
||||||
struct locarhead newhead;
|
struct locarhead newhead;
|
||||||
size_t total;
|
size_t total;
|
||||||
void *p;
|
|
||||||
unsigned int cnt, loccnt;
|
unsigned int cnt, loccnt;
|
||||||
struct namehashent *oldnamehashtab;
|
struct namehashent *oldnamehashtab;
|
||||||
struct locarhandle new_ah;
|
struct locarhandle new_ah;
|
||||||
@ -390,19 +401,9 @@ enlarge_archive (struct locarhandle *ah, const struct locarhead *head)
|
|||||||
error (EXIT_FAILURE, errval, _("cannot resize archive file"));
|
error (EXIT_FAILURE, errval, _("cannot resize archive file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* To prepare for enlargements of the mmaped area reserve some
|
size_t reserved;
|
||||||
address space. */
|
int xflags;
|
||||||
size_t reserved = RESERVE_MMAP_SIZE;
|
void *p = prepare_address_space (fd, total, &reserved, &xflags);
|
||||||
int xflags = 0;
|
|
||||||
if (total < reserved
|
|
||||||
&& ((p = mmap64 (NULL, reserved, PROT_NONE, MAP_PRIVATE | MAP_ANON,
|
|
||||||
-1, 0)) != MAP_FAILED))
|
|
||||||
xflags = MAP_FIXED;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p = NULL;
|
|
||||||
reserved = total;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Map the header and all the administration data structures. */
|
/* Map the header and all the administration data structures. */
|
||||||
p = mmap64 (p, total, PROT_READ | PROT_WRITE, MAP_SHARED | xflags, fd, 0);
|
p = mmap64 (p, total, PROT_READ | PROT_WRITE, MAP_SHARED | xflags, fd, 0);
|
||||||
@ -605,20 +606,9 @@ open_archive (struct locarhandle *ah, bool readonly)
|
|||||||
ah->fd = fd;
|
ah->fd = fd;
|
||||||
ah->mmaped = st.st_size;
|
ah->mmaped = st.st_size;
|
||||||
|
|
||||||
/* To prepare for enlargements of the mmaped area reserve some
|
size_t reserved;
|
||||||
address space. */
|
int xflags;
|
||||||
size_t reserved = RESERVE_MMAP_SIZE;
|
void *p = prepare_address_space (fd, st.st_size, &reserved, &xflags);
|
||||||
int xflags = 0;
|
|
||||||
void *p;
|
|
||||||
if (st.st_size < reserved
|
|
||||||
&& ((p = mmap64 (NULL, reserved, PROT_NONE, MAP_PRIVATE | MAP_ANON,
|
|
||||||
-1, 0)) != MAP_FAILED))
|
|
||||||
xflags = MAP_FIXED;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p = NULL;
|
|
||||||
reserved = st.st_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Map the entire file. We might need to compare the category data
|
/* Map the entire file. We might need to compare the category data
|
||||||
in the file with the newly added data. */
|
in the file with the newly added data. */
|
||||||
|
Loading…
Reference in New Issue
Block a user