diff options
author | Neel Natu <neelnatu@google.com> | 2019-06-20 12:54:40 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-06-20 12:56:00 -0700 |
commit | 0b2135072d3a6b418f87f166b58dcf877f7c2fba (patch) | |
tree | 40c316afa59e5786fac24b7e8be940ae645ffb16 /test/util | |
parent | b46ec3704b60bebdd63a597c62f3f471ee0d9be9 (diff) |
Implement madvise(MADV_DONTFORK)
PiperOrigin-RevId: 254253777
Diffstat (limited to 'test/util')
-rw-r--r-- | test/util/memory_util.h | 11 |
1 files changed, 11 insertions, 0 deletions
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<Mapping> 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<void*>(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 |