aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/function_wrappers.h72
-rw-r--r--src/core/hle/kernel/mutex.cpp3
-rw-r--r--src/core/hle/kernel/mutex.h3
-rw-r--r--src/core/hle/kernel/process.cpp47
-rw-r--r--src/core/hle/kernel/process.h17
-rw-r--r--src/core/hle/kernel/semaphore.cpp3
-rw-r--r--src/core/hle/kernel/semaphore.h3
-rw-r--r--src/core/hle/kernel/thread.cpp9
-rw-r--r--src/core/hle/kernel/thread.h8
-rw-r--r--src/core/hle/kernel/vm_manager.cpp28
-rw-r--r--src/core/hle/kernel/vm_manager.h20
-rw-r--r--src/core/hle/service/apt/apt.cpp12
-rw-r--r--src/core/hle/service/csnd_snd.cpp2
-rw-r--r--src/core/hle/service/ldr_ro/cro_helper.cpp2
-rw-r--r--src/core/hle/service/sm/srv.cpp2
-rw-r--r--src/core/hle/svc.cpp158
16 files changed, 188 insertions, 201 deletions
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h
index f93439f21..31fda6db3 100644
--- a/src/core/hle/function_wrappers.h
+++ b/src/core/hle/function_wrappers.h
@@ -20,23 +20,41 @@ namespace HLE {
* HLE a function return from the current ARM11 userland process
* @param res Result to return
*/
-static inline void FuncReturn(u32 res) {
+static inline void FuncReturn(u64 res) {
Core::CPU().SetReg(0, res);
}
-/**
- * HLE a function return (64-bit) from the current ARM11 userland process
- * @param res Result to return (64-bit)
- * @todo Verify that this function is correct
- */
-static inline void FuncReturn64(u64 res) {
- Core::CPU().SetReg(0, (u32)(res & 0xFFFFFFFF));
- Core::CPU().SetReg(1, (u32)((res >> 32) & 0xFFFFFFFF));
-}
-
////////////////////////////////////////////////////////////////////////////////////////////////////
// Function wrappers that return type ResultCode
+template <ResultCode func(u64)>
+void Wrap() {
+ FuncReturn(func(PARAM(0)).raw);
+}
+
+template <ResultCode func(u32, u64, u32)>
+void Wrap() {
+ FuncReturn(func(PARAM(0), PARAM(1), PARAM(2)).raw);
+}
+
+template <ResultCode func(u64, u32)>
+void Wrap() {
+ FuncReturn(func(PARAM(0), PARAM(1)).raw);
+}
+
+template <ResultCode func(u64, u64, u64)>
+void Wrap() {
+ FuncReturn(func(PARAM(0), PARAM(1), PARAM(2)).raw);
+}
+
+template <ResultCode func(u64*, u64, u64, u64)>
+void Wrap() {
+ u64 param_1 = 0;
+ u32 retval = func(&param_1, PARAM(1), PARAM(2), PARAM(3)).raw;
+ Core::CPU().SetReg(1, param_1);
+ FuncReturn(retval);
+}
+
template <ResultCode func(u32, u32, u32, u32)>
void Wrap() {
FuncReturn(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)).raw);
@@ -84,6 +102,14 @@ void Wrap() {
func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), (((s64)PARAM(5) << 32) | PARAM(4))).raw);
}
+template <ResultCode func(u32, u64*)>
+void Wrap() {
+ u64 param_1 = 0;
+ u32 retval = func(PARAM(0), &param_1).raw;
+ Core::CPU().SetReg(1, param_1);
+ FuncReturn(retval);
+}
+
template <ResultCode func(u32*)>
void Wrap() {
u32 param_1 = 0;
@@ -99,16 +125,17 @@ void Wrap() {
FuncReturn(retval);
}
-template <ResultCode func(MemoryInfo*, PageInfo*, u32)>
+template <ResultCode func(MemoryInfo*, PageInfo*, u64)>
void Wrap() {
MemoryInfo memory_info = {};
PageInfo page_info = {};
u32 retval = func(&memory_info, &page_info, PARAM(2)).raw;
- Core::CPU().SetReg(1, memory_info.base_address);
- Core::CPU().SetReg(2, memory_info.size);
- Core::CPU().SetReg(3, memory_info.permission);
- Core::CPU().SetReg(4, memory_info.state);
- Core::CPU().SetReg(5, page_info.flags);
+
+ Memory::Write64(PARAM(0), memory_info.base_address);
+ Memory::Write64(PARAM(0) + 8, memory_info.size);
+ Memory::Write64(PARAM(0) + 16, memory_info.permission);
+ Memory::Write64(PARAM(0) + 24, memory_info.state);
+
FuncReturn(retval);
}
@@ -138,7 +165,7 @@ void Wrap() {
FuncReturn(func(PARAM(0), (s32)PARAM(1)).raw);
}
-template <ResultCode func(u32*, u32)>
+template <ResultCode func(u32*, u64)>
void Wrap() {
u32 param_1 = 0;
u32 retval = func(&param_1, PARAM(1)).raw;
@@ -226,6 +253,11 @@ void Wrap() {
FuncReturn(retval);
}
+template <ResultCode func(u32, u32, u32)>
+void Wrap() {
+ FuncReturn(func(PARAM(0), PARAM(1), PARAM(2)).raw);
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////
// Function wrappers that return type u32
@@ -255,9 +287,9 @@ void Wrap() {
func(PARAM(0), PARAM(1));
}
-template <void func(u8)>
+template <void func(u64, u64, u64)>
void Wrap() {
- func((u8)PARAM(0));
+ func(PARAM(0), PARAM(1), PARAM(2));
}
#undef PARAM
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 2cbca5e5b..30dade552 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -25,10 +25,11 @@ void ReleaseThreadMutexes(Thread* thread) {
Mutex::Mutex() {}
Mutex::~Mutex() {}
-SharedPtr<Mutex> Mutex::Create(bool initial_locked, std::string name) {
+SharedPtr<Mutex> Mutex::Create(bool initial_locked, VAddr addr, std::string name) {
SharedPtr<Mutex> mutex(new Mutex);
mutex->lock_count = 0;
+ mutex->addr = addr;
mutex->name = std::move(name);
mutex->holding_thread = nullptr;
diff --git a/src/core/hle/kernel/mutex.h b/src/core/hle/kernel/mutex.h
index bacacd690..503d3ee75 100644
--- a/src/core/hle/kernel/mutex.h
+++ b/src/core/hle/kernel/mutex.h
@@ -21,7 +21,7 @@ public:
* @param name Optional name of mutex
* @return Pointer to new Mutex object
*/
- static SharedPtr<Mutex> Create(bool initial_locked, std::string name = "Unknown");
+ static SharedPtr<Mutex> Create(bool initial_locked, VAddr addr, std::string name = "Unknown");
std::string GetTypeName() const override {
return "Mutex";
@@ -39,6 +39,7 @@ public:
u32 priority; ///< The priority of the mutex, used for priority inheritance.
std::string name; ///< Name of mutex (optional)
SharedPtr<Thread> holding_thread; ///< Thread that has acquired the mutex
+ VAddr addr;
/**
* Elevate the mutex priority to the best priority
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index cf3163e0f..9e145866f 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -30,10 +30,10 @@ CodeSet::~CodeSet() {}
u32 Process::next_process_id;
-SharedPtr<Process> Process::Create(SharedPtr<CodeSet> code_set) {
+SharedPtr<Process> Process::Create(std::string&& name) {
SharedPtr<Process> process(new Process);
- process->codeset = std::move(code_set);
+ process->name = std::move(name);
process->flags.raw = 0;
process->flags.memory_region.Assign(MemoryRegion::APPLICATION);
@@ -112,25 +112,7 @@ void Process::ParseKernelCaps(const u32* kernel_caps, size_t len) {
}
}
-void Process::Run(s32 main_thread_priority, u32 stack_size) {
- memory_region = GetMemoryRegion(flags.memory_region);
-
- auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions,
- MemoryState memory_state) {
- auto vma = vm_manager
- .MapMemoryBlock(segment.addr, codeset->memory, segment.offset, segment.size,
- memory_state)
- .Unwrap();
- vm_manager.Reprotect(vma, permissions);
- misc_memory_used += segment.size;
- memory_region->used += segment.size;
- };
-
- // Map CodeSet segments
- MapSegment(codeset->code, VMAPermission::ReadExecute, MemoryState::Code);
- MapSegment(codeset->rodata, VMAPermission::Read, MemoryState::Code);
- MapSegment(codeset->data, VMAPermission::ReadWrite, MemoryState::Private);
-
+void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) {
// Allocate and map stack
vm_manager
.MapMemoryBlock(Memory::HEAP_VADDR_END - stack_size,
@@ -147,7 +129,28 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
}
vm_manager.LogLayout(Log::Level::Debug);
- Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority, this);
+
+ Kernel::SetupMainThread(entry_point, main_thread_priority, this);
+}
+
+void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) {
+ memory_region = GetMemoryRegion(flags.memory_region);
+
+ auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions,
+ MemoryState memory_state) {
+ auto vma = vm_manager
+ .MapMemoryBlock(segment.addr + base_addr, module_->memory, segment.offset, segment.size,
+ memory_state)
+ .Unwrap();
+ vm_manager.Reprotect(vma, permissions);
+ misc_memory_used += segment.size;
+ memory_region->used += segment.size;
+ };
+
+ // Map CodeSet segments
+ MapSegment(module_->code, VMAPermission::ReadWrite, MemoryState::Private);
+ MapSegment(module_->rodata, VMAPermission::Read, MemoryState::Static);
+ MapSegment(module_->data, VMAPermission::ReadWrite, MemoryState::Static);
}
VAddr Process::GetLinearHeapAreaAddress() const {
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index b52211d2a..f05f2703e 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -79,7 +79,11 @@ struct CodeSet final : public Object {
u32 size = 0;
};
- Segment code, rodata, data;
+ Segment segments[3];
+ Segment& code = segments[0];
+ Segment& rodata = segments[1];
+ Segment& data = segments[2];
+
VAddr entrypoint;
private:
@@ -89,13 +93,13 @@ private:
class Process final : public Object {
public:
- static SharedPtr<Process> Create(SharedPtr<CodeSet> code_set);
+ static SharedPtr<Process> Create(std::string&& name);
std::string GetTypeName() const override {
return "Process";
}
std::string GetName() const override {
- return codeset->name;
+ return name;
}
static const HandleType HANDLE_TYPE = HandleType::Process;
@@ -105,7 +109,6 @@ public:
static u32 next_process_id;
- SharedPtr<CodeSet> codeset;
/// Resource limit descriptor for this process
SharedPtr<ResourceLimit> resource_limit;
@@ -134,7 +137,9 @@ public:
/**
* Applies address space changes and launches the process main thread.
*/
- void Run(s32 main_thread_priority, u32 stack_size);
+ void Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size);
+
+ void LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr);
///////////////////////////////////////////////////////////////////////////////////////////////
// Memory Management
@@ -160,6 +165,8 @@ public:
/// This vector will grow as more pages are allocated for new threads.
std::vector<std::bitset<8>> tls_slots;
+ std::string name;
+
VAddr GetLinearHeapAreaAddress() const;
VAddr GetLinearHeapBase() const;
VAddr GetLinearHeapLimit() const;
diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp
index fcf586728..2605b2595 100644
--- a/src/core/hle/kernel/semaphore.cpp
+++ b/src/core/hle/kernel/semaphore.cpp
@@ -13,7 +13,7 @@ namespace Kernel {
Semaphore::Semaphore() {}
Semaphore::~Semaphore() {}
-ResultVal<SharedPtr<Semaphore>> Semaphore::Create(s32 initial_count, s32 max_count,
+ResultVal<SharedPtr<Semaphore>> Semaphore::Create(s32 initial_count, s32 max_count, VAddr address,
std::string name) {
if (initial_count > max_count)
@@ -25,6 +25,7 @@ ResultVal<SharedPtr<Semaphore>> Semaphore::Create(s32 initial_count, s32 max_cou
// and the rest is reserved for the caller thread
semaphore->max_count = max_count;
semaphore->available_count = initial_count;
+ semaphore->address = address;
semaphore->name = std::move(name);
return MakeResult<SharedPtr<Semaphore>>(std::move(semaphore));
diff --git a/src/core/hle/kernel/semaphore.h b/src/core/hle/kernel/semaphore.h
index 7b0cacf2e..77c491a24 100644
--- a/src/core/hle/kernel/semaphore.h
+++ b/src/core/hle/kernel/semaphore.h
@@ -22,7 +22,7 @@ public:
* @param name Optional name of semaphore
* @return The created semaphore
*/
- static ResultVal<SharedPtr<Semaphore>> Create(s32 initial_count, s32 max_count,
+ static ResultVal<SharedPtr<Semaphore>> Create(s32 initial_count, s32 max_count, VAddr address,
std::string name = "Unknown");
std::string GetTypeName() const override {
@@ -39,6 +39,7 @@ public:
s32 max_count; ///< Maximum number of simultaneous holders the semaphore can have
s32 available_count; ///< Number of free slots left in the semaphore
+ VAddr address;
std::string name; ///< Name of semaphore (optional)
bool ShouldWait(Thread* thread) const override;
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 0f7970ebe..75df49ac2 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -358,8 +358,8 @@ std::tuple<u32, u32, bool> GetFreeThreadLocalSlot(std::vector<std::bitset<8>>& t
* @param entry_point Address of entry point for execution
* @param arg User argument for thread
*/
-static void ResetThreadContext(ARM_Interface::ThreadContext& context, u32 stack_top,
- u32 entry_point, u32 arg) {
+static void ResetThreadContext(ARM_Interface::ThreadContext& context, VAddr stack_top,
+ VAddr entry_point, u64 arg) {
memset(&context, 0, sizeof(ARM_Interface::ThreadContext));
context.cpu_registers[0] = arg;
@@ -446,7 +446,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
// Map the page to the current process' address space.
// TODO(Subv): Find the correct MemoryState for this region.
vm_manager.MapMemoryBlock(Memory::TLS_AREA_VADDR + available_page * Memory::PAGE_SIZE,
- linheap_memory, offset, Memory::PAGE_SIZE, MemoryState::Private);
+ linheap_memory, offset, Memory::PAGE_SIZE, MemoryState::Static);
}
// Mark the slot as used
@@ -495,6 +495,9 @@ void Thread::BoostPriority(u32 priority) {
}
SharedPtr<Thread> SetupMainThread(u32 entry_point, u32 priority, SharedPtr<Process> owner_process) {
+ // Setup page table so we can write to memory
+ SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table);
+
// Initialize new "main" thread
auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0,
Memory::HEAP_VADDR_END, owner_process);
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 314fba81f..fafcab156 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -184,8 +184,8 @@ public:
u32 thread_id;
u32 status;
- u32 entry_point;
- u32 stack_top;
+ VAddr entry_point;
+ VAddr stack_top;
u32 nominal_priority; ///< Nominal thread priority, as set by the emulated application
u32 current_priority; ///< Current thread priority, can be temporarily changed
@@ -250,13 +250,13 @@ void Reschedule();
* Arbitrate the highest priority thread that is waiting
* @param address The address for which waiting threads should be arbitrated
*/
-Thread* ArbitrateHighestPriorityThread(u32 address);
+Thread* ArbitrateHighestPriorityThread(VAddr address);
/**
* Arbitrate all threads currently waiting.
* @param address The address for which waiting threads should be arbitrated
*/
-void ArbitrateAllThreads(u32 address);
+void ArbitrateAllThreads(VAddr address);
/**
* Gets the current thread
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index 7a007c065..9762ef535 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -4,8 +4,10 @@
#include <iterator>
#include "common/assert.h"
+#include "core/arm/arm_interface.h"
#include "core/hle/kernel/errors.h"
#include "core/hle/kernel/vm_manager.h"
+#include "core/core.h"
#include "core/memory.h"
#include "core/memory_setup.h"
#include "core/mmio.h"
@@ -60,7 +62,7 @@ void VMManager::Reset() {
page_table.attributes.fill(Memory::PageType::Unmapped);
page_table.cached_res_count.fill(0);
- UpdatePageTableForVMA(initial_vma);
+ //UpdatePageTableForVMA(initial_vma);
}
VMManager::VMAHandle VMManager::FindVMA(VAddr target) const {
@@ -73,7 +75,7 @@ VMManager::VMAHandle VMManager::FindVMA(VAddr target) const {
ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target,
std::shared_ptr<std::vector<u8>> block,
- size_t offset, u32 size,
+ size_t offset, u64 size,
MemoryState state) {
ASSERT(block != nullptr);
ASSERT(offset + size <= block->size());
@@ -83,6 +85,8 @@ ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target,
VirtualMemoryArea& final_vma = vma_handle->second;
ASSERT(final_vma.size == size);
+ Core::CPU().MapBackingMemory(target, size, block->data() + offset, VMAPermission::ReadWriteExecute);
+
final_vma.type = VMAType::AllocatedMemoryBlock;
final_vma.permissions = VMAPermission::ReadWrite;
final_vma.meminfo_state = state;
@@ -93,7 +97,7 @@ ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target,
return MakeResult<VMAHandle>(MergeAdjacent(vma_handle));
}
-ResultVal<VMManager::VMAHandle> VMManager::MapBackingMemory(VAddr target, u8* memory, u32 size,
+ResultVal<VMManager::VMAHandle> VMManager::MapBackingMemory(VAddr target, u8* memory, u64 size,
MemoryState state) {
ASSERT(memory != nullptr);
@@ -102,6 +106,8 @@ ResultVal<VMManager::VMAHandle> VMManager::MapBackingMemory(VAddr target, u8* me
VirtualMemoryArea& final_vma = vma_handle->second;
ASSERT(final_vma.size == size);
+ Core::CPU().MapBackingMemory(target, size, memory, VMAPermission::ReadWriteExecute);
+
final_vma.type = VMAType::BackingMemory;
final_vma.permissions = VMAPermission::ReadWrite;
final_vma.meminfo_state = state;
@@ -111,7 +117,7 @@ ResultVal<VMManager::VMAHandle> VMManager::MapBackingMemory(VAddr target, u8* me
return MakeResult<VMAHandle>(MergeAdjacent(vma_handle));
}
-ResultVal<VMManager::VMAHandle> VMManager::MapMMIO(VAddr target, PAddr paddr, u32 size,
+ResultVal<VMManager::VMAHandle> VMManager::MapMMIO(VAddr target, PAddr paddr, u64 size,
MemoryState state,
Memory::MMIORegionPointer mmio_handler) {
// This is the appropriately sized VMA that will turn into our allocation.
@@ -145,7 +151,7 @@ VMManager::VMAIter VMManager::Unmap(VMAIter vma_handle) {
return MergeAdjacent(vma_handle);
}
-ResultCode VMManager::UnmapRange(VAddr target, u32 size) {
+ResultCode VMManager::UnmapRange(VAddr target, u64 size) {
CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size));
VAddr target_end = target + size;
@@ -170,7 +176,7 @@ VMManager::VMAHandle VMManager::Reprotect(VMAHandle vma_handle, VMAPermission ne
return MergeAdjacent(iter);
}
-ResultCode VMManager::ReprotectRange(VAddr target, u32 size, VMAPermission new_perms) {
+ResultCode VMManager::ReprotectRange(VAddr target, u64 size, VMAPermission new_perms) {
CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size));
VAddr target_end = target + size;
@@ -213,7 +219,7 @@ VMManager::VMAIter VMManager::StripIterConstness(const VMAHandle& iter) {
return vma_map.erase(iter, iter); // Erases an empty range of elements
}
-ResultVal<VMManager::VMAIter> VMManager::CarveVMA(VAddr base, u32 size) {
+ResultVal<VMManager::VMAIter> VMManager::CarveVMA(VAddr base, u64 size) {
ASSERT_MSG((size & Memory::PAGE_MASK) == 0, "non-page aligned size: 0x%8X", size);
ASSERT_MSG((base & Memory::PAGE_MASK) == 0, "non-page aligned base: 0x%08X", base);
@@ -229,8 +235,8 @@ ResultVal<VMManager::VMAIter> VMManager::CarveVMA(VAddr base, u32 size) {
return ERR_INVALID_ADDRESS_STATE;
}
- u32 start_in_vma = base - vma.base;
- u32 end_in_vma = start_in_vma + size;
+ u64 start_in_vma = base - vma.base;
+ u64 end_in_vma = start_in_vma + size;
if (end_in_vma > vma.size) {
// Requested allocation doesn't fit inside VMA
@@ -249,7 +255,7 @@ ResultVal<VMManager::VMAIter> VMManager::CarveVMA(VAddr base, u32 size) {
return MakeResult<VMAIter>(vma_handle);
}
-ResultVal<VMManager::VMAIter> VMManager::CarveVMARange(VAddr target, u32 size) {
+ResultVal<VMManager::VMAIter> VMManager::CarveVMARange(VAddr target, u64 size) {
ASSERT_MSG((size & Memory::PAGE_MASK) == 0, "non-page aligned size: 0x%8X", size);
ASSERT_MSG((target & Memory::PAGE_MASK) == 0, "non-page aligned base: 0x%08X", target);
@@ -278,7 +284,7 @@ ResultVal<VMManager::VMAIter> VMManager::CarveVMARange(VAddr target, u32 size) {
return MakeResult<VMAIter>(begin_vma);
}
-VMManager::VMAIter VMManager::SplitVMA(VMAIter vma_handle, u32 offset_in_vma) {
+VMManager::VMAIter VMManager::SplitVMA(VMAIter vma_handle, u64 offset_in_vma) {
VirtualMemoryArea& old_vma = vma_handle->second;
VirtualMemoryArea new_vma = old_vma; // Make a copy of the VMA
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h
index 1302527bb..cb5bb8243 100644
--- a/src/core/hle/kernel/vm_manager.h
+++ b/src/core/hle/kernel/vm_manager.h
@@ -64,7 +64,7 @@ struct VirtualMemoryArea {
/// Virtual base address of the region.
VAddr base = 0;
/// Size of the region.
- u32 size = 0;
+ u64 size = 0;
VMAType type = VMAType::Free;
VMAPermission permissions = VMAPermission::None;
@@ -109,7 +109,7 @@ public:
* used.
* @note This is the limit used by the New 3DS kernel. Old 3DS used 0x20000000.
*/
- static const u32 MAX_ADDRESS = 0x40000000;
+ static const VAddr MAX_ADDRESS = 0x8000000000;
/**
* A map covering the entirety of the managed address space, keyed by the `base` field of each
@@ -142,7 +142,7 @@ public:
* @param state MemoryState tag to attach to the VMA.
*/
ResultVal<VMAHandle> MapMemoryBlock(VAddr target, std::shared_ptr<std::vector<u8>> block,
- size_t offset, u32 size, MemoryState state);
+ size_t offset, u64 size, MemoryState state);
/**
* Maps an unmanaged host memory pointer at a given address.
@@ -152,7 +152,7 @@ public:
* @param size Size of the mapping.
* @param state MemoryState tag to attach to the VMA.
*/
- ResultVal<VMAHandle> MapBackingMemory(VAddr target, u8* memory, u32 size, MemoryState state);
+ ResultVal<VMAHandle> MapBackingMemory(VAddr target, u8* memory, u64 size, MemoryState state);
/**
* Maps a memory-mapped IO region at a given address.
@@ -163,17 +163,17 @@ public:
* @param state MemoryState tag to attach to the VMA.
* @param mmio_handler The handler that will implement read and write for this MMIO region.
*/
- ResultVal<VMAHandle> MapMMIO(VAddr target, PAddr paddr, u32 size, MemoryState state,
+ ResultVal<VMAHandle> MapMMIO(VAddr target, PAddr paddr, u64 size, MemoryState state,
Memory::MMIORegionPointer mmio_handler);
/// Unmaps a range of addresses, splitting VMAs as necessary.
- ResultCode UnmapRange(VAddr target, u32 size);
+ ResultCode UnmapRange(VAddr target, u64 size);
/// Changes the permissions of the given VMA.
VMAHandle Reprotect(VMAHandle vma, VMAPermission new_perms);
/// Changes the permissions of a range of addresses, splitting VMAs as necessary.
- ResultCode ReprotectRange(VAddr target, u32 size, VMAPermission new_perms);
+ ResultCode ReprotectRange(VAddr target, u64 size, VMAPermission new_perms);
/**
* Scans all VMAs and updates the page table range of any that use the given vector as backing
@@ -201,19 +201,19 @@ private:
* Carves a VMA of a specific size at the specified address by splitting Free VMAs while doing
* the appropriate error checking.
*/
- ResultVal<VMAIter> CarveVMA(VAddr base, u32 size);
+ ResultVal<VMAIter> CarveVMA(VAddr base, u64 size);
/**
* Splits the edges of the given range of non-Free VMAs so that there is a VMA split at each
* end of the range.
*/
- ResultVal<VMAIter> CarveVMARange(VAddr base, u32 size);
+ ResultVal<VMAIter> CarveVMARange(VAddr base, u64 size);
/**
* Splits a VMA in two, at the specified offset.
* @returns the right side of the split, with the original iterator becoming the left side.
*/
- VMAIter SplitVMA(VMAIter vma, u32 offset_in_vma);
+ VMAIter SplitVMA(VMAIter vma, u64 offset_in_vma);
/**
* Checks for and merges the specified VMA with adjacent ones if possible.
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp
index 59ea9823d..912ab550d 100644
--- a/src/core/hle/service/apt/apt.cpp
+++ b/src/core/hle/service/apt/apt.cpp
@@ -1073,7 +1073,17 @@ void Init() {
MemoryPermission::ReadWrite, MemoryPermission::Read, 0,
Kernel::MemoryRegion::SYSTEM, "APT:SharedFont");
- lock = Kernel::Mutex::Create(false, "APT_U:Lock");
+ if (LoadSharedFont()) {
+ shared_font_loaded = true;
+ } else if (LoadLegacySharedFont()) {
+ LOG_WARNING(Service_APT, "Loaded shared font by legacy method");
+ shared_font_loaded = true;
+ } else {
+ LOG_WARNING(Service_APT, "Unable to load shared font");
+ shared_font_loaded = false;
+ }
+
+ lock = Kernel::Mutex::Create(false, 0, "APT_U:Lock");
cpu_percent = 0;
unknown_ns_state_field = 0;
diff --git a/src/core/hle/service/csnd_snd.cpp b/src/core/hle/service/csnd_snd.cpp
index 9471ec1ef..aac903ccb 100644
--- a/src/core/hle/service/csnd_snd.cpp
+++ b/src/core/hle/service/csnd_snd.cpp
@@ -47,7 +47,7 @@ static void Initialize(Interface* self) {
MemoryPermission::ReadWrite, 0,
Kernel::MemoryRegion::BASE, "CSND:SharedMemory");
- mutex = Kernel::Mutex::Create(false, "CSND:mutex");
+ mutex = Kernel::Mutex::Create(false, 0, "CSND:mutex");
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = IPC::CopyHandleDesc(2);
diff --git a/src/core/hle/service/ldr_ro/cro_helper.cpp b/src/core/hle/service/ldr_ro/cro_helper.cpp
index f78545f37..6128f8a6c 100644
--- a/src/core/hle/service/ldr_ro/cro_helper.cpp
+++ b/src/core/hle/service/ldr_ro/cro_helper.cpp
@@ -274,7 +274,7 @@ ResultVal<VAddr> CROHelper::RebaseSegmentTable(u32 cro_size, VAddr data_segment_
}
SetEntry(i, segment);
}
- return MakeResult<u32>(prev_data_segment + module_address);
+ return MakeResult<VAddr>(prev_data_segment + module_address);
}
ResultCode CROHelper::RebaseExportNamedSymbolTable() {
diff --git a/src/core/hle/service/sm/srv.cpp b/src/core/hle/service/sm/srv.cpp
index 5c955cf54..fb873981c 100644
--- a/src/core/hle/service/sm/srv.cpp
+++ b/src/core/hle/service/sm/srv.cpp
@@ -62,7 +62,7 @@ void SRV::EnableNotification(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x2, 0, 0);
notification_semaphore =
- Kernel::Semaphore::Create(0, MAX_PENDING_NOTIFICATIONS, "SRV:Notification").Unwrap();
+ Kernel::Semaphore::Create(0, MAX_PENDING_NOTIFICATIONS, 0, "SRV:Notification").Unwrap();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(RESULT_SUCCESS);
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index e8ca419d5..e4b803046 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -31,7 +31,6 @@
#include "core/hle/kernel/timer.h"
#include "core/hle/kernel/vm_manager.h"
#include "core/hle/kernel/wait_object.h"
-#include "core/hle/lock.h"
#include "core/hle/result.h"
#include "core/hle/service/service.h"
@@ -201,21 +200,17 @@ static ResultCode UnmapMemoryBlock(Kernel::Handle handle, u32 addr) {
}
/// Connect to an OS service given the port name, returns the handle to the port to out
-static ResultCode ConnectToPort(Kernel::Handle* out_handle, VAddr port_name_address) {
- if (!Memory::IsValidVirtualAddress(port_name_address))
+static ResultCode ConnectToPort(Kernel::Handle* out_handle, const char* port_name) {
+ if (port_name == nullptr)
return Kernel::ERR_NOT_FOUND;
-
- static constexpr std::size_t PortNameMaxLength = 11;
- // Read 1 char beyond the max allowed port name to detect names that are too long.
- std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1);
- if (port_name.size() > PortNameMaxLength)
+ if (std::strlen(port_name) > 11)
return Kernel::ERR_PORT_NAME_TOO_LONG;
- LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name.c_str());
+ LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name);
auto it = Service::g_kernel_named_ports.find(port_name);
if (it == Service::g_kernel_named_ports.end()) {
- LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: %s", port_name.c_str());
+ LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: %s", port_name);
return Kernel::ERR_NOT_FOUND;
}
@@ -275,24 +270,6 @@ static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds)
// Create an event to wake the thread up after the specified nanosecond delay has passed
thread->WakeAfterDelay(nano_seconds);
- thread->wakeup_callback = [](ThreadWakeupReason reason,
- Kernel::SharedPtr<Kernel::Thread> thread,
- Kernel::SharedPtr<Kernel::WaitObject> object) {
-
- ASSERT(thread->status == THREADSTATUS_WAIT_SYNCH_ANY);
-
- if (reason == ThreadWakeupReason::Timeout) {
- thread->SetWaitSynchronizationResult(Kernel::RESULT_TIMEOUT);
- return;
- }
-
- ASSERT(reason == ThreadWakeupReason::Signal);
- thread->SetWaitSynchronizationResult(RESULT_SUCCESS);
-
- // WaitSynchronization1 doesn't have an output index like WaitSynchronizationN, so we
- // don't have to do anything else here.
- };
-
Core::System::GetInstance().PrepareReschedule();
// Note: The output of this SVC will be set to RESULT_SUCCESS if the thread
@@ -307,11 +284,12 @@ static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds)
}
/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
-static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle_count,
+static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 handle_count,
bool wait_all, s64 nano_seconds) {
Kernel::Thread* thread = Kernel::GetCurrentThread();
- if (!Memory::IsValidVirtualAddress(handles_address))
+ // Check if 'handles' is invalid
+ if (handles == nullptr)
return Kernel::ERR_INVALID_POINTER;
// NOTE: on real hardware, there is no nullptr check for 'out' (tested with firmware 4.4). If
@@ -326,8 +304,7 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand
std::vector<ObjectPtr> objects(handle_count);
for (int i = 0; i < handle_count; ++i) {
- Kernel::Handle handle = Memory::Read32(handles_address + i * sizeof(Kernel::Handle));
- auto object = Kernel::g_handle_table.Get<Kernel::WaitObject>(handle);
+ auto object = Kernel::g_handle_table.Get<Kernel::WaitObject>(handles[i]);
if (object == nullptr)
return ERR_INVALID_HANDLE;
objects[i] = object;
@@ -366,23 +343,6 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand
// Create an event to wake the thread up after the specified nanosecond delay has passed
thread->WakeAfterDelay(nano_seconds);
- thread->wakeup_callback = [](ThreadWakeupReason reason,
- Kernel::SharedPtr<Kernel::Thread> thread,
- Kernel::SharedPtr<Kernel::WaitObject> object) {
-
- ASSERT(thread->status == THREADSTATUS_WAIT_SYNCH_ALL);
-
- if (reason == ThreadWakeupReason::Timeout) {
- thread->SetWaitSynchronizationResult(Kernel::RESULT_TIMEOUT);
- return;
- }
-
- ASSERT(reason == ThreadWakeupReason::Signal);
-
- thread->SetWaitSynchronizationResult(RESULT_SUCCESS);
- // The wait_all case does not update the output index.
- };
-
Core::System::GetInstance().PrepareReschedule();
// This value gets set to -1 by default in this case, it is not modified after this.
@@ -400,7 +360,7 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand
// We found a ready object, acquire it and set the result value
Kernel::WaitObject* object = itr->get();
object->Acquire(thread);
- *out = static_cast<s32>(std::distance(objects.begin(), itr));
+ *out = std::distance(objects.begin(), itr);
return RESULT_SUCCESS;
}
@@ -428,37 +388,22 @@ static ResultCode WaitSynchronizationN(s32* out, VAddr handles_address, s32 hand
// Create an event to wake the thread up after the specified nanosecond delay has passed
thread->WakeAfterDelay(nano_seconds);
- thread->wakeup_callback = [](ThreadWakeupReason reason,
- Kernel::SharedPtr<Kernel::Thread> thread,
- Kernel::SharedPtr<Kernel::WaitObject> object) {
-
- ASSERT(thread->status == THREADSTATUS_WAIT_SYNCH_ANY);
-
- if (reason == ThreadWakeupReason::Timeout) {
- thread->SetWaitSynchronizationResult(Kernel::RESULT_TIMEOUT);
- return;
- }
-
- ASSERT(reason == ThreadWakeupReason::Signal);
-
- thread->SetWaitSynchronizationResult(RESULT_SUCCESS);
- thread->SetWaitSynchronizationOutput(thread->GetWaitObjectIndex(object.get()));
- };
-
Core::System::GetInstance().PrepareReschedule();
// Note: The output of this SVC will be set to RESULT_SUCCESS if the thread resumes due to a
// signal in one of its wait objects.
// Otherwise we retain the default value of timeout, and -1 in the out parameter
+ thread->wait_set_output = true;
*out = -1;
return Kernel::RESULT_TIMEOUT;
}
}
/// In a single operation, sends a IPC reply and waits for a new request.
-static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_count,
+static ResultCode ReplyAndReceive(s32* index, Kernel::Handle* handles, s32 handle_count,
Kernel::Handle reply_target) {
- if (!Memory::IsValidVirtualAddress(handles_address))
+ // 'handles' has to be a valid pointer even if 'handle_count' is 0.
+ if (handles == nullptr)
return Kernel::ERR_INVALID_POINTER;
// Check if 'handle_count' is invalid
@@ -469,8 +414,7 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_
std::vector<ObjectPtr> objects(handle_count);
for (int i = 0; i < handle_count; ++i) {
- Kernel::Handle handle = Memory::Read32(handles_address + i * sizeof(Kernel::Handle));
- auto object = Kernel::g_handle_table.Get<Kernel::WaitObject>(handle);
+ auto object = Kernel::g_handle_table.Get<Kernel::WaitObject>(handles[i]);
if (object == nullptr)
return ERR_INVALID_HANDLE;
objects[i] = object;
@@ -524,7 +468,7 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_
// We found a ready object, acquire it and set the result value
Kernel::WaitObject* object = itr->get();
object->Acquire(thread);
- *index = static_cast<s32>(std::distance(objects.begin(), itr));
+ *index = std::distance(objects.begin(), itr);
if (object->GetHandleType() == Kernel::HandleType::ServerSession) {
auto server_session = static_cast<Kernel::ServerSession*>(object);
@@ -538,6 +482,8 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_
// No objects were ready to be acquired, prepare to suspend the thread.
+ // TODO(Subv): Perform IPC translation upon wakeup.
+
// Put the thread to sleep
thread->status = THREADSTATUS_WAIT_SYNCH_ANY;
@@ -549,24 +495,12 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_
thread->wait_objects = std::move(objects);
- thread->wakeup_callback = [](ThreadWakeupReason reason,
- Kernel::SharedPtr<Kernel::Thread> thread,
- Kernel::SharedPtr<Kernel::WaitObject> object) {
-
- ASSERT(thread->status == THREADSTATUS_WAIT_SYNCH_ANY);
- ASSERT(reason == ThreadWakeupReason::Signal);
-
- thread->SetWaitSynchronizationResult(RESULT_SUCCESS);
- thread->SetWaitSynchronizationOutput(thread->GetWaitObjectIndex(object.get()));
-
- // TODO(Subv): Perform IPC translation upon wakeup.
- };
-
Core::System::GetInstance().PrepareReschedule();
// Note: The output of this SVC will be set to RESULT_SUCCESS if the thread resumes due to a
// signal in one of its wait objects, or to 0xC8A01836 if there was a translation error.
// By default the index is set to -1.
+ thread->wait_set_output = true;
*index = -1;
return RESULT_SUCCESS;
}
@@ -623,10 +557,8 @@ static void Break(u8 break_reason) {
}
/// Used to output a message on a debug hardware unit - does nothing on a retail unit
-static void OutputDebugString(VAddr address, int len) {
- std::vector<char> string(len);
- Memory::ReadBlock(address, string.data(), len);
- LOG_DEBUG(Debug_Emulated, "%.*s", len, string.data());
+static void OutputDebugString(const char* string, int len) {
+ LOG_DEBUG(Debug_Emulated, "%.*s", len, string);
}
/// Get resource limit
@@ -644,9 +576,9 @@ static ResultCode GetResourceLimit(Kernel::Handle* resource_limit, Kernel::Handl
}
/// Get resource limit current values
-static ResultCode GetResourceLimitCurrentValues(VAddr values, Kernel::Handle resource_limit_handle,
- VAddr names, u32 name_count) {
- LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%08X, name_count=%d",
+static ResultCode GetResourceLimitCurrentValues(s64* values, Kernel::Handle resource_limit_handle,
+ u32* names, u32 name_count) {
+ LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d",
resource_limit_handle, names, name_count);
SharedPtr<Kernel::ResourceLimit> resource_limit =
@@ -654,19 +586,16 @@ static ResultCode GetResourceLimitCurrentValues(VAddr values, Kernel::Handle res
if (resource_limit == nullptr)
return ERR_INVALID_HANDLE;
- for (unsigned int i = 0; i < name_count; ++i) {
- u32 name = Memory::Read32(names + i * sizeof(u32));
- s64 value = resource_limit->GetCurrentResourceValue(name);
- Memory::Write64(values + i * sizeof(u64), value);
- }
+ for (unsigned int i = 0; i < name_count; ++i)
+ values[i] = resource_limit->GetCurrentResourceValue(names[i]);
return RESULT_SUCCESS;
}
/// Get resource limit max values
-static ResultCode GetResourceLimitLimitValues(VAddr values, Kernel::Handle resource_limit_handle,
- VAddr names, u32 name_count) {
- LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%08X, name_count=%d",
+static ResultCode GetResourceLimitLimitValues(s64* values, Kernel::Handle resource_limit_handle,
+ u32* names, u32 name_count) {
+ LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d",
resource_limit_handle, names, name_count);
SharedPtr<Kernel::ResourceLimit> resource_limit =
@@ -674,11 +603,8 @@ static ResultCode GetResourceLimitLimitValues(VAddr values, Kernel::Handle resou
if (resource_limit == nullptr)
return ERR_INVALID_HANDLE;
- for (unsigned int i = 0; i < name_count; ++i) {
- u32 name = Memory::Read32(names + i * sizeof(u32));
- s64 value = resource_limit->GetMaxResourceValue(names);
- Memory::Write64(values + i * sizeof(u64), value);
- }
+ for (unsigned int i = 0; i < name_count; ++i)
+ values[i] = resource_limit->GetMaxResourceValue(names[i]);
return RESULT_SUCCESS;
}
@@ -729,9 +655,8 @@ static ResultCode CreateThread(Kernel::Handle* out_handle, u32 priority, u32 ent
"Newly created thread must run in the SysCore (Core1), unimplemented.");
}
- CASCADE_RESULT(SharedPtr<Thread> thread,
- Kernel::Thread::Create(name, entry_point, priority, arg, processor_id, stack_top,
- Kernel::g_current_process));
+ CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create(name, entry_point, priority,
+ arg, processor_id, stack_top));
thread->context.fpscr =
FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000
@@ -756,7 +681,7 @@ static void ExitThread() {
}
/// Gets the priority for the specified thread
-static ResultCode GetThreadPriority(u32* priority, Kernel::Handle handle) {
+static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) {
const SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
if (thread == nullptr)
return ERR_INVALID_HANDLE;
@@ -766,7 +691,7 @@ static ResultCode GetThreadPriority(u32* priority, Kernel::Handle handle) {
}
/// Sets the priority for the specified thread
-static ResultCode SetThreadPriority(Kernel::Handle handle, u32 priority) {
+static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) {
if (priority > THREADPRIO_LOWEST) {
return Kernel::ERR_OUT_OF_RANGE;
}
@@ -1051,7 +976,7 @@ static void SleepThread(s64 nanoseconds) {
static s64 GetSystemTick() {
s64 result = CoreTiming::GetTicks();
// Advance time to defeat dumb games (like Cubic Ninja) that busy-wait for the frame to end.
- CoreTiming::AddTicks(150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b
+ Core::CPU().AddTicks(150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b
return result;
}
@@ -1110,9 +1035,9 @@ static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 si
}
static ResultCode CreatePort(Kernel::Handle* server_port, Kernel::Handle* client_port,
- VAddr name_address, u32 max_sessions) {
+ const char* name, u32 max_sessions) {
// TODO(Subv): Implement named ports.
- ASSERT_MSG(name_address == 0, "Named ports are currently unimplemented");
+ ASSERT_MSG(name == nullptr, "Named ports are currently unimplemented");
using Kernel::ServerPort;
using Kernel::ClientPort;
@@ -1263,7 +1188,7 @@ struct FunctionDef {
Func* func;
const char* name;
};
-} // namespace
+}
static const FunctionDef SVC_Table[] = {
{0x00, nullptr, "Unknown"},
@@ -1407,9 +1332,6 @@ MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70));
void CallSVC(u32 immediate) {
MICROPROFILE_SCOPE(Kernel_SVC);
- // Lock the global kernel mutex when we enter the kernel HLE.
- std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
-
const FunctionDef* info = GetSVCInfo(immediate);
if (info) {
if (info->func) {
@@ -1420,4 +1342,4 @@ void CallSVC(u32 immediate) {
}
}
-} // namespace SVC
+} // namespace