sceNpWebApi2GetMemoryPoolStats

This commit is contained in:
Stephen Miller 2026-06-28 10:48:12 -05:00
parent 5f52e2ee1d
commit 6fb761aba1
4 changed files with 41 additions and 20 deletions

View File

@ -86,15 +86,15 @@ s32 PS4_SYSV_ABI sceNpWebApi2GetHttpResponseHeaderValueLength() {
s32 PS4_SYSV_ABI sceNpWebApi2GetMemoryPoolStats(s32 lib_ctx_id,
OrbisNpWebApi2MemoryPoolStats* stats) {
LOG_ERROR(Lib_NpWebApi2, "(STUBBED) called, lib_ctx_id = {:#x}", lib_ctx_id);
return ORBIS_OK;
LOG_INFO(Lib_NpWebApi2, "called, lib_ctx_id = {:#x}", lib_ctx_id);
return getMemoryPoolStats(lib_ctx_id, stats);
}
s32 PS4_SYSV_ABI sceNpWebApi2Initialize(s32 lib_http_ctx_id, u64 pool_size) {
LOG_DEBUG(Lib_NpWebApi2, "called, lib_http_ctx_id = {:#x}, pool_size = {:#x}", lib_http_ctx_id,
pool_size);
s32 ctx_id = createLibraryContext(lib_http_ctx_id, nullptr);
s32 ctx_id = createLibraryContext(lib_http_ctx_id, pool_size, nullptr);
if (ctx_id > 0) {
LOG_INFO(Lib_NpWebApi2, "created lib_ctx_id = {:#x}", ctx_id);
}
@ -105,7 +105,7 @@ s32 PS4_SYSV_ABI sceNpWebApi2InitializeForPresence(s32 lib_http_ctx_id, u64 pool
LOG_DEBUG(Lib_NpWebApi2, "called, lib_http_ctx_id = {:#x}, pool_size = {:#x}", lib_http_ctx_id,
pool_size);
s32 ctx_id = createLibraryContext(lib_http_ctx_id, nullptr);
s32 ctx_id = createLibraryContext(lib_http_ctx_id, pool_size, nullptr);
if (ctx_id > 0) {
LOG_INFO(Lib_NpWebApi2, "created lib_ctx_id = {:#x}", ctx_id);
}
@ -125,7 +125,7 @@ s32 PS4_SYSV_ABI sceNpWebApi2IntInitialize(const OrbisNpWebApi2IntInitializeArgs
LOG_DEBUG(Lib_NpWebApi2, "called, lib_http_ctx_id = {:#x}, pool_size = {:#x}, name = {}",
args->lib_http_ctx_id, args->pool_size, args->name ? args->name : "(null)");
s32 ctx_id = createLibraryContext(args->lib_http_ctx_id, args->name);
s32 ctx_id = createLibraryContext(args->lib_http_ctx_id, args->pool_size, args->name);
if (ctx_id > 0) {
LOG_INFO(Lib_NpWebApi2, "created lib_ctx_id = {:#x}", ctx_id);
}
@ -144,7 +144,7 @@ s32 PS4_SYSV_ABI sceNpWebApi2IntInitialize2(const OrbisNpWebApi2IntInitialize2Ar
args->lib_http_ctx_id, args->pool_size, args->name ? args->name : "(null)",
args->push_config_group);
s32 ctx_id = createLibraryContext(args->lib_http_ctx_id, args->name);
s32 ctx_id = createLibraryContext(args->lib_http_ctx_id, args->pool_size, args->name);
if (ctx_id > 0) {
LOG_INFO(Lib_NpWebApi2, "created lib_ctx_id = {:#x}", ctx_id);
}

View File

@ -18,35 +18,40 @@ class Request;
class LibraryContext {
public:
LibraryContext(s32 ctx_id, s32 http_ctx_id) : id(ctx_id), http_ctx_id(http_ctx_id) {};
LibraryContext(s32 ctx_id, s32 http_ctx_id, const char* name)
: id(ctx_id), http_ctx_id(http_ctx_id), name(name) {};
LibraryContext(s32 ctx_id, s32 http_ctx_id, u64 pool_size)
: id(ctx_id), http_ctx_id(http_ctx_id), pool_size(pool_size) {}
LibraryContext(s32 ctx_id, s32 http_ctx_id, u64 pool_size, const char* name)
: id(ctx_id), http_ctx_id(http_ctx_id), pool_size(pool_size), name(name) {}
void Lock() {
lock.lock();
};
}
void Unlock() {
lock.unlock();
};
}
void AddUser() {
std::scoped_lock lk{lock};
user_count++;
};
}
void RemoveUser() {
std::scoped_lock lk{lock};
user_count--;
};
}
s32 GetId() {
return id;
};
}
s32 GetHttpCtxId() {
return http_ctx_id;
};
}
u64 GetPoolSize() {
return pool_size;
}
const char* GetName() {
return name.empty() ? nullptr : name.data();
@ -59,12 +64,13 @@ public:
void RemoveUserContext(s32 user_ctx_id) {
std::scoped_lock lk{lock};
user_contexts.erase(user_ctx_id);
};
}
private:
s32 id{};
s32 http_ctx_id{};
s32 user_count{};
u64 pool_size{};
std::recursive_mutex lock{};
std::string name{};
std::map<s32, UserContext*> user_contexts{};

View File

@ -17,7 +17,7 @@ std::recursive_mutex g_mutex{};
s32 g_current_lib_context_id{};
std::map<s32, LibraryContext*> g_lib_contexts{};
s32 createLibraryContext(s32 http_ctx_id, const char* name) {
s32 createLibraryContext(s32 http_ctx_id, u64 pool_size, const char* name) {
std::scoped_lock lk{g_mutex};
if (g_lib_contexts.size() >= 0x8000) {
@ -34,10 +34,10 @@ s32 createLibraryContext(s32 http_ctx_id, const char* name) {
if (!name) {
g_lib_contexts[g_current_lib_context_id] =
new LibraryContext(g_current_lib_context_id, http_ctx_id);
new LibraryContext(g_current_lib_context_id, http_ctx_id, pool_size);
} else {
g_lib_contexts[g_current_lib_context_id] =
new LibraryContext(g_current_lib_context_id, http_ctx_id, name);
new LibraryContext(g_current_lib_context_id, http_ctx_id, pool_size, name);
}
return g_current_lib_context_id;
};
@ -53,6 +53,20 @@ LibraryContext* getLibraryContext(s32 lib_ctx_id) {
return lib_ctx;
}
s32 getMemoryPoolStats(s32 lib_ctx_id, OrbisNpWebApi2MemoryPoolStats* stats) {
LibraryContext* lib_ctx = getLibraryContext(lib_ctx_id);
if (!lib_ctx) {
LOG_ERROR(Lib_NpWebApi2, "No library context with id {:#x}", lib_ctx_id);
return ORBIS_NP_WEBAPI2_ERROR_LIB_CONTEXT_NOT_FOUND;
}
if (stats) {
memset(stats, 0, sizeof(*stats));
stats->pool_size = lib_ctx->GetPoolSize();
}
return ORBIS_OK;
}
s32 createUserContext(s32 lib_ctx_id, Libraries::UserService::OrbisUserServiceUserId user_id) {
LibraryContext* lib_ctx = getLibraryContext(lib_ctx_id);
if (!lib_ctx) {

View File

@ -5,6 +5,7 @@
namespace Libraries::Np::NpWebApi2 {
s32 createLibraryContext(s32 http_ctx_id, const char* name);
s32 createLibraryContext(s32 http_ctx_id, u64 pool_size, const char* name);
s32 getMemoryPoolStats(s32 lib_ctx_id, OrbisNpWebApi2MemoryPoolStats* stats);
s32 createUserContext(s32 lib_ctx_id, Libraries::UserService::OrbisUserServiceUserId user_id);
}; // namespace Libraries::Np::NpWebApi2