Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions nx/include/switch/kernel/svc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef enum {
MemType_CodeWritable=0x15, ///< Mapped in kernel during \ref svcControlCodeMemory.
MemType_Coverage=0x16, ///< Not available.
MemType_Insecure=0x17, ///< Mapped in kernel during \ref svcMapInsecurePhysicalMemory.
MemType_ShadowStack=0x1A, ///< Mapped in kernel.
} MemoryType;

/// Memory state bitmasks.
Expand Down Expand Up @@ -213,6 +214,10 @@ typedef enum {
InfoType_AliasRegionExtraSize = 28, ///< [18.0.0+] Extra size added to the reserved region.

InfoType_TransferMemoryHint = 34, ///< [19.0.0+] Low bits of the process address for a KTransferMemory.

InfoType_AddressSpaceSize = 36, ///< [23.0.0+]
InfoType_ShadowStackRegionAddress = 37, ///< [23.0.0+]
InfoType_ShadowStackRegionSize = 38, ///< [23.0.0+]

InfoType_ThreadTickCountDeprecated = 0xF0000002, ///< [1.0.0-12.1.0] Number of ticks spent on thread.
} InfoType;
Expand Down Expand Up @@ -341,10 +346,11 @@ typedef enum {

/// Address space types for CreateProcessFlags
typedef enum {
CreateProcessFlagAddressSpace_32bit = 0,
CreateProcessFlagAddressSpace_64bitDeprecated = 1, ///< 36-bit width
CreateProcessFlagAddressSpace_32bitWithoutAlias = 2,
CreateProcessFlagAddressSpace_64bit = 3, ///< [2.0.0+] 39-bit width
CreateProcessFlagAddressSpace_32bit = 0,
CreateProcessFlagAddressSpace_64Bit36 = 1, ///< 36-bit width
CreateProcessFlagAddressSpace_32BitNoReserved = 2,
CreateProcessFlagAddressSpace_64Bit39 = 3, ///< [2.0.0+] 39-bit width
CreateProcessFlagAddressSpace_64Bit42 = 4, ///< [23.0.0+] 42-bit width
} CreateProcessFlagAddressSpace;

/// Memory regions
Expand All @@ -364,7 +370,9 @@ typedef struct {
u32 optimize_memory_allocation: 1; ///< [7.0.0+] Only allowed in combination with is_application
u32 disable_device_address_space_merge: 1; ///< [11.0.0+]
u32 enable_alias_region_extra_size: 1; ///< [18.0.0+]
u32 reserved: 18;
u32 unk: 4;
u32 enable_shadow_stack: 1; ///< [23.0.0+]
u32 reserved: 13;
} CreateProcessFlags;

/// DebugEvent structure
Expand Down
29 changes: 16 additions & 13 deletions nx/include/switch/services/pgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ typedef enum {
} PglSnapShotDumpType;

typedef struct {
u64 id; ///< Program Id
u32 version; ///< Version
u8 content_type; ///< NcmContentType
u8 id_offset; ///< Id Offset
u8 reserved_0E[2]; ///< Padding
} PglContentMetaInfo;
u64 id; ///< Program Id
u32 version; ///< Version
u8 content_type; ///< NcmContentType
u8 id_offset; ///< Id Offset
u8 content_meta_type; ///< NcmContentMetaType
u8 reserved_0F; ///< Padding
} PglProgramLaunchProperty;

typedef union {
Service s;
Expand All @@ -54,16 +55,18 @@ TipcService* pglGetServiceSessionTipc(void);
Result pglLaunchProgram(u64 *out_pid, const NcmProgramLocation *loc, u32 pm_launch_flags, u8 pgl_launch_flags);
Result pglTerminateProcess(u64 pid);
Result pglLaunchProgramFromHost(u64 *out_pid, const char *content_path, u32 pm_launch_flags);
Result pglGetHostContentMetaInfo(PglContentMetaInfo *out, const char *content_path);
Result pglGetApplicationProcessId(u64 *out);
Result pglGetHostProgramLaunchProperty(PglProgramLaunchProperty *out, const char *content_path);
Result pglGetRunningApplicationProcessId(u64 *out_pid);
Result pglBoostSystemMemoryResourceLimit(u64 size);
Result pglIsProcessTracked(bool *out, u64 pid);
Result pglIsRunningProcess(bool *out, u64 pid);
Result pglEnableApplicationCrashReport(bool en);
Result pglIsApplicationCrashReportEnabled(bool *out);
Result pglEnableApplicationAllThreadDumpOnCrash(bool en);
Result pglTriggerApplicationSnapShotDumper(PglSnapShotDumpType dump_type, const char *arg);
Result pglGetEventObserver(PglEventObserver *out);
Result pglGetProcessId(u64 *out_pid, u64 program_id); ///< [19.0.0+]
Result pglTriggerSnapShotDumper(PglSnapShotDumpType dump_type, const char *arg); ///< [10.0.0-11.0.1]
Result pglCreateShellEvent(PglEventObserver *out);
Result pglEnableApplicationCrashReport2(u64 pid, bool en); ///< [23.0.0+]

Result pglEventObserverGetProcessEvent(PglEventObserver *observer, Event *out);
Result pglEventObserverGetProcessEventInfo(PglEventObserver *observer, PmProcessEventInfo *out);
Result pglEventObserverGetShellEvent(PglEventObserver *observer, Event *out);
Result pglEventObserverGetShellEventInfo(PglEventObserver *observer, PmProcessEventInfo *out);
void pglEventObserverClose(PglEventObserver *observer);
1 change: 1 addition & 0 deletions nx/include/switch/services/spl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef enum {
SplConfigItem_NewHardwareType = 15,
SplConfigItem_NewKeyGeneration = 16,
SplConfigItem_Package2Hash = 17,
SplConfigItem_Unknown18 = 18,
} SplConfigItem;

typedef enum {
Expand Down
41 changes: 31 additions & 10 deletions nx/source/services/pgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Result pglLaunchProgramFromHost(u64 *out_pid, const char *content_path, u32 pm_l
}
}

Result pglGetHostContentMetaInfo(PglContentMetaInfo *out, const char *content_path) {
Result pglGetHostProgramLaunchProperty(PglProgramLaunchProperty *out, const char *content_path) {
if (_pglShouldUseTipc()) {
return tipcDispatchOut(&g_pglSrv.tipc, 4, *out,
.buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcMapAlias },
Expand All @@ -134,19 +134,19 @@ Result pglGetHostContentMetaInfo(PglContentMetaInfo *out, const char *content_pa
}
}

Result pglGetApplicationProcessId(u64 *out) {
Result pglGetRunningApplicationProcessId(u64 *out_pid) {
if (_pglShouldUseTipc()) {
return tipcDispatchOut(&g_pglSrv.tipc, 5, *out);
return tipcDispatchOut(&g_pglSrv.tipc, 5, *out_pid);
} else {
return serviceDispatchOut(&g_pglSrv.cmif, 5, *out);
return serviceDispatchOut(&g_pglSrv.cmif, 5, *out_pid);
}
}

Result pglBoostSystemMemoryResourceLimit(u64 size) {
return _pglCmdInU64(size, 6);
}

Result pglIsProcessTracked(bool *out, u64 pid) {
Result pglIsRunningProcess(bool *out, u64 pid) {
u8 outval = 0;
Result rc;

Expand Down Expand Up @@ -174,8 +174,16 @@ Result pglEnableApplicationAllThreadDumpOnCrash(bool en) {
return _pglCmdInBool(en, 10);
}

Result pglTriggerApplicationSnapShotDumper(PglSnapShotDumpType dump_type, const char *arg) {
if (hosversionAtLeast(12,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
Result pglGetProcessId(u64 *out_pid, u64 program_id) {
if (hosversionBefore(19,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);

return tipcDispatchInOut(&g_pglSrv.tipc, 11, program_id, *out_pid);
}

Result pglTriggerSnapShotDumper(PglSnapShotDumpType dump_type, const char *arg) {
if (hosversionAtLeast(12,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);

_Static_assert(sizeof(dump_type) == sizeof(u32), "PglSnapShotDumpType");
return serviceDispatchIn(&g_pglSrv.cmif, 12, dump_type,
Expand All @@ -184,7 +192,7 @@ Result pglTriggerApplicationSnapShotDumper(PglSnapShotDumpType dump_type, const
);
}

Result pglGetEventObserver(PglEventObserver *out) {
Result pglCreateShellEvent(PglEventObserver *out) {
if (_pglShouldUseTipc()) {
return tipcDispatch(&g_pglSrv.tipc, 20,
.out_num_objects = 1,
Expand All @@ -198,7 +206,20 @@ Result pglGetEventObserver(PglEventObserver *out) {
}
}

Result pglEventObserverGetProcessEvent(PglEventObserver *observer, Event *out) {
Result pglEnableApplicationCrashReport2(u64 pid, bool en) {
if (hosversionBefore(23,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);

const struct {
u64 pid;
u8 en;
u8 pad[3];
} in = { pid, en, {0} };

return tipcDispatchIn(&g_pglSrv.tipc, 31, in);
}

Result pglEventObserverGetShellEvent(PglEventObserver *observer, Event *out) {
Handle evt_handle;
Result rc;

Expand All @@ -221,7 +242,7 @@ Result pglEventObserverGetProcessEvent(PglEventObserver *observer, Event *out) {
return rc;
}

Result pglEventObserverGetProcessEventInfo(PglEventObserver *observer, PmProcessEventInfo *out) {
Result pglEventObserverGetShellEventInfo(PglEventObserver *observer, PmProcessEventInfo *out) {
if (_pglShouldUseTipc()) {
return tipcDispatchOut(&observer->t, 1, *out);
} else {
Expand Down
Loading