2019-07-07 02:05:30 +02:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2019-07-07 02:05:30 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/port/FileFd.h"
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class MemoryMapping {
|
|
|
|
public:
|
|
|
|
struct Options {
|
|
|
|
int64 offset{0};
|
|
|
|
int64 size{-1};
|
|
|
|
|
|
|
|
Options() {
|
|
|
|
}
|
|
|
|
Options &with_offset(int64 new_offset) {
|
|
|
|
offset = new_offset;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Options &with_size(int64 new_size) {
|
|
|
|
size = new_size;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static Result<MemoryMapping> create_anonymous(const Options &options = {});
|
|
|
|
static Result<MemoryMapping> create_from_file(const FileFd &file, const Options &options = {});
|
|
|
|
|
|
|
|
Slice as_slice() const;
|
|
|
|
MutableSlice as_mutable_slice(); // returns empty slice if memory is read-only
|
|
|
|
|
2023-05-05 12:51:19 +02:00
|
|
|
MemoryMapping(const MemoryMapping &) = delete;
|
2023-05-05 13:31:55 +02:00
|
|
|
MemoryMapping &operator=(const MemoryMapping &) = delete;
|
2021-10-18 13:36:15 +02:00
|
|
|
MemoryMapping(MemoryMapping &&other) noexcept;
|
|
|
|
MemoryMapping &operator=(MemoryMapping &&other) noexcept;
|
2019-07-07 02:05:30 +02:00
|
|
|
~MemoryMapping();
|
|
|
|
|
|
|
|
private:
|
2019-07-21 20:07:07 +02:00
|
|
|
class Impl;
|
|
|
|
unique_ptr<Impl> impl_;
|
|
|
|
explicit MemoryMapping(unique_ptr<Impl> impl);
|
2019-07-07 02:05:30 +02:00
|
|
|
};
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2019-07-07 02:05:30 +02:00
|
|
|
} // namespace td
|