2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-07-11 16:14:30 +03:00
|
|
|
#include <AK/Noncopyable.h>
|
|
|
|
#include <AK/StringView.h>
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
class MappedFile {
|
2019-07-11 16:14:30 +03:00
|
|
|
AK_MAKE_NONCOPYABLE(MappedFile);
|
2018-10-10 12:53:07 +03:00
|
|
|
public:
|
2019-05-28 12:53:16 +03:00
|
|
|
MappedFile() {}
|
2019-06-02 15:58:02 +03:00
|
|
|
explicit MappedFile(const StringView& file_name);
|
2018-10-10 12:53:07 +03:00
|
|
|
MappedFile(MappedFile&&);
|
|
|
|
~MappedFile();
|
|
|
|
|
2019-04-03 14:51:49 +03:00
|
|
|
MappedFile& operator=(MappedFile&&);
|
|
|
|
|
2019-01-31 19:31:23 +03:00
|
|
|
bool is_valid() const { return m_map != (void*)-1; }
|
2019-04-03 14:51:49 +03:00
|
|
|
void unmap();
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2019-09-30 09:57:01 +03:00
|
|
|
void* data() { return m_map; }
|
|
|
|
const void* data() const { return m_map; }
|
2019-04-03 15:15:35 +03:00
|
|
|
size_t size() const { return m_size; }
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
private:
|
2019-04-03 15:15:35 +03:00
|
|
|
size_t m_size { 0 };
|
2018-10-10 12:53:07 +03:00
|
|
|
void* m_map { (void*)-1 };
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::MappedFile;
|