Move services out of the kernel and fix service registration

In addition, this adds a constructor for "RegionInfo".
This commit is contained in:
◱ PixelyIon 2019-11-17 01:50:08 +05:30 committed by ◱ PixelyIon
parent 8aea45170f
commit 26a67f70b7
30 changed files with 43 additions and 48 deletions

View File

@ -213,7 +213,7 @@ namespace skyline::gpu::device {
try {
function = vTable.at(cmd);
} catch (std::out_of_range &) {
state.logger->Warn("Cannot find IOCTL for device '{}': 0x{:X}", getName(), deviceType, cmd);
state.logger->Warn("Cannot find IOCTL for device '{}': 0x{:X}", getName(), cmd);
input.status = NvStatus::NotImplemented;
return;
}

View File

@ -34,7 +34,7 @@ namespace skyline::kernel::svc {
break;
}
if (!subFound)
region->regionInfoVec.push_back(memory::RegionInfo{.address=addr, .size=size, .isUncached=isUncached});
region->regionInfoVec.emplace_back(addr, size, isUncached);
found = true;
break;
}

View File

@ -70,7 +70,9 @@ namespace skyline::memory {
struct RegionInfo {
u64 address; //!< The starting address of the chunk of memory
u64 size; //!< The size of the chunk of memory
bool isUncached{}; //!< If the following region is uncached
bool isUncached; //!< If the following region is uncached
RegionInfo(u64 address, u64 size, bool isUncached) : address(address), size(size), isUncached(isUncached) {}
};
/**

View File

@ -1,7 +1,7 @@
#include "applet.h"
#include "appletController.h"
namespace skyline::kernel::service::am {
namespace skyline::service::am {
appletOE::appletOE(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::am_appletOE, {
{0x0, SFUNC(appletOE::OpenApplicationProxy)}
}) {}

View File

@ -3,7 +3,7 @@
#include <services/base_service.h>
#include <services/serviceman.h>
namespace skyline::kernel::service::am {
namespace skyline::service::am {
/**
* @brief appletOE is used to open an application proxy (https://switchbrew.org/wiki/Applet_Manager_services#appletOE)
*/

View File

@ -1,6 +1,6 @@
#include "appletController.h"
namespace skyline::kernel::service::am {
namespace skyline::service::am {
void ICommonStateGetter::QueueMessage(ICommonStateGetter::Message message) {
messageQueue.emplace(message);
messageEvent->Signal();

View File

@ -6,7 +6,7 @@
#include <kernel/types/KEvent.h>
#include <gpu.h>
namespace skyline::kernel::service::am {
namespace skyline::service::am {
/**
* @brief https://switchbrew.org/wiki/Applet_Manager_services#ICommonStateGetter
*/

View File

@ -1,6 +1,6 @@
#include "apm.h"
namespace skyline::kernel::service::apm {
namespace skyline::service::apm {
apm::apm(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::apm, {
{0x0, SFUNC(apm::OpenSession)}
}) {}

View File

@ -3,7 +3,7 @@
#include <services/base_service.h>
#include <services/serviceman.h>
namespace skyline::kernel::service::apm {
namespace skyline::service::apm {
/**
* @brief apm is used to control performance modes of the device, this service however is mostly only used to open an ISession (https://switchbrew.org/wiki/PPC_services#apm)
*/

View File

@ -10,7 +10,8 @@
namespace skyline::kernel::type {
class KSession;
}
namespace skyline::kernel::service {
namespace skyline::service {
using namespace kernel;
/**
* @brief This contains an enum for every service that's present
*/

View File

@ -1,6 +1,6 @@
#include "fatal.h"
namespace skyline::kernel::service::fatal {
namespace skyline::service::fatal {
fatalU::fatalU(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::fatal_u, {
{0x0, SFUNC(fatalU::ThrowFatal)},
{0x1, SFUNC(fatalU::ThrowFatal)},

View File

@ -3,7 +3,7 @@
#include <services/base_service.h>
#include <services/serviceman.h>
namespace skyline::kernel::service::fatal {
namespace skyline::service::fatal {
/**
* @brief fatal_u is used by applications to throw errors (https://switchbrew.org/wiki/Fatal_services#fatal:u)
*/

View File

@ -1,6 +1,6 @@
#include "fs.h"
namespace skyline::kernel::service::fs {
namespace skyline::service::fs {
fsp::fsp(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::fs_fsp, {
{0x1, SFUNC(fsp::SetCurrentProcess)},
{0x12, SFUNC(fsp::OpenSdCardFileSystem)}

View File

@ -3,7 +3,7 @@
#include <services/base_service.h>
#include <services/serviceman.h>
namespace skyline::kernel::service::fs {
namespace skyline::service::fs {
/**
* @brief These are the possible types of the filesystem
*/

View File

@ -1,7 +1,7 @@
#include "hid.h"
#include <os.h>
namespace skyline::kernel::service::hid {
namespace skyline::service::hid {
IAppletResource::IAppletResource(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::hid_IAppletResource, {
{0x0, SFUNC(IAppletResource::GetSharedMemoryHandle)}
}) {}

View File

@ -8,7 +8,7 @@ namespace skyline::constant {
constexpr size_t hidSharedMemSize = 0x40000; //!< The size of HID Shared Memory (https://switchbrew.org/wiki/HID_Shared_Memory)
}
namespace skyline::kernel::service::hid {
namespace skyline::service::hid {
/**
* @brief IAppletResource is used to get the handle to the HID shared memory (https://switchbrew.org/wiki/HID_services#IAppletResource)
*/

View File

@ -1,7 +1,7 @@
#include "nvdrv.h"
#include <kernel/types/KProcess.h>
namespace skyline::kernel::service::nvdrv {
namespace skyline::service::nvdrv {
nvdrv::nvdrv(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::nvdrv, {
{0x0, SFUNC(nvdrv::Open)},
{0x1, SFUNC(nvdrv::Ioctl)},

View File

@ -5,7 +5,7 @@
#include <kernel/types/KTransferMemory.h>
#include <gpu.h>
namespace skyline::kernel::service::nvdrv {
namespace skyline::service::nvdrv {
/**
* @brief nvdrv or INvDrvServices is used to access the Nvidia GPU inside the Switch (https://switchbrew.org/wiki/NV_services#nvdrv.2C_nvdrv:a.2C_nvdrv:s.2C_nvdrv:t)
*/

View File

@ -3,7 +3,7 @@
#include <gpu.h>
#include <android/native_window.h>
namespace skyline::kernel::service::nvnflinger {
namespace skyline::service::nvnflinger {
dispdrv::dispdrv(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::nvnflinger_dispdrv, {
{0x0, SFUNC(dispdrv::TransactParcel)},
{0x1, SFUNC(dispdrv::AdjustRefcount)},

View File

@ -4,7 +4,7 @@
#include "services/serviceman.h"
#include <gpu/parcel.h>
namespace skyline::kernel::service::nvnflinger {
namespace skyline::service::nvnflinger {
/**
* @brief This enumerates the functions called by TransactParcel for android.gui.IGraphicBufferProducer
* @refitem https://android.googlesource.com/platform/frameworks/native/+/8dc5539/libs/gui/IGraphicBufferProducer.cpp#35

View File

@ -13,10 +13,13 @@
#include "vi/vi_m.h"
#include "nvnflinger/dispdrv.h"
namespace skyline::kernel::service {
namespace skyline::service {
ServiceManager::ServiceManager(const DeviceState &state) : state(state) {}
std::shared_ptr<BaseService> ServiceManager::GetService(const Service serviceType) {
if(serviceMap.count(serviceType)) {
return serviceMap.at(serviceType);
}
std::shared_ptr<BaseService> serviceObj;
switch (serviceType) {
case Service::sm:
@ -112,7 +115,7 @@ namespace skyline::kernel::service {
default:
throw exception("GetService called on missing object, type: {}", serviceType);
}
serviceVec.push_back(serviceObj);
serviceMap[serviceType] = serviceObj;
return serviceObj;
}
@ -136,7 +139,6 @@ namespace skyline::kernel::service {
}
void ServiceManager::RegisterService(std::shared_ptr<BaseService> serviceObject, type::KSession &session, ipc::IpcResponse &response) { // NOLINT(performance-unnecessary-value-param)
serviceVec.push_back(serviceObject);
handle_t handle{};
if (response.isDomain) {
session.domainTable[session.handleIndex] = serviceObject;
@ -154,15 +156,15 @@ namespace skyline::kernel::service {
if (session->serviceStatus == type::KSession::ServiceStatus::Open) {
if (session->isDomain) {
for (const auto &[objectId, service] : session->domainTable)
serviceVec.erase(std::remove(serviceVec.begin(), serviceVec.end(), service), serviceVec.end());
serviceMap.erase(service->serviceType);
} else
serviceVec.erase(std::remove(serviceVec.begin(), serviceVec.end(), session->serviceObject), serviceVec.end());
serviceMap.erase(session->serviceObject->serviceType);
session->serviceStatus = type::KSession::ServiceStatus::Closed;
}
};
void ServiceManager::Loop() {
for (auto &service : serviceVec)
for (auto& [type, service] : serviceMap)
if (service->hasLoop)
service->Loop();
}
@ -187,7 +189,7 @@ namespace skyline::kernel::service {
service->HandleRequest(*session, request, response);
break;
case ipc::DomainCommand::CloseVHandle:
serviceVec.erase(std::remove(serviceVec.begin(), serviceVec.end(), service), serviceVec.end());
serviceMap.erase(service->serviceType);
session->domainTable.erase(request.domain->objectId);
break;
}
@ -209,7 +211,7 @@ namespace skyline::kernel::service {
break;
case ipc::ControlCommand::CloneCurrentObject:
case ipc::ControlCommand::CloneCurrentObjectEx:
CloneSession(*session, request, response);
response.WriteValue(state.thisProcess->InsertItem(session));
break;
case ipc::ControlCommand::QueryPointerBufferSize:
response.WriteValue<u32>(0x1000);
@ -232,8 +234,4 @@ namespace skyline::kernel::service {
state.logger->Warn("svcSendSyncRequest called on closed handle: 0x{:X}", handle);
state.logger->Debug("====End====");
}
void ServiceManager::CloneSession(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
//NewService(session.serviceType, session, response);
}
}

View File

@ -4,14 +4,14 @@
#include <kernel/types/KSession.h>
#include "base_service.h"
namespace skyline::kernel::service {
namespace skyline::service {
/**
* @brief The ServiceManager class manages passing IPC requests to the right Service and running event loops of Services
*/
class ServiceManager {
private:
const DeviceState &state; //!< The state of the device
std::vector<std::shared_ptr<BaseService>> serviceVec; //!< A vector with all of the services
std::unordered_map<Service, std::shared_ptr<BaseService>> serviceMap; //!< A mapping from a Service to the underlying object
/**
* @param serviceType The type of service requested
@ -64,11 +64,5 @@ namespace skyline::kernel::service {
* @param handle The handle of the object
*/
void SyncRequestHandler(const handle_t handle);
/**
* @brief Duplicates a session
* @param handle The handle of the object
*/
void CloneSession(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
};
}

View File

@ -1,7 +1,7 @@
#include "sys.h"
#include <kernel/types/KProcess.h>
namespace skyline::kernel::service::set {
namespace skyline::service::set {
sys::sys(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::set_sys, {{0x3, SFUNC(sys::GetFirmwareVersion)}}) {}
void sys::GetFirmwareVersion(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {

View File

@ -3,7 +3,7 @@
#include <services/base_service.h>
#include <services/serviceman.h>
namespace skyline::kernel::service::set {
namespace skyline::service::set {
/**
* @brief set:sys or System Settings service provides access to system settings
*/

View File

@ -1,6 +1,6 @@
#include "sm.h"
namespace skyline::kernel::service::sm {
namespace skyline::service::sm {
sm::sm(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::sm, {
{0x0, SFUNC(sm::Initialize)},
{0x1, SFUNC(sm::GetService)}

View File

@ -3,7 +3,7 @@
#include <services/base_service.h>
#include <services/serviceman.h>
namespace skyline::kernel::service::sm {
namespace skyline::service::sm {
/**
* @brief sm: or Service Manager is responsible for providing handles to services (https://switchbrew.org/wiki/Services_API)
*/

View File

@ -1,6 +1,6 @@
#include "timesrv.h"
namespace skyline::kernel::service::time {
namespace skyline::service::time {
time::time(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::time, {
{0x0, SFUNC(time::GetStandardUserSystemClock)},
{0x1, SFUNC(time::GetStandardNetworkSystemClock)},

View File

@ -3,7 +3,7 @@
#include <services/base_service.h>
#include <services/serviceman.h>
namespace skyline::kernel::service::time {
namespace skyline::service::time {
/**
* @brief The type of a #SystemClockType
*/

View File

@ -3,7 +3,7 @@
#include <services/nvnflinger/dispdrv.h>
#include <gpu/display.h>
namespace skyline::kernel::service::vi {
namespace skyline::service::vi {
vi_m::vi_m(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, false, Service::nvdrv, {
{0x2, SFUNC(vi_m::GetDisplayService)}
}) {}

View File

@ -5,7 +5,7 @@
#include <gpu.h>
#include <gpu/parcel.h>
namespace skyline::kernel::service::vi {
namespace skyline::service::vi {
/**
* @brief This service is used to get an handle to #IApplicationDisplayService (https://switchbrew.org/wiki/Display_services#vi:m)
*/