From: Waldemar Kozaczuk <[email protected]>
Committer: Waldemar Kozaczuk <[email protected]>
Branch: master

libc: implement posix_madvise

Some apps/runtimes like dotnet call posix_madvise
which we do not implement. This patch adds a simple
implementation of it based on madvise with a difference
that only POSIX_MADV_DONTNEED is supported. On top of
this as required posix_madvise() returns an error without
setting errno.

Signed-off-by: Waldemar Kozaczuk <[email protected]>

---
diff --git a/exported_symbols/osv_ld-musl.so.1.symbols 
b/exported_symbols/osv_ld-musl.so.1.symbols
--- a/exported_symbols/osv_ld-musl.so.1.symbols
+++ b/exported_symbols/osv_ld-musl.so.1.symbols
@@ -722,6 +722,7 @@ posix_fadvise64
 posix_fallocate
 posix_fallocate64
 __posix_getopt
+posix_madvise
 posix_memalign
 pow
 pow10
diff --git a/exported_symbols/osv_libc.so.6.symbols 
b/exported_symbols/osv_libc.so.6.symbols
--- a/exported_symbols/osv_libc.so.6.symbols
+++ b/exported_symbols/osv_libc.so.6.symbols
@@ -595,6 +595,7 @@ posix_fadvise64
 posix_fallocate
 posix_fallocate64
 __posix_getopt
+posix_madvise
 posix_memalign
 ppoll
 prctl
diff --git a/libc/mman.cc b/libc/mman.cc
--- a/libc/mman.cc
+++ b/libc/mman.cc
@@ -257,3 +257,17 @@ void *sbrk(intptr_t increment)
     errno = ENOMEM;
     return (void *)-1;
 }
+
+static unsigned posix_madvise_to_advise(int advice)
+{
+    if (advice == POSIX_MADV_DONTNEED) {
+        return mmu::advise_dontneed;
+    }
+    return 0;
+}
+
+OSV_LIBC_API
+int posix_madvise(void *addr, size_t len, int advice) {
+    auto err = mmu::advise(addr, len, posix_madvise_to_advise(advice));
+    return err.get();
+}

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/00000000000063f01105d4934de6%40google.com.

Reply via email to