Browse Source
Merge pull request #731 from yuriks/app-info
Merge pull request #731 from yuriks/app-info
Kernel: Process class and ExHeader caps parsingpull/15/merge
19 changed files with 335 additions and 103 deletions
-
2src/common/common_funcs.h
-
8src/common/string_util.cpp
-
6src/common/string_util.h
-
44src/core/CMakeLists.txt
-
5src/core/file_sys/archive_savedata.cpp
-
18src/core/hle/kernel/kernel.cpp
-
16src/core/hle/kernel/kernel.h
-
96src/core/hle/kernel/process.cpp
-
90src/core/hle/kernel/process.h
-
2src/core/hle/kernel/thread.h
-
12src/core/loader/3dsx.cpp
-
8src/core/loader/3dsx.h
-
14src/core/loader/elf.cpp
-
8src/core/loader/elf.h
-
39src/core/loader/loader.cpp
-
8src/core/loader/loader.h
-
24src/core/loader/ncch.cpp
-
36src/core/loader/ncch.h
-
2src/core/mem_map.h
@ -0,0 +1,96 @@ |
|||
// Copyright 2015 Citra Emulator Project
|
|||
// Licensed under GPLv2 or any later version
|
|||
// Refer to the license.txt file included.
|
|||
|
|||
#include "common/assert.h"
|
|||
#include "common/common_funcs.h"
|
|||
#include "common/logging/log.h"
|
|||
|
|||
#include "core/hle/kernel/process.h"
|
|||
#include "core/hle/kernel/thread.h"
|
|||
#include "core/mem_map.h"
|
|||
|
|||
namespace Kernel { |
|||
|
|||
SharedPtr<Process> Process::Create(std::string name, u64 program_id) { |
|||
SharedPtr<Process> process(new Process); |
|||
|
|||
process->name = std::move(name); |
|||
process->program_id = program_id; |
|||
|
|||
process->flags.raw = 0; |
|||
process->flags.memory_region = MemoryRegion::APPLICATION; |
|||
|
|||
return process; |
|||
} |
|||
|
|||
void Process::ParseKernelCaps(const u32* kernel_caps, size_t len) { |
|||
for (int i = 0; i < len; ++i) { |
|||
u32 descriptor = kernel_caps[i]; |
|||
u32 type = descriptor >> 20; |
|||
|
|||
if (descriptor == 0xFFFFFFFF) { |
|||
// Unused descriptor entry
|
|||
continue; |
|||
} else if ((type & 0xF00) == 0xE00) { // 0x0FFF
|
|||
// Allowed interrupts list
|
|||
LOG_WARNING(Loader, "ExHeader allowed interrupts list ignored"); |
|||
} else if ((type & 0xF80) == 0xF00) { // 0x07FF
|
|||
// Allowed syscalls mask
|
|||
unsigned int index = ((descriptor >> 24) & 7) * 24; |
|||
u32 bits = descriptor & 0xFFFFFF; |
|||
|
|||
while (bits && index < svc_access_mask.size()) { |
|||
svc_access_mask.set(index, bits & 1); |
|||
++index; bits >>= 1; |
|||
} |
|||
} else if ((type & 0xFF0) == 0xFE0) { // 0x00FF
|
|||
// Handle table size
|
|||
handle_table_size = descriptor & 0x3FF; |
|||
} else if ((type & 0xFF8) == 0xFF0) { // 0x007F
|
|||
// Misc. flags
|
|||
flags.raw = descriptor & 0xFFFF; |
|||
} else if ((type & 0xFFE) == 0xFF8) { // 0x001F
|
|||
// Mapped memory range
|
|||
if (i+1 >= len || ((kernel_caps[i+1] >> 20) & 0xFFE) != 0xFF8) { |
|||
LOG_WARNING(Loader, "Incomplete exheader memory range descriptor ignored."); |
|||
continue; |
|||
} |
|||
u32 end_desc = kernel_caps[i+1]; |
|||
++i; // Skip over the second descriptor on the next iteration
|
|||
|
|||
AddressMapping mapping; |
|||
mapping.address = descriptor << 12; |
|||
mapping.size = (end_desc << 12) - mapping.address; |
|||
mapping.writable = descriptor & BIT(20); |
|||
mapping.unk_flag = end_desc & BIT(20); |
|||
|
|||
address_mappings.push_back(mapping); |
|||
} else if ((type & 0xFFF) == 0xFFE) { // 0x000F
|
|||
// Mapped memory page
|
|||
AddressMapping mapping; |
|||
mapping.address = descriptor << 12; |
|||
mapping.size = Memory::PAGE_SIZE; |
|||
mapping.writable = true; // TODO: Not sure if correct
|
|||
mapping.unk_flag = false; |
|||
} else if ((type & 0xFE0) == 0xFC0) { // 0x01FF
|
|||
// Kernel version
|
|||
int minor = descriptor & 0xFF; |
|||
int major = (descriptor >> 8) & 0xFF; |
|||
LOG_INFO(Loader, "ExHeader kernel version ignored: %d.%d", major, minor); |
|||
} else { |
|||
LOG_ERROR(Loader, "Unhandled kernel caps descriptor: 0x%08X", descriptor); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { |
|||
Kernel::SetupMainThread(stack_size, entry_point, main_thread_priority); |
|||
} |
|||
|
|||
Kernel::Process::Process() {} |
|||
Kernel::Process::~Process() {} |
|||
|
|||
SharedPtr<Process> g_current_process; |
|||
|
|||
} |
|||
@ -0,0 +1,90 @@ |
|||
// Copyright 2015 Citra Emulator Project |
|||
// Licensed under GPLv2 or any later version |
|||
// Refer to the license.txt file included. |
|||
|
|||
#pragma once |
|||
|
|||
#include <bitset> |
|||
|
|||
#include <boost/container/static_vector.hpp> |
|||
|
|||
#include "common/bit_field.h" |
|||
#include "common/common_types.h" |
|||
|
|||
#include "core/hle/kernel/kernel.h" |
|||
#include "core/hle/result.h" |
|||
|
|||
namespace Kernel { |
|||
|
|||
struct AddressMapping { |
|||
// Address and size must be page-aligned |
|||
VAddr address; |
|||
u32 size; |
|||
bool writable; |
|||
bool unk_flag; |
|||
}; |
|||
|
|||
enum class MemoryRegion : u16 { |
|||
APPLICATION = 1, |
|||
SYSTEM = 2, |
|||
BASE = 3, |
|||
}; |
|||
|
|||
union ProcessFlags { |
|||
u16 raw; |
|||
|
|||
BitField< 0, 1, u16> allow_debug; ///< Allows other processes to attach to and debug this process. |
|||
BitField< 1, 1, u16> force_debug; ///< Allows this process to attach to processes even if they don't have allow_debug set. |
|||
BitField< 2, 1, u16> allow_nonalphanum; |
|||
BitField< 3, 1, u16> shared_page_writable; ///< Shared page is mapped with write permissions. |
|||
BitField< 4, 1, u16> privileged_priority; ///< Can use priority levels higher than 24. |
|||
BitField< 5, 1, u16> allow_main_args; |
|||
BitField< 6, 1, u16> shared_device_mem; |
|||
BitField< 7, 1, u16> runnable_on_sleep; |
|||
BitField< 8, 4, MemoryRegion> memory_region; ///< Default region for memory allocations for this process |
|||
BitField<12, 1, u16> loaded_high; ///< Application loaded high (not at 0x00100000). |
|||
}; |
|||
|
|||
class Process final : public Object { |
|||
public: |
|||
static SharedPtr<Process> Create(std::string name, u64 program_id); |
|||
|
|||
std::string GetTypeName() const override { return "Process"; } |
|||
std::string GetName() const override { return name; } |
|||
|
|||
static const HandleType HANDLE_TYPE = HandleType::Process; |
|||
HandleType GetHandleType() const override { return HANDLE_TYPE; } |
|||
|
|||
/// Name of the process |
|||
std::string name; |
|||
/// Title ID corresponding to the process |
|||
u64 program_id; |
|||
|
|||
/// The process may only call SVCs which have the corresponding bit set. |
|||
std::bitset<0x80> svc_access_mask; |
|||
/// Maximum size of the handle table for the process. |
|||
unsigned int handle_table_size = 0x200; |
|||
/// Special memory ranges mapped into this processes address space. This is used to give |
|||
/// processes access to specific I/O regions and device memory. |
|||
boost::container::static_vector<AddressMapping, 8> address_mappings; |
|||
ProcessFlags flags; |
|||
|
|||
/** |
|||
* Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them |
|||
* to this process. |
|||
*/ |
|||
void ParseKernelCaps(const u32* kernel_caps, size_t len); |
|||
|
|||
/** |
|||
* Applies address space changes and launches the process main thread. |
|||
*/ |
|||
void Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size); |
|||
|
|||
private: |
|||
Process(); |
|||
~Process() override; |
|||
}; |
|||
|
|||
extern SharedPtr<Process> g_current_process; |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue