folly/folly/system/MemoryMapping.cpp

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <folly/system/MemoryMapping.h>

#include <algorithm>
#include <cerrno>
#include <utility>

#include <fmt/core.h>
#include <glog/logging.h>

#include <folly/Portability.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/SysMman.h>
#include <folly/portability/SysSyscall.h>
#include <folly/portability/Unistd.h>

#ifdef __linux__
#include <folly/experimental/io/HugePages.h> // @manual
#endif

#include <fcntl.h>
#include <sys/types.h>

#include <system_error>

static constexpr ssize_t kDefaultMlockChunkSize =;

FOLLY_GFLAGS_DEFINE_int64();

namespace folly {

namespace {

enum mmap_flags : int {};

} // namespace

MemoryMapping::MemoryMapping(MemoryMapping&& other) noexcept {}

MemoryMapping::MemoryMapping(
    File file, off64_t offset, off64_t length, Options options)
    :{}

MemoryMapping::MemoryMapping(
    const char* name, off64_t offset, off64_t length, Options options)
    :{}

MemoryMapping::MemoryMapping(
    int fd, off64_t offset, off64_t length, Options options)
    :{}

MemoryMapping::MemoryMapping(AnonymousType, off64_t length, Options options)
    :{}

namespace {

#ifdef __linux__
void getDeviceOptions(dev_t device, off64_t& pageSize, bool& autoExtend) {
  auto ps = getHugePageSizeForDevice(device);
  if (ps) {
    pageSize = ps->size;
    autoExtend = true;
  }
}
#else
inline void getDeviceOptions(dev_t, off64_t&, bool&) {}
#endif

} // namespace

void MemoryMapping::init(off64_t offset, off64_t length) {}

namespace {

off64_t memOpChunkSize(off64_t length, off64_t pageSize) {}

/**
 * Run @op in chunks over the buffer @mem of @bufSize length.
 *
 * Return:
 * - success: true + amountSucceeded == bufSize (op success on whole buffer)
 * - failure: false + amountSucceeded == nr bytes on which op succeeded.
 */
template <typename Op>
bool memOpInChunks(
    Op op,
    void* mem,
    size_t bufSize,
    off64_t pageSize,
    size_t& amountSucceeded) {}

} // namespace

int mlock2wrapper(
    [[maybe_unused]] const void* addr,
    [[maybe_unused]] size_t len,
    MemoryMapping::LockFlags flags) {}

bool MemoryMapping::mlock(LockMode mode, LockFlags flags) {}

void MemoryMapping::munlock(bool dontneed) {}

void MemoryMapping::hintLinearScan() {}

MemoryMapping::~MemoryMapping() {}

void MemoryMapping::advise(int advice) const {}

void MemoryMapping::advise(int advice, size_t offset, size_t length) const {}

MemoryMapping& MemoryMapping::operator=(MemoryMapping&& other) {}

void MemoryMapping::swap(MemoryMapping& other) noexcept {}

void swap(MemoryMapping& a, MemoryMapping& b) noexcept {}

void alignedForwardMemcpy(void* dst, const void* src, size_t size) {}

void mmapFileCopy(const char* src, const char* dest, mode_t mode) {}

bool MemoryMapping::LockFlags::operator==(const LockFlags& other) const {}

} // namespace folly