forked from dolphin-emu/dolphin
This allows avoiding two copies of the executable data being created in
the following scenario (using pseudocode):
some_function()
{
std::vector<u8> data = ...;
DolReader reader{data};
...
}
In this scenario, if we only use the data for passing it to DolReader,
then we have to perform a copy, as the constructor takes the std::vector
as a constant reference -- you cannot move from a constant reference,
and so we copy data into the DolReader, and perform another copy in the
constructor itself when assigning the data to the m_bytes member
variable. However, we can do better.
Now, the following is allowable as well:
some_function()
{
std::vector<u8> data = ...;
DolReader reader{std::move(data)};
...
}
and now we perform no copy at any point in the reader's construction, as
we just std::move the data all the way through to m_bytes.
In the case where we *do* want to keep the executable data around after
constructing the reader, then we can just pass the vector without
std::move-ing it, and we only perform a copy once (as we'll std::move
said copy into m_bytes). Therefore, we get a more flexible interface
resource-wise out of it.
65 lines
1.4 KiB
C++
65 lines
1.4 KiB
C++
// Copyright 2008 Dolphin Emulator Project
|
|
// Licensed under GPLv2+
|
|
// Refer to the license.txt file included.
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "Common/CommonTypes.h"
|
|
#include "Core/Boot/Boot.h"
|
|
|
|
namespace File
|
|
{
|
|
class IOFile;
|
|
}
|
|
|
|
class DolReader final : public BootExecutableReader
|
|
{
|
|
public:
|
|
explicit DolReader(const std::string& filename);
|
|
explicit DolReader(File::IOFile file);
|
|
explicit DolReader(std::vector<u8> buffer);
|
|
~DolReader();
|
|
|
|
bool IsValid() const override { return m_is_valid; }
|
|
bool IsWii() const override { return m_is_wii; }
|
|
u32 GetEntryPoint() const override { return m_dolheader.entryPoint; }
|
|
bool LoadIntoMemory(bool only_in_mem1 = false) const override;
|
|
bool LoadSymbols() const override { return false; }
|
|
|
|
private:
|
|
enum
|
|
{
|
|
DOL_NUM_TEXT = 7,
|
|
DOL_NUM_DATA = 11
|
|
};
|
|
|
|
struct SDolHeader
|
|
{
|
|
u32 textOffset[DOL_NUM_TEXT];
|
|
u32 dataOffset[DOL_NUM_DATA];
|
|
|
|
u32 textAddress[DOL_NUM_TEXT];
|
|
u32 dataAddress[DOL_NUM_DATA];
|
|
|
|
u32 textSize[DOL_NUM_TEXT];
|
|
u32 dataSize[DOL_NUM_DATA];
|
|
|
|
u32 bssAddress;
|
|
u32 bssSize;
|
|
u32 entryPoint;
|
|
};
|
|
SDolHeader m_dolheader;
|
|
|
|
std::vector<std::vector<u8>> m_data_sections;
|
|
std::vector<std::vector<u8>> m_text_sections;
|
|
|
|
bool m_is_valid;
|
|
bool m_is_wii;
|
|
|
|
// Copy sections to internal buffers
|
|
bool Initialize(const std::vector<u8>& buffer);
|
|
};
|