if ((index = ptr2index(tail) - 1) > last_index) last_index = index;
last_index = lindex; }
map_pages(size_t pages){    struct pdinfo *pi, *spi;    struct pginfo **pd;    u_long pidx,lidx;    void *result, *tail;    u_long index;    pages <<= malloc_pageshift;    result = MMAP(pages + malloc_guard);    if (result == MAP_FAILED) {	errno = ENOMEM;#ifdef	MALLOC_EXTRA_SANITY	wrtwarning("(ES): map_pages fails\n");#endif	/* MALLOC_EXTRA_SANITY */	return (NULL);    }    tail = result + pages + malloc_guard;    if (malloc_guard)	mprotect(result + pages, malloc_guard, PROT_NONE);    if (tail > malloc_brk)	malloc_brk = tail;    if ((index = ptr2index(tail) - 1) > last_index)	last_index = index;    /* Insert directory pages, if needed. */    pidx = PI_IDX(ptr2index(result));    lidx = PI_IDX(index);    pdir_lookup(ptr2index(result), &pi);    for (index=pidx,spi=pi;index<=lidx;index++) {	if (pi == NULL || PD_IDX(pi->dirnum) != index) {	    if ((pd = MMAP(malloc_pagesize)) == MAP_FAILED) {		errno = ENOMEM;		munmap(result, tail - result);#ifdef	MALLOC_EXTRA_SANITY		wrtwarning("(ES): map_pages fails\n");#endif	/* MALLOC_EXTRA_SANITY */		return (NULL);	    }	    memset(pd, 0, malloc_pagesize);	    pi = (struct pdinfo *)((caddr_t)pd + pdi_off);	    pi->base = pd;	    pi->prev = spi;	    pi->next = spi->next;	    pi->dirnum = index * (malloc_pagesize/sizeof(struct pginfo *));	    if (spi->next != NULL)		spi->next->prev = pi;	    spi->next = pi;	}        if (index > pidx && index < lidx) {	    pi->dirnum += pdi_mod;	} else if (index == pidx) {	    if (pidx == lidx) {		pi->dirnum += (tail - result) >> malloc_pageshift;	    } else {		pi->dirnum += pdi_mod - PI_OFF(ptr2index(result));	    }	} else {	    pi->dirnum += PI_OFF(ptr2index(tail - 1)) + 1;	}#ifdef	MALLOC_EXTRA_SANITY	if (PD_OFF(pi->dirnum) > pdi_mod || PD_IDX(pi->dirnum) > index) {	    wrterror("(ES): pages directory overflow\n");	    errno = EFAULT;	    return (NULL);	}#endif	/* MALLOC_EXTRA_SANITY */	if (index == pidx && pi != last_dir) {	   prev_dir = last_dir;	   last_dir = pi;	}	spi = pi;	pi = spi->next;    }    return (result);}