2018-05-04 06:58:25 +01:00
|
|
|
#pragma once
|
|
|
|
#include <switch.h>
|
|
|
|
#include <stratosphere.hpp>
|
2018-06-15 07:47:07 +01:00
|
|
|
#include <memory>
|
2018-05-04 06:58:25 +01:00
|
|
|
|
2018-05-04 08:01:53 +01:00
|
|
|
#define LAUNCHFLAGS_NOTIFYWHENEXITED(flags) (flags & 1)
|
|
|
|
#define LAUNCHFLAGS_STARTSUSPENDED(flags) (flags & (kernelAbove500() ? 0x10 : 0x2))
|
|
|
|
#define LAUNCHFLAGS_ARGLOW(flags) (kernelAbove500() ? ((flags & 0x14) != 0x10) : (kernelAbove200() ? ((flags & 0x6) != 0x2) : ((flags >> 2) & 1)))
|
2018-05-06 09:23:47 +01:00
|
|
|
#define LAUNCHFLAGS_ARGHIGH(flags) ((flags & (kernelAbove500() ? 0x20 : 0x8)) ? 2 : 0)
|
2018-05-04 08:01:53 +01:00
|
|
|
#define LAUNCHFLAGS_NOTIFYDEBUGEVENTS(flags) (flags & (kernelAbove500() ? 0x8 : 0x10))
|
|
|
|
#define LAUNCHFLAGS_NOTIYDEBUGSPECIAL(flags) (flags & (kernelAbove500() ? 0x2 : (kernelAbove200() ? 0x20 : 0x0)))
|
|
|
|
|
|
|
|
|
2018-05-04 06:58:25 +01:00
|
|
|
class Registration {
|
|
|
|
public:
|
|
|
|
struct TidSid {
|
|
|
|
u64 title_id;
|
|
|
|
FsStorageId storage_id;
|
|
|
|
};
|
|
|
|
struct Process {
|
|
|
|
Handle handle;
|
|
|
|
u64 pid;
|
|
|
|
u64 ldr_queue_index;
|
|
|
|
Registration::TidSid tid_sid;
|
|
|
|
ProcessState state;
|
|
|
|
u32 flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ProcessLaunchState {
|
|
|
|
TidSid tid_sid;
|
|
|
|
u64 launch_flags;
|
|
|
|
u64* out_pid;
|
|
|
|
Result result;
|
|
|
|
};
|
2018-05-05 02:56:59 +01:00
|
|
|
class AutoProcessListLock {
|
|
|
|
private:
|
|
|
|
bool has_lock;
|
|
|
|
public:
|
|
|
|
AutoProcessListLock();
|
|
|
|
~AutoProcessListLock();
|
|
|
|
void Unlock();
|
|
|
|
};
|
|
|
|
|
2018-05-04 06:58:25 +01:00
|
|
|
static void InitializeSystemResources();
|
2018-05-07 05:59:54 +01:00
|
|
|
static IWaitable *GetProcessLaunchStartEvent();
|
2018-06-15 07:47:07 +01:00
|
|
|
static void SetProcessListManager(WaitableManager *m);
|
2018-06-15 06:32:01 +01:00
|
|
|
static Result ProcessLaunchStartCallback(void *arg, Handle *handles, size_t num_handles, u64 timeout);
|
2018-05-04 06:58:25 +01:00
|
|
|
|
2018-06-15 07:47:07 +01:00
|
|
|
static Result HandleSignaledProcess(std::shared_ptr<Process> process);
|
|
|
|
static void FinalizeExitedProcess(std::shared_ptr<Process> process);
|
2018-05-04 06:58:25 +01:00
|
|
|
|
2018-06-15 07:47:07 +01:00
|
|
|
static void AddProcessToList(std::shared_ptr<Process> process);
|
2018-05-04 06:58:25 +01:00
|
|
|
static void RemoveProcessFromList(u64 pid);
|
|
|
|
static void SetProcessState(u64 pid, ProcessState new_state);
|
|
|
|
|
2018-06-15 07:47:07 +01:00
|
|
|
static std::shared_ptr<Registration::Process> GetProcess(u64 pid);
|
|
|
|
static std::shared_ptr<Registration::Process> GetProcessByTitleId(u64 tid);
|
2018-05-07 11:45:44 +01:00
|
|
|
static Result GetDebugProcessIds(u64 *out_pids, u32 max_out, u32 *num_out);
|
2018-05-05 02:56:59 +01:00
|
|
|
static Handle GetProcessEventHandle();
|
|
|
|
static void GetProcessEventType(u64 *out_pid, u64 *out_type);
|
2018-05-07 11:45:44 +01:00
|
|
|
static Result EnableDebugForTitleId(u64 tid, Handle *out);
|
|
|
|
static Result EnableDebugForApplication(Handle *out);
|
2018-05-05 02:56:59 +01:00
|
|
|
static Handle GetDebugTitleEventHandle();
|
|
|
|
static Handle GetDebugApplicationEventHandle();
|
|
|
|
|
2018-05-04 06:58:25 +01:00
|
|
|
static void HandleProcessLaunch();
|
2018-05-07 11:45:44 +01:00
|
|
|
static Result LaunchDebugProcess(u64 pid);
|
2018-05-04 06:58:25 +01:00
|
|
|
static void SignalFinishLaunchProcess();
|
|
|
|
static Result LaunchProcess(u64 title_id, FsStorageId storage_id, u64 launch_flags, u64 *out_pid);
|
|
|
|
static Result LaunchProcessByTidSid(TidSid tid_sid, u64 launch_flags, u64 *out_pid);
|
|
|
|
|
2018-06-15 07:47:07 +01:00
|
|
|
static bool HasApplicationProcess(std::shared_ptr<Process> *out);
|
2018-05-04 06:58:25 +01:00
|
|
|
};
|
|
|
|
|