2021-02-24 12:17:00 +00:00
|
|
|
/*
|
2021-10-04 20:59:10 +01:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2021-02-24 12:17:00 +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/>.
|
|
|
|
*/
|
|
|
|
#include <stratosphere.hpp>
|
2021-02-24 15:16:41 +00:00
|
|
|
#include "tio_file_server.hpp"
|
2021-02-24 12:17:00 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
namespace ams {
|
2021-02-24 12:17:00 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
namespace tio {
|
2021-02-24 12:17:00 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
namespace {
|
2021-02-24 15:16:41 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
alignas(0x40) constinit u8 g_fs_heap_buffer[64_KB];
|
|
|
|
alignas(0x40) constinit u8 g_htcs_buffer[1_KB];
|
|
|
|
lmem::HeapHandle g_fs_heap_handle;
|
2021-02-24 15:16:41 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void *AllocateForFs(size_t size) {
|
|
|
|
return lmem::AllocateFromExpHeap(g_fs_heap_handle, size);
|
|
|
|
}
|
2021-02-24 15:16:41 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void DeallocateForFs(void *p, size_t size) {
|
|
|
|
AMS_UNUSED(size);
|
2021-02-24 15:16:41 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
return lmem::FreeToExpHeap(g_fs_heap_handle, p);
|
|
|
|
}
|
2021-10-07 07:22:54 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void InitializeFsHeap() {
|
|
|
|
/* Setup fs allocator. */
|
|
|
|
g_fs_heap_handle = lmem::CreateExpHeap(g_fs_heap_buffer, sizeof(g_fs_heap_buffer), lmem::CreateOption_ThreadSafe);
|
|
|
|
}
|
2021-02-24 15:16:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
namespace init {
|
2021-02-24 12:17:00 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void InitializeSystemModule() {
|
|
|
|
/* Initialize heap. */
|
|
|
|
tio::InitializeFsHeap();
|
2021-02-24 15:16:41 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Initialize our connection to sm. */
|
|
|
|
R_ABORT_UNLESS(sm::Initialize());
|
2021-02-24 15:16:41 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Initialize fs. */
|
|
|
|
fs::InitializeForSystem();
|
|
|
|
fs::SetAllocator(tio::AllocateForFs, tio::DeallocateForFs);
|
|
|
|
fs::SetEnabledAutoAbort(false);
|
2021-04-14 07:58:10 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Verify that we can sanely execute. */
|
|
|
|
ams::CheckApiVersion();
|
|
|
|
}
|
2021-02-24 12:17:00 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void FinalizeSystemModule() { /* ... */ }
|
2021-02-24 12:17:00 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void Startup() { /* ... */ }
|
2021-02-24 12:17:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void Main() {
|
|
|
|
/* Set thread name. */
|
|
|
|
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(TioServer, Main));
|
|
|
|
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(TioServer, Main));
|
2021-02-24 12:17:00 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Initialize htcs. */
|
|
|
|
constexpr auto HtcsSocketCountMax = 2;
|
|
|
|
const size_t buffer_size = htcs::GetWorkingMemorySize(HtcsSocketCountMax);
|
|
|
|
AMS_ABORT_UNLESS(sizeof(tio::g_htcs_buffer) >= buffer_size);
|
|
|
|
htcs::InitializeForSystem(tio::g_htcs_buffer, buffer_size, HtcsSocketCountMax);
|
2021-02-24 12:17:00 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Initialize the file server. */
|
|
|
|
tio::InitializeFileServer();
|
2021-02-24 12:17:00 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Start the file server. */
|
|
|
|
tio::StartFileServer();
|
2021-10-07 07:22:54 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Wait for the file server to finish. */
|
|
|
|
tio::WaitFileServer();
|
|
|
|
}
|
2021-02-24 15:16:41 +00:00
|
|
|
|
2021-02-24 12:17:00 +00:00
|
|
|
}
|