Some tweaks to get this to cope with ELF where the address space starts

higher up in memory (0x0800000 upwards) rather than near zero (0x1000
for our qmagic a.out format).  The method that mount_mfs uses to allocate
the memory within data size rlimits for the ram disk is entirely too much
of a kludge for my liking.  I mean, if it's run as root, surely it makes
sense to just raise the resource limits to infinity or something, and if
it's a non-root user mount (do these work? with mfs?) it could just fail
if it's outside limits.
This commit is contained in:
peter 1997-09-13 11:41:50 +00:00
parent dbe59c771a
commit 848a4c94ef

View File

@ -208,9 +208,9 @@ mkfs(pp, fsys, fi, fo)
#ifndef STANDALONE
get_memleft();
#endif
if (fssize * sectorsize > (memleft - 16384))
fssize = (memleft - 16384) / sectorsize;
if ((membase = malloc(fssize * sectorsize)) == 0) {
if (fssize * sectorsize > (memleft - 131072))
fssize = (memleft - 131072) / sectorsize;
if ((membase = malloc(fssize * sectorsize)) == NULL) {
perror("malloc");
exit(13);
}
@ -1210,18 +1210,28 @@ raise_data_limit()
perror("setrlimit");
}
#ifdef __ELF__
extern char *_etext;
#define etext _etext
#else
extern char *etext;
#endif
get_memleft()
{
char *base;
static u_long pgsz, i;
static u_long pgsz;
struct rlimit rlp;
u_long freestart;
u_long dstart;
u_long memused;
base = sbrk(0);
pgsz = getpagesize() - 1;
i = ((u_long)(base + pgsz) &~ pgsz);
dstart = ((u_long)&etext) &~ pgsz;
freestart = ((u_long)(sbrk(0) + pgsz) &~ pgsz);
if (getrlimit(RLIMIT_DATA, &rlp) < 0)
perror("getrlimit");
memleft = rlp.rlim_cur - (u_long)base - i;
memused = freestart - dstart;
memleft = rlp.rlim_cur - memused;
}
#endif /* STANDALONE */