mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-08-10 01:19:31 +02:00
kern/dmnt2: allow retrieval of process info via extension
This also fixes ctrl-c break in gdbstub, and fixes crash on unknown monitor cmd.
This commit is contained in:
parent
cfb192e8a2
commit
1c7ae0d066
@ -40,6 +40,12 @@
|
|||||||
/* of the right side, and so this does not actually cost any space. */
|
/* of the right side, and so this does not actually cost any space. */
|
||||||
#define MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST
|
#define MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST
|
||||||
|
|
||||||
|
/* NOTE: This enables usage of KDebug handles as parameter for svc::GetInfo */
|
||||||
|
/* calls which require a process parameter. This enables a debugger to obtain */
|
||||||
|
/* address space/layout information, for example. However, it changes abi, and so */
|
||||||
|
/* this define allows toggling the extension. */
|
||||||
|
#define MESOSPHERE_ENABLE_GET_INFO_OF_DEBUG_PROCESS
|
||||||
|
|
||||||
/* NOTE: This uses currently-reserved bits inside the MapRange capability */
|
/* NOTE: This uses currently-reserved bits inside the MapRange capability */
|
||||||
/* in order to support large physical addresses (40-bit instead of 36). */
|
/* in order to support large physical addresses (40-bit instead of 36). */
|
||||||
/* This is toggleable in order to disable it if N ever uses those bits. */
|
/* This is toggleable in order to disable it if N ever uses those bits. */
|
||||||
|
@ -38,36 +38,7 @@ namespace ams::kern::svc {
|
|||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result GetInfo(u64 *out, ams::svc::InfoType info_type, ams::svc::Handle handle, u64 info_subtype) {
|
Result GetInfoImpl(u64 *out, ams::svc::InfoType info_type, KProcess *process) {
|
||||||
switch (info_type) {
|
|
||||||
case ams::svc::InfoType_CoreMask:
|
|
||||||
case ams::svc::InfoType_PriorityMask:
|
|
||||||
case ams::svc::InfoType_AliasRegionAddress:
|
|
||||||
case ams::svc::InfoType_AliasRegionSize:
|
|
||||||
case ams::svc::InfoType_HeapRegionAddress:
|
|
||||||
case ams::svc::InfoType_HeapRegionSize:
|
|
||||||
case ams::svc::InfoType_TotalMemorySize:
|
|
||||||
case ams::svc::InfoType_UsedMemorySize:
|
|
||||||
case ams::svc::InfoType_AslrRegionAddress:
|
|
||||||
case ams::svc::InfoType_AslrRegionSize:
|
|
||||||
case ams::svc::InfoType_StackRegionAddress:
|
|
||||||
case ams::svc::InfoType_StackRegionSize:
|
|
||||||
case ams::svc::InfoType_SystemResourceSizeTotal:
|
|
||||||
case ams::svc::InfoType_SystemResourceSizeUsed:
|
|
||||||
case ams::svc::InfoType_ProgramId:
|
|
||||||
case ams::svc::InfoType_UserExceptionContextAddress:
|
|
||||||
case ams::svc::InfoType_TotalNonSystemMemorySize:
|
|
||||||
case ams::svc::InfoType_UsedNonSystemMemorySize:
|
|
||||||
case ams::svc::InfoType_IsApplication:
|
|
||||||
case ams::svc::InfoType_FreeThreadCount:
|
|
||||||
{
|
|
||||||
/* These info types don't support non-zero subtypes. */
|
|
||||||
R_UNLESS(info_subtype == 0, svc::ResultInvalidCombination());
|
|
||||||
|
|
||||||
/* Get the process from its handle. */
|
|
||||||
KScopedAutoObject process = GetCurrentProcess().GetHandleTable().GetObject<KProcess>(handle);
|
|
||||||
R_UNLESS(process.IsNotNull(), svc::ResultInvalidHandle());
|
|
||||||
|
|
||||||
switch (info_type) {
|
switch (info_type) {
|
||||||
case ams::svc::InfoType_CoreMask:
|
case ams::svc::InfoType_CoreMask:
|
||||||
*out = process->GetCoreMask();
|
*out = process->GetCoreMask();
|
||||||
@ -137,6 +108,66 @@ namespace ams::kern::svc {
|
|||||||
break;
|
break;
|
||||||
MESOSPHERE_UNREACHABLE_DEFAULT_CASE();
|
MESOSPHERE_UNREACHABLE_DEFAULT_CASE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result GetInfo(u64 *out, ams::svc::InfoType info_type, ams::svc::Handle handle, u64 info_subtype) {
|
||||||
|
switch (info_type) {
|
||||||
|
case ams::svc::InfoType_CoreMask:
|
||||||
|
case ams::svc::InfoType_PriorityMask:
|
||||||
|
case ams::svc::InfoType_AliasRegionAddress:
|
||||||
|
case ams::svc::InfoType_AliasRegionSize:
|
||||||
|
case ams::svc::InfoType_HeapRegionAddress:
|
||||||
|
case ams::svc::InfoType_HeapRegionSize:
|
||||||
|
case ams::svc::InfoType_TotalMemorySize:
|
||||||
|
case ams::svc::InfoType_UsedMemorySize:
|
||||||
|
case ams::svc::InfoType_AslrRegionAddress:
|
||||||
|
case ams::svc::InfoType_AslrRegionSize:
|
||||||
|
case ams::svc::InfoType_StackRegionAddress:
|
||||||
|
case ams::svc::InfoType_StackRegionSize:
|
||||||
|
case ams::svc::InfoType_SystemResourceSizeTotal:
|
||||||
|
case ams::svc::InfoType_SystemResourceSizeUsed:
|
||||||
|
case ams::svc::InfoType_ProgramId:
|
||||||
|
case ams::svc::InfoType_UserExceptionContextAddress:
|
||||||
|
case ams::svc::InfoType_TotalNonSystemMemorySize:
|
||||||
|
case ams::svc::InfoType_UsedNonSystemMemorySize:
|
||||||
|
case ams::svc::InfoType_IsApplication:
|
||||||
|
case ams::svc::InfoType_FreeThreadCount:
|
||||||
|
{
|
||||||
|
/* These info types don't support non-zero subtypes. */
|
||||||
|
R_UNLESS(info_subtype == 0, svc::ResultInvalidCombination());
|
||||||
|
|
||||||
|
/* Get the process from its handle. */
|
||||||
|
KScopedAutoObject process = GetCurrentProcess().GetHandleTable().GetObject<KProcess>(handle);
|
||||||
|
|
||||||
|
#if defined(MESOSPHERE_ENABLE_GET_INFO_OF_DEBUG_PROCESS)
|
||||||
|
/* If we the process is valid, use it. */
|
||||||
|
if (process.IsNotNull()) {
|
||||||
|
return GetInfoImpl(out, info_type, process.GetPointerUnsafe());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, as a mesosphere extension check if we were passed a usable KDebug. */
|
||||||
|
KScopedAutoObject debug = GetCurrentProcess().GetHandleTable().GetObject<KDebug>(handle);
|
||||||
|
R_UNLESS(debug.IsNotNull(), svc::ResultInvalidHandle());
|
||||||
|
|
||||||
|
/* Get the process from the debug object. */
|
||||||
|
/* TODO: ResultInvalidHandle()? */
|
||||||
|
R_UNLESS(debug->IsAttached(), svc::ResultProcessTerminated());
|
||||||
|
R_UNLESS(debug->OpenProcess(), svc::ResultProcessTerminated());
|
||||||
|
|
||||||
|
/* Close the process when we're done. */
|
||||||
|
ON_SCOPE_EXIT { debug->CloseProcess(); };
|
||||||
|
|
||||||
|
/* Return the info. */
|
||||||
|
return GetInfoImpl(out, info_type, debug->GetProcessUnsafe());
|
||||||
|
#else
|
||||||
|
/* Verify that the process is valid. */
|
||||||
|
R_UNLESS(process.IsNotNull(), svc::ResultInvalidHandle());
|
||||||
|
|
||||||
|
/* Return the relevant info. */
|
||||||
|
return GetInfoImpl(out, info_type, process.GetPointerUnsafe());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ams::svc::InfoType_DebuggerAttached:
|
case ams::svc::InfoType_DebuggerAttached:
|
||||||
|
Loading…
Reference in New Issue
Block a user