From c724955d54134b05f26653944b3e6f4b153c3c07 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Wed, 22 Dec 2021 00:05:10 -0800 Subject: [PATCH] LibC: Add support for `posix_madvise(..)` Add the `posix_madvise(..)` LibC implementation that just forwards to the normal `madvise(..)` implementation. Also define a few POSIX_MADV_DONTNEED and POSIX_MADV_NORMAL as they are part of the POSIX API for `posix_madvise(..)`. This is needed by the `fio` port. --- Kernel/API/POSIX/sys/mman.h | 10 ++++++++++ Userland/Libraries/LibC/sys/mman.cpp | 6 ++++++ Userland/Libraries/LibC/sys/mman.h | 1 + 3 files changed, 17 insertions(+) diff --git a/Kernel/API/POSIX/sys/mman.h b/Kernel/API/POSIX/sys/mman.h index 519ed184fc..187da47020 100644 --- a/Kernel/API/POSIX/sys/mman.h +++ b/Kernel/API/POSIX/sys/mman.h @@ -31,10 +31,20 @@ extern "C" { #define MAP_FAILED ((void*)-1) +#define MADV_NORMAL 0x0 #define MADV_SET_VOLATILE 0x1 #define MADV_SET_NONVOLATILE 0x2 #define MADV_DONTNEED 0x3 +// https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_madvise.html +#define POSIX_MADV_NORMAL MADV_NORMAL +#define POSIX_MADV_DONTNEED MADV_DONTNEED + +// Unsupported posix_madvise() advise: +// POSIX_MADV_SEQUENTIAL +// POSIX_MADV_RANDOM +// POSIX_MADV_WILLNEED + #define MS_SYNC 1 #define MS_ASYNC 2 #define MS_INVALIDATE 4 diff --git a/Userland/Libraries/LibC/sys/mman.cpp b/Userland/Libraries/LibC/sys/mman.cpp index df796f3e86..7982da44b3 100644 --- a/Userland/Libraries/LibC/sys/mman.cpp +++ b/Userland/Libraries/LibC/sys/mman.cpp @@ -77,6 +77,12 @@ int madvise(void* address, size_t size, int advice) __RETURN_WITH_ERRNO(rc, rc, -1); } +// https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_madvise.html +int posix_madvise(void* address, size_t len, int advice) +{ + return madvise(address, len, advice); +} + void* allocate_tls(const char* initial_data, size_t size) { ptrdiff_t rc = syscall(SC_allocate_tls, initial_data, size); diff --git a/Userland/Libraries/LibC/sys/mman.h b/Userland/Libraries/LibC/sys/mman.h index 1a304478fd..d5cd1d80ec 100644 --- a/Userland/Libraries/LibC/sys/mman.h +++ b/Userland/Libraries/LibC/sys/mman.h @@ -18,6 +18,7 @@ int munmap(void*, size_t); int mprotect(void*, size_t, int prot); int set_mmap_name(void*, size_t, const char*); int madvise(void*, size_t, int advice); +int posix_madvise(void*, size_t, int advice); void* allocate_tls(const char* initial_data, size_t); int mlock(const void*, size_t); int munlock(const void*, size_t);