cs: implement GetFirmwareVersion command

This commit is contained in:
Michael Scire 2021-03-17 21:46:32 -07:00 committed by SciresM
parent 1a1b1355ba
commit 899efec302
7 changed files with 171 additions and 18 deletions

View file

@ -24,12 +24,26 @@ namespace ams::scs {
u32 result;
};
struct ResponseProgramExited {
ResponseHeader header;
u64 process_id;
};
struct ResponseProgramLaunched {
ResponseHeader header;
u64 process_id;
};
constinit os::SdkMutex g_htcs_send_mutex;
}
os::SdkMutex &GetHtcsSendMutex() {
return g_htcs_send_mutex;
std::scoped_lock<os::SdkMutex> CommandProcessor::MakeSendGuardBlock() {
return std::scoped_lock<os::SdkMutex>{g_htcs_send_mutex};
}
void CommandProcessor::Send(s32 socket, const void *data, size_t size) {
htcs::Send(socket, data, size, 0);
}
void CommandProcessor::SendSuccess(s32 socket, const CommandHeader &header) {
@ -41,8 +55,8 @@ namespace ams::scs {
};
/* Send the response. */
std::scoped_lock lk(GetHtcsSendMutex());
htcs::Send(socket, std::addressof(response), sizeof(response), 0);
auto lk = MakeSendGuardBlock();
Send(socket, std::addressof(response), sizeof(response));
}
void CommandProcessor::SendErrorResult(s32 socket, const CommandHeader &header, Result result) {
@ -61,23 +75,65 @@ namespace ams::scs {
};
/* Send the response. */
std::scoped_lock lk(GetHtcsSendMutex());
htcs::Send(socket, std::addressof(response), sizeof(response), 0);
auto lk = MakeSendGuardBlock();
Send(socket, std::addressof(response), sizeof(response));
}
void CommandProcessor::SendExited(s32 socket, u64 id, u64 process_id) {
/* Build the response. */
const ResponseProgramExited response = {
.header = {
.id = id,
.response = Response_ProgramExited,
.body_size = sizeof(response) - sizeof(response.header),
},
.process_id = process_id,
};
/* Send the response. */
auto lk = MakeSendGuardBlock();
Send(socket, std::addressof(response), sizeof(response));
}
void CommandProcessor::SendJitDebug(s32 socket, u64 id) {
/* Build the response. */
const ResponseHeader response = {
.id = id,
.response = Response_JitDebug,
.body_size = 0,
};
/* Send the response. */
auto lk = MakeSendGuardBlock();
Send(socket, std::addressof(response), sizeof(response));
}
void CommandProcessor::SendLaunched(s32 socket, u64 id, u64 process_id) {
/* Build the response. */
const ResponseProgramLaunched response = {
.header = {
.id = id,
.response = Response_ProgramLaunched,
.body_size = sizeof(response) - sizeof(response.header),
},
.process_id = process_id,
};
/* Send the response. */
auto lk = MakeSendGuardBlock();
Send(socket, std::addressof(response), sizeof(response));
}
void CommandProcessor::OnProcessStart(u64 id, s32 socket, os::ProcessId process_id) {
/* TODO */
AMS_ABORT("CommandProcessor::OnProcessStart");
SendLaunched(socket, id, process_id.value);
}
void CommandProcessor::OnProcessExit(u64 id, s32 socket, os::ProcessId process_id) {
/* TODO */
AMS_ABORT("CommandProcessor::OnProcessExit");
SendExited(socket, id, process_id.value);
}
void CommandProcessor::OnProcessJitDebug(u64 id, s32 socket, os::ProcessId process_id) {
/* TODO */
AMS_ABORT("CommandProcessor::OnProcessJitDebug");
SendJitDebug(socket, id);
}
void CommandProcessor::Initialize() {