mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-10 06:01:52 +00:00
htc: add RpcTaskTable
This commit is contained in:
parent
0880cebc4d
commit
f5e98de1a3
5 changed files with 126 additions and 8 deletions
|
@ -39,8 +39,8 @@ namespace ams::htc::server::rpc {
|
|||
};
|
||||
|
||||
enum class HtcmiscPacketType : s16 {
|
||||
GetMaxProtocolVersion = 0,
|
||||
SetProtocolVersion = 1,
|
||||
GetMaxProtocolVersion = 0,
|
||||
SetProtocolVersion = 1,
|
||||
GetEnvironmentVariable = 16,
|
||||
GetEnvironmentVariableLength = 17,
|
||||
SetTargetStatus = 18,
|
||||
|
@ -75,6 +75,8 @@ namespace ams::htc::server::rpc {
|
|||
};
|
||||
|
||||
class GetEnvironmentVariableTask : public HtcmiscTask {
|
||||
public:
|
||||
static constexpr inline HtcmiscTaskType TaskType = HtcmiscTaskType::GetEnvironmentVariable;
|
||||
private:
|
||||
char m_name[0x800];
|
||||
int m_name_size;
|
||||
|
@ -96,6 +98,8 @@ namespace ams::htc::server::rpc {
|
|||
};
|
||||
|
||||
class GetEnvironmentVariableLengthTask : public HtcmiscTask {
|
||||
public:
|
||||
static constexpr inline HtcmiscTaskType TaskType = HtcmiscTaskType::GetEnvironmentVariableLength;
|
||||
private:
|
||||
char m_name[0x800];
|
||||
int m_name_size;
|
||||
|
@ -116,6 +120,8 @@ namespace ams::htc::server::rpc {
|
|||
};
|
||||
|
||||
class RunOnHostTask : public HtcmiscTask {
|
||||
public:
|
||||
static constexpr inline HtcmiscTaskType TaskType = HtcmiscTaskType::RunOnHost;
|
||||
private:
|
||||
char m_command[0x2000];
|
||||
int m_command_size;
|
||||
|
|
|
@ -36,12 +36,12 @@ namespace ams::htc::server::rpc {
|
|||
m_receive_thread_stack(g_receive_thread_stack),
|
||||
m_send_thread_stack(g_send_thread_stack),
|
||||
m_mutex(g_rpc_mutex),
|
||||
m_task_table(),
|
||||
m_cancelled(false),
|
||||
m_thread_running(false)
|
||||
{
|
||||
/* Initialize all events. */
|
||||
/* TODO: MaxTaskCount? */
|
||||
for (size_t i = 0; i < util::size(m_5F8_events); ++i) {
|
||||
for (size_t i = 0; i < MaxTaskCount; ++i) {
|
||||
os::InitializeEvent(std::addressof(m_5F8_events[i]), false, os::EventClearMode_AutoClear);
|
||||
os::InitializeEvent(std::addressof(m_1138_events[i]), false, os::EventClearMode_AutoClear);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "../driver/htc_i_driver.hpp"
|
||||
#include "htc_rpc_task_table.hpp"
|
||||
|
||||
namespace ams::htc::server::rpc {
|
||||
|
||||
|
@ -30,13 +31,13 @@ namespace ams::htc::server::rpc {
|
|||
os::ThreadType m_send_thread;
|
||||
os::SdkMutex &m_mutex;
|
||||
/* TODO: m_task_id_free_list */
|
||||
/* TODO: m_task_table */
|
||||
/* TODO: m_3C0[0x48] */
|
||||
RpcTaskTable m_task_table;
|
||||
/* TODO: m_3C0[MaxTaskCount] */
|
||||
/* TODO: m_rpc_task_queue */
|
||||
bool m_cancelled;
|
||||
bool m_thread_running;
|
||||
os::EventType m_5F8_events[0x48];
|
||||
os::EventType m_1138_events[0x48];
|
||||
os::EventType m_5F8_events[MaxTaskCount];
|
||||
os::EventType m_1138_events[MaxTaskCount];
|
||||
public:
|
||||
RpcClient(driver::IDriver *driver, htclow::ChannelId channel);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stratosphere.hpp>
|
||||
#include "htc_rpc_tasks.hpp"
|
||||
#include "htc_htcmisc_rpc_tasks.hpp"
|
||||
|
||||
namespace ams::htc::server::rpc {
|
||||
|
||||
/* For convenience. */
|
||||
template<typename T>
|
||||
concept IsTypeCheckableTask = std::derived_from<T, Task> && requires (T &t) {
|
||||
{ t.GetTaskType() } -> std::convertible_to<decltype(T::TaskType)>;
|
||||
};
|
||||
|
||||
static_assert(!IsTypeCheckableTask<Task>);
|
||||
static_assert(IsTypeCheckableTask<GetEnvironmentVariableTask>);
|
||||
|
||||
class RpcTaskTable {
|
||||
private:
|
||||
/* TODO: How is this variable derived...? */
|
||||
/* Nintendo has a value of 0xE1D8, which is deeply magic. */
|
||||
static constexpr size_t MaxTaskSize = 0xA000;
|
||||
using TaskStorage = typename std::aligned_storage<MaxTaskSize, alignof(void *)>::type;
|
||||
private:
|
||||
bool m_valid[MaxTaskCount];
|
||||
TaskStorage m_storages[MaxTaskCount];
|
||||
private:
|
||||
template<typename T>
|
||||
ALWAYS_INLINE T *GetPointer(u32 index) {
|
||||
static_assert(alignof(T) <= alignof(TaskStorage));
|
||||
static_assert(sizeof(T) <= sizeof(TaskStorage));
|
||||
return reinterpret_cast<T *>(std::addressof(m_storages[index]));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool IsValid(u32 index) {
|
||||
return index < MaxTaskCount && m_valid[index];
|
||||
}
|
||||
public:
|
||||
RpcTaskTable() : m_valid() { /* ... */ }
|
||||
|
||||
template<typename T> requires std::derived_from<T, Task>
|
||||
T *New(u32 index) {
|
||||
/* Sanity check input. */
|
||||
AMS_ASSERT(!this->IsValid(index));
|
||||
|
||||
/* Set valid. */
|
||||
m_valid[index] = true;
|
||||
|
||||
/* Allocate the task. */
|
||||
T *task = this->GetPointer<T>(index);
|
||||
|
||||
/* Create the task. */
|
||||
std::construct_at(task);
|
||||
|
||||
/* Return the task. */
|
||||
return task;
|
||||
}
|
||||
|
||||
template<typename T> requires std::derived_from<T, Task>
|
||||
T *Get(u32 index) {
|
||||
/* Check that the task is valid. */
|
||||
if (!this->IsValid(index)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get the task pointer. */
|
||||
T *task = this->GetPointer<T>(index);
|
||||
|
||||
/* Type check the task. */
|
||||
if constexpr (IsTypeCheckableTask<T>) {
|
||||
if (task->GetTaskType() != T::TaskType) {
|
||||
task = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the task. */
|
||||
return task;
|
||||
}
|
||||
|
||||
template<typename T> requires std::derived_from<T, Task>
|
||||
void Delete(u32 index) {
|
||||
/* Check that the task is valid. */
|
||||
if (!this->IsValid(index)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Delete the task. */
|
||||
std::destroy_at(this->GetPointer<T>(index));
|
||||
|
||||
/* Mark the task as invalid. */
|
||||
m_valid[index] = false;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
namespace ams::htc::server::rpc {
|
||||
|
||||
constexpr inline size_t MaxTaskCount = 0x48;
|
||||
|
||||
enum class RpcTaskCancelReason {
|
||||
None = 0,
|
||||
/* ... */
|
||||
|
|
Loading…
Reference in a new issue