Address code review: remove redundant static, overflow-safe UID, precise kubridge filename check

Agent-Logs-Url: https://github.com/Vita3K/Vita3K/sessions/ff797ac6-f582-4597-b0b8-7205bc71a270

Co-authored-by: frangarcj <399894+frangarcj@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-11 20:07:01 +00:00
committed by GitHub
parent 18d96261c0
commit 05d3f17fb0
4 changed files with 28 additions and 10 deletions
+1 -1
View File
@@ -488,7 +488,7 @@ static ExitCode load_app_impl(SceUID &main_module_id, EmuEnvState &emuenv) {
// Kernel plugins — only HLE-backed ones are meaningful.
for (const auto &plugin_path : tai_config.kernel_plugins) {
const bool is_kubridge = plugin_path.find("kubridge") != std::string::npos;
const bool is_kubridge = fs::path(plugin_path).filename() == "kubridge.skprx";
if (is_kubridge) {
LOG_INFO("Tai: kernel plugin '{}' is HLE-backed (kubridge), skipping real load", plugin_path);
} else {
+20 -5
View File
@@ -50,10 +50,25 @@ struct KuBridgeState {
Address abort_handler{};
// Maps a SceUID → base address of the reserved virtual memory region.
// These regions are created by kuKernelMemReserve and tracked so that
// kuKernelMemDecommit can locate and free sub-regions.
// These regions are created by kuKernelMemReserve / kuKernelAllocMemBlock
// and tracked so that kuKernelMemDecommit can locate and free sub-regions.
std::unordered_map<SceUID, Address> reserved_blocks;
SceUID next_reserved_uid{ 0x70000000 }; // synthetic UIDs for reserved blocks
// Synthetic UIDs are issued from a separate range well above what the
// kernel SysmemState counter will reach in practice. We use 32-bit
// arithmetic on SceUID (int32_t), so we detect near-wrap and saturate.
static constexpr SceUID ku_uid_base = 0x40000001;
SceUID next_reserved_uid{ ku_uid_base };
SceUID get_next_uid() {
const SceUID uid = next_reserved_uid;
// Advance, wrapping back to base on exhaustion (extremely unlikely).
if (next_reserved_uid < 0x7FFFFFFE)
++next_reserved_uid;
else
next_reserved_uid = ku_uid_base;
return uid;
}
};
LIBRARY_INIT(SceKuBridge) {
@@ -129,7 +144,7 @@ EXPORT(SceUID, kuKernelAllocMemBlock, const char *name, SceKernelMemBlockType ty
// Track the block in KuBridgeState so we can free it later.
const auto state = emuenv.kernel.obj_store.get<KuBridgeState>();
std::lock_guard<std::mutex> lock(state->mutex);
const SceUID uid = state->next_reserved_uid++;
const SceUID uid = state->get_next_uid();
state->reserved_blocks[uid] = base;
LOG_INFO("kuKernelAllocMemBlock: '{}' size={} base={:#010x} uid={}", name, size, base, uid);
@@ -260,7 +275,7 @@ EXPORT(SceUID, kuKernelMemReserve, Ptr<Ptr<void>> addr, SceSize size, SceKernelM
// Register in KuBridgeState.
const auto state = emuenv.kernel.obj_store.get<KuBridgeState>();
std::lock_guard<std::mutex> lock(state->mutex);
const SceUID uid = state->next_reserved_uid++;
const SceUID uid = state->get_next_uid();
state->reserved_blocks[uid] = base;
LOG_INFO("kuKernelMemReserve: size={} base={:#010x} uid={}", size, base, uid);
+5 -2
View File
@@ -551,8 +551,11 @@ EXPORT(SceUID, taiLoadStartKernelModule, const char *path, SceSize args, Ptr<con
if (path) {
const std::string_view path_view(path);
// kubridge.skprx is fully HLE-implemented as SceKuBridge.
// Return a synthetic module UID so the caller doesn't fail on the check.
if (path_view.find("kubridge") != std::string_view::npos) {
// Match only the exact filename to avoid false positives like
// "my_kubridge_proxy.skprx". Extract the part after the last '/' or ':'.
const auto sep = path_view.find_last_of("/:");
const std::string_view filename = (sep != std::string_view::npos) ? path_view.substr(sep + 1) : path_view;
if (filename == "kubridge.skprx") {
LOG_INFO("taiLoadStartKernelModule: '{}' is HLE-implemented, returning synthetic UID", path);
// Return a fixed synthetic UID in the positive kernel module range.
return 0x40000001;
+2 -2
View File
@@ -27,7 +27,7 @@ namespace tai {
namespace {
/// Trim leading and trailing whitespace (including CR) from a string.
static std::string trim(std::string s) {
std::string trim(std::string s) {
// Erase leading whitespace.
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char c) {
return !std::isspace(c);
@@ -42,7 +42,7 @@ static std::string trim(std::string s) {
/// Return true if the string looks like a Vita title ID.
/// Title IDs are exactly 9 characters: 4 uppercase letters + 5 digits
/// (e.g. "PCSX00000").
static bool is_title_id(const std::string &s) {
bool is_title_id(const std::string &s) {
if (s.size() != 9)
return false;
for (int i = 0; i < 4; ++i) {