libstrat: convert to experimental new (super-accurate) sf allocation semantics
This commit is contained in:
@@ -23,13 +23,13 @@ namespace ams::gpio {
|
||||
constinit os::SdkMutex g_init_mutex;
|
||||
constinit int g_initialize_count = 0;
|
||||
constinit bool g_remote = false;
|
||||
std::shared_ptr<sf::IManager> g_manager;
|
||||
ams::sf::SharedPointer<gpio::sf::IManager> g_manager;
|
||||
|
||||
using InternalSession = std::shared_ptr<gpio::sf::IPadSession>;
|
||||
ams::sf::UnmanagedServiceObject<gpio::sf::IManager, RemoteManagerImpl> g_remote_manager_impl;
|
||||
|
||||
InternalSession &GetInterface(GpioPadSession *session) {
|
||||
gpio::sf::IPadSession *GetInterface(GpioPadSession *session) {
|
||||
AMS_ASSERT(session->_session != nullptr);
|
||||
return *static_cast<InternalSession *>(session->_session);
|
||||
return static_cast<gpio::sf::IPadSession *>(session->_session);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,17 +39,17 @@ namespace ams::gpio {
|
||||
|
||||
if ((g_initialize_count++) == 0) {
|
||||
R_ABORT_UNLESS(::gpioInitialize());
|
||||
g_manager = ams::sf::MakeShared<sf::IManager, RemoteManagerImpl>();
|
||||
g_manager = g_remote_manager_impl.GetShared();
|
||||
g_remote = true;
|
||||
}
|
||||
}
|
||||
|
||||
void InitializeWith(std::shared_ptr<gpio::sf::IManager> &&sp) {
|
||||
void InitializeWith(ams::sf::SharedPointer<gpio::sf::IManager> manager) {
|
||||
std::scoped_lock lk(g_init_mutex);
|
||||
|
||||
AMS_ABORT_UNLESS(g_initialize_count == 0);
|
||||
|
||||
g_manager = std::move(sp);
|
||||
g_manager = manager;
|
||||
g_initialize_count = 1;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace ams::gpio {
|
||||
AMS_ASSERT(g_initialize_count > 0);
|
||||
|
||||
if ((--g_initialize_count) == 0) {
|
||||
g_manager.reset();
|
||||
g_manager = nullptr;
|
||||
if (g_remote) {
|
||||
::gpioExit();
|
||||
}
|
||||
@@ -67,28 +67,21 @@ namespace ams::gpio {
|
||||
}
|
||||
|
||||
Result OpenSession(GpioPadSession *out_session, ams::DeviceCode device_code) {
|
||||
/* Allocate the session. */
|
||||
InternalSession *internal_session = new (std::nothrow) InternalSession;
|
||||
AMS_ABORT_UNLESS(internal_session != nullptr);
|
||||
auto session_guard = SCOPE_GUARD { delete internal_session; };
|
||||
|
||||
/* Get the session. */
|
||||
ams::sf::SharedPointer<gpio::sf::IPadSession> session;
|
||||
{
|
||||
ams::sf::cmif::ServiceObjectHolder object_holder;
|
||||
if (hos::GetVersion() >= hos::Version_7_0_0) {
|
||||
R_TRY(g_manager->OpenSession2(std::addressof(object_holder), device_code, ddsf::AccessMode_ReadWrite));
|
||||
R_TRY(g_manager->OpenSession2(std::addressof(session), device_code, ddsf::AccessMode_ReadWrite));
|
||||
} else {
|
||||
R_TRY(g_manager->OpenSession(std::addressof(object_holder), ConvertToGpioPadName(device_code)));
|
||||
R_TRY(g_manager->OpenSession(std::addressof(session), ConvertToGpioPadName(device_code)));
|
||||
}
|
||||
*internal_session = object_holder.GetServiceObject<sf::IPadSession>();
|
||||
}
|
||||
|
||||
/* Set output. */
|
||||
out_session->_session = internal_session;
|
||||
out_session->_session = session.Detach();
|
||||
out_session->_event = nullptr;
|
||||
|
||||
/* We succeeded. */
|
||||
session_guard.Cancel();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -101,7 +94,7 @@ namespace ams::gpio {
|
||||
}
|
||||
|
||||
/* Close the session. */
|
||||
delete std::addressof(GetInterface(session));
|
||||
ams::sf::ReleaseSharedObject(GetInterface(session));
|
||||
session->_session = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "gpio_remote_manager_impl.hpp"
|
||||
|
||||
namespace ams::gpio {
|
||||
|
||||
namespace {
|
||||
|
||||
struct GpioRemoteManagerTag;
|
||||
using RemoteAllocator = ams::sf::ExpHeapStaticAllocator<16_KB, GpioRemoteManagerTag>;
|
||||
using RemoteObjectFactory = ams::sf::ObjectFactory<typename RemoteAllocator::Policy>;
|
||||
|
||||
class StaticAllocatorInitializer {
|
||||
public:
|
||||
StaticAllocatorInitializer() {
|
||||
RemoteAllocator::Initialize(lmem::CreateOption_None);
|
||||
}
|
||||
} g_static_allocator_initializer;
|
||||
|
||||
}
|
||||
|
||||
Result RemoteManagerImpl::OpenSession(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
::GpioPadSession p;
|
||||
R_TRY(::gpioOpenSession(std::addressof(p), static_cast<::GpioPadName>(static_cast<u32>(pad_name))));
|
||||
|
||||
out.SetValue(RemoteObjectFactory::CreateSharedEmplaced<gpio::sf::IPadSession, RemotePadSessionImpl>(p));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result RemoteManagerImpl::OpenSession2(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode) {
|
||||
::GpioPadSession p;
|
||||
R_TRY(::gpioOpenSession2(std::addressof(p), device_code.GetInternalValue(), access_mode));
|
||||
|
||||
out.SetValue(RemoteObjectFactory::CreateSharedEmplaced<gpio::sf::IPadSession, RemotePadSessionImpl>(p));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,20 +26,14 @@ namespace ams::gpio {
|
||||
~RemoteManagerImpl() { /* ... */ }
|
||||
public:
|
||||
/* Actual commands. */
|
||||
Result OpenSessionForDev(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, s32 pad_descriptor) {
|
||||
Result OpenSessionForDev(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, s32 pad_descriptor) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result OpenSession(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
::GpioPadSession p;
|
||||
R_TRY(::gpioOpenSession(std::addressof(p), static_cast<::GpioPadName>(static_cast<u32>(pad_name))));
|
||||
Result OpenSession(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name);
|
||||
|
||||
out.SetValue(ams::sf::MakeShared<gpio::sf::IPadSession, RemotePadSessionImpl>(p));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result OpenSessionForTest(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
Result OpenSessionForTest(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
/* TODO: libnx bindings */
|
||||
AMS_ABORT();
|
||||
}
|
||||
@@ -63,13 +57,7 @@ namespace ams::gpio {
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result OpenSession2(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode) {
|
||||
::GpioPadSession p;
|
||||
R_TRY(::gpioOpenSession2(std::addressof(p), device_code.GetInternalValue(), access_mode));
|
||||
|
||||
out.SetValue(ams::sf::MakeShared<gpio::sf::IPadSession, RemotePadSessionImpl>(p));
|
||||
return ResultSuccess();
|
||||
}
|
||||
Result OpenSession2(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode);
|
||||
|
||||
Result IsWakeEventActive2(ams::sf::Out<bool> out, DeviceCode device_code) {
|
||||
return ::gpioIsWakeEventActive2(out.GetPointer(), device_code.GetInternalValue());
|
||||
|
||||
@@ -20,17 +20,12 @@ namespace ams::gpio::server {
|
||||
|
||||
namespace {
|
||||
|
||||
ManagerImpl g_manager_impl;
|
||||
|
||||
std::shared_ptr<gpio::sf::IManager> GetManagerServiceObject() {
|
||||
static std::shared_ptr<gpio::sf::IManager> s_sp = ams::sf::GetSharedPointerTo<gpio::sf::IManager>(g_manager_impl);
|
||||
return s_sp;
|
||||
}
|
||||
ams::sf::UnmanagedServiceObject<gpio::sf::IManager, gpio::server::ManagerImpl> g_manager_impl;
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<gpio::sf::IManager> GetServiceObject() {
|
||||
return GetManagerServiceObject();
|
||||
ams::sf::SharedPointer<gpio::sf::IManager> GetServiceObject() {
|
||||
return g_manager_impl.GetShared();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,25 +18,25 @@
|
||||
|
||||
namespace ams::gpio::server {
|
||||
|
||||
ManagerImpl::ManagerImpl() : pad_session_memory_resource(), pad_allocator(std::addressof(pad_session_memory_resource)) {
|
||||
ManagerImpl::ManagerImpl() {
|
||||
this->heap_handle = lmem::CreateExpHeap(this->heap_buffer, sizeof(this->heap_buffer), lmem::CreateOption_None);
|
||||
this->pad_session_memory_resource.Attach(this->heap_handle);
|
||||
this->pad_allocator.Attach(this->heap_handle);
|
||||
}
|
||||
|
||||
ManagerImpl::~ManagerImpl() {
|
||||
lmem::DestroyExpHeap(this->heap_handle);
|
||||
}
|
||||
|
||||
Result ManagerImpl::OpenSessionForDev(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, s32 pad_descriptor) {
|
||||
Result ManagerImpl::OpenSessionForDev(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, s32 pad_descriptor) {
|
||||
/* TODO */
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result ManagerImpl::OpenSession(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
Result ManagerImpl::OpenSession(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
return this->OpenSession2(out, ConvertToDeviceCode(pad_name), ddsf::AccessMode_ReadWrite);
|
||||
}
|
||||
|
||||
Result ManagerImpl::OpenSessionForTest(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
Result ManagerImpl::OpenSessionForTest(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name) {
|
||||
/* TODO */
|
||||
AMS_ABORT();
|
||||
}
|
||||
@@ -61,15 +61,15 @@ namespace ams::gpio::server {
|
||||
AMS_ABORT();
|
||||
}
|
||||
|
||||
Result ManagerImpl::OpenSession2(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode) {
|
||||
Result ManagerImpl::OpenSession2(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode) {
|
||||
/* Allocate a session. */
|
||||
auto session = ams::sf::AllocateShared<gpio::sf::IPadSession, PadSessionImpl>(this->pad_allocator, this);
|
||||
auto session = Factory::CreateSharedEmplaced<gpio::sf::IPadSession, PadSessionImpl>(std::addressof(this->pad_allocator), this);
|
||||
|
||||
/* Open the session. */
|
||||
R_TRY(session->GetImpl().OpenSession(device_code, access_mode));
|
||||
R_TRY(session.GetImpl().OpenSession(device_code, access_mode));
|
||||
|
||||
/* We succeeded. */
|
||||
out.SetValue(std::move(session));
|
||||
*out = std::move(session);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
|
||||
namespace ams::gpio::server {
|
||||
|
||||
class ManagerImpl {
|
||||
class ManagerImpl : public ams::sf::ISharedObject {
|
||||
private:
|
||||
using Allocator = ams::sf::ExpHeapAllocator;
|
||||
using Factory = ams::sf::ObjectFactory<Allocator::Policy>;
|
||||
private:
|
||||
lmem::HeapHandle heap_handle;
|
||||
ams::sf::ExpHeapMemoryResource pad_session_memory_resource;
|
||||
typename ams::sf::ServiceObjectAllocator<gpio::sf::IPadSession, PadSessionImpl> pad_allocator;
|
||||
Allocator pad_allocator;
|
||||
u8 heap_buffer[12_KB];
|
||||
public:
|
||||
ManagerImpl();
|
||||
@@ -31,14 +33,14 @@ namespace ams::gpio::server {
|
||||
~ManagerImpl();
|
||||
public:
|
||||
/* Actual commands. */
|
||||
Result OpenSessionForDev(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, s32 pad_descriptor);
|
||||
Result OpenSession(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name);
|
||||
Result OpenSessionForTest(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name);
|
||||
Result OpenSessionForDev(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, s32 pad_descriptor);
|
||||
Result OpenSession(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name);
|
||||
Result OpenSessionForTest(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, gpio::GpioPadName pad_name);
|
||||
Result IsWakeEventActive(ams::sf::Out<bool> out, gpio::GpioPadName pad_name);
|
||||
Result GetWakeEventActiveFlagSet(ams::sf::Out<gpio::WakeBitFlag> out);
|
||||
Result SetWakeEventActiveFlagSetForDebug(gpio::GpioPadName pad_name, bool is_enabled);
|
||||
Result SetWakePinDebugMode(s32 mode);
|
||||
Result OpenSession2(ams::sf::Out<std::shared_ptr<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode);
|
||||
Result OpenSession2(ams::sf::Out<ams::sf::SharedPointer<gpio::sf::IPadSession>> out, DeviceCode device_code, ddsf::AccessMode access_mode);
|
||||
Result IsWakeEventActive2(ams::sf::Out<bool> out, DeviceCode device_code);
|
||||
Result SetWakeEventActiveFlagSetForDebug2(DeviceCode device_code, bool is_enabled);
|
||||
Result SetRetryValues(u32 arg0, u32 arg1);
|
||||
|
||||
Reference in New Issue
Block a user