aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorPeter Wemm <peter@FreeBSD.org>1997-03-31 16:43:16 +0000
committerPeter Wemm <peter@FreeBSD.org>1997-03-31 16:43:16 +0000
commit4af9705ceb4d13a1e2e04accd8ab7060195b0e16 (patch)
tree4c230498adc6a415a74165033c58e8353b517448 /sbin
parent0e1cf9a328882cd60028c0aba3f63aaae144661c (diff)
downloadsrc-4af9705ceb4d13a1e2e04accd8ab7060195b0e16.tar.gz
src-4af9705ceb4d13a1e2e04accd8ab7060195b0e16.zip
Fix the mount_mfs case from the last cleanup. The code was (ab)using
it's internal malloc() implementation to try and avoid overstepping it's resource limits (yuk!). Remain using libc's malloc(), but check the resource limits right before trying to malloc the ramdisk space and leave some spare memory for libc. In Andrey's words, the internal malloc was "true evil".. Among it's sins is it's ability to allocate less memory than asked for and still return success. stdio would just love that. :-) Reviewed by: ache
Notes
Notes: svn path=/head/; revision=24457
Diffstat (limited to 'sbin')
-rw-r--r--sbin/newfs/mkfs.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index 1dbc3a5edf79..0c6c1d7649c3 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -206,7 +206,10 @@ mkfs(pp, fsys, fi, fo)
}
close(fd);
} else {
- if (fssize * sectorsize > memleft)
+#ifndef STANDALONE
+ get_memleft();
+#endif
+ if (fssize * sectorsize > (memleft - 16384))
fssize = (memleft - 16384) / sectorsize;
if ((membase = malloc(fssize * sectorsize)) == 0) {
perror("malloc");
@@ -1210,6 +1213,19 @@ raise_data_limit()
perror("setrlimit");
}
+get_memleft()
+{
+ char *base;
+ static u_long pgsz, i;
+ struct rlimit rlp;
+
+ base = sbrk(0);
+ pgsz = getpagesize() - 1;
+ i = ((u_long)(base + pgsz) &~ pgsz);
+ if (getrlimit(RLIMIT_DATA, &rlp) < 0)
+ perror("getrlimit");
+ memleft = rlp.rlim_cur - (u_long)base - i;
+}
#endif /* STANDALONE */
/*