2019-04-24 09:18:18 +01:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-04-24 09:18:18 +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/>.
|
|
|
|
*/
|
2019-06-22 20:23:46 +01:00
|
|
|
#include "spl_api_impl.hpp"
|
|
|
|
|
2019-04-24 09:18:18 +01:00
|
|
|
#include "spl_random_service.hpp"
|
|
|
|
#include "spl_general_service.hpp"
|
2019-04-25 05:00:39 +01:00
|
|
|
#include "spl_crypto_service.hpp"
|
2019-04-25 07:16:47 +01:00
|
|
|
#include "spl_ssl_service.hpp"
|
|
|
|
#include "spl_es_service.hpp"
|
2019-04-25 08:33:10 +01:00
|
|
|
#include "spl_fs_service.hpp"
|
2019-04-25 08:01:47 +01:00
|
|
|
#include "spl_manu_service.hpp"
|
2019-04-24 09:18:18 +01:00
|
|
|
|
2019-04-25 19:12:30 +01:00
|
|
|
#include "spl_deprecated_service.hpp"
|
|
|
|
|
2019-04-24 09:18:18 +01:00
|
|
|
extern "C" {
|
|
|
|
extern u32 __start__;
|
|
|
|
|
|
|
|
u32 __nx_applet_type = AppletType_None;
|
|
|
|
|
2019-10-20 01:42:53 +01:00
|
|
|
#define INNER_HEAP_SIZE 0x4000
|
2019-04-24 09:18:18 +01:00
|
|
|
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
|
|
|
char nx_inner_heap[INNER_HEAP_SIZE];
|
|
|
|
|
|
|
|
void __libnx_initheap(void);
|
|
|
|
void __appInit(void);
|
|
|
|
void __appExit(void);
|
|
|
|
|
|
|
|
/* Exception handling. */
|
2019-12-06 07:41:33 +00:00
|
|
|
alignas(16) u8 __nx_exception_stack[ams::os::MemoryPageSize];
|
2019-04-24 09:18:18 +01:00
|
|
|
u64 __nx_exception_stack_size = sizeof(__nx_exception_stack);
|
|
|
|
void __libnx_exception_handler(ThreadExceptionDump *ctx);
|
|
|
|
}
|
|
|
|
|
2019-10-24 10:30:10 +01:00
|
|
|
namespace ams {
|
2019-10-20 01:42:53 +01:00
|
|
|
|
2020-03-08 08:06:23 +00:00
|
|
|
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Spl;
|
2019-07-03 04:54:16 +01:00
|
|
|
|
2019-10-24 10:30:10 +01:00
|
|
|
namespace result {
|
2019-04-24 09:18:18 +01:00
|
|
|
|
2019-10-24 10:30:10 +01:00
|
|
|
bool CallFatalOnResultAssertion = false;
|
2019-10-24 09:40:44 +01:00
|
|
|
|
2019-10-24 10:30:10 +01:00
|
|
|
}
|
2019-10-24 09:40:44 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-24 10:30:10 +01:00
|
|
|
using namespace ams;
|
2019-10-20 01:42:53 +01:00
|
|
|
|
|
|
|
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
|
|
|
|
ams::CrashHandler(ctx);
|
|
|
|
}
|
2019-04-24 09:18:18 +01:00
|
|
|
|
|
|
|
void __libnx_initheap(void) {
|
|
|
|
void* addr = nx_inner_heap;
|
|
|
|
size_t size = nx_inner_heap_size;
|
|
|
|
|
|
|
|
/* Newlib */
|
|
|
|
extern char* fake_heap_start;
|
|
|
|
extern char* fake_heap_end;
|
|
|
|
|
|
|
|
fake_heap_start = (char*)addr;
|
|
|
|
fake_heap_end = (char*)addr + size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __appInit(void) {
|
2019-10-16 20:50:04 +01:00
|
|
|
hos::SetVersionForLibnx();
|
2019-04-24 09:18:18 +01:00
|
|
|
|
|
|
|
/* SPL doesn't really access any services... */
|
2019-10-20 01:42:53 +01:00
|
|
|
|
|
|
|
ams::CheckApiVersion();
|
2019-04-24 09:18:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void __appExit(void) {
|
|
|
|
/* SPL doesn't really access any services... */
|
|
|
|
}
|
|
|
|
|
2019-10-16 20:50:04 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct SplServerOptions {
|
|
|
|
static constexpr size_t PointerBufferSize = 0x800;
|
|
|
|
static constexpr size_t MaxDomains = 0;
|
|
|
|
static constexpr size_t MaxDomainObjects = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr sm::ServiceName RandomServiceName = sm::ServiceName::Encode("csrng");
|
|
|
|
constexpr size_t RandomMaxSessions = 3;
|
|
|
|
|
|
|
|
constexpr sm::ServiceName DeprecatedServiceName = sm::ServiceName::Encode("spl:");
|
|
|
|
constexpr size_t DeprecatedMaxSessions = 12;
|
|
|
|
|
|
|
|
constexpr sm::ServiceName GeneralServiceName = sm::ServiceName::Encode("spl:");
|
|
|
|
constexpr size_t GeneralMaxSessions = 6;
|
|
|
|
|
|
|
|
constexpr sm::ServiceName CryptoServiceName = sm::ServiceName::Encode("spl:mig");
|
|
|
|
constexpr size_t CryptoMaxSessions = 6;
|
|
|
|
|
|
|
|
constexpr sm::ServiceName SslServiceName = sm::ServiceName::Encode("spl:ssl");
|
|
|
|
constexpr size_t SslMaxSessions = 2;
|
|
|
|
|
|
|
|
constexpr sm::ServiceName EsServiceName = sm::ServiceName::Encode("spl:es");
|
|
|
|
constexpr size_t EsMaxSessions = 2;
|
|
|
|
|
|
|
|
constexpr sm::ServiceName FsServiceName = sm::ServiceName::Encode("spl:fs");
|
|
|
|
constexpr size_t FsMaxSessions = 3;
|
|
|
|
|
|
|
|
constexpr sm::ServiceName ManuServiceName = sm::ServiceName::Encode("spl:manu");
|
|
|
|
constexpr size_t ManuMaxSessions = 1;
|
|
|
|
|
|
|
|
/* csrng, spl:, spl:mig, spl:ssl, spl:es, spl:fs, spl:manu. */
|
|
|
|
/* TODO: Consider max sessions enforcement? */
|
|
|
|
constexpr size_t NumServers = 7;
|
|
|
|
constexpr size_t ModernMaxSessions = GeneralMaxSessions + CryptoMaxSessions + SslMaxSessions + EsMaxSessions + FsMaxSessions + ManuMaxSessions;
|
|
|
|
constexpr size_t NumSessions = RandomMaxSessions + std::max(DeprecatedMaxSessions, ModernMaxSessions) + 1;
|
|
|
|
sf::hipc::ServerManager<NumServers, SplServerOptions, NumSessions> g_server_manager;
|
|
|
|
|
|
|
|
}
|
2019-04-24 09:18:18 +01:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2019-04-24 13:38:11 +01:00
|
|
|
/* Initialize global context. */
|
2019-10-16 20:50:04 +01:00
|
|
|
spl::impl::Initialize();
|
2019-04-24 09:18:18 +01:00
|
|
|
|
|
|
|
/* Create services. */
|
2020-02-23 07:05:14 +00:00
|
|
|
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::RandomService>(RandomServiceName, RandomMaxSessions));
|
2019-10-16 20:50:04 +01:00
|
|
|
if (hos::GetVersion() >= hos::Version_400) {
|
2020-02-23 07:05:14 +00:00
|
|
|
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::GeneralService>(GeneralServiceName, GeneralMaxSessions));
|
|
|
|
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::CryptoService>(CryptoServiceName, CryptoMaxSessions));
|
|
|
|
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::SslService>(SslServiceName, SslMaxSessions));
|
|
|
|
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::EsService>(EsServiceName, EsMaxSessions));
|
|
|
|
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::FsService>(FsServiceName, FsMaxSessions));
|
2019-10-16 20:50:04 +01:00
|
|
|
if (hos::GetVersion() >= hos::Version_500) {
|
2020-02-23 07:05:14 +00:00
|
|
|
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::ManuService>(ManuServiceName, ManuMaxSessions));
|
2019-04-25 08:01:47 +01:00
|
|
|
}
|
2019-04-24 09:18:18 +01:00
|
|
|
} else {
|
2020-02-23 07:05:14 +00:00
|
|
|
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::DeprecatedService>(DeprecatedServiceName, DeprecatedMaxSessions));
|
2019-04-24 09:18:18 +01:00
|
|
|
}
|
2019-06-20 21:00:32 +01:00
|
|
|
|
2019-04-24 09:18:18 +01:00
|
|
|
/* Loop forever, servicing our services. */
|
2019-10-16 20:50:04 +01:00
|
|
|
g_server_manager.LoopProcess();
|
2019-04-24 09:18:18 +01:00
|
|
|
|
|
|
|
return 0;
|
2019-10-20 01:42:53 +01:00
|
|
|
}
|