summaryrefslogtreecommitdiffstats
path: root/src/core/hle
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2017-09-29 20:58:42 +0200
committerGitHub <noreply@github.com>2017-09-29 20:58:42 +0200
commitb07af7dda822898e9c8f231c5ddcd1741d93dbef (patch)
treed41c9221d6065b8cf9e6a2405565b675a9c83c51 /src/core/hle
parentMerge pull request #2907 from Subv/warnings3 (diff)
parentLoaders: Don't automatically set the current process every time we load an application. (diff)
downloadyuzu-b07af7dda822898e9c8f231c5ddcd1741d93dbef.tar
yuzu-b07af7dda822898e9c8f231c5ddcd1741d93dbef.tar.gz
yuzu-b07af7dda822898e9c8f231c5ddcd1741d93dbef.tar.bz2
yuzu-b07af7dda822898e9c8f231c5ddcd1741d93dbef.tar.lz
yuzu-b07af7dda822898e9c8f231c5ddcd1741d93dbef.tar.xz
yuzu-b07af7dda822898e9c8f231c5ddcd1741d93dbef.tar.zst
yuzu-b07af7dda822898e9c8f231c5ddcd1741d93dbef.zip
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/kernel/process.cpp2
-rw-r--r--src/core/hle/kernel/thread.cpp17
-rw-r--r--src/core/hle/kernel/thread.h15
-rw-r--r--src/core/hle/svc.cpp5
4 files changed, 22 insertions, 17 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index 522ad2333..cf3163e0f 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -147,7 +147,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
}
vm_manager.LogLayout(Log::Level::Debug);
- Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority);
+ Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority, this);
}
VAddr Process::GetLinearHeapAreaAddress() const {
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 61378211f..1033f8552 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -361,7 +361,8 @@ static void ResetThreadContext(ARM_Interface::ThreadContext& context, u32 stack_
}
ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, u32 priority,
- u32 arg, s32 processor_id, VAddr stack_top) {
+ u32 arg, s32 processor_id, VAddr stack_top,
+ SharedPtr<Process> owner_process) {
// Check if priority is in ranged. Lowest priority -> highest priority id.
if (priority > THREADPRIO_LOWEST) {
LOG_ERROR(Kernel_SVC, "Invalid thread priority: %d", priority);
@@ -375,7 +376,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
// TODO(yuriks): Other checks, returning 0xD9001BEA
- if (!Memory::IsValidVirtualAddress(entry_point)) {
+ if (!Memory::IsValidVirtualAddress(*owner_process, entry_point)) {
LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point);
// TODO: Verify error
return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel,
@@ -399,10 +400,10 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
thread->wait_address = 0;
thread->name = std::move(name);
thread->callback_handle = wakeup_callback_handle_table.Create(thread).Unwrap();
- thread->owner_process = g_current_process;
+ thread->owner_process = owner_process;
// Find the next available TLS index, and mark it as used
- auto& tls_slots = Kernel::g_current_process->tls_slots;
+ auto& tls_slots = owner_process->tls_slots;
bool needs_allocation = true;
u32 available_page; // Which allocated page has free space
u32 available_slot; // Which slot within the page is free
@@ -426,13 +427,13 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
// Allocate some memory from the end of the linear heap for this region.
linheap_memory->insert(linheap_memory->end(), Memory::PAGE_SIZE, 0);
memory_region->used += Memory::PAGE_SIZE;
- Kernel::g_current_process->linear_heap_used += Memory::PAGE_SIZE;
+ owner_process->linear_heap_used += Memory::PAGE_SIZE;
tls_slots.emplace_back(0); // The page is completely available at the start
available_page = tls_slots.size() - 1;
available_slot = 0; // Use the first slot in the new page
- auto& vm_manager = Kernel::g_current_process->vm_manager;
+ auto& vm_manager = owner_process->vm_manager;
vm_manager.RefreshMemoryBlockMappings(linheap_memory.get());
// Map the page to the current process' address space.
@@ -486,10 +487,10 @@ void Thread::BoostPriority(s32 priority) {
current_priority = priority;
}
-SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority) {
+SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority, SharedPtr<Process> owner_process) {
// Initialize new "main" thread
auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0,
- Memory::HEAP_VADDR_END);
+ Memory::HEAP_VADDR_END, owner_process);
SharedPtr<Thread> thread = std::move(thread_res).Unwrap();
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 6a3566f15..ddc0d15c5 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -56,10 +56,12 @@ public:
* @param arg User data to pass to the thread
* @param processor_id The ID(s) of the processors on which the thread is desired to be run
* @param stack_top The address of the thread's stack top
+ * @param owner_process The parent process for the thread
* @return A shared pointer to the newly created thread
*/
static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, u32 priority,
- u32 arg, s32 processor_id, VAddr stack_top);
+ u32 arg, s32 processor_id, VAddr stack_top,
+ SharedPtr<Process> owner_process);
std::string GetName() const override {
return name;
@@ -116,9 +118,9 @@ public:
void ResumeFromWait();
/**
- * Schedules an event to wake up the specified thread after the specified delay
- * @param nanoseconds The time this thread will be allowed to sleep for
- */
+ * Schedules an event to wake up the specified thread after the specified delay
+ * @param nanoseconds The time this thread will be allowed to sleep for
+ */
void WakeAfterDelay(s64 nanoseconds);
/**
@@ -214,9 +216,10 @@ private:
* Sets up the primary application thread
* @param entry_point The address at which the thread should start execution
* @param priority The priority to give the main thread
+ * @param owner_process The parent process for the main thread
* @return A shared pointer to the main thread
*/
-SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority);
+SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority, SharedPtr<Process> owner_process);
/**
* Returns whether there are any threads that are ready to run.
@@ -276,4 +279,4 @@ void ThreadingShutdown();
*/
const std::vector<SharedPtr<Thread>>& GetThreadList();
-} // namespace
+} // namespace Kernel
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index dfc36748c..05c6897bf 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -656,8 +656,9 @@ 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));
+ CASCADE_RESULT(SharedPtr<Thread> thread,
+ Kernel::Thread::Create(name, entry_point, priority, arg, processor_id, stack_top,
+ Kernel::g_current_process));
thread->context.fpscr =
FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000