mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
AK: Make MappedFile store why it is invalid
This makes AK::MappedFile save the errno either open() or mmap() failed with.
This commit is contained in:
parent
d04c833002
commit
6131417904
Notes:
sideshowbarker
2024-07-19 04:25:21 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/61314179043 Pull-request: https://github.com/SerenityOS/serenity/pull/2694 Issue: https://github.com/SerenityOS/serenity/issues/2685 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bugaevc
@ -41,6 +41,7 @@ MappedFile::MappedFile(const StringView& file_name)
|
||||
int fd = open_with_path_length(file_name.characters_without_null_termination(), file_name.length(), O_RDONLY | O_CLOEXEC, 0);
|
||||
|
||||
if (fd == -1) {
|
||||
m_errno = errno;
|
||||
perror("open");
|
||||
return;
|
||||
}
|
||||
@ -50,8 +51,10 @@ MappedFile::MappedFile(const StringView& file_name)
|
||||
m_size = st.st_size;
|
||||
m_map = mmap(nullptr, m_size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
|
||||
if (m_map == MAP_FAILED)
|
||||
if (m_map == MAP_FAILED) {
|
||||
m_errno = errno;
|
||||
perror("mmap");
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MAPPED_FILE
|
||||
dbgprintf("MappedFile{%s} := { fd=%d, m_size=%u, m_map=%p }\n", file_name.characters(), fd, m_size, m_map);
|
||||
|
@ -33,8 +33,9 @@ namespace AK {
|
||||
|
||||
class MappedFile {
|
||||
AK_MAKE_NONCOPYABLE(MappedFile);
|
||||
|
||||
public:
|
||||
MappedFile() {}
|
||||
MappedFile() { }
|
||||
explicit MappedFile(const StringView& file_name);
|
||||
MappedFile(MappedFile&&);
|
||||
~MappedFile();
|
||||
@ -42,6 +43,11 @@ public:
|
||||
MappedFile& operator=(MappedFile&&);
|
||||
|
||||
bool is_valid() const { return m_map != (void*)-1; }
|
||||
int errno_if_invalid() const
|
||||
{
|
||||
ASSERT(!is_valid());
|
||||
return m_errno;
|
||||
}
|
||||
void unmap();
|
||||
|
||||
void* data() { return m_map; }
|
||||
@ -51,6 +57,7 @@ public:
|
||||
private:
|
||||
size_t m_size { 0 };
|
||||
void* m_map { (void*)-1 };
|
||||
int m_errno { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user