#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/memory/madv_free_discardable_memory_posix.h"
#include <errno.h>
#include <inttypes.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <atomic>
#include "base/atomicops.h"
#include "base/bits.h"
#include "base/functional/callback.h"
#include "base/logging.h"
#include "base/memory/madv_free_discardable_memory_allocator_posix.h"
#include "base/memory/page_size.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/tracing_buildflags.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_ANDROID)
#include <sys/prctl.h>
#endif
#if BUILDFLAG(ENABLE_BASE_TRACING)
#include "base/trace_event/memory_allocator_dump.h"
#include "base/trace_event/memory_dump_manager.h"
#endif
#if defined(ADDRESS_SANITIZER)
#include <sanitizer/asan_interface.h>
#endif
namespace {
constexpr intptr_t kPageMagicCookie = …;
void* AllocatePages(size_t size_in_pages) { … }
base::MadvFreeSupport ProbePlatformMadvFreeSupport() { … }
}
namespace base {
MadvFreeDiscardableMemoryPosix::MadvFreeDiscardableMemoryPosix(
size_t size_in_bytes,
std::atomic<size_t>* allocator_byte_count)
: … { … }
MadvFreeDiscardableMemoryPosix::~MadvFreeDiscardableMemoryPosix() { … }
bool MadvFreeDiscardableMemoryPosix::Lock() { … }
void MadvFreeDiscardableMemoryPosix::Unlock() { … }
void* MadvFreeDiscardableMemoryPosix::data() const { … }
bool MadvFreeDiscardableMemoryPosix::LockPage(size_t page_index) { … }
void MadvFreeDiscardableMemoryPosix::UnlockPage(size_t page_index) { … }
void MadvFreeDiscardableMemoryPosix::DiscardPage(size_t page_index) { … }
bool MadvFreeDiscardableMemoryPosix::IsLockedForTesting() const { … }
void MadvFreeDiscardableMemoryPosix::DiscardForTesting() { … }
trace_event::MemoryAllocatorDump*
MadvFreeDiscardableMemoryPosix::CreateMemoryAllocatorDump(
const char* name,
trace_event::ProcessMemoryDump* pmd) const { … }
bool MadvFreeDiscardableMemoryPosix::IsValid() const { … }
void MadvFreeDiscardableMemoryPosix::SetKeepMemoryForTesting(bool keep_memory) { … }
bool MadvFreeDiscardableMemoryPosix::IsResident() const { … }
bool MadvFreeDiscardableMemoryPosix::IsDiscarded() const { … }
bool MadvFreeDiscardableMemoryPosix::Deallocate() { … }
MadvFreeSupport GetMadvFreeSupport() { … }
}