results: use kernel results, add dbg results

This commit is contained in:
Michael Scire 2019-03-28 16:56:44 -07:00
parent 6b54534f47
commit a3ca9cf1a3
7 changed files with 95 additions and 63 deletions

View File

@ -23,6 +23,8 @@
#include <type_traits>
#include <memory>
#include "../results.hpp"
#include "ipc_out.hpp"
#include "ipc_buffers.hpp"
#include "ipc_special.hpp"
@ -341,32 +343,32 @@ struct Validator {
template<typename MetaInfo>
static constexpr Result Validate(IpcResponseContext *ctx) {
if (ctx->request.RawSize < MetaInfo::InRawArgSizeWithOutPointers) {
return 0xF601;
return ResultKernelConnectionClosed;
}
if (ctx->request.NumBuffers != MetaInfo::NumInBuffers + MetaInfo::NumOutBuffers) {
return 0xF601;
return ResultKernelConnectionClosed;
}
if (ctx->request.NumStatics != MetaInfo::NumInPointers) {
return 0xF601;
return ResultKernelConnectionClosed;
}
if (ctx->request.NumStaticsOut != MetaInfo::NumClientSizeOutPointers + MetaInfo::NumServerSizeOutPointers) {
return 0xF601;
return ResultKernelConnectionClosed;
}
if (ctx->request.NumHandles != MetaInfo::NumInHandles) {
return 0xF601;
return ResultKernelConnectionClosed;
}
if ((ctx->request.HasPid && MetaInfo::NumPidDescs == 0) || (!ctx->request.HasPid && MetaInfo::NumPidDescs != 0)) {
return 0xF601;
return ResultKernelConnectionClosed;
}
if (((u32 *)ctx->request.Raw)[0] != SFCI_MAGIC) {
return 0xF601;
return ResultKernelConnectionClosed;
}
size_t a_index = 0, b_index = MetaInfo::NumInBuffers, x_index = 0, h_index = 0;
@ -374,11 +376,11 @@ struct Validator {
size_t total_c_size = 0;
if (!ValidateCommandTuple<typename MetaInfo::Args>::IsValid(ctx, a_index, b_index, x_index, h_index, cur_c_size_offset, total_c_size)) {
return 0xF601;
return ResultKernelConnectionClosed;
}
if (total_c_size > ctx->pb_size) {
return 0xF601;
return ResultKernelConnectionClosed;
}
return 0;

View File

@ -17,6 +17,7 @@
#pragma once
#include <switch.h>
#include "../results.hpp"
#include "../iwaitable.hpp"
#include "ipc_service_object.hpp"
#include "ipc_serialization.hpp"
@ -133,7 +134,7 @@ class ServiceSession : public IWaitable
}
virtual Result GetResponse(IpcResponseContext *ctx) {
Result rc = 0xF601;
Result rc = ResultKernelConnectionClosed;
FirmwareVersion fw = GetRuntimeFirmwareVersion();
const ServiceCommandMeta *dispatch_table = ctx->obj_holder->GetDispatchTable();
@ -142,7 +143,7 @@ class ServiceSession : public IWaitable
if (IsDomainObject(ctx->obj_holder)) {
switch (ctx->request.InMessageType) {
case DomainMessageType_Invalid:
return 0xF601;
return ResultKernelConnectionClosed;
case DomainMessageType_Close:
return PrepareBasicDomainResponse(ctx, ctx->obj_holder->GetServiceObject<IDomainObject>()->FreeObject(ctx->request.InThisObjectId));
case DomainMessageType_SendMessage:
@ -180,14 +181,14 @@ class ServiceSession : public IWaitable
case IpcCommandType_Invalid:
case IpcCommandType_LegacyRequest:
case IpcCommandType_LegacyControl:
return 0xF601;
return ResultKernelConnectionClosed;
case IpcCommandType_Close:
{
/* Clean up gracefully. */
PrepareBasicResponse(&ctx, 0);
this->Reply();
}
return 0xF601;
return ResultKernelConnectionClosed;
case IpcCommandType_Control:
case IpcCommandType_ControlWithContext:
ctx.rc = ipcParse(&ctx.request);
@ -202,7 +203,7 @@ class ServiceSession : public IWaitable
}
break;
default:
return 0xF601;
return ResultKernelConnectionClosed;
}
@ -215,7 +216,7 @@ class ServiceSession : public IWaitable
if (ctx.rc == RESULT_DEFER_SESSION) {
/* Session defer. */
this->SetDeferred(true);
} else if (ctx.rc == 0xF601) {
} else if (ctx.rc == ResultKernelConnectionClosed) {
/* Session close, nothing to do. */
} else {
if (R_SUCCEEDED(ctx.rc)) {
@ -224,7 +225,7 @@ class ServiceSession : public IWaitable
ctx.rc = this->Reply();
if (ctx.rc == 0xEA01) {
if (ctx.rc == ResultKernelTimedOut) {
ctx.rc = 0x0;
}

View File

@ -19,8 +19,10 @@
#include <stratosphere.hpp>
#include "imitmserviceobject.hpp"
#include "../results.hpp"
#include "mitm_query_service.hpp"
/* TODO: Change this. */
#define RESULT_FORWARD_TO_SESSION 0xCAFEFC
class MitmSession final : public ServiceSession {
@ -112,7 +114,7 @@ class MitmSession final : public ServiceSession {
}
virtual Result GetResponse(IpcResponseContext *ctx) {
Result rc = 0xF601;
Result rc = ResultKernelConnectionClosed;
FirmwareVersion fw = GetRuntimeFirmwareVersion();
const ServiceCommandMeta *dispatch_table = ctx->obj_holder->GetDispatchTable();
@ -121,7 +123,7 @@ class MitmSession final : public ServiceSession {
if (IsDomainObject(ctx->obj_holder)) {
switch (ctx->request.InMessageType) {
case DomainMessageType_Invalid:
return 0xF601;
return ResultKernelConnectionClosed;
case DomainMessageType_Close:
rc = ForwardRequest(ctx);
if (R_SUCCEEDED(rc)) {
@ -216,7 +218,7 @@ class MitmSession final : public ServiceSession {
public:
Result ConvertCurrentObjectToDomain(Out<u32> object_id) {
if (IsDomainObject(this->session->obj_holder)) {
return 0xF601;
return ResultKernelConnectionClosed;
}
Result rc = serviceConvertToDomain(this->session->forward_service.get());
@ -230,12 +232,12 @@ class MitmSession final : public ServiceSession {
auto new_domain = this->session->GetDomainManager()->AllocateDomain();
if (new_domain == nullptr) {
/* If our domains mismatch, we're in trouble. */
return 0xF601;
return ResultKernelConnectionClosed;
}
/* Reserve the expected object in the domain for our session. */
if (R_FAILED(new_domain->ReserveSpecificObject(expected_id))) {
return 0xF601;
return ResultKernelConnectionClosed;
}
new_domain->SetObject(expected_id, std::move(this->session->obj_holder));
this->session->obj_holder = std::move(ServiceObjectHolder(std::move(new_domain)));

View File

@ -17,9 +17,11 @@
#pragma once
#include "results/creport_results.hpp"
#include "results/debug_results.hpp"
#include "results/dmnt_results.hpp"
#include "results/fatal_results.hpp"
#include "results/fs_results.hpp"
#include "results/kernel_results.hpp"
#include "results/loader_results.hpp"
#include "results/pm_results.hpp"
#include "results/sm_results.hpp"

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2018 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 <switch.h>
static constexpr u32 Module_Debug = 183;
static constexpr Result ResultDebugCannotDebug = MAKERESULT(Module_Debug, 1);
static constexpr Result ResultDebugAlreadyAttached = MAKERESULT(Module_Debug, 2);
static constexpr Result ResultDebugCancelled = MAKERESULT(Module_Debug, 3);

View File

@ -17,47 +17,47 @@
#pragma once
#include <switch.h>
static constexpr u32 Module_Kernel = 1;
/* libnx already has: static constexpr u32 Module_Kernel = 1; */
static constexpr Result ResultKernelOutOfSessions = MAKERESULT(Module_Kernel, 7);
static constexpr Result ResultKernelOutOfSessions = MAKERESULT(Module_Kernel, KernelError_OutOfSessions);
static constexpr Result ResultKernelInvalidCapabilityDescriptor = MAKERESULT(Module_Kernel, 14);
static constexpr Result ResultKernelInvalidCapabilityDescriptor = MAKERESULT(Module_Kernel, KernelError_InvalidCapabilityDescriptor);
static constexpr Result ResultKernelNotImplemented = MAKERESULT(Module_Kernel, 33);
static constexpr Result ResultKernelThreadTerminating = MAKERESULT(Module_Kernel, 59);
static constexpr Result ResultKernelNotImplemented = MAKERESULT(Module_Kernel, KernelError_NotImplemented);
static constexpr Result ResultKernelThreadTerminating = MAKERESULT(Module_Kernel, KernelError_ThreadTerminating);
static constexpr Result ResultKernelOutOfDebugEvents = MAKERESULT(Module_Kernel, 70);
static constexpr Result ResultKernelOutOfDebugEvents = MAKERESULT(Module_Kernel, KernelError_OutOfDebugEvents);
static constexpr Result ResultKernelInvalidSize = MAKERESULT(Module_Kernel, 101);
static constexpr Result ResultKernelInvalidAddress = MAKERESULT(Module_Kernel, 102);
static constexpr Result ResultKernelResourceExhausted = MAKERESULT(Module_Kernel, 103);
static constexpr Result ResultKernelOutOfMemory = MAKERESULT(Module_Kernel, 104);
static constexpr Result ResultKernelOutOfHandles = MAKERESULT(Module_Kernel, 105);
static constexpr Result ResultKernelInvalidMemoryState = MAKERESULT(Module_Kernel, 106);
static constexpr Result ResultKernelInvalidMemoryPermissions = MAKERESULT(Module_Kernel, 108);
static constexpr Result ResultKernelInvalidMemoryRange = MAKERESULT(Module_Kernel, 110);
static constexpr Result ResultKernelInvalidPriority = MAKERESULT(Module_Kernel, 112);
static constexpr Result ResultKernelInvalidCoreId = MAKERESULT(Module_Kernel, 113);
static constexpr Result ResultKernelInvalidHandle = MAKERESULT(Module_Kernel, 114);
static constexpr Result ResultKernelInvalidUserBuffer = MAKERESULT(Module_Kernel, 115);
static constexpr Result ResultKernelInvalidCombination = MAKERESULT(Module_Kernel, 116);
static constexpr Result ResultKernelTimedOut = MAKERESULT(Module_Kernel, 117);
static constexpr Result ResultKernelCancelled = MAKERESULT(Module_Kernel, 118);
static constexpr Result ResultKernelOutOfRange = MAKERESULT(Module_Kernel, 119);
static constexpr Result ResultKernelInvalidEnumValue = MAKERESULT(Module_Kernel, 120);
static constexpr Result ResultKernelNotFound = MAKERESULT(Module_Kernel, 121);
static constexpr Result ResultKernelAlreadyExists = MAKERESULT(Module_Kernel, 122);
static constexpr Result ResultKernelConnectionClosed = MAKERESULT(Module_Kernel, 123);
static constexpr Result ResultKernelUnhandledUserInterrupt = MAKERESULT(Module_Kernel, 124);
static constexpr Result ResultKernelInvalidState = MAKERESULT(Module_Kernel, 125);
static constexpr Result ResultKernelReservedValue = MAKERESULT(Module_Kernel, 126);
static constexpr Result ResultKernelInvalidHwBreakpoint = MAKERESULT(Module_Kernel, 127);
static constexpr Result ResultKernelFatalUserException = MAKERESULT(Module_Kernel, 128);
static constexpr Result ResultKernelOwnedByAnotherProcess = MAKERESULT(Module_Kernel, 129);
static constexpr Result ResultKernelConnectionRefused = MAKERESULT(Module_Kernel, 131);
static constexpr Result ResultKernelOutOfResource = MAKERESULT(Module_Kernel, 132);
static constexpr Result ResultKernelInvalidSize = MAKERESULT(Module_Kernel, KernelError_InvalidSize);
static constexpr Result ResultKernelInvalidAddress = MAKERESULT(Module_Kernel, KernelError_InvalidAddress);
static constexpr Result ResultKernelResourceExhausted = MAKERESULT(Module_Kernel, KernelError_ResourceExhausted);
static constexpr Result ResultKernelOutOfMemory = MAKERESULT(Module_Kernel, KernelError_OutOfMemory);
static constexpr Result ResultKernelOutOfHandles = MAKERESULT(Module_Kernel, KernelError_OutOfHandles);
static constexpr Result ResultKernelInvalidMemoryState = MAKERESULT(Module_Kernel, KernelError_InvalidMemoryState);
static constexpr Result ResultKernelInvalidMemoryPermissions = MAKERESULT(Module_Kernel, KernelError_InvalidMemoryPermissions);
static constexpr Result ResultKernelInvalidMemoryRange = MAKERESULT(Module_Kernel, KernelError_InvalidMemoryRange);
static constexpr Result ResultKernelInvalidPriority = MAKERESULT(Module_Kernel, KernelError_InvalidPriority);
static constexpr Result ResultKernelInvalidCoreId = MAKERESULT(Module_Kernel, KernelError_InvalidCoreId);
static constexpr Result ResultKernelInvalidHandle = MAKERESULT(Module_Kernel, KernelError_InvalidHandle);
static constexpr Result ResultKernelInvalidUserBuffer = MAKERESULT(Module_Kernel, KernelError_InvalidUserBuffer);
static constexpr Result ResultKernelInvalidCombination = MAKERESULT(Module_Kernel, KernelError_InvalidCombination);
static constexpr Result ResultKernelTimedOut = MAKERESULT(Module_Kernel, KernelError_TimedOut);
static constexpr Result ResultKernelCancelled = MAKERESULT(Module_Kernel, KernelError_Cancelled);
static constexpr Result ResultKernelOutOfRange = MAKERESULT(Module_Kernel, KernelError_OutOfRange);
static constexpr Result ResultKernelInvalidEnumValue = MAKERESULT(Module_Kernel, KernelError_InvalidEnumValue);
static constexpr Result ResultKernelNotFound = MAKERESULT(Module_Kernel, KernelError_NotFound);
static constexpr Result ResultKernelAlreadyExists = MAKERESULT(Module_Kernel, KernelError_AlreadyExists);
static constexpr Result ResultKernelConnectionClosed = MAKERESULT(Module_Kernel, KernelError_ConnectionClosed);
static constexpr Result ResultKernelUnhandledUserInterrupt = MAKERESULT(Module_Kernel, KernelError_UnhandledUserInterrupt);
static constexpr Result ResultKernelInvalidState = MAKERESULT(Module_Kernel, KernelError_InvalidState);
static constexpr Result ResultKernelReservedValue = MAKERESULT(Module_Kernel, KernelError_ReservedValue);
static constexpr Result ResultKernelInvalidHwBreakpoint = MAKERESULT(Module_Kernel, KernelError_InvalidHwBreakpoint);
static constexpr Result ResultKernelFatalUserException = MAKERESULT(Module_Kernel, KernelError_FatalUserException);
static constexpr Result ResultKernelOwnedByAnotherProcess = MAKERESULT(Module_Kernel, KernelError_OwnedByAnotherProcess);
static constexpr Result ResultKernelConnectionRefused = MAKERESULT(Module_Kernel, KernelError_ConnectionRefused);
static constexpr Result ResultKernelLimitReached = MAKERESULT(Module_Kernel, 132 /* KernelError_OutOfResource */);
static constexpr Result ResultKernelIpcMapFailed = MAKERESULT(Module_Kernel, 259);
static constexpr Result ResultKernelIpcCmdBufTooSmall = MAKERESULT(Module_Kernel, 260);
static constexpr Result ResultKernelIpcMapFailed = MAKERESULT(Module_Kernel, KernelError_IpcMapFailed);
static constexpr Result ResultKernelIpcCmdBufTooSmall = MAKERESULT(Module_Kernel, KernelError_IpcCmdbufTooSmall);
static constexpr Result ResultKernelNotDebugged = MAKERESULT(Module_Kernel, 520);
static constexpr Result ResultKernelNotDebugged = MAKERESULT(Module_Kernel, KernelError_NotDebugged);

View File

@ -21,6 +21,7 @@
#include "../meta_tools.hpp"
#include "results.hpp"
#include "waitable_manager_base.hpp"
#include "event.hpp"
#include "ipc.hpp"
@ -167,7 +168,7 @@ class WaitableManager : public SessionManagerBase {
}
if (w) {
Result rc = w->HandleSignaled(0);
if (rc == 0xF601) {
if (rc == ResultKernelConnectionClosed) {
/* Close! */
delete w;
} else {
@ -189,10 +190,10 @@ class WaitableManager : public SessionManagerBase {
for (auto it = this_ptr->deferred_waitables.begin(); it != this_ptr->deferred_waitables.end();) {
auto w = *it;
Result rc = w->HandleDeferred();
if (rc == 0xF601 || !w->IsDeferred()) {
if (rc == ResultKernelConnectionClosed || !w->IsDeferred()) {
/* Remove from the deferred list, set iterator. */
it = this_ptr->deferred_waitables.erase(it);
if (rc == 0xF601) {
if (rc == ResultKernelConnectionClosed) {
/* Delete the closed waitable. */
delete w;
} else {
@ -279,10 +280,10 @@ class WaitableManager : public SessionManagerBase {
size_t w_ind = std::distance(this->waitables.begin(), std::find(this->waitables.begin(), this->waitables.end(), w));
std::for_each(waitables.begin(), waitables.begin() + w_ind + 1, std::mem_fn(&IWaitable::UpdatePriority));
result = w;
} else if (rc == 0xEA01) {
} else if (rc == ResultKernelTimedOut) {
/* Timeout: Just update priorities. */
std::for_each(waitables.begin(), waitables.end(), std::mem_fn(&IWaitable::UpdatePriority));
} else if (rc == 0xEC01) {
} else if (rc == ResultKernelCancelled) {
/* svcCancelSynchronization was called. */
AddWaitablesInternal();
{