2019-12-09 11:57:37 +00:00
|
|
|
/*
|
2021-10-04 20:59:10 +01:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-12-09 11:57:37 +00:00
|
|
|
*
|
|
|
|
* 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 <stratosphere.hpp>
|
2022-03-06 20:08:20 +00:00
|
|
|
|
|
|
|
#if defined(ATMOSPHERE_OS_HORIZON)
|
|
|
|
#include "sm_ams.os.horizon.h"
|
|
|
|
#endif
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
namespace ams::sm::impl {
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
#if defined(ATMOSPHERE_OS_HORIZON)
|
2019-12-09 11:57:37 +00:00
|
|
|
/* Utilities. */
|
2021-09-30 06:52:50 +01:00
|
|
|
os::SdkRecursiveMutex &GetMitmAcknowledgementSessionMutex();
|
|
|
|
os::SdkRecursiveMutex &GetPerThreadSessionMutex();
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
template<typename F>
|
|
|
|
Result DoWithMitmAcknowledgementSession(F f) {
|
2020-04-08 10:21:35 +01:00
|
|
|
std::scoped_lock lk(GetMitmAcknowledgementSessionMutex());
|
2019-12-09 11:57:37 +00:00
|
|
|
{
|
2020-02-23 07:05:14 +00:00
|
|
|
R_ABORT_UNLESS(smAtmosphereMitmInitialize());
|
2019-12-09 11:57:37 +00:00
|
|
|
ON_SCOPE_EXIT { smAtmosphereMitmExit(); };
|
|
|
|
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(f());
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename F>
|
|
|
|
Result DoWithPerThreadSession(F f) {
|
2021-04-11 01:59:54 +01:00
|
|
|
TipcService srv;
|
2019-12-09 11:57:37 +00:00
|
|
|
{
|
2020-04-08 10:21:35 +01:00
|
|
|
std::scoped_lock lk(GetPerThreadSessionMutex());
|
2021-10-09 22:49:53 +01:00
|
|
|
R_ABORT_UNLESS(smAtmosphereOpenSession(std::addressof(srv)));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
{
|
2021-10-09 22:49:53 +01:00
|
|
|
ON_SCOPE_EXIT { smAtmosphereCloseSession(std::addressof(srv)); };
|
2022-03-26 21:48:33 +00:00
|
|
|
R_RETURN(f(std::addressof(srv)));
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-09 22:49:53 +01:00
|
|
|
constexpr ALWAYS_INLINE SmServiceName ConvertName(sm::ServiceName name) {
|
2019-12-09 11:57:37 +00:00
|
|
|
static_assert(sizeof(SmServiceName) == sizeof(sm::ServiceName));
|
2021-10-09 22:49:53 +01:00
|
|
|
return std::bit_cast<SmServiceName>(name);
|
2019-12-09 11:57:37 +00:00
|
|
|
}
|
2022-03-06 20:08:20 +00:00
|
|
|
#endif
|
2019-12-09 11:57:37 +00:00
|
|
|
|
|
|
|
}
|