summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile2
-rw-r--r--src/include/liburing.h1
-rw-r--r--src/liburing.map5
-rw-r--r--src/setup.c32
4 files changed, 39 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index 88ca597..47e0ba5 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -12,7 +12,7 @@ ENABLE_SHARED ?= 1
soname=liburing.so.1
minor=0
-micro=3
+micro=4
libname=$(soname).$(minor).$(micro)
all_targets += liburing.a
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 7e6ad8f..6f76c99 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -69,6 +69,7 @@ extern int io_uring_queue_init(unsigned entries, struct io_uring *ring,
unsigned flags);
extern int io_uring_queue_mmap(int fd, struct io_uring_params *p,
struct io_uring *ring);
+extern int io_uring_ring_dontfork(struct io_uring *ring);
extern void io_uring_queue_exit(struct io_uring *ring);
unsigned io_uring_peek_batch_cqe(struct io_uring *ring,
struct io_uring_cqe **cqes, unsigned count);
diff --git a/src/liburing.map b/src/liburing.map
index a50b208..e29db68 100644
--- a/src/liburing.map
+++ b/src/liburing.map
@@ -65,3 +65,8 @@ LIBURING_0.3 {
__sys_io_uring_enter;
__sys_io_uring_register;
};
+
+LIBURING_0.4 {
+ global:
+ io_uring_ring_dontfork;
+} LIBURING_0.3;
diff --git a/src/setup.c b/src/setup.c
index 550c0de..c53f234 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -96,6 +96,38 @@ int io_uring_queue_mmap(int fd, struct io_uring_params *p, struct io_uring *ring
return ret;
}
+/*
+ * Ensure that the mmap'ed rings aren't available to a child after a fork(2).
+ * This uses madvise(..., MADV_DONTFORK) on the mmap'ed ranges.
+ */
+int io_uring_ring_dontfork(struct io_uring *ring)
+{
+ size_t len;
+ int ret;
+
+ if (!ring->sq.ring_ptr || !ring->sq.sqes || !ring->cq.ring_ptr)
+ return -EINVAL;
+
+ len = *ring->sq.kring_entries * sizeof(struct io_uring_sqe);
+ ret = madvise(ring->sq.sqes, len, MADV_DONTFORK);
+ if (ret == -1)
+ return -errno;
+
+ len = ring->sq.ring_sz;
+ ret = madvise(ring->sq.ring_ptr, len, MADV_DONTFORK);
+ if (ret == -1)
+ return -errno;
+
+ if (ring->cq.ring_ptr != ring->sq.ring_ptr) {
+ len = ring->cq.ring_sz;
+ ret = madvise(ring->cq.ring_ptr, len, MADV_DONTFORK);
+ if (ret == -1)
+ return -errno;
+ }
+
+ return 0;
+}
+
int io_uring_queue_init_params(unsigned entries, struct io_uring *ring,
struct io_uring_params *p)
{