* mempool. Rely on copy-on-write (COW) of per-cpu pages to
* populate per-cpu pages from the initial values pages on
* first write. This mempool is only meant for single-process
- * use (private mapping).
+ * use (private mapping). Note that this type of pool cannot
+ * be accessed from children processes across fork.
*/
RSEQ_MEMPOOL_POPULATE_PRIVATE_NONE = 0,
/*
MAP_SHARED | MAP_FIXED, memfd, 0) != (void *) range->init) {
goto error_alloc;
}
- /*
- * Make sure the init values shared mapping is not
- * shared with the children processes across fork.
- */
- if (madvise(range->init, pool->attr.stride, MADV_DONTFORK))
- goto error_alloc;
assert(pool->attr.type == MEMPOOL_TYPE_PERCPU);
/*
* Map per-cpu memory as private COW mappings of init values.
}
}
}
+ /*
+ * The init values shared mapping should not be shared
+ * with the children processes across fork. Prevent the
+ * whole mapping from being used across fork.
+ */
+ if (madvise(range->mmap_addr, pool->mmap_len, MADV_DONTFORK))
+ goto error_alloc;
rseq_memfd_close(memfd);
memfd = -1;
}