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/)
|
|
|
|
|
2020-06-19 22:14:40 +02:00
|
|
|
#include <nce.h>
|
2020-10-07 17:41:13 +02:00
|
|
|
#include <kernel/types/KProcess.h>
|
2020-06-19 22:14:40 +02:00
|
|
|
#include <vfs/nacp.h>
|
|
|
|
#include <vfs/region_backing.h>
|
2019-09-24 22:54:27 +02:00
|
|
|
#include "nro.h"
|
|
|
|
|
|
|
|
namespace skyline::loader {
|
2020-06-26 14:23:29 +02:00
|
|
|
NroLoader::NroLoader(const std::shared_ptr<vfs::Backing> &backing) : backing(backing) {
|
2020-09-29 14:46:17 +02:00
|
|
|
header = backing->Read<NroHeader>();
|
2020-03-25 18:59:37 +01:00
|
|
|
|
2020-04-17 23:19:19 +02:00
|
|
|
if (header.magic != util::MakeMagic<u32>("NRO0"))
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
throw exception("Invalid NRO magic! 0x{0:X}", header.magic);
|
2020-06-19 22:14:40 +02:00
|
|
|
|
|
|
|
// The homebrew asset section is appended to the end of an NRO file
|
|
|
|
if (backing->size > header.size) {
|
2020-09-29 14:46:17 +02:00
|
|
|
assetHeader = backing->Read<NroAssetHeader>(header.size);
|
2020-06-19 22:14:40 +02:00
|
|
|
|
|
|
|
if (assetHeader.magic != util::MakeMagic<u32>("ASET"))
|
|
|
|
throw exception("Invalid ASET magic! 0x{0:X}", assetHeader.magic);
|
|
|
|
|
2020-09-26 07:17:57 +02:00
|
|
|
NroAssetSection &nacpHeader{assetHeader.nacp};
|
2020-10-21 19:09:35 +02:00
|
|
|
nacp.emplace(std::make_shared<vfs::RegionBacking>(backing, header.size + nacpHeader.offset, nacpHeader.size));
|
2020-06-22 13:20:26 +02:00
|
|
|
|
2020-09-26 07:17:57 +02:00
|
|
|
NroAssetSection &romFsHeader{assetHeader.romFs};
|
2020-06-22 13:20:26 +02:00
|
|
|
romFs = std::make_shared<vfs::RegionBacking>(backing, header.size + romFsHeader.offset, romFsHeader.size);
|
2020-06-19 22:14:40 +02:00
|
|
|
}
|
2019-10-13 10:04:47 +02:00
|
|
|
}
|
2019-09-24 22:54:27 +02:00
|
|
|
|
2020-06-19 22:14:40 +02:00
|
|
|
std::vector<u8> NroLoader::GetIcon() {
|
2020-09-26 07:17:57 +02:00
|
|
|
NroAssetSection &segmentHeader{assetHeader.icon};
|
2020-06-19 22:14:40 +02:00
|
|
|
std::vector<u8> buffer(segmentHeader.size);
|
|
|
|
|
2020-09-29 14:46:17 +02:00
|
|
|
backing->Read(buffer, header.size + segmentHeader.offset);
|
2020-06-19 22:14:40 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
2019-09-24 22:54:27 +02:00
|
|
|
|
2020-06-25 17:29:35 +02:00
|
|
|
std::vector<u8> NroLoader::GetSegment(const NroSegmentHeader &segment) {
|
|
|
|
std::vector<u8> buffer(segment.size);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
2020-09-29 14:46:17 +02:00
|
|
|
backing->Read(buffer, segment.offset);
|
2020-06-19 22:14:40 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2020-11-08 20:54:15 +01:00
|
|
|
void *NroLoader::LoadProcessData(const std::shared_ptr<kernel::type::KProcess> process, const DeviceState &state) {
|
2020-06-25 17:29:35 +02:00
|
|
|
Executable nroExecutable{};
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
|
2020-06-25 17:29:35 +02:00
|
|
|
nroExecutable.text.contents = GetSegment(header.text);
|
|
|
|
nroExecutable.text.offset = 0;
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
|
2020-06-25 17:29:35 +02:00
|
|
|
nroExecutable.ro.contents = GetSegment(header.ro);
|
|
|
|
nroExecutable.ro.offset = header.text.size;
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
|
2020-06-25 17:29:35 +02:00
|
|
|
nroExecutable.data.contents = GetSegment(header.data);
|
|
|
|
nroExecutable.data.offset = header.text.size + header.ro.size;
|
2019-12-25 20:03:57 +01:00
|
|
|
|
2020-06-25 17:29:35 +02:00
|
|
|
nroExecutable.bssSize = header.bssSize;
|
2020-01-21 08:16:57 +01:00
|
|
|
|
2020-10-07 17:41:13 +02:00
|
|
|
state.process->memory.InitializeVmm(memory::AddressSpaceType::AddressSpace39Bit);
|
2020-09-26 07:17:57 +02:00
|
|
|
auto loadInfo{LoadExecutable(process, state, nroExecutable)};
|
2020-10-07 17:41:13 +02:00
|
|
|
state.process->memory.InitializeRegions(loadInfo.base, loadInfo.size);
|
2020-10-13 22:43:52 +02:00
|
|
|
|
|
|
|
return loadInfo.entry;
|
2019-09-24 22:54:27 +02:00
|
|
|
}
|
2020-06-22 13:20:26 +02:00
|
|
|
}
|