void mminit(char *file, int mode) { Dir *d; uintptr va; void *p, *np; int hashsize; /* make it a power of two -- see why later */ ventifd = open(file, mode); if (ventifd < 0) sysfatal("Can't open %s: %r\n", file); d = dirfstat(ventifd); if (! d) sysfatal("Can't stat %s: %r", file); /* allocate: size for the file, 1/32 that size for the map, and * start it at the 1 GB boundary, please. */ /* get top of heap */ p = segbrk(0, 0); va = (uintptr)p; /* no non-nix systems we just usr sbrk and only have little pages */ hashsize = d->length/32; maxmap = hashsize / sizeof(*maps); hashb = log2(maxmap); if (va == (uintptr)-1) { p = sbrk(0); va = (uintptr)p; maps = (void *)va; va += hashsize; mmventidatabase = mmventidata = (void *)va; va += d->length; va = ROUNDUP((va), 4096); if (brk((void *)va) < 0) sysfatal("brk to %#p failed\n", (void *)va); } else { va = ROUNDUP((va), 1ULL*GiB); maps = (void *)va; va += hashsize; mmventidatabase = mmventidata = (void *)va; va += d->length; va = ROUNDUP((va), 1ULL*GiB); segbrk(0, (void *)va); } fprint(2, "mmventidatabase is %#p\n", mmventidatabase); fprint(2, "File size %lld, hashsize %d, maps %#p, data %#p\n", d->length, hashsize, maps, mmventidata); /* morecore */ np=(void*)va; segbrk(p, np); reload(); }
void main(void) { char *p = segbrk((void *)(1024ULL * 1024 * 1024 * 1024), nil); print("%p\n", p); memset(p, 0, 4096); }