summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorpk <pk@NetBSD.org>1998-03-18 23:21:46 +0000
committerpk <pk@NetBSD.org>1998-03-18 23:21:46 +0000
commitd47d43b95657fa31475bbd89eee6abe25c188059 (patch)
treeb53fc5c088d75b37fc8cc2696c4c757d91c76d87 /libexec
parent15adb17803f193307aa5b2f6cac33c746b4b5bf2 (diff)
Use file size from fstat(2) to map the hints file, instead of fiddling
with incremental mmap()'s. Squashes a bug which caused only the first page of the hints file to unmapped.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ld.aout_so/rtld.c57
1 files changed, 21 insertions, 36 deletions
diff --git a/libexec/ld.aout_so/rtld.c b/libexec/ld.aout_so/rtld.c
index a8a51dad4c0..bb2673c1eb9 100644
--- a/libexec/ld.aout_so/rtld.c
+++ b/libexec/ld.aout_so/rtld.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rtld.c,v 1.57 1998/03/15 23:10:21 pk Exp $ */
+/* $NetBSD: rtld.c,v 1.58 1998/03/18 23:21:46 pk Exp $ */
/*
* Copyright (c) 1993 Paul Kranenburg
@@ -1224,7 +1224,7 @@ xprintf(" BINDER: %s located at = %#x in %s\n", sym, addr, src_map->som_path);
static int hfd;
-static long hsize;
+static size_t hsize;
static struct hints_header *hheader;
static struct hints_bucket *hbuckets;
static char *hstrtab;
@@ -1238,58 +1238,43 @@ maphints()
caddr_t addr;
struct stat statbuf;
- if ((hfd = open(_PATH_LD_HINTS, O_RDONLY, 0)) == -1) {
- hheader = (struct hints_header *)-1;
- return;
- }
+ if ((hfd = open(_PATH_LD_HINTS, O_RDONLY, 0)) == -1)
+ goto nohints;
if (fstat(hfd, &statbuf) != 0 ||
- statbuf.st_size < sizeof(struct hints_header)) {
- hheader = (struct hints_header *)-1;
- return;
- }
+ (hsize = (size_t)statbuf.st_size) < sizeof(struct hints_header))
+ goto nohints;
- hsize = PAGSIZ;
- addr = mmap(0, hsize, PROT_READ, MAP_FILE|MAP_COPY, hfd, 0);
+ hsize = roundup(hsize, PAGSIZ);
- if (addr == (caddr_t)-1) {
- close(hfd);
- hheader = (struct hints_header *)-1;
- return;
- }
+ addr = mmap(0, hsize, PROT_READ, MAP_FILE|MAP_COPY, hfd, 0);
+ if (addr == (caddr_t)-1)
+ goto nohints;
hheader = (struct hints_header *)addr;
- if (HH_BADMAG(*hheader)) {
+ if (HH_BADMAG(*hheader) || hheader->hh_ehints > hsize) {
munmap(addr, hsize);
- close(hfd);
- hheader = (struct hints_header *)-1;
- return;
+ goto nohints;
}
if (hheader->hh_version != LD_HINTS_VERSION_1 &&
hheader->hh_version != LD_HINTS_VERSION_2) {
munmap(addr, hsize);
- close(hfd);
- hheader = (struct hints_header *)-1;
- return;
- }
-
- if (hheader->hh_ehints > hsize) {
- if (mmap(addr+hsize, hheader->hh_ehints - hsize,
- PROT_READ, MAP_FILE|MAP_COPY|MAP_FIXED,
- hfd, hsize) != (caddr_t)(addr+hsize)) {
-
- munmap((caddr_t)hheader, hsize);
- close(hfd);
- hheader = (struct hints_header *)-1;
- return;
- }
+ goto nohints;
}
hbuckets = (struct hints_bucket *)(addr + hheader->hh_hashtab);
hstrtab = (char *)(addr + hheader->hh_strtab);
if (hheader->hh_version >= LD_HINTS_VERSION_2)
hint_search_path = hstrtab + hheader->hh_dirlist;
+
+ return;
+
+nohints:
+ if (hfd >= 0)
+ close(hfd);
+ hheader = (struct hints_header *)-1;
+ return;
}
static void