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)
{
#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<CellNetCtlInfo> 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<CellNetCtlInfo> 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<CellNetCtlInfo> 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<CellNetCtlInfo> 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<CellNetCtlInfo> 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++)

View File

@ -11,6 +11,8 @@
extern Module cellSysutil;
std::unique_ptr<sysutil_t> 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<void> 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<CellSysCacheParam> 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<CellSysutilBgmPlaybackExtraParam> pa
s32 cellSysutilGetBgmPlaybackStatus(vm::ptr<CellSysutilBgmPlaybackStatus> 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<CellSysutilBgmPlaybackStatus> status
s32 cellSysutilGetBgmPlaybackStatus2(vm::ptr<CellSysutilBgmPlaybackStatus2> 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<sysutil_t>();
for (auto& v : g_sys_callback)
{
v.func.set(0);

View File

@ -189,3 +189,15 @@ struct CellSysutilBgmPlaybackExtraParam
be_t<s32> gameBgmFadeOutTime;
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 };
};