[Kernel, Memory] Add GetProcessInfo, fix memory management bugs

This commit is contained in:
wheremyfoodat 2022-09-21 22:43:43 +03:00
parent 71ca62e2cc
commit db48d08c34
6 changed files with 66 additions and 7 deletions

View file

@ -30,6 +30,9 @@ class Kernel {
u32 threadCount;
ServiceManager serviceManager;
// Top 8 bits are the major version, bottom 8 are the minor version
u16 kernelVersion = 0;
// Get pointer to the object with the specified handle
KernelObject* getObject(Handle handle) {
// Accessing an object that has not been created
@ -89,6 +92,7 @@ class Kernel {
void controlMemory();
void mapMemoryBlock();
void queryMemory();
void getProcessInfo();
void getResourceLimit();
void getResourceLimitLimitValues();
void getResourceLimitCurrentValues();
@ -101,6 +105,7 @@ class Kernel {
public:
Kernel(CPU& cpu, Memory& mem, GPU& gpu);
void setVersion(u8 major, u8 minor);
void serviceSVC(u32 svc);
void reset();
};

View file

@ -5,6 +5,12 @@
#include <vector>
#include "helpers.hpp"
namespace PhysicalAddrs {
enum : u32 {
FCRAM = 0x20000000
};
}
namespace VirtualAddrs {
enum : u32 {
ExecutableStart = 0x00100000,
@ -18,7 +24,8 @@ namespace VirtualAddrs {
StackSize = 0x4000,
NormalHeapStart = 0x08000000,
LinearHeapStart = 0x14000000,
LinearHeapStartOld = 0x14000000, // If kernel version <
LinearHeapStartNew = 0x30000000,
// Start of TLS for first thread. Next thread's storage will be at TLSBase + 0x1000, and so on
TLSBase = 0xFF400000,
@ -87,6 +94,7 @@ class Memory {
std::optional<u32> findPaddr(u32 size);
public:
u16 kernelVersion = 0;
u32 usedUserMemory = 0;
std::optional<int> gspMemIndex; // Index of GSP shared mem in lockedMemoryInfo or nullopt if it's already reserved
@ -107,6 +115,8 @@ public:
void write32(u32 vaddr, u32 value);
void write64(u32 vaddr, u64 value);
u32 getLinearHeapVaddr();
// Returns whether "addr" is aligned to a page (4096 byte) boundary
static constexpr bool isAligned(u32 addr) {
return (addr & pageMask) == 0;