mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-04 23:35:12 +01:00
Make regions public members of the memory class and drop the type enum
There isn't really much benefit in having a getter or an enum, so drop it.
This commit is contained in:
parent
eadc016525
commit
7884a60679
@ -285,7 +285,7 @@ namespace skyline {
|
||||
* @param size The length of the string (0 means the string is null terminated)
|
||||
*/
|
||||
inline std::string_view PopString(size_t size = 0) {
|
||||
auto view = size ? std::string_view(reinterpret_cast<const char*>(payloadOffset), size) : std::string_view(reinterpret_cast<const char*>(payloadOffset));
|
||||
auto view = size ? std::string_view(reinterpret_cast<const char *>(payloadOffset), size) : std::string_view(reinterpret_cast<const char *>(payloadOffset));
|
||||
payloadOffset += view.length();
|
||||
return view;
|
||||
}
|
||||
|
@ -173,23 +173,6 @@ namespace skyline::kernel {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
memory::Region MemoryManager::GetRegion(memory::Regions region) {
|
||||
switch (region) {
|
||||
case memory::Regions::Base:
|
||||
return base;
|
||||
case memory::Regions::Code:
|
||||
return code;
|
||||
case memory::Regions::Alias:
|
||||
return alias;
|
||||
case memory::Regions::Heap:
|
||||
return heap;
|
||||
case memory::Regions::Stack:
|
||||
return stack;
|
||||
case memory::Regions::TlsIo:
|
||||
return tlsIo;
|
||||
}
|
||||
}
|
||||
|
||||
size_t MemoryManager::GetProgramSize() {
|
||||
size_t size = 0;
|
||||
|
||||
|
@ -170,23 +170,10 @@ namespace skyline {
|
||||
constexpr MemoryState CodeWritable = 0x00402015;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This enumerates all of the memory regions in the process address space
|
||||
*/
|
||||
enum class Regions {
|
||||
Base, //!< The region representing the entire address space
|
||||
Code, //!< The code region contains all of the loaded in code
|
||||
Alias, //!< The alias region is reserved for allocating thread stack before 2.0.0
|
||||
Heap, //!< The heap region is reserved for heap allocations
|
||||
Stack, //!< The stack region is reserved for allocating thread stack after 2.0.0
|
||||
TlsIo, //!< The TLS/IO region is reserved for allocating TLS and Device MMIO
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This struct is used to hold the location and size of a memory region
|
||||
*/
|
||||
struct Region {
|
||||
Regions id; //!< The ID of the region
|
||||
u64 address; //!< The base address of the region
|
||||
u64 size; //!< The size of the region in bytes
|
||||
|
||||
@ -265,12 +252,6 @@ namespace skyline {
|
||||
private:
|
||||
const DeviceState &state; //!< The state of the device
|
||||
std::vector<ChunkDescriptor> chunkList; //!< This vector holds all the chunk descriptors
|
||||
memory::Region base{memory::Regions::Base}; //!< The Region object for the entire address space
|
||||
memory::Region code{memory::Regions::Code}; //!< The Region object for the code memory region
|
||||
memory::Region alias{memory::Regions::Alias}; //!< The Region object for the alias memory region
|
||||
memory::Region heap{memory::Regions::Heap}; //!< The Region object for the heap memory region
|
||||
memory::Region stack{memory::Regions::Stack}; //!< The Region object for the stack memory region
|
||||
memory::Region tlsIo{memory::Regions::TlsIo}; //!< The Region object for the TLS/IO memory region
|
||||
|
||||
/**
|
||||
* @param address The address to find a chunk at
|
||||
@ -331,6 +312,13 @@ namespace skyline {
|
||||
|
||||
friend void svc::MapMemory(skyline::DeviceState &state);
|
||||
|
||||
memory::Region base{}; //!< The Region object for the entire address space
|
||||
memory::Region code{}; //!< The Region object for the code memory region
|
||||
memory::Region alias{}; //!< The Region object for the alias memory region
|
||||
memory::Region heap{}; //!< The Region object for the heap memory region
|
||||
memory::Region stack{}; //!< The Region object for the stack memory region
|
||||
memory::Region tlsIo{}; //!< The Region object for the TLS/IO memory region
|
||||
|
||||
MemoryManager(const DeviceState &state);
|
||||
|
||||
/**
|
||||
@ -339,12 +327,6 @@ namespace skyline {
|
||||
*/
|
||||
std::optional<DescriptorPack> Get(u64 address);
|
||||
|
||||
/**
|
||||
* @param region The region to retrieve
|
||||
* @return A Region object for the specified region
|
||||
*/
|
||||
memory::Region GetRegion(memory::Regions region);
|
||||
|
||||
/**
|
||||
* @brief The total amount of space in bytes occupied by all memory mappings
|
||||
* @return The cumulative size of all memory mappings in bytes
|
||||
|
@ -88,7 +88,7 @@ namespace skyline::kernel::svc {
|
||||
return;
|
||||
}
|
||||
|
||||
auto stack = state.os->memory.GetRegion(memory::Regions::Stack);
|
||||
auto stack = state.os->memory.stack;
|
||||
if (!stack.IsInside(destination)) {
|
||||
state.ctx->registers.w0 = constant::status::InvMemRange;
|
||||
state.logger->Warn("svcMapMemory: Destination not within stack region: Source: 0x{:X}, Destination: 0x{:X} (Size: 0x{:X} bytes)", source, destination, size);
|
||||
@ -137,7 +137,7 @@ namespace skyline::kernel::svc {
|
||||
return;
|
||||
}
|
||||
|
||||
auto stack = state.os->memory.GetRegion(memory::Regions::Stack);
|
||||
auto stack = state.os->memory.stack;
|
||||
if (!stack.IsInside(source)) {
|
||||
state.ctx->registers.w0 = constant::status::InvMemRange;
|
||||
state.logger->Warn("svcUnmapMemory: Source not within stack region: Source: 0x{:X}, Destination: 0x{:X} (Size: 0x{:X} bytes)", source, destination, size);
|
||||
@ -195,7 +195,7 @@ namespace skyline::kernel::svc {
|
||||
|
||||
state.logger->Debug("svcQueryMemory: Address: 0x{:X}, Size: 0x{:X}, Type: 0x{:X}, Is Uncached: {}, Permissions: {}{}{}", memInfo.address, memInfo.size, memInfo.type, static_cast<bool>(descriptor->block.attributes.isUncached), descriptor->block.permission.r ? "R" : "-", descriptor->block.permission.w ? "W" : "-", descriptor->block.permission.x ? "X" : "-");
|
||||
} else {
|
||||
auto region = state.os->memory.GetRegion(memory::Regions::Base);
|
||||
auto region = state.os->memory.base;
|
||||
auto baseEnd = region.address + region.size;
|
||||
|
||||
memInfo = {
|
||||
@ -645,19 +645,19 @@ namespace skyline::kernel::svc {
|
||||
break;
|
||||
|
||||
case constant::infoState::AliasRegionBaseAddr:
|
||||
out = state.os->memory.GetRegion(memory::Regions::Alias).address;
|
||||
out = state.os->memory.alias.address;
|
||||
break;
|
||||
|
||||
case constant::infoState::AliasRegionSize:
|
||||
out = state.os->memory.GetRegion(memory::Regions::Alias).size;
|
||||
out = state.os->memory.alias.size;
|
||||
break;
|
||||
|
||||
case constant::infoState::HeapRegionBaseAddr:
|
||||
out = state.os->memory.GetRegion(memory::Regions::Heap).address;
|
||||
out = state.os->memory.heap.address;
|
||||
break;
|
||||
|
||||
case constant::infoState::HeapRegionSize:
|
||||
out = state.os->memory.GetRegion(memory::Regions::Heap).size;
|
||||
out = state.os->memory.heap.size;
|
||||
break;
|
||||
|
||||
case constant::infoState::TotalMemoryAvailable:
|
||||
@ -669,19 +669,19 @@ namespace skyline::kernel::svc {
|
||||
break;
|
||||
|
||||
case constant::infoState::AddressSpaceBaseAddr:
|
||||
out = state.os->memory.GetRegion(memory::Regions::Base).address;
|
||||
out = state.os->memory.base.address;
|
||||
break;
|
||||
|
||||
case constant::infoState::AddressSpaceSize:
|
||||
out = state.os->memory.GetRegion(memory::Regions::Base).size;
|
||||
out = state.os->memory.base.size;
|
||||
break;
|
||||
|
||||
case constant::infoState::StackRegionBaseAddr:
|
||||
out = state.os->memory.GetRegion(memory::Regions::Stack).address;
|
||||
out = state.os->memory.stack.address;
|
||||
break;
|
||||
|
||||
case constant::infoState::StackRegionSize:
|
||||
out = state.os->memory.GetRegion(memory::Regions::Stack).size;
|
||||
out = state.os->memory.stack.size;
|
||||
break;
|
||||
|
||||
case constant::infoState::PersonalMmHeapSize:
|
||||
|
@ -39,7 +39,7 @@ namespace skyline::kernel::type {
|
||||
|
||||
u64 address;
|
||||
if (tlsPages.empty()) {
|
||||
auto region = state.os->memory.GetRegion(memory::Regions::TlsIo);
|
||||
auto region = state.os->memory.tlsIo;
|
||||
address = region.size ? region.address : 0;
|
||||
} else {
|
||||
address = (*(tlsPages.end() - 1))->address + PAGE_SIZE;
|
||||
@ -57,7 +57,7 @@ namespace skyline::kernel::type {
|
||||
|
||||
void KProcess::InitializeMemory() {
|
||||
constexpr size_t DefHeapSize = 0x200000; // The default amount of heap
|
||||
heap = NewHandle<KPrivateMemory>(state.os->memory.GetRegion(memory::Regions::Heap).address, DefHeapSize, memory::Permission{true, true, false}, memory::states::Heap).item;
|
||||
heap = NewHandle<KPrivateMemory>(state.os->memory.heap.address, DefHeapSize, memory::Permission{true, true, false}, memory::states::Heap).item;
|
||||
threads[pid]->tls = GetTlsSlot();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user