From 1012a3e312ecc930ef74af13ba4f6916e0d3edca Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Fri, 31 Jul 2015 15:15:52 +0300 Subject: [PATCH] Minor cellSysutil improvements, cellNetCtl fixes --- rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp | 84 ++++++++++++---------- rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp | 29 ++++---- rpcs3/Emu/SysCalls/Modules/cellSysutil.h | 12 ++++ 3 files changed, 74 insertions(+), 51 deletions(-) diff --git a/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp b/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp index c17033ab74..ba2960ca9f 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellNetCtl.cpp @@ -89,25 +89,20 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr info) if (code == CELL_NET_CTL_INFO_MTU) { #ifdef _WIN32 - PIP_ADAPTER_ADDRESSES pAddresses; + ULONG bufLen = sizeof(PIP_ADAPTER_ADDRESSES) + 1; + PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(bufLen); DWORD ret; - ULONG outBufLen = sizeof(PIP_ADAPTER_ADDRESSES); - pAddresses = (IP_ADAPTER_ADDRESSES*)vm::alloc(outBufLen, vm::main); + ret = GetAdaptersAddresses(AF_INET, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &bufLen); - if (pAddresses == nullptr) + if (ret == ERROR_BUFFER_OVERFLOW) { - cellNetCtl.Error("cellNetCtlGetInfo(INFO_MTU): pAddresses memory allocation failed."); - } - else - { - ret = GetAdaptersAddresses(AF_INET, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &outBufLen); - - if (ret == ERROR_BUFFER_OVERFLOW) - { - free(pAddresses); - } + cellNetCtl.Error("cellNetCtlGetInfo(INFO_MTU): GetAdaptersAddresses buffer overflow."); + free(pAddresses); + pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(bufLen); } + + ret = GetAdaptersAddresses(AF_INET, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &bufLen); if (ret == NO_ERROR) { @@ -122,16 +117,18 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr info) } else { - cellNetCtl.Error("cellNetCtlGetInfo(INFO_MTU): Call to GetAdaptersAddresses failed."); - info->mtu = 1490; // Seems to be the default value on Windows, generally. + cellNetCtl.Error("cellNetCtlGetInfo(INFO_MTU): Call to GetAdaptersAddresses failed. (%d)", ret); + info->mtu = 1500; // Seems to be the default value on Windows 10. } + + free(pAddresses); #else struct ifaddrs *ifaddr, *ifa; - int family, s, n; + int family, n; if (getifaddrs(&ifaddr) == -1) { - LOG_ERROR(HLE, "Call to getifaddrs returned negative."); + cellNetCtl.Error("cellNetCtlGetInfo(INFO_MTU): Call to getifaddrs returned negative."); } for (ifa = ifaddr, n = 0; ifa != nullptr; ifa = ifa->ifa_next, n++) @@ -174,16 +171,22 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr info) else if (code == CELL_NET_CTL_INFO_IP_ADDRESS) { #ifdef _WIN32 - PIP_ADAPTER_INFO pAdapterInfo; - pAdapterInfo = (IP_ADAPTER_INFO*)vm::alloc(sizeof(IP_ADAPTER_INFO), vm::main); - ULONG buflen = sizeof(IP_ADAPTER_INFO); + ULONG bufLen = sizeof(IP_ADAPTER_INFO) + 1; + PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)malloc(bufLen); + DWORD ret; - if (GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW) + ret = GetAdaptersInfo(pAdapterInfo, &bufLen); + + if (ret == ERROR_BUFFER_OVERFLOW) { + cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): GetAdaptersAddresses buffer overflow."); free(pAdapterInfo); + pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen); } + + ret = GetAdaptersInfo(pAdapterInfo, &bufLen); - if (GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) + if (ret == NO_ERROR) { PIP_ADAPTER_INFO pAdapter = pAdapterInfo; @@ -196,17 +199,19 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr info) } else { - cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): Call to GetAdaptersInfo failed."); + cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): Call to GetAdaptersInfo failed. (%d)", ret); // 0.0.0.0 seems to be the default address when no ethernet cables are connected to the PS3 strcpy_trunc(info->ip_address, "0.0.0.0"); } + + free(pAdapterInfo); #else struct ifaddrs *ifaddr, *ifa; - int family, s, n; + int family, n; if (getifaddrs(&ifaddr) == -1) { - LOG_ERROR(HLE, "Call to getifaddrs returned negative."); + cellNetCtl.Error("cellNetCtlGetInfo(IP_ADDRESS): Call to getifaddrs returned negative."); } for (ifa = ifaddr, n = 0; ifa != nullptr; ifa = ifa->ifa_next, n++) @@ -235,16 +240,22 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr info) else if (code == CELL_NET_CTL_INFO_NETMASK) { #ifdef _WIN32 - PIP_ADAPTER_INFO pAdapterInfo; - pAdapterInfo = (IP_ADAPTER_INFO*)vm::alloc(sizeof(IP_ADAPTER_INFO), vm::main); - ULONG buflen = sizeof(IP_ADAPTER_INFO); + ULONG bufLen = sizeof(IP_ADAPTER_INFO) + 1; + PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)malloc(bufLen); + DWORD ret; - if (GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW) + ret = GetAdaptersInfo(pAdapterInfo, &bufLen); + + if (ret == ERROR_BUFFER_OVERFLOW) { + cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): GetAdaptersAddresses buffer overflow."); free(pAdapterInfo); + pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen); } + + ret = GetAdaptersInfo(pAdapterInfo, &bufLen); - if (GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) + if (ret == NO_ERROR) { PIP_ADAPTER_INFO pAdapter = pAdapterInfo; @@ -260,21 +271,22 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr info) } else { - cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): Call to GetAdaptersInfo failed."); - // TODO: Is the default netmask default? + cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): Call to GetAdaptersInfo failed. (%d)", ret); + // TODO: Is this the default netmask? info->netmask[0] = 255; info->netmask[1] = 255; info->netmask[2] = 255; info->netmask[3] = 0; } + + free(pAdapterInfo); #else struct ifaddrs *ifaddr, *ifa; - int family, s, n; - char host[NI_MAXHOST]; + int family, n; if (getifaddrs(&ifaddr) == -1) { - LOG_ERROR(HLE, "Call to getifaddrs returned negative."); + cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): Call to getifaddrs returned negative."); } for (ifa = ifaddr, n = 0; ifa != nullptr; ifa = ifa->ifa_next, n++) diff --git a/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp index ea49057c69..1abe4cc66a 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp @@ -11,6 +11,8 @@ extern Module cellSysutil; +std::unique_ptr g_sysutil; + const char* get_systemparam_id_name(s32 id) { switch (id) @@ -200,23 +202,20 @@ s32 cellSysutilUnregisterCallback(s32 slot) return CELL_OK; } -struct CellSysCacheParam -{ - char cacheId[CELL_SYSCACHE_ID_SIZE]; - char getCachePath[CELL_SYSCACHE_PATH_MAX]; - vm::ptr reserved; -}; - s32 cellSysCacheClear(void) { cellSysutil.Todo("cellSysCacheClear()"); - //if some software expects CELL_SYSCACHE_ERROR_NOTMOUNTED we need to check whether - //it was mounted before, for that we would need to save the state which I don't know - //where to put + if (g_sysutil->cacheMounted.exchange(false)) + { + return CELL_SYSCACHE_ERROR_NOTMOUNTED; + } + std::string localPath; Emu.GetVFS().GetDevice(std::string("/dev_hdd1/cache/"), localPath); + // TODO: Delete everything in the cache folder, except the README + return CELL_SYSCACHE_RET_OK_CLEARED; } @@ -224,7 +223,7 @@ s32 cellSysCacheMount(vm::ptr param) { cellSysutil.Warning("cellSysCacheMount(param=*0x%x)", param); - //TODO: implement + // TODO: implement char id[CELL_SYSCACHE_ID_SIZE]; strncpy(id, param->cacheId, CELL_SYSCACHE_ID_SIZE); strncpy(param->getCachePath, ("/dev_hdd1/cache/" + std::string(id) + "/").c_str(), CELL_SYSCACHE_PATH_MAX); @@ -278,7 +277,7 @@ s32 cellSysutilDisableBgmPlaybackEx(vm::ptr pa s32 cellSysutilGetBgmPlaybackStatus(vm::ptr status) { - cellSysutil.Log("cellSysutilGetBgmPlaybackStatus(status=*0x%x)", status); + cellSysutil.Warning("cellSysutilGetBgmPlaybackStatus(status=*0x%x)", status); // TODO status->playerState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_STOP; @@ -292,7 +291,7 @@ s32 cellSysutilGetBgmPlaybackStatus(vm::ptr status s32 cellSysutilGetBgmPlaybackStatus2(vm::ptr status2) { - cellSysutil.Log("cellSysutilGetBgmPlaybackStatus2(status2=*0x%x)", status2); + cellSysutil.Warning("cellSysutilGetBgmPlaybackStatus2(status2=*0x%x)", status2); // TODO status2->playerState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_STOP; @@ -316,7 +315,6 @@ s32 cellSysutilPacketWrite() throw EXCEPTION(""); } - s32 cellSysutilGameDataAssignVmc() { throw EXCEPTION(""); @@ -342,7 +340,6 @@ s32 cellSysutilGameReboot_I() throw EXCEPTION(""); } - extern void cellSysutil_SaveData_init(); extern void cellSysutil_GameData_init(); extern void cellSysutil_MsgDialog_init(); @@ -356,6 +353,8 @@ extern void cellSysutil_VideoOut_init(); Module cellSysutil("cellSysutil", []() { + g_sysutil = std::make_unique(); + for (auto& v : g_sys_callback) { v.func.set(0); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSysutil.h b/rpcs3/Emu/SysCalls/Modules/cellSysutil.h index 385a0bef70..1018ba4d89 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysutil.h +++ b/rpcs3/Emu/SysCalls/Modules/cellSysutil.h @@ -189,3 +189,15 @@ struct CellSysutilBgmPlaybackExtraParam be_t gameBgmFadeOutTime; char reserved[8]; }; + +struct CellSysCacheParam +{ + char cacheId[CELL_SYSCACHE_ID_SIZE]; + char getCachePath[CELL_SYSCACHE_PATH_MAX]; + vm::ptr reserved; +}; + +struct sysutil_t +{ + std::atomic cacheMounted{ false }; +};