Do not use `madvise()` directly from the libc in the liburing internal sources. Wrap them in `src/syscall.c`. This is the part of implementing the kernel style return value (which later is supposed to support no libc environment). `liburing_madvise()` does the same thing with `madvise()` from the libc. The only different is when error happens, the return value is of `liburing_madvise()` will be a negative error code. Signed-off-by: Ammar Faizi <ammar.faizi@xxxxxxxxxxxxxxxxxxxxx> --- src/setup.c | 18 +++++++++--------- src/syscall.c | 8 ++++++++ src/syscall.h | 1 + 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/setup.c b/src/setup.c index 01cb151..52f3557 100644 --- a/src/setup.c +++ b/src/setup.c @@ -120,20 +120,20 @@ int io_uring_ring_dontfork(struct io_uring *ring) 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; + ret = liburing_madvise(ring->sq.sqes, len, MADV_DONTFORK); + if (uring_unlikely(ret)) + return ret; len = ring->sq.ring_sz; - ret = madvise(ring->sq.ring_ptr, len, MADV_DONTFORK); - if (ret == -1) - return -errno; + ret = liburing_madvise(ring->sq.ring_ptr, len, MADV_DONTFORK); + if (uring_unlikely(ret)) + return ret; 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; + ret = liburing_madvise(ring->cq.ring_ptr, len, MADV_DONTFORK); + if (uring_unlikely(ret)) + return ret; } return 0; diff --git a/src/syscall.c b/src/syscall.c index cb48a94..44861f6 100644 --- a/src/syscall.c +++ b/src/syscall.c @@ -133,3 +133,11 @@ int liburing_munmap(void *addr, size_t length) ret = munmap(addr, length); return (ret < 0) ? -errno : ret; } + +int liburing_madvise(void *addr, size_t length, int advice) +{ + int ret; + + ret = madvise(addr, length, advice); + return (ret < 0) ? -errno : ret; +} diff --git a/src/syscall.h b/src/syscall.h index feccf67..32381ce 100644 --- a/src/syscall.h +++ b/src/syscall.h @@ -29,5 +29,6 @@ int ____sys_io_uring_register(int fd, unsigned int opcode, const void *arg, void *liburing_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); int liburing_munmap(void *addr, size_t length); +int liburing_madvise(void *addr, size_t length, int advice); #endif -- 2.30.2