2020-04-19 23:04:05 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-27 20:36:02 +01:00
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2019-07-24 22:19:43 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-03-26 15:33:19 +01:00
|
|
|
#include <unistd.h>
|
2019-10-13 10:04:47 +02:00
|
|
|
#include <os.h>
|
|
|
|
#include <kernel/types/KProcess.h>
|
2019-07-24 22:19:43 +02:00
|
|
|
|
2019-09-24 22:54:27 +02:00
|
|
|
namespace skyline::loader {
|
2019-07-24 22:19:43 +02:00
|
|
|
class Loader {
|
2019-09-14 14:41:00 +02:00
|
|
|
protected:
|
2020-04-22 19:02:27 +02:00
|
|
|
int fd; //!< An FD to the ROM file
|
2019-07-24 22:19:43 +02:00
|
|
|
|
2019-09-05 14:42:19 +02:00
|
|
|
/**
|
2019-09-24 22:54:27 +02:00
|
|
|
* @brief Read the file at a particular offset
|
2019-09-05 14:42:19 +02:00
|
|
|
* @tparam T The type of object to write to
|
|
|
|
* @param output The object to write to
|
|
|
|
* @param offset The offset to read the file at
|
|
|
|
* @param size The amount to read in bytes
|
|
|
|
*/
|
2019-07-24 22:19:43 +02:00
|
|
|
template<typename T>
|
2020-01-09 02:37:54 +01:00
|
|
|
inline void ReadOffset(T *output, u64 offset, size_t size) {
|
2020-04-22 19:02:27 +02:00
|
|
|
pread64(fd, output, size, offset);
|
2019-07-24 22:19:43 +02:00
|
|
|
}
|
|
|
|
|
2019-09-14 14:41:00 +02:00
|
|
|
public:
|
2019-09-05 14:42:19 +02:00
|
|
|
/**
|
2019-11-14 20:06:38 +01:00
|
|
|
* @param filePath The path to the ROM file
|
2019-09-05 14:42:19 +02:00
|
|
|
*/
|
2020-04-22 19:02:27 +02:00
|
|
|
Loader(int fd) : fd(fd) {}
|
2019-10-13 10:04:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This loads in the data of the main process
|
|
|
|
* @param process The process to load in the data
|
|
|
|
* @param state The state of the device
|
|
|
|
*/
|
|
|
|
virtual void LoadProcessData(const std::shared_ptr<kernel::type::KProcess> process, const DeviceState &state) = 0;
|
2019-07-24 22:19:43 +02:00
|
|
|
};
|
2019-09-05 14:42:19 +02:00
|
|
|
}
|