util::string_view, update pgl for new sf semantics

This commit is contained in:
Michael Scire 2021-01-18 05:20:27 -08:00 committed by SciresM
parent 83c04fa5d7
commit 3bb94aa146
13 changed files with 448 additions and 70 deletions

View file

@ -21,7 +21,7 @@ extern "C" {
u32 __nx_applet_type = AppletType_None;
u32 __nx_fs_num_sessions = 1;
#define INNER_HEAP_SIZE 0x4000
#define INNER_HEAP_SIZE 0x0
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
char nx_inner_heap[INNER_HEAP_SIZE];
@ -33,6 +33,9 @@ extern "C" {
alignas(16) u8 __nx_exception_stack[ams::os::MemoryPageSize];
u64 __nx_exception_stack_size = sizeof(__nx_exception_stack);
void __libnx_exception_handler(ThreadExceptionDump *ctx);
void *__libnx_thread_alloc(size_t size);
void __libnx_thread_free(void *mem);
}
namespace ams {
@ -57,41 +60,52 @@ namespace ams::pgl {
namespace {
/* pgl. */
constexpr size_t NumServers = 1;
ams::sf::hipc::ServerManager<NumServers> g_server_manager;
constexpr sm::ServiceName ShellServiceName = sm::ServiceName::Encode("pgl");
constexpr size_t ShellMaxSessions = 8; /* Official maximum is 8. */
constinit pgl::srv::ShellInterface g_shell_interface;
void RegisterServiceSession() {
R_ABORT_UNLESS((g_server_manager.RegisterServer<pgl::sf::IShellInterface, pgl::srv::ShellInterface>(ShellServiceName, ShellMaxSessions, ams::sf::GetSharedPointerTo<pgl::sf::IShellInterface>(g_shell_interface))));
}
void LoopProcess() {
g_server_manager.LoopProcess();
}
/* NOTE: Nintendo reserves only 0x2000 bytes for this heap, which is used "mostly" to allocate shell event observers. */
/* However, we would like very much for homebrew sysmodules to be able to subscribe to events if they so choose */
/* And so we will use a larger heap (32 KB). */
/* We should have a smaller memory footprint than N in the end, regardless. */
u8 g_heap_memory[32_KB];
TYPED_STORAGE(ams::sf::ExpHeapMemoryResource) g_heap_memory_resource;
constinit u8 g_heap_memory[32_KB];
lmem::HeapHandle g_server_heap_handle;
constinit ams::sf::ExpHeapAllocator g_server_allocator;
void *Allocate(size_t size) {
return lmem::AllocateFromExpHeap(GetReference(g_heap_memory_resource).GetHandle(), size);
return lmem::AllocateFromExpHeap(g_server_heap_handle, size);
}
void Deallocate(void *p, size_t size) {
return lmem::FreeToExpHeap(GetReference(g_heap_memory_resource).GetHandle(), p);
return lmem::FreeToExpHeap(g_server_heap_handle, p);
}
void InitializeHeap() {
auto heap_handle = lmem::CreateExpHeap(g_heap_memory, sizeof(g_heap_memory), lmem::CreateOption_ThreadSafe);
new (GetPointer(g_heap_memory_resource)) ams::sf::ExpHeapMemoryResource(heap_handle);
g_server_heap_handle = lmem::CreateExpHeap(g_heap_memory, sizeof(g_heap_memory), lmem::CreateOption_ThreadSafe);
g_server_allocator.Attach(g_server_heap_handle);
}
}
namespace {
/* pgl. */
enum PortIndex {
PortIndex_Shell,
PortIndex_Count,
};
constexpr sm::ServiceName ShellServiceName = sm::ServiceName::Encode("pgl");
constexpr size_t ShellMaxSessions = 8; /* Official maximum is 8. */
using ServerManager = ams::sf::hipc::ServerManager<PortIndex_Count>;
ServerManager g_server_manager;
constinit ams::sf::UnmanagedServiceObject<pgl::sf::IShellInterface, pgl::srv::ShellInterface> g_shell_interface(std::addressof(g_server_allocator));
void RegisterServiceSession() {
R_ABORT_UNLESS(g_server_manager.RegisterObjectForServer(g_shell_interface.GetShared(), ShellServiceName, ShellMaxSessions));
}
void LoopProcess() {
g_server_manager.LoopProcess();
}
}
@ -138,6 +152,33 @@ void __appExit(void) {
setExit();
}
namespace ams {
void *Malloc(size_t size) {
AMS_ABORT("ams::Malloc was called");
}
void Free(void *ptr) {
AMS_ABORT("ams::Free was called");
}
}
void *operator new(size_t size) {
return pgl::Allocate(size);
}
void operator delete(void *p) {
return pgl::Deallocate(p, 0);
}
void *__libnx_thread_alloc(size_t size) {
AMS_ABORT("__libnx_thread_alloc was called");
}
void __libnx_thread_free(void *mem) {
AMS_ABORT("__libnx_thread_free was called");
}
int main(int argc, char **argv)
{
@ -152,7 +193,7 @@ int main(int argc, char **argv)
pgl::RegisterServiceSession();
/* Initialize the server library. */
pgl::srv::Initialize(std::addressof(pgl::g_shell_interface), GetPointer(pgl::g_heap_memory_resource));
pgl::srv::Initialize();
/* Loop forever, servicing our services. */
pgl::LoopProcess();