summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-08-21 19:25:37 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-08-21 19:25:37 +0000
commitfa558d325ba4bd343e43d5d0b8ece644c1d38fa2 (patch)
tree3612dc24e05e1950d5adad8170259a57c2eaf22c /lib/libc
parentf58001d6719063f0d6419204ae9002eba1f77d0d (diff)
For a.out use read, not mmap, to get the string table so this works on
/dev/ksyms. mmap was only used because, at the time, free did not give memory back to the system (our malloc/free uses mmap/munmap so we are ok).
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/nlist.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c
index 1b248199a7b..8822c93a0c7 100644
--- a/lib/libc/gen/nlist.c
+++ b/lib/libc/gen/nlist.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: nlist.c,v 1.24 1998/01/20 22:10:48 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: nlist.c,v 1.25 1998/08/21 19:25:36 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -69,34 +69,35 @@ __aout_fdnlist(fd, list)
register off_t stroff, symoff;
register u_long symsize;
register int nent, cc;
- size_t strsize;
+ int strsize;
struct nlist nbuf[1024];
struct exec exec;
- struct stat st;
if (lseek(fd, (off_t)0, SEEK_SET) == -1 ||
read(fd, &exec, sizeof(exec)) != sizeof(exec) ||
- N_BADMAG(exec) || fstat(fd, &st) < 0)
+ N_BADMAG(exec) || exec.a_syms == NULL)
return (-1);
symoff = N_SYMOFF(exec);
symsize = exec.a_syms;
stroff = symoff + symsize;
- /* Check for files too large to mmap. */
- if (st.st_size - stroff > SIZE_T_MAX) {
- errno = EFBIG;
+ /* Read in the size of the string table. */
+ if (read(fd, (char *)&strsize, sizeof(strsize)) != sizeof(strsize))
return (-1);
- }
+
/*
* Map string table into our address space. This gives us
* an easy way to randomly access all the strings, without
* making the memory allocation permanent as with malloc/free
- * (i.e., munmap will return it to the system).
+ * (i.e., munmap will return it to the system). We try to
+ * get a clean snapshot via MAP_COPY but that does not work
+ * for cdevs (like /dev/ksyms) so we try without if that fails.
*/
- strsize = st.st_size - stroff;
- strtab = mmap(NULL, (size_t)strsize, PROT_READ, MAP_COPY|MAP_FILE,
- fd, stroff);
+ if ((strtab = mmap(NULL, (size_t)strsize, PROT_READ, MAP_COPY|MAP_FILE,
+ fd, stroff)) == MAP_FAILED)
+ strtab = mmap(NULL, (size_t)strsize, PROT_READ, 0, fd,
+ stroff);
if (strtab == MAP_FAILED)
return (-1);
/*