Minor cellSysutil improvements, cellNetCtl fixes

This commit is contained in:
Raul Tambre 2015-07-31 15:15:52 +03:00
parent c69dfff16e
commit 1012a3e312
3 changed files with 74 additions and 51 deletions

View File

@ -89,25 +89,20 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
if (code == CELL_NET_CTL_INFO_MTU) if (code == CELL_NET_CTL_INFO_MTU)
{ {
#ifdef _WIN32 #ifdef _WIN32
PIP_ADAPTER_ADDRESSES pAddresses; ULONG bufLen = sizeof(PIP_ADAPTER_ADDRESSES) + 1;
PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(bufLen);
DWORD ret; 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)
{
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) if (ret == ERROR_BUFFER_OVERFLOW)
{ {
cellNetCtl.Error("cellNetCtlGetInfo(INFO_MTU): GetAdaptersAddresses buffer overflow.");
free(pAddresses); free(pAddresses);
pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(bufLen);
} }
}
ret = GetAdaptersAddresses(AF_INET, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAddresses, &bufLen);
if (ret == NO_ERROR) if (ret == NO_ERROR)
{ {
@ -122,16 +117,18 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
} }
else else
{ {
cellNetCtl.Error("cellNetCtlGetInfo(INFO_MTU): Call to GetAdaptersAddresses failed."); cellNetCtl.Error("cellNetCtlGetInfo(INFO_MTU): Call to GetAdaptersAddresses failed. (%d)", ret);
info->mtu = 1490; // Seems to be the default value on Windows, generally. info->mtu = 1500; // Seems to be the default value on Windows 10.
} }
free(pAddresses);
#else #else
struct ifaddrs *ifaddr, *ifa; struct ifaddrs *ifaddr, *ifa;
int family, s, n; int family, n;
if (getifaddrs(&ifaddr) == -1) 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++) for (ifa = ifaddr, n = 0; ifa != nullptr; ifa = ifa->ifa_next, n++)
@ -174,16 +171,22 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
else if (code == CELL_NET_CTL_INFO_IP_ADDRESS) else if (code == CELL_NET_CTL_INFO_IP_ADDRESS)
{ {
#ifdef _WIN32 #ifdef _WIN32
PIP_ADAPTER_INFO pAdapterInfo; ULONG bufLen = sizeof(IP_ADAPTER_INFO) + 1;
pAdapterInfo = (IP_ADAPTER_INFO*)vm::alloc(sizeof(IP_ADAPTER_INFO), vm::main); PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)malloc(bufLen);
ULONG buflen = sizeof(IP_ADAPTER_INFO); 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); free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen);
} }
if (GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) ret = GetAdaptersInfo(pAdapterInfo, &bufLen);
if (ret == NO_ERROR)
{ {
PIP_ADAPTER_INFO pAdapter = pAdapterInfo; PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
@ -196,17 +199,19 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
} }
else 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 // 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"); strcpy_trunc(info->ip_address, "0.0.0.0");
} }
free(pAdapterInfo);
#else #else
struct ifaddrs *ifaddr, *ifa; struct ifaddrs *ifaddr, *ifa;
int family, s, n; int family, n;
if (getifaddrs(&ifaddr) == -1) 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++) for (ifa = ifaddr, n = 0; ifa != nullptr; ifa = ifa->ifa_next, n++)
@ -235,16 +240,22 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
else if (code == CELL_NET_CTL_INFO_NETMASK) else if (code == CELL_NET_CTL_INFO_NETMASK)
{ {
#ifdef _WIN32 #ifdef _WIN32
PIP_ADAPTER_INFO pAdapterInfo; ULONG bufLen = sizeof(IP_ADAPTER_INFO) + 1;
pAdapterInfo = (IP_ADAPTER_INFO*)vm::alloc(sizeof(IP_ADAPTER_INFO), vm::main); PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)malloc(bufLen);
ULONG buflen = sizeof(IP_ADAPTER_INFO); 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); free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO*)malloc(bufLen);
} }
if (GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) ret = GetAdaptersInfo(pAdapterInfo, &bufLen);
if (ret == NO_ERROR)
{ {
PIP_ADAPTER_INFO pAdapter = pAdapterInfo; PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
@ -260,21 +271,22 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
} }
else else
{ {
cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): Call to GetAdaptersInfo failed."); cellNetCtl.Error("cellNetCtlGetInfo(INFO_NETMASK): Call to GetAdaptersInfo failed. (%d)", ret);
// TODO: Is the default netmask default? // TODO: Is this the default netmask?
info->netmask[0] = 255; info->netmask[0] = 255;
info->netmask[1] = 255; info->netmask[1] = 255;
info->netmask[2] = 255; info->netmask[2] = 255;
info->netmask[3] = 0; info->netmask[3] = 0;
} }
free(pAdapterInfo);
#else #else
struct ifaddrs *ifaddr, *ifa; struct ifaddrs *ifaddr, *ifa;
int family, s, n; int family, n;
char host[NI_MAXHOST];
if (getifaddrs(&ifaddr) == -1) 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++) for (ifa = ifaddr, n = 0; ifa != nullptr; ifa = ifa->ifa_next, n++)

View File

@ -11,6 +11,8 @@
extern Module cellSysutil; extern Module cellSysutil;
std::unique_ptr<sysutil_t> g_sysutil;
const char* get_systemparam_id_name(s32 id) const char* get_systemparam_id_name(s32 id)
{ {
switch (id) switch (id)
@ -200,23 +202,20 @@ s32 cellSysutilUnregisterCallback(s32 slot)
return CELL_OK; return CELL_OK;
} }
struct CellSysCacheParam
{
char cacheId[CELL_SYSCACHE_ID_SIZE];
char getCachePath[CELL_SYSCACHE_PATH_MAX];
vm::ptr<void> reserved;
};
s32 cellSysCacheClear(void) s32 cellSysCacheClear(void)
{ {
cellSysutil.Todo("cellSysCacheClear()"); cellSysutil.Todo("cellSysCacheClear()");
//if some software expects CELL_SYSCACHE_ERROR_NOTMOUNTED we need to check whether if (g_sysutil->cacheMounted.exchange(false))
//it was mounted before, for that we would need to save the state which I don't know {
//where to put return CELL_SYSCACHE_ERROR_NOTMOUNTED;
}
std::string localPath; std::string localPath;
Emu.GetVFS().GetDevice(std::string("/dev_hdd1/cache/"), 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; return CELL_SYSCACHE_RET_OK_CLEARED;
} }
@ -224,7 +223,7 @@ s32 cellSysCacheMount(vm::ptr<CellSysCacheParam> param)
{ {
cellSysutil.Warning("cellSysCacheMount(param=*0x%x)", param); cellSysutil.Warning("cellSysCacheMount(param=*0x%x)", param);
//TODO: implement // TODO: implement
char id[CELL_SYSCACHE_ID_SIZE]; char id[CELL_SYSCACHE_ID_SIZE];
strncpy(id, param->cacheId, 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); strncpy(param->getCachePath, ("/dev_hdd1/cache/" + std::string(id) + "/").c_str(), CELL_SYSCACHE_PATH_MAX);
@ -278,7 +277,7 @@ s32 cellSysutilDisableBgmPlaybackEx(vm::ptr<CellSysutilBgmPlaybackExtraParam> pa
s32 cellSysutilGetBgmPlaybackStatus(vm::ptr<CellSysutilBgmPlaybackStatus> status) s32 cellSysutilGetBgmPlaybackStatus(vm::ptr<CellSysutilBgmPlaybackStatus> status)
{ {
cellSysutil.Log("cellSysutilGetBgmPlaybackStatus(status=*0x%x)", status); cellSysutil.Warning("cellSysutilGetBgmPlaybackStatus(status=*0x%x)", status);
// TODO // TODO
status->playerState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_STOP; status->playerState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_STOP;
@ -292,7 +291,7 @@ s32 cellSysutilGetBgmPlaybackStatus(vm::ptr<CellSysutilBgmPlaybackStatus> status
s32 cellSysutilGetBgmPlaybackStatus2(vm::ptr<CellSysutilBgmPlaybackStatus2> status2) s32 cellSysutilGetBgmPlaybackStatus2(vm::ptr<CellSysutilBgmPlaybackStatus2> status2)
{ {
cellSysutil.Log("cellSysutilGetBgmPlaybackStatus2(status2=*0x%x)", status2); cellSysutil.Warning("cellSysutilGetBgmPlaybackStatus2(status2=*0x%x)", status2);
// TODO // TODO
status2->playerState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_STOP; status2->playerState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_STOP;
@ -316,7 +315,6 @@ s32 cellSysutilPacketWrite()
throw EXCEPTION(""); throw EXCEPTION("");
} }
s32 cellSysutilGameDataAssignVmc() s32 cellSysutilGameDataAssignVmc()
{ {
throw EXCEPTION(""); throw EXCEPTION("");
@ -342,7 +340,6 @@ s32 cellSysutilGameReboot_I()
throw EXCEPTION(""); throw EXCEPTION("");
} }
extern void cellSysutil_SaveData_init(); extern void cellSysutil_SaveData_init();
extern void cellSysutil_GameData_init(); extern void cellSysutil_GameData_init();
extern void cellSysutil_MsgDialog_init(); extern void cellSysutil_MsgDialog_init();
@ -356,6 +353,8 @@ extern void cellSysutil_VideoOut_init();
Module cellSysutil("cellSysutil", []() Module cellSysutil("cellSysutil", []()
{ {
g_sysutil = std::make_unique<sysutil_t>();
for (auto& v : g_sys_callback) for (auto& v : g_sys_callback)
{ {
v.func.set(0); v.func.set(0);

View File

@ -189,3 +189,15 @@ struct CellSysutilBgmPlaybackExtraParam
be_t<s32> gameBgmFadeOutTime; be_t<s32> gameBgmFadeOutTime;
char reserved[8]; char reserved[8];
}; };
struct CellSysCacheParam
{
char cacheId[CELL_SYSCACHE_ID_SIZE];
char getCachePath[CELL_SYSCACHE_PATH_MAX];
vm::ptr<void> reserved;
};
struct sysutil_t
{
std::atomic<bool> cacheMounted{ false };
};