feat(libs): report Http2, Ssl and Net memory pool statistics (#1119)

sceHttp2GetMemoryPoolStats, sceSslGetMemoryPoolStats and
sceNetGetMemoryPoolStats threw. PPSA16064 (Minecraft Dungeons II,
Unreal Engine) queries all three while its HTTP module starts, and
aborted there.

Each library now records the pool size given at sceHttp2Init,
sceSslInit or sceNetPoolCreate and reports it with a peak and current
use of 0: the offline Http2 and Ssl models and the host-socket Net
library allocate nothing from these pools. The layouts follow the PS4
SDK's *MemoryPoolStats structures. Net returns EBADF for an unknown
pool and EINVAL for a null output, like its other pool calls; Http2 and
Ssl throw for both, as their error codes are unknown. Terminating a
context or destroying a pool forgets its size.

sceHttp2SetResolveRetry, which the title calls next, accepts and
ignores its value like the other Http2 settings. The four Http2
WebSocket exports the title imports are added as unimplemented.

guest_http2, guest_ssl and guest_sce_net check the reported sizes;
guest_sce_net also checks the null-output and unknown-pool errors.
This commit is contained in:
Obi Newman
2026-10-09 09:03:06 +01:00
committed by GitHub
parent d3a926ad36
commit 881fb01069
7 changed files with 146 additions and 14 deletions
+51 -5
View File
@@ -5,13 +5,25 @@
#include "prx/libkernel/Equeue/Equeue.hpp"
#include <atomic>
#include <deque>
#include <map>
#include <mutex>
#include <stdexcept>
#include <unordered_map>
// No network is emulated: contexts, templates and requests can be created, but any request
// that would touch the network fails with the library's network error.
static constexpr int ERROR_NETWORK = static_cast<int>(0x80436063);
static std::atomic<int> g_nextHandle{1};
static std::mutex g_poolsMutex;
static std::map<int, size_t> g_pools;
struct Http2MemoryPoolStats {
size_t pool_size;
size_t max_inuse_size;
size_t current_inuse_size;
int32_t reserved;
};
static std::mutex g_completionsMutex;
static std::unordered_map<int, std::deque<Http2AsyncResult>> g_completions;
@@ -92,9 +104,11 @@ int APS5_VABI sceHttp2GetStatusCode(int req_id, int* status_code) {
int APS5_VABI sceHttp2Init(int libnet_mem_id, int libssl_ctx_id, size_t pool_size, int max_concurrent_request) {
(void)libnet_mem_id;
(void)libssl_ctx_id;
(void)pool_size;
(void)max_concurrent_request;
return g_nextHandle.fetch_add(1, std::memory_order_relaxed);
const int id = g_nextHandle.fetch_add(1, std::memory_order_relaxed);
std::lock_guard lock(g_poolsMutex);
g_pools[id] = pool_size;
return id;
}
int APS5_VABI sceHttp2ReadData(int req_id, void* data, size_t size) {
@@ -220,7 +234,8 @@ int APS5_VABI sceHttp2SetMinSslVersion(int id, uint32_t ssl_version) {
}
int APS5_VABI sceHttp2Term(int lib_http2_ctx_id) {
(void)lib_http2_ctx_id;
std::lock_guard lock(g_poolsMutex);
g_pools.erase(lib_http2_ctx_id);
return 0;
}
@@ -240,8 +255,12 @@ int APS5_VABI sceHttp2AbortRequest(int req_id) {
return 0;
}
int APS5_VABI sceHttp2GetMemoryPoolStats() {
NotImplemented_nid_no_patch(__func__);
int APS5_VABI sceHttp2GetMemoryPoolStats(int lib_http2_ctx_id, Http2MemoryPoolStats* stats) {
if (stats == nullptr) APS5_INVALID_ARG_EX;
std::lock_guard lock(g_poolsMutex);
const auto pool = g_pools.find(lib_http2_ctx_id);
if (pool == g_pools.end()) throw std::invalid_argument("sceHttp2GetMemoryPoolStats: unknown context");
*stats = {pool->second, 0, 0, 0};
return 0;
}
@@ -266,4 +285,31 @@ int APS5_VABI sceHttp2SetRequestNoContentLength(int id) {
return 0;
}
int APS5_VABI sceHttp2SetResolveRetry(int id, int32_t retry) {
(void)id;
(void)retry;
return 0;
}
int APS5_VABI sceHttp2WebSocketCreateRequest() {
NotImplemented_nid_no_patch(__func__);
return 0;
}
int APS5_VABI sceHttp2WebSocketCloseAsync() {
NotImplemented_nid_no_patch(__func__);
return 0;
}
int APS5_VABI sceHttp2WebSocketSendTextMessageAsync() {
NotImplemented_nid_no_patch(__func__);
return 0;
}
int APS5_VABI sceHttp2WebSocketSendDataMessageAsync() {
NotImplemented_nid_no_patch(__func__);
return 0;
}
}
+18 -4
View File
@@ -230,7 +230,13 @@ std::map<int, Sock> g_socks;
std::set<int> g_epolls;
std::map<int, std::map<int, NetEpollEvent>> g_epoll_socks;
std::set<int> g_epoll_aborted;
std::set<int> g_pools;
std::map<int, std::size_t> g_pools;
struct NetMemoryPoolStats {
std::size_t pool_size;
std::size_t max_inuse_size;
std::size_t current_inuse_size;
};
std::map<int, int> g_resolvers;
int g_next_sock = 32;
int g_next_epoll = 0x4000;
@@ -395,7 +401,7 @@ int APS5_VABI sceNetPoolCreate(const char* name, int size, int flags) {
}
std::lock_guard<std::mutex> lk(g_mutex);
const int id = g_next_pool++;
g_pools.insert(id);
g_pools.emplace(id, static_cast<std::size_t>(size));
return id;
}
@@ -848,8 +854,16 @@ int APS5_VABI sceNetEpollCreate(const char* name, int flags) {
return id;
}
int APS5_VABI sceNetGetMemoryPoolStats() {
NotImplemented_nid_no_patch(__func__);
int APS5_VABI sceNetGetMemoryPoolStats(int memid, NetMemoryPoolStats* stats) {
if (stats == nullptr) {
return fail(NET_EINVAL);
}
std::lock_guard<std::mutex> lk(g_mutex);
const auto pool = g_pools.find(memid);
if (pool == g_pools.end()) {
return fail(NET_EBADF);
}
*stats = {pool->second, 0, 0};
return 0;
}
+24 -5
View File
@@ -3,11 +3,16 @@
#include "SceTypes.hpp"
#include "prx/libc/include/General.hpp"
#include <atomic>
#include <map>
#include <mutex>
#include <stdexcept>
// No network is emulated: contexts, templates and requests can be created, but any request
// that would touch the network fails with the library's network error.
static constexpr int ERROR_NETWORK = static_cast<int>(0x80435001);
static std::atomic<int> g_nextHandle{1};
static std::mutex g_poolsMutex;
static std::map<int, uint64_t> g_pools;
namespace {
@@ -19,6 +24,13 @@ struct SslData {
size_t size;
};
struct SslMemoryPoolStats {
size_t pool_size;
size_t max_inuse_size;
size_t current_inuse_size;
int32_t reserved;
};
struct SslCaCerts {
SslData* certs;
size_t num;
@@ -44,12 +56,15 @@ int APS5_VABI sceSslGetCaCerts(int ssl_ctx_id, void* ca_certs) {
}
int APS5_VABI sceSslInit_nid_postfix(uint64_t pool_size) {
(void)pool_size;
return g_nextHandle.fetch_add(1, std::memory_order_relaxed);
const int id = g_nextHandle.fetch_add(1, std::memory_order_relaxed);
std::lock_guard lock(g_poolsMutex);
g_pools[id] = pool_size;
return id;
}
int APS5_VABI sceSslTerm_nid_postfix(int ssl_ctx_id) {
(void)ssl_ctx_id;
std::lock_guard lock(g_poolsMutex);
g_pools.erase(ssl_ctx_id);
return 0;
}
@@ -68,8 +83,12 @@ int APS5_VABI sceSslLoadCert() {
return 0;
}
int APS5_VABI sceSslGetMemoryPoolStats() {
NotImplemented_nid_no_patch(__func__);
int APS5_VABI sceSslGetMemoryPoolStats(int ssl_ctx_id, SslMemoryPoolStats* stats) {
if (stats == nullptr) APS5_INVALID_ARG_EX;
std::lock_guard lock(g_poolsMutex);
const auto pool = g_pools.find(ssl_ctx_id);
if (pool == g_pools.end()) throw std::invalid_argument("sceSslGetMemoryPoolStats: unknown context");
*stats = {static_cast<size_t>(pool->second), 0, 0, 0};
return 0;
}
+16
View File
@@ -25,6 +25,18 @@ uintptr_t APS5_VABI sceKernelGetEventId(const KernelEvent* ev);
void* APS5_VABI sceKernelGetEventUserData(const KernelEvent* ev);
}
struct Http2MemoryPoolStats {
std::size_t pool_size;
std::size_t max_inuse_size;
std::size_t current_inuse_size;
std::int32_t reserved;
};
extern "C" {
int APS5_VABI sceHttp2GetMemoryPoolStats(int, Http2MemoryPoolStats*);
int APS5_VABI sceHttp2SetResolveRetry(int, std::int32_t);
}
static void Require(bool value) { if (!value) std::abort(); }
template <typename TCall>
@@ -40,11 +52,15 @@ static bool Throws(TCall call) {
int main() {
const int context = sceHttp2Init(1, 1, 0x10000, 4);
Require(context > 0);
Http2MemoryPoolStats stats{1, 1, 1, 1};
Require(sceHttp2GetMemoryPoolStats(context, &stats) == 0);
Require(stats.pool_size == 0x10000 && stats.max_inuse_size == 0 && stats.current_inuse_size == 0 && stats.reserved == 0);
const int box = sceHttp2CreateCookieBox(context);
const int other = sceHttp2CreateCookieBox(context);
Require(box > 0 && other > 0 && box != other && box != context);
const int tmpl = sceHttp2CreateTemplate(context, "agent", 2, 0);
Require(tmpl > 0 && tmpl != box && tmpl != other);
Require(sceHttp2SetResolveRetry(tmpl, 3) == 0);
Require(sceHttp2SetCookieBox(tmpl, box) == 0);
Require(sceHttp2SetCookieBox(tmpl, 0) == 0);
const int request = sceHttp2CreateRequestWithURL(tmpl, "POST", "https://example.com/", 16);
+21
View File
@@ -59,9 +59,18 @@ struct NetMsghdr {
int flags;
};
struct NetMemoryPoolStats {
std::size_t pool_size;
std::size_t max_inuse_size;
std::size_t current_inuse_size;
};
extern "C" {
std::int64_t APS5_VABI sceNetSendmsg(int, const NetMsghdr*, int);
std::int64_t APS5_VABI sceNetRecvmsg(int, NetMsghdr*, int);
int APS5_VABI sceNetPoolCreate(const char*, int, int);
int APS5_VABI sceNetPoolDestroy(int);
int APS5_VABI sceNetGetMemoryPoolStats(int, NetMemoryPoolStats*);
}
static void Require(bool condition) {
@@ -72,6 +81,17 @@ static bool Failed(std::int64_t result, int error) {
return result == static_cast<int>(0x80410100u | static_cast<unsigned>(error)) && *sceNetErrnoLoc() == error;
}
static void CheckPoolStats() {
const int pool = sceNetPoolCreate("stats", 0x4000, 0);
Require(pool > 0);
NetMemoryPoolStats stats{1, 1, 1};
Require(sceNetGetMemoryPoolStats(pool, &stats) == 0);
Require(stats.pool_size == 0x4000 && stats.max_inuse_size == 0 && stats.current_inuse_size == 0);
Require(Failed(sceNetGetMemoryPoolStats(pool, nullptr), 22));
Require(sceNetPoolDestroy(pool) == 0);
Require(Failed(sceNetGetMemoryPoolStats(pool, &stats), 9));
}
static void CheckMessages(int receiver, int sender, const std::array<std::uint8_t, 16>& address) {
char head[] = "scatter ";
char tail[] = "gather";
@@ -189,6 +209,7 @@ int main() {
Require(in6addr_loopback_nid_postfix[i] == (i == 15 ? 1 : 0));
}
Require(sceNetInit_nid_postfix() == 0);
CheckPoolStats();
CheckAddressText(2, "127.0.0.1");
CheckAddressText(2, "255.255.255.255");
CheckAddressText(28, "::1");
+13
View File
@@ -1,5 +1,6 @@
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstddef>
#include <cstdint>
#include <cstdlib>
extern "C" {
@@ -8,6 +9,15 @@ int APS5_VABI sceSslGetCaCerts(int, void*);
int APS5_VABI sceSslFreeCaCerts(int, void*);
}
struct SslMemoryPoolStats {
std::size_t pool_size;
std::size_t max_inuse_size;
std::size_t current_inuse_size;
std::int32_t reserved;
};
extern "C" int APS5_VABI sceSslGetMemoryPoolStats(int, SslMemoryPoolStats*);
static void Require(bool value) { if (!value) std::abort(); }
struct SslCaCerts {
@@ -23,6 +33,9 @@ int main() {
const int context = sceSslInit_nid_postfix(0x10000);
Require(context > 0);
SslMemoryPoolStats stats{1, 1, 1, 1};
Require(sceSslGetMemoryPoolStats(context, &stats) == 0);
Require(stats.pool_size == 0x10000 && stats.max_inuse_size == 0 && stats.current_inuse_size == 0 && stats.reserved == 0);
Require(sceSslGetCaCerts(context, nullptr) == invalidArg);
Require(sceSslFreeCaCerts(context, nullptr) == invalidArg);
+3
View File
@@ -157,6 +157,9 @@ Throughout the project, every function at every stage either **does exactly what
- [scePadSetAngularVelocityBiasCorrectionState](../../core/libs/prx/libScePad/Export.cpp) (libScePad) - imported by PPSA16064 and not called during its start-up; unknown signature
- [sceKernelGetOperationMode](../../core/libs/prx/libkernel/System/src/Process.cpp) (libkernel) - the signature `(int* mode, int* submode)` comes from PPSA12544, which logs both values after the call; the values are unknown and 0 is reported for both, as in the [prosper](https://github.com/mattias800/prosper/pull/4153) reimplementation. Null outputs throw
- Font, Http2, Net, Ssl, SystemService and libkernel exports imported by PPSA12544 and added without an implementation have unknown signatures
- [sceHttp2GetMemoryPoolStats, sceSslGetMemoryPoolStats, sceNetGetMemoryPoolStats](../../core/libs/prx/libSceNet/Export.cpp) (libSceHttp2, libSceSsl, libSceNet) - signatures `(int id, stats*)` and the statistics layouts (pool size, peak and current use, and for Http2 and Ssl a 32-bit reserved field) follow the PS4 SDK's `SceHttp2MemoryPoolStats`, `SceSslMemoryPoolStats` and `SceNetMemoryPoolStats`, not confirmed for the PS5. The pool size is the one given at init or pool creation; nothing is allocated from these pools, so the peak and current use are 0. Net returns `EBADF` for an unknown pool and `EINVAL` for a null output, as its other pool calls do; for Http2 and Ssl the error codes are unknown, so both cases throw
- [sceHttp2SetResolveRetry](../../core/libs/prx/libSceHttp2/Export.cpp) (libSceHttp2) - signature `(int id, int32_t retry)` from libSceHttp's `sceHttpSetResolveRetry`; the value is accepted and ignored like the other Http2 settings, since no request reaches the network
- [sceHttp2WebSocketCreateRequest, sceHttp2WebSocketCloseAsync, sceHttp2WebSocketSendTextMessageAsync, sceHttp2WebSocketSendDataMessageAsync](../../core/libs/prx/libSceHttp2/Export.cpp) (libSceHttp2) - imported by PPSA16064 and not called during its start-up; unknown signatures
- [libSceVrSetupDialog](../../core/libs/prx/libSceVrSetupDialog/Export.cpp), and the Share, NpTrophy2, NpEntitlementAccess and WebBrowserDialog exports imported by PPSA12544's Unity plugins and added without an implementation, have unknown signatures
- [sceAjmDecWVorbisCreateHeaderPacket, sceAjmDecWVorbisCreateSetupPacket](../../core/libs/prx/libSceAjm.native/Export.cpp) (libSceAjmWVorbis, implemented in libSceAjm.native) - unknown signatures
- Acm, GameLiveStreaming, Net, NpEntitlementAccess, NpManager, NpWebApi2, VoiceQoS, WebBrowserDialog and libkernel exports imported by PPSA14632 and added without an implementation are declared without parameters