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