sm: add smDetachClient (#509)

This commit is contained in:
SciresM 2020-12-02 08:42:09 -08:00 committed by GitHub
parent 83dc9203dc
commit 2d470ee2af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -124,6 +124,13 @@ Result smRegisterService(Handle* handle_out, SmServiceName name, bool is_light,
*/
Result smUnregisterService(SmServiceName name);
/**
* @brief Detaches the current SM session.
* @note After this function is called, the rest of the SM API cannot be used.
* @note Only available on [11.0.0+].
*/
Result smDetachClient(void);
/**
* @brief Gets the Service session used to communicate with SM.
* @return Pointer to service session used to communicate with SM.

View File

@ -1,5 +1,6 @@
#define NX_SERVICE_ASSUME_NON_DOMAIN
#include "service_guard.h"
#include "runtime/hosversion.h"
#include "runtime/diag.h"
static Service g_smSrv;
@ -35,6 +36,11 @@ Handle smGetServiceOverride(SmServiceName name) {
NX_GENERATE_SERVICE_GUARD(sm);
static Result _smCmdInPid(u32 cmd_id) {
u64 pid_placeholder = 0;
return serviceDispatchIn(&g_smSrv, cmd_id, pid_placeholder, .in_send_pid = true);
}
Result _smInitialize(void) {
Handle sm_handle;
Result rc = svcConnectToNamedPort(&sm_handle, "sm:");
@ -49,8 +55,7 @@ Result _smInitialize(void) {
Handle tmp;
if (R_SUCCEEDED(rc) && R_VALUE(smGetServiceOriginal(&tmp, (SmServiceName){})) == 0x415) {
u64 pid_placeholder = 0;
rc = serviceDispatchIn(&g_smSrv, 0, pid_placeholder, .in_send_pid = true);
rc = _smCmdInPid(0);
}
return rc;
@ -105,3 +110,8 @@ Result smRegisterService(Handle* handle_out, SmServiceName name, bool is_light,
Result smUnregisterService(SmServiceName name) {
return serviceDispatchIn(&g_smSrv, 3, name);
}
Result smDetachClient(void) {
if (hosversionBefore(11,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return _smCmdInPid(4);
}