From 0b2135072d3a6b418f87f166b58dcf877f7c2fba Mon Sep 17 00:00:00 2001 From: Neel Natu Date: Thu, 20 Jun 2019 12:54:40 -0700 Subject: Implement madvise(MADV_DONTFORK) PiperOrigin-RevId: 254253777 --- test/util/memory_util.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/util') diff --git a/test/util/memory_util.h b/test/util/memory_util.h index 8c77778ea..190c469b5 100644 --- a/test/util/memory_util.h +++ b/test/util/memory_util.h @@ -118,6 +118,17 @@ inline PosixErrorOr MmapAnon(size_t length, int prot, int flags) { return Mmap(nullptr, length, prot, flags | MAP_ANONYMOUS, -1, 0); } +// Returns true if the page containing addr is mapped. +inline bool IsMapped(uintptr_t addr) { + int const rv = msync(reinterpret_cast(addr & ~(kPageSize - 1)), + kPageSize, MS_ASYNC); + if (rv == 0) { + return true; + } + TEST_PCHECK_MSG(errno == ENOMEM, "msync failed with unexpected errno"); + return false; +} + } // namespace testing } // namespace gvisor -- cgit v1.2.3