Revert C++ libnx bindings and call-site conversion

This commit is contained in:
Lightos1 committed 2026-10-06 10:42:15 +02:00
1 parent fb46ac4199
commit 5f973f60b2
44 files changed
+246 -34097

No files matched your search

@@ -26,20 +26,18 @@
#include <string.h>
#include "ipc_server.hpp"
using namespace nx;
#include "ipc_server.h"
Result ipcServerInit(IpcServer *server, const char *name, u32 max_sessions) {
if (max_sessions < 1 || max_sessions > (MAX_WAIT_OBJECTS - 1)) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
}
server->srvName = sm::EncodeName(name);
server->srvName = smEncodeName(name);
server->max = max_sessions + 1;
server->count = 0;
Result rc = sm::RegisterService(&server->handles[0], server->srvName, false, max_sessions);
Result rc = smRegisterService(&server->handles[0], server->srvName, false, max_sessions);
if (R_SUCCEEDED(rc)) {
server->count = 1;
}
@@ -48,10 +46,10 @@ Result ipcServerInit(IpcServer *server, const char *name, u32 max_sessions) {
Result ipcServerExit(IpcServer *server) {
for (u32 i = 0; i < server->count; i++) {
svc::CloseHandle(server->handles[i]);
svcCloseHandle(server->handles[i]);
}
server->count = 0;
return sm::UnregisterService(server->srvName);
return smUnregisterService(server->srvName);
}
static Result _ipcServerAddSession(IpcServer *server, Handle session) {
@@ -69,7 +67,7 @@ static Result _ipcServerDeleteSession(IpcServer *server, u32 index) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
}
svc::CloseHandle(server->handles[index]);
svcCloseHandle(server->handles[index]);
for (u32 j = index; j < (server->count - 1); j++) {
server->handles[j] = server->handles[j + 1];
@@ -79,15 +77,15 @@ static Result _ipcServerDeleteSession(IpcServer *server, u32 index) {
}
static Result _ipcServerParseRequest(IpcServerRequest *r) {
u8 *base = (u8*)armGetTls();
u8 *base = armGetTls();
r->hipc = hipc::ParseRequest(base);
r->hipc = hipcParseRequest(base);
r->data.cmdId = 0;
r->data.size = 0;
r->data.ptr = NULL;
if (r->hipc.meta.type == CmifCommandType_Request) {
IpcServerRawHeader *header = (IpcServerRawHeader*)cmif::GetAlignedDataStart(r->hipc.data.data_words, base);
IpcServerRawHeader *header = cmifGetAlignedDataStart(r->hipc.data.data_words, base);
size_t dataSize = r->hipc.meta.num_data_words * 4;
if (!header || dataSize < sizeof(IpcServerRawHeader) || header->magic != CMIF_IN_HEADER_MAGIC) {
@@ -105,11 +103,11 @@ static Result _ipcServerParseRequest(IpcServerRequest *r) {
}
static void _ipcServerPrepareResponse(Result rc, void *data, size_t dataSize) {
u8 *base = (u8*)arm::GetTls();
u8 *base = armGetTls();
HipcRequest hipc =
hipcMakeRequestInline(base, .type = CmifCommandType_Request, .num_data_words = (u32)(sizeof(IpcServerRawHeader) + dataSize + 0x10) / 4, );
hipcMakeRequestInline(base, .type = CmifCommandType_Request, .num_data_words = (sizeof(IpcServerRawHeader) + dataSize + 0x10) / 4, );
IpcServerRawHeader *rawHeader = (IpcServerRawHeader*)cmif::GetAlignedDataStart(hipc.data_words, base);
IpcServerRawHeader *rawHeader = cmifGetAlignedDataStart(hipc.data_words, base);
rawHeader->magic = CMIF_OUT_HEADER_MAGIC;
rawHeader->result = rc;
@@ -120,9 +118,9 @@ static void _ipcServerPrepareResponse(Result rc, void *data, size_t dataSize) {
static Result _ipcServerProcessNewSession(IpcServer *server) {
Handle session;
Result rc = svc::AcceptSession(&session, server->handles[0]);
Result rc = svcAcceptSession(&session, server->handles[0]);
if (R_SUCCEEDED(rc) && R_FAILED(rc = _ipcServerAddSession(server, session))) {
svc::CloseHandle(session);
svcCloseHandle(session);
}
return rc;
}
@@ -134,7 +132,7 @@ static Result _ipcServerProcessSession(IpcServer *server, IpcServerRequestHandle
u8 data[IPC_SERVER_EXT_RESPONSE_MAX_DATA_SIZE];
bool close = false;
Result rc = svc::ReplyAndReceive(&unusedIndex, &server->handles[handleIndex], 1, 0, UINT64_MAX);
Result rc = svcReplyAndReceive(&unusedIndex, &server->handles[handleIndex], 1, 0, UINT64_MAX);
if (R_SUCCEEDED(rc)) {
rc = _ipcServerParseRequest(&r);
}
@@ -168,9 +166,9 @@ static Result _ipcServerProcessSession(IpcServer *server, IpcServerRequestHandle
Result ipcServerProcess(IpcServer *server, IpcServerRequestHandler handler, void *userdata) {
s32 handleIndex = -1;
Result rc = svc::WaitSynchronization(&handleIndex, server->handles, server->count, UINT64_MAX);
Result rc = svcWaitSynchronization(&handleIndex, server->handles, server->count, UINT64_MAX);
if (R_SUCCEEDED(rc) && (handleIndex < 0 || handleIndex >= (s32)server->count)) {
if (R_SUCCEEDED(rc) && (handleIndex < 0 || handleIndex >= server->count)) {
rc = MAKERESULT(Module_Libnx, LibnxError_NotFound);
}
@@ -31,7 +31,6 @@ extern "C" {
#endif
#include <switch.h>
#include <switch.hpp>
#define IPC_SERVER_EXT_RESPONSE_MAX_DATA_SIZE (0x100 - 0x10 - sizeof(IpcServerRawHeader))
@@ -25,11 +25,10 @@
*/
#include <cstring>
#include <i2c.hpp>
#include <max17050.hpp>
#include <i2c.h>
#include <max17050.h>
#include <switch.h>
#include <switch.hpp>
#include <tmp451.hpp>
#include <tmp451.h>
#include "../file/config.hpp"
#include "../file/errors.hpp"
@@ -38,11 +37,8 @@
#include "../hos/apm_ext.h"
#include "../mgr/clock_manager.hpp"
#include "ipc_service.hpp"
#include <ipc_server.hpp>
#include <ipc_server.h>
#include <lockable_mutex.h>
using namespace nx;
namespace ipcService {
namespace {
@@ -274,7 +270,7 @@ namespace ipcService {
void Initialize() {
std::int32_t priority;
Result rc = svc::GetThreadPriority(&priority, CUR_THREAD_HANDLE);
Result rc = svcGetThreadPriority(&priority, CUR_THREAD_HANDLE);
ASSERT_RESULT_OK(rc, "svcGetThreadPriority");
rc = ipcServerInit(&gServer, HOCCLK_IPC_SERVICE_NAME, 42);
ASSERT_RESULT_OK(rc, "ipcServerInit");
@@ -285,7 +281,7 @@ namespace ipcService {
void Exit() {
SetRunning(false);
Result rc = thread::Close(&gThread);
Result rc = threadClose(&gThread);
ASSERT_RESULT_OK(rc, "threadClose");
rc = ipcServerExit(&gServer);
ASSERT_RESULT_OK(rc, "ipcServerExit");
@@ -300,11 +296,11 @@ namespace ipcService {
gRunning = running;
if (running) {
Result rc = thread::Start(&gThread);
Result rc = threadStart(&gThread);
ASSERT_RESULT_OK(rc, "threadStart");
} else {
svc::CancelSynchronization(gThread.handle);
thread::WaitForExit(&gThread);
svcCancelSynchronization(gThread.handle);
threadWaitForExit(&gThread);
}
}