2019-07-07 02:05:30 +02:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
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
|
|
|
|
|
|
|
|
MemoryMapping(const MemoryMapping &other) = delete;
|
|
|
|
const MemoryMapping &operator=(const MemoryMapping &other) = delete;
|
|
|
|
MemoryMapping(MemoryMapping &&other);
|
|
|
|
MemoryMapping &operator=(MemoryMapping &&other);
|
|
|
|
~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
|