2014-05-10 02:11:18 +00:00
|
|
|
// Copyright 2014 Citra Emulator Project / PPSSPP Project
|
2014-12-17 05:38:14 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-19 08:49:13 +00:00
|
|
|
// Refer to the license.txt file included.
|
2014-05-10 02:11:18 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-10-13 21:24:51 +00:00
|
|
|
#include <atomic>
|
2018-10-13 20:41:34 +00:00
|
|
|
#include <memory>
|
2018-10-11 19:19:45 +00:00
|
|
|
#include <string>
|
2018-10-17 18:06:47 +00:00
|
|
|
#include <vector>
|
2018-10-11 19:19:45 +00:00
|
|
|
#include <boost/smart_ptr/intrusive_ptr.hpp>
|
2015-05-06 07:06:12 +00:00
|
|
|
#include "common/common_types.h"
|
2018-10-12 19:47:06 +00:00
|
|
|
#include "core/hle/result.h"
|
2014-05-10 02:11:18 +00:00
|
|
|
|
2018-10-25 14:51:00 +00:00
|
|
|
namespace ConfigMem {
|
|
|
|
class Handler;
|
|
|
|
}
|
|
|
|
|
2014-05-20 22:13:25 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2018-10-11 19:19:45 +00:00
|
|
|
class AddressArbiter;
|
2018-10-11 19:48:16 +00:00
|
|
|
class Event;
|
2018-10-11 20:00:09 +00:00
|
|
|
class Mutex;
|
2018-10-12 19:21:32 +00:00
|
|
|
class CodeSet;
|
2018-10-12 19:33:36 +00:00
|
|
|
class Process;
|
2018-10-12 19:47:06 +00:00
|
|
|
class Thread;
|
2018-10-12 20:12:08 +00:00
|
|
|
class Semaphore;
|
2018-10-12 20:26:23 +00:00
|
|
|
class Timer;
|
2018-10-12 23:00:16 +00:00
|
|
|
class ClientPort;
|
|
|
|
class ServerPort;
|
2018-10-13 20:11:20 +00:00
|
|
|
class ClientSession;
|
|
|
|
class ServerSession;
|
2018-10-13 20:41:34 +00:00
|
|
|
class ResourceLimitList;
|
2018-10-13 21:08:37 +00:00
|
|
|
class SharedMemory;
|
2018-10-23 13:57:59 +00:00
|
|
|
class ThreadManager;
|
2018-10-23 18:17:30 +00:00
|
|
|
class TimerManager;
|
2018-10-25 14:51:00 +00:00
|
|
|
class VMManager;
|
2018-10-11 19:48:16 +00:00
|
|
|
|
|
|
|
enum class ResetType {
|
|
|
|
OneShot,
|
|
|
|
Sticky,
|
|
|
|
Pulse,
|
|
|
|
};
|
2018-10-11 19:19:45 +00:00
|
|
|
|
2018-10-13 21:08:37 +00:00
|
|
|
/// Permissions for mapped shared memory blocks
|
|
|
|
enum class MemoryPermission : u32 {
|
|
|
|
None = 0,
|
|
|
|
Read = (1u << 0),
|
|
|
|
Write = (1u << 1),
|
|
|
|
ReadWrite = (Read | Write),
|
|
|
|
Execute = (1u << 2),
|
|
|
|
ReadExecute = (Read | Execute),
|
|
|
|
WriteExecute = (Write | Execute),
|
|
|
|
ReadWriteExecute = (Read | Write | Execute),
|
|
|
|
DontCare = (1u << 28)
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class MemoryRegion : u16 {
|
|
|
|
APPLICATION = 1,
|
|
|
|
SYSTEM = 2,
|
|
|
|
BASE = 3,
|
|
|
|
};
|
|
|
|
|
2018-10-11 19:19:45 +00:00
|
|
|
template <typename T>
|
|
|
|
using SharedPtr = boost::intrusive_ptr<T>;
|
|
|
|
|
2018-10-11 18:49:52 +00:00
|
|
|
class KernelSystem {
|
|
|
|
public:
|
|
|
|
explicit KernelSystem(u32 system_mode);
|
|
|
|
~KernelSystem();
|
2018-10-11 19:19:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an address arbiter.
|
|
|
|
*
|
|
|
|
* @param name Optional name used for debugging.
|
|
|
|
* @returns The created AddressArbiter.
|
|
|
|
*/
|
|
|
|
SharedPtr<AddressArbiter> CreateAddressArbiter(std::string name = "Unknown");
|
2018-10-11 19:48:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an event
|
|
|
|
* @param reset_type ResetType describing how to create event
|
|
|
|
* @param name Optional name of event
|
|
|
|
*/
|
|
|
|
SharedPtr<Event> CreateEvent(ResetType reset_type, std::string name = "Unknown");
|
2018-10-11 20:00:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a mutex.
|
|
|
|
* @param initial_locked Specifies if the mutex should be locked initially
|
|
|
|
* @param name Optional name of mutex
|
|
|
|
* @return Pointer to new Mutex object
|
|
|
|
*/
|
|
|
|
SharedPtr<Mutex> CreateMutex(bool initial_locked, std::string name = "Unknown");
|
2018-10-12 19:21:32 +00:00
|
|
|
|
|
|
|
SharedPtr<CodeSet> CreateCodeSet(std::string name, u64 program_id);
|
2018-10-12 19:33:36 +00:00
|
|
|
|
|
|
|
SharedPtr<Process> CreateProcess(SharedPtr<CodeSet> code_set);
|
2018-10-12 19:47:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns a new thread. The new thread is immediately scheduled
|
|
|
|
* @param name The friendly name desired for the thread
|
|
|
|
* @param entry_point The address at which the thread should start execution
|
|
|
|
* @param priority The thread's priority
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
ResultVal<SharedPtr<Thread>> CreateThread(std::string name, VAddr entry_point, u32 priority,
|
|
|
|
u32 arg, s32 processor_id, VAddr stack_top,
|
2018-10-26 13:37:46 +00:00
|
|
|
Process& owner_process);
|
2018-10-12 20:12:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a semaphore.
|
|
|
|
* @param initial_count Number of slots reserved for other threads
|
|
|
|
* @param max_count Maximum number of slots the semaphore can have
|
|
|
|
* @param name Optional name of semaphore
|
|
|
|
* @return The created semaphore
|
|
|
|
*/
|
|
|
|
ResultVal<SharedPtr<Semaphore>> CreateSemaphore(s32 initial_count, s32 max_count,
|
|
|
|
std::string name = "Unknown");
|
2018-10-12 20:26:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a timer
|
|
|
|
* @param reset_type ResetType describing how to create the timer
|
|
|
|
* @param name Optional name of timer
|
|
|
|
* @return The created Timer
|
|
|
|
*/
|
|
|
|
SharedPtr<Timer> CreateTimer(ResetType reset_type, std::string name = "Unknown");
|
2018-10-12 23:00:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a pair of ServerPort and an associated ClientPort.
|
|
|
|
*
|
|
|
|
* @param max_sessions Maximum number of sessions to the port
|
|
|
|
* @param name Optional name of the ports
|
|
|
|
* @return The created port tuple
|
|
|
|
*/
|
|
|
|
std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> CreatePortPair(
|
|
|
|
u32 max_sessions, std::string name = "UnknownPort");
|
2018-10-13 20:11:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a pair of ServerSession and an associated ClientSession.
|
|
|
|
* @param name Optional name of the ports.
|
|
|
|
* @param client_port Optional The ClientPort that spawned this session.
|
|
|
|
* @return The created session tuple
|
|
|
|
*/
|
|
|
|
std::tuple<SharedPtr<ServerSession>, SharedPtr<ClientSession>> CreateSessionPair(
|
|
|
|
const std::string& name = "Unknown", SharedPtr<ClientPort> client_port = nullptr);
|
2018-10-13 20:41:34 +00:00
|
|
|
|
|
|
|
ResourceLimitList& ResourceLimit();
|
|
|
|
const ResourceLimitList& ResourceLimit() const;
|
|
|
|
|
2018-10-13 21:08:37 +00:00
|
|
|
/**
|
|
|
|
* Creates a shared memory object.
|
|
|
|
* @param owner_process Process that created this shared memory object.
|
|
|
|
* @param size Size of the memory block. Must be page-aligned.
|
|
|
|
* @param permissions Permission restrictions applied to the process which created the block.
|
|
|
|
* @param other_permissions Permission restrictions applied to other processes mapping the
|
|
|
|
* block.
|
|
|
|
* @param address The address from which to map the Shared Memory.
|
|
|
|
* @param region If the address is 0, the shared memory will be allocated in this region of the
|
|
|
|
* linear heap.
|
|
|
|
* @param name Optional object name, used for debugging purposes.
|
|
|
|
*/
|
2018-10-25 23:54:06 +00:00
|
|
|
SharedPtr<SharedMemory> CreateSharedMemory(Process* owner_process, u32 size,
|
2018-10-13 21:08:37 +00:00
|
|
|
MemoryPermission permissions,
|
|
|
|
MemoryPermission other_permissions,
|
|
|
|
VAddr address = 0,
|
|
|
|
MemoryRegion region = MemoryRegion::BASE,
|
|
|
|
std::string name = "Unknown");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a shared memory object from a block of memory managed by an HLE applet.
|
|
|
|
* @param heap_block Heap block of the HLE applet.
|
|
|
|
* @param offset The offset into the heap block that the SharedMemory will map.
|
|
|
|
* @param size Size of the memory block. Must be page-aligned.
|
|
|
|
* @param permissions Permission restrictions applied to the process which created the block.
|
|
|
|
* @param other_permissions Permission restrictions applied to other processes mapping the
|
|
|
|
* block.
|
|
|
|
* @param name Optional object name, used for debugging purposes.
|
|
|
|
*/
|
|
|
|
SharedPtr<SharedMemory> CreateSharedMemoryForApplet(std::shared_ptr<std::vector<u8>> heap_block,
|
|
|
|
u32 offset, u32 size,
|
|
|
|
MemoryPermission permissions,
|
|
|
|
MemoryPermission other_permissions,
|
|
|
|
std::string name = "Unknown Applet");
|
|
|
|
|
2018-10-13 21:24:51 +00:00
|
|
|
u32 GenerateObjectID();
|
|
|
|
|
2018-10-17 18:06:47 +00:00
|
|
|
/// Retrieves a process from the current list of processes.
|
|
|
|
SharedPtr<Process> GetProcessById(u32 process_id) const;
|
|
|
|
|
2018-10-17 19:23:56 +00:00
|
|
|
SharedPtr<Process> GetCurrentProcess() const;
|
|
|
|
void SetCurrentProcess(SharedPtr<Process> process);
|
|
|
|
|
2018-10-23 13:57:59 +00:00
|
|
|
ThreadManager& GetThreadManager();
|
|
|
|
const ThreadManager& GetThreadManager() const;
|
|
|
|
|
2018-10-23 18:17:30 +00:00
|
|
|
TimerManager& GetTimerManager();
|
|
|
|
const TimerManager& GetTimerManager() const;
|
|
|
|
|
2018-10-25 14:51:00 +00:00
|
|
|
void MapSharedPages(VMManager& address_space);
|
|
|
|
|
2018-10-13 20:41:34 +00:00
|
|
|
private:
|
2018-10-25 14:51:00 +00:00
|
|
|
void MemoryInit(u32 mem_type);
|
|
|
|
|
2018-10-13 20:41:34 +00:00
|
|
|
std::unique_ptr<ResourceLimitList> resource_limits;
|
2018-10-13 21:24:51 +00:00
|
|
|
std::atomic<u32> next_object_id{0};
|
2018-10-17 17:47:42 +00:00
|
|
|
|
|
|
|
// TODO(Subv): Start the process ids from 10 for now, as lower PIDs are
|
|
|
|
// reserved for low-level services
|
|
|
|
u32 next_process_id = 10;
|
2018-10-17 18:06:47 +00:00
|
|
|
|
|
|
|
// Lists all processes that exist in the current session.
|
|
|
|
std::vector<SharedPtr<Process>> process_list;
|
2018-10-17 19:23:56 +00:00
|
|
|
|
|
|
|
SharedPtr<Process> current_process;
|
2018-10-23 13:57:59 +00:00
|
|
|
|
|
|
|
std::unique_ptr<ThreadManager> thread_manager;
|
2018-10-23 18:17:30 +00:00
|
|
|
std::unique_ptr<TimerManager> timer_manager;
|
2018-10-25 14:51:00 +00:00
|
|
|
|
|
|
|
std::unique_ptr<ConfigMem::Handler> config_mem_handler;
|
2018-10-11 18:49:52 +00:00
|
|
|
};
|
2014-06-11 02:43:50 +00:00
|
|
|
|
2017-07-21 04:52:50 +00:00
|
|
|
} // namespace Kernel
|