- assert(size > 0);
- assert(ret);
-
- if (context >= m->contexts_max) {
- unsigned k, *n;
- Window *w;
-
- /* Increase the number of contexts if necessary, and
- * make sure we have twice the number of windows */
-
- k = context * 2;
- n = realloc(m->by_context, sizeof(unsigned) * k);
- if (!n)
- return -ENOMEM;
- memset(n + m->contexts_max, -1, (k - m->contexts_max) * sizeof(unsigned));
- m->contexts_max = k;
- m->by_context = n;
-
- k = MAX(m->windows_max, m->contexts_max*2);
- w = realloc(m->windows, sizeof(Window) * k);
- if (!w)
- return -ENOMEM;
-
- m->windows_max = k;
- m->windows = w;
- }
-
- /* Maybe the current pointer for this context is already the
- * right one? */
- r = mmap_cache_current(m, fd, context, offset, size, ret);
- if (r != 0)
- return r;
-
- /* Hmm, drop the reference to the current one, since it wasn't
- * good enough */
- mmap_cache_context_unset(m, context);
-
- /* OK, let's find the chain for this FD */
- r = mmap_cache_get_fd_index(m, fd, &fd_index);
- if (r < 0)
- return r;