Flutter Engine
 
Loading...
Searching...
No Matches
MMapFile Class Reference

A memory mapped file. More...

#include <mmap_file.h>

Public Member Functions

 ~MMapFile ()
 
 MMapFile (const MMapFile &)=delete
 
MMapFileoperator= (const MMapFile &)=delete
 
 MMapFile (MMapFile &&other)
 
const char * GetData () const
 
size_t GetSize () const
 

Static Public Member Functions

static absl::StatusOr< MMapFileMake (std::string_view path)
 

Detailed Description

A memory mapped file.

Definition at line 12 of file mmap_file.h.

Constructor & Destructor Documentation

◆ ~MMapFile()

MMapFile::~MMapFile ( )

Definition at line 42 of file mmap_file.cc.

42 {
43 if (data_) {
44 munmap(const_cast<char*>(data_), size_);
45 }
46 if (fd_ >= 0) {
47 close(fd_);
48 }
49}

◆ MMapFile() [1/2]

MMapFile::MMapFile ( const MMapFile )
delete

◆ MMapFile() [2/2]

MMapFile::MMapFile ( MMapFile &&  other)

Definition at line 51 of file mmap_file.cc.

51 {
52 fd_ = other.fd_;
53 data_ = other.data_;
54 size_ = other.size_;
55 other.fd_ = -1;
56 other.data_ = nullptr;
57 other.size_ = 0;
58}

Member Function Documentation

◆ GetData()

const char * MMapFile::GetData ( ) const
inline

Definition at line 23 of file mmap_file.h.

23{ return data_; }

◆ GetSize()

size_t MMapFile::GetSize ( ) const
inline

Definition at line 25 of file mmap_file.h.

25{ return size_; }

◆ Make()

absl::StatusOr< MMapFile > MMapFile::Make ( std::string_view  path)
static

Definition at line 13 of file mmap_file.cc.

13 {
14 int fd = open(path.data(), O_RDONLY);
15 if (fd < 0) {
16 return absl::UnavailableError("can't open file");
17 }
18
19 struct stat st;
20 if (fstat(fd, &st) < 0) {
21 close(fd);
22 return absl::UnavailableError("can't stat file");
23 }
24
25 if (st.st_size <= 0) {
26 close(fd);
27 return absl::InvalidArgumentError("file of zero length");
28 }
29
30 const char* data = static_cast<const char*>(
31 mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0));
32
33 if (data == MAP_FAILED) {
34 close(fd);
35 return absl::UnavailableError(
36 absl::StrCat("can't mmap file (", path, "): ", std::strerror(errno)));
37 }
38
39 return MMapFile(fd, data, st.st_size);
40}
A memory mapped file.
Definition mmap_file.h:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52
std::shared_ptr< const fml::Mapping > data

References data.

Referenced by main(), and LicenseChecker::Run().

◆ operator=()

MMapFile & MMapFile::operator= ( const MMapFile )
delete

The documentation for this class was generated from the following files: