1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-26 04:32:35 +01:00

More defect fixes, added some error codes

This commit is contained in:
Raul Tambre 2015-10-23 17:42:34 +03:00
parent fac9d74344
commit 9c2f48cd1d
9 changed files with 190 additions and 84 deletions

View File

@ -16,10 +16,20 @@ namespace memory_helper
void* reserve_memory(size_t size) void* reserve_memory(size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
return VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS); void* ret = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
if (ret == NULL)
{
LOG_ERROR(HLE, "reserve_memory VirtualAlloc failed.");
return (void*)VM_FAILURE;
}
#else #else
return mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); void* ret = mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (ret == (void*)VM_FAILURE)
{
LOG_ERROR(HLE, "reserve_memory mmap failed.");
}
#endif #endif
return ret;
} }
s32 commit_page_memory(void* pointer, size_t page_size) s32 commit_page_memory(void* pointer, size_t page_size)
@ -28,25 +38,34 @@ namespace memory_helper
if (VirtualAlloc((u8*)pointer, page_size, MEM_COMMIT, PAGE_READWRITE) == NULL) if (VirtualAlloc((u8*)pointer, page_size, MEM_COMMIT, PAGE_READWRITE) == NULL)
{ {
LOG_ERROR(HLE, "commit_page_memory VirtualAlloc failed."); LOG_ERROR(HLE, "commit_page_memory VirtualAlloc failed.");
return -1; return VM_FAILURE;
} }
#else #else
s32 ret = mprotect((u8*)pointer, page_size, PROT_READ | PROT_WRITE) s32 ret = mprotect((u8*)pointer, page_size, PROT_READ | PROT_WRITE);
if (ret < 0) if (ret < VM_SUCCESS)
{ {
LOG_ERROR(HLE, "commit_page_memory mprotect failed. (%d)", ret); LOG_ERROR(HLE, "commit_page_memory mprotect failed. (%d)", ret);
return -1; return VM_FAILURE;
} }
#endif #endif
return 0; return VM_SUCCESS;
} }
void free_reserved_memory(void* pointer, size_t size) s32 free_reserved_memory(void* pointer, size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
VirtualFree(pointer, 0, MEM_RELEASE); if (VirtualFree(pointer, 0, MEM_RELEASE) == 0)
{
LOG_ERROR(HLE, "free_reserved_memory VirtualFree failed.");
return VM_FAILURE;
}
#else #else
munmap(pointer, size); if (munmap(pointer, size) != VM_SUCCESS)
{
LOG_ERROR(HLE, "free_reserved_memory munmap failed.");
return VM_FAILURE;
}
#endif #endif
return VM_SUCCESS;
} }
} }

View File

@ -1,10 +1,20 @@
#pragma once #pragma once
// Failure codes for the functions
enum
{
VM_SUCCESS = 0,
VM_FAILURE = -1,
};
namespace memory_helper namespace memory_helper
{ {
/** /**
* Reserve size bytes of virtual memory and returns it. * Reserve size bytes of virtual memory and returns it.
* The memory should be commited before usage. * The memory should be commited before usage.
*
* Returns the base address of the allocated region of pages, if successful.
* Returns (void*)VM_FAILURE, if unsuccessful.
*/ */
void* reserve_memory(size_t size); void* reserve_memory(size_t size);
@ -13,13 +23,16 @@ namespace memory_helper
* That is, bake reserved memory with physical memory. * That is, bake reserved memory with physical memory.
* pointer should belong to a range of reserved memory. * pointer should belong to a range of reserved memory.
* *
* Returns 0, if was successful. * Returns VM_SUCCESS, if successful.
* Returns -1, if was unsuccessful. * Returns VM_FAILURE, if unsuccessful.
*/ */
s32 commit_page_memory(void* pointer, size_t page_size); s32 commit_page_memory(void* pointer, size_t page_size);
/** /**
* Free memory alloced via reserve_memory. * Free memory alloced via reserve_memory.
*
* Returns VM_SUCCESS, if successful.
* Returns VM_FAILURE, if unsuccessful.
*/ */
void free_reserved_memory(void* pointer, size_t size); s32 free_reserved_memory(void* pointer, size_t size);
} }

View File

@ -57,7 +57,7 @@ std::string rPlatform::getConfigDir()
dir = "./config"; dir = "./config";
dir = dir + "/rpcs3/"; dir = dir + "/rpcs3/";
s32 ret = mkdir(dir.c_str(), 0777) s32 ret = mkdir(dir.c_str(), 0777);
if (ret == EEXIST) if (ret == EEXIST)
{ {
LOG_WARNING(HLE, "Configuration directory already exists. (%s)", dir); LOG_WARNING(HLE, "Configuration directory already exists. (%s)", dir);

View File

@ -164,15 +164,19 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
unsigned char empty_iv[0x10] = {}; unsigned char empty_iv[0x10] = {};
// Decrypt the metadata. // Decrypt the metadata.
int i; for (int i = 0; i < block_num; i++)
for (i = 0; i < block_num; i++)
{ {
memset(hash_result, 0, 0x14); memset(hash_result, 0, 0x14);
if ((edat->flags & EDAT_COMPRESSED_FLAG) != 0) if ((edat->flags & EDAT_COMPRESSED_FLAG) != 0)
{ {
metadata_sec_offset = metadata_offset + (unsigned long long) i * metadata_section_size; metadata_sec_offset = metadata_offset + (unsigned long long) i * metadata_section_size;
in->seek(metadata_sec_offset);
if (in->seek(metadata_sec_offset) < 0)
{
LOG_ERROR(LOADER, "EDAT: Seeking medata section offset at %u failed.", metadata_sec_offset);
return 1;
}
unsigned char metadata[0x20]; unsigned char metadata[0x20];
memset(metadata, 0, 0x20); memset(metadata, 0, 0x20);
@ -244,7 +248,12 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
memset(hash, 0, 0x10); memset(hash, 0, 0x10);
memset(key_result, 0, 0x10); memset(key_result, 0, 0x10);
in->seek(offset); if (in->seek(offset) < 0)
{
LOG_ERROR(LOADER, "EDAT: Seeking offset at %u failed.", offset);
return 1;
}
in->read(enc_data, length); in->read(enc_data, length);
// Generate a key for the current block. // Generate a key for the current block.

View File

@ -890,8 +890,9 @@ bool SELFDecrypter::DecryptNPDRM(u8 *metadata, u32 metadata_size)
memcpy(klicensee_key, key_v.GetKlicenseeKey(), 0x10); memcpy(klicensee_key, key_v.GetKlicenseeKey(), 0x10);
// Use klicensee if available. // Use klicensee if available.
if (memcmp(klicensee_key, key_v.GetKlicenseeKey(), 0x10) != 0) // FIXME: Check is always false.
memcpy(npdrm_key, klicensee_key, 0x10); /*if (klicensee_key != NULL)
memcpy(npdrm_key, klicensee_key, 0x10);*/
if (ctrl->npdrm.license == 1) // Network license. if (ctrl->npdrm.license == 1) // Network license.
{ {

View File

@ -48,15 +48,15 @@ s32 vfsHDDManager::CreateHDD(const std::string& path, u64 size, u64 block_size)
u8 null = 0; u8 null = 0;
if (f.seek(hdr.block_count * hdr.block_size - sizeof(null)) < 0) if (f.seek(hdr.block_count * hdr.block_size - sizeof(null)) < HDD_OK)
{ {
LOG_ERROR(HLE, "CreateHDD seek to %u failed.", hdr.block_count * hdr.block_size - sizeof(null)); LOG_ERROR(HLE, "CreateHDD seek to %u failed.", hdr.block_count * hdr.block_size - sizeof(null));
return -1; return HDD_SEEK_FAILURE;
} }
f.write(&null, sizeof(null)); f.write(&null, sizeof(null));
return 0; return HDD_OK;
} }
void vfsHDDManager::Format() void vfsHDDManager::Format()
@ -76,17 +76,27 @@ bool vfsHDDFile::goto_block(u64 n)
return false; return false;
} }
m_hdd.Seek(m_info.data_block * m_hdd_info.block_size); if (m_hdd.Seek(m_info.data_block * m_hdd_info.block_size) < HDD_OK)
{
LOG_ERROR(HLE, "goto_block seek to %u failed.", m_info.data_block * m_hdd_info.block_size);
return false;
}
block_info.next_block = m_info.data_block; block_info.next_block = m_info.data_block;
for (u64 i = 0; i<n; ++i) for (u64 i = 0; i < n; ++i)
{ {
if (!block_info.next_block || !block_info.is_used || block_info.next_block >= m_hdd_info.block_count) if (!block_info.next_block || !block_info.is_used || block_info.next_block >= m_hdd_info.block_count)
{ {
return false; return false;
} }
m_hdd.Seek(block_info.next_block * m_hdd_info.block_size); if (m_hdd.Seek(block_info.next_block * m_hdd_info.block_size) < HDD_OK)
{
LOG_ERROR(HLE, "goto_block seek to %u failed.", block_info.next_block * m_hdd_info.block_size);
return false;
}
m_hdd.Read(&block_info, sizeof(vfsHDD_Block)); m_hdd.Read(&block_info, sizeof(vfsHDD_Block));
} }
@ -109,97 +119,97 @@ void vfsHDDFile::RemoveBlocks(u64 start_block)
s32 vfsHDDFile::WriteBlock(u64 block, const vfsHDD_Block& data) s32 vfsHDDFile::WriteBlock(u64 block, const vfsHDD_Block& data)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "WriteBlock seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "WriteBlock seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd.Write(&data, sizeof(vfsHDD_Block)); m_hdd.Write(&data, sizeof(vfsHDD_Block));
return 0; return HDD_OK;
} }
s32 vfsHDDFile::ReadBlock(u64 block, vfsHDD_Block& data) s32 vfsHDDFile::ReadBlock(u64 block, vfsHDD_Block& data)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "ReadBlock seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "ReadBlock seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd.Read(&data, sizeof(vfsHDD_Block)); m_hdd.Read(&data, sizeof(vfsHDD_Block));
return 0; return HDD_OK;
} }
s32 vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data) s32 vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd.Write(&data, sizeof(vfsHDD_Entry)); m_hdd.Write(&data, sizeof(vfsHDD_Entry));
return 0; return HDD_OK;
} }
s32 vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data) s32 vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd.Read(&data, sizeof(vfsHDD_Entry)); m_hdd.Read(&data, sizeof(vfsHDD_Entry));
return 0; return HDD_OK;
} }
s32 vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name) s32 vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd.Read(&data, sizeof(vfsHDD_Entry)); m_hdd.Read(&data, sizeof(vfsHDD_Entry));
name.resize(GetMaxNameLen()); name.resize(GetMaxNameLen());
m_hdd.Read(&name.front(), GetMaxNameLen()); m_hdd.Read(&name.front(), GetMaxNameLen());
return 0; return HDD_OK;
} }
s32 vfsHDDFile::ReadEntry(u64 block, std::string& name) s32 vfsHDDFile::ReadEntry(u64 block, std::string& name)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) < 0) if (m_hdd.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) < HDD_OK)
{ {
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)); LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size + sizeof(vfsHDD_Entry));
return -1; return HDD_SEEK_FAILURE;
} }
name.resize(GetMaxNameLen()); name.resize(GetMaxNameLen());
m_hdd.Read(&name.front(), GetMaxNameLen()); m_hdd.Read(&name.front(), GetMaxNameLen());
return 0; return HDD_OK;
} }
s32 vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name) s32 vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name)
{ {
if (m_hdd.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd.Write(&data, sizeof(vfsHDD_Entry)); m_hdd.Write(&data, sizeof(vfsHDD_Entry));
m_hdd.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1)); m_hdd.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1));
return 0; return HDD_OK;
} }
void vfsHDDFile::Open(u64 info_block) void vfsHDDFile::Open(u64 info_block)
@ -214,7 +224,7 @@ u64 vfsHDDFile::FindFreeBlock()
{ {
vfsHDD_Block block_info; vfsHDD_Block block_info;
for (u64 i = 0; i<m_hdd_info.block_count; ++i) for (u64 i = 0; i < m_hdd_info.block_count; ++i)
{ {
ReadBlock(i, block_info); ReadBlock(i, block_info);
@ -238,10 +248,19 @@ bool vfsHDDFile::Seek(u64 pos)
return true; return true;
} }
void vfsHDDFile::SaveInfo() s32 vfsHDDFile::SaveInfo()
{ {
m_hdd.Seek(m_info_block * m_hdd_info.block_size); m_hdd.Seek(m_info_block * m_hdd_info.block_size);
if (m_hdd.Seek(m_info_block * m_hdd_info.block_size) < HDD_OK)
{
LOG_ERROR(HLE, "SaveInfo seek to %u failed.", m_info_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Write(&m_info, sizeof(vfsHDD_Entry)); m_hdd.Write(&m_info, sizeof(vfsHDD_Entry));
return HDD_OK;
} }
u64 vfsHDDFile::Read(void* dst, u64 size) u64 vfsHDDFile::Read(void* dst, u64 size)
@ -255,9 +274,21 @@ u64 vfsHDDFile::Read(void* dst, u64 size)
u64 rsize = std::min<u64>(block_size - m_position, size); u64 rsize = std::min<u64>(block_size - m_position, size);
vfsHDD_Block cur_block_info; vfsHDD_Block cur_block_info;
m_hdd.Seek(m_cur_block * m_hdd_info.block_size);
if (m_hdd.Seek(m_cur_block * m_hdd_info.block_size) < HDD_OK)
{
LOG_ERROR(HLE, "Read seek to %u failed.", m_cur_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block)); m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block));
m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block)+m_position);
if (m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position) < HDD_OK)
{
LOG_ERROR(HLE, "Read seek to %u failed.", m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position);
return HDD_SEEK_FAILURE;
}
m_hdd.Read(dst, rsize); m_hdd.Read(dst, rsize);
size -= rsize; size -= rsize;
m_position += rsize; m_position += rsize;
@ -278,7 +309,12 @@ u64 vfsHDDFile::Read(void* dst, u64 size)
m_cur_block = cur_block_info.next_block; m_cur_block = cur_block_info.next_block;
rsize = std::min<u64>(block_size, size); rsize = std::min<u64>(block_size, size);
m_hdd.Seek(cur_block_info.next_block * m_hdd_info.block_size); if (m_hdd.Seek(cur_block_info.next_block * m_hdd_info.block_size) < HDD_OK)
{
LOG_ERROR(HLE, "Read seek to %u failed.", cur_block_info.next_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block)); m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block));
if (m_hdd.Read((u8*)dst + offset, rsize) != rsize) if (m_hdd.Read((u8*)dst + offset, rsize) != rsize)
@ -329,7 +365,12 @@ u64 vfsHDDFile::Write(const void* src, u64 size)
if (wsize) if (wsize)
{ {
m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block)+m_position); if (m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position) < HDD_OK)
{
LOG_ERROR(HLE, "Write seek to %u failed.", m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position);
return HDD_SEEK_FAILURE;
}
m_hdd.Write(src, wsize); m_hdd.Write(src, wsize);
size -= wsize; size -= wsize;
m_info.size += wsize; m_info.size += wsize;
@ -359,7 +400,13 @@ u64 vfsHDDFile::Write(const void* src, u64 size)
wsize = std::min<u64>(block_size, size); wsize = std::min<u64>(block_size, size);
block_info.next_block = m_cur_block; block_info.next_block = m_cur_block;
m_hdd.Seek(last_block * m_hdd_info.block_size);
if (m_hdd.Seek(last_block * m_hdd_info.block_size) < HDD_OK)
{
LOG_ERROR(HLE, "Write seek to %u failed.", last_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block)) if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block))
{ {
m_position = 0; m_position = 0;
@ -368,13 +415,20 @@ u64 vfsHDDFile::Write(const void* src, u64 size)
} }
block_info.next_block = 0; block_info.next_block = 0;
m_hdd.Seek(m_cur_block * m_hdd_info.block_size);
if (m_hdd.Seek(m_cur_block * m_hdd_info.block_size) < HDD_OK)
{
LOG_ERROR(HLE, "Write seek to %u failed.", m_cur_block * m_hdd_info.block_size);
return HDD_SEEK_FAILURE;
}
if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block)) if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block))
{ {
m_position = 0; m_position = 0;
SaveInfo(); SaveInfo();
return offset; return offset;
} }
if ((m_position = m_hdd.Write((u8*)src + offset, wsize)) != wsize) if ((m_position = m_hdd.Write((u8*)src + offset, wsize)) != wsize)
{ {
m_info.size += wsize; m_info.size += wsize;
@ -419,7 +473,7 @@ vfsHDD::vfsHDD(vfsDevice* device, const std::string& hdd_path)
m_hdd_info.block_size = 2048; m_hdd_info.block_size = 2048;
} }
if (m_hdd_file.Seek(m_cur_dir_block * m_hdd_info.block_size) < 0) if (m_hdd_file.Seek(m_cur_dir_block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "vfsHDD initialization seek to %u failed.", m_cur_dir_block * m_hdd_info.block_size); LOG_ERROR(HLE, "vfsHDD initialization seek to %u failed.", m_cur_dir_block * m_hdd_info.block_size);
return; return;
@ -462,13 +516,13 @@ s32 vfsHDD::OpenDir(const std::string& name)
if (!SearchEntry(name, entry_block)) if (!SearchEntry(name, entry_block))
{ {
LOG_ERROR(HLE, "OpenDir could not find the entry. (%s)", name); LOG_ERROR(HLE, "OpenDir could not find the entry. (%s)", name);
return -1; return HDD_ENTRY_NOT_FOUND;
} }
if (m_hdd_file.Seek(entry_block * m_hdd_info.block_size) < 0) if (m_hdd_file.Seek(entry_block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "OpenDir seek to %u failed.", entry_block * m_hdd_info.block_size); LOG_ERROR(HLE, "OpenDir seek to %u failed.", entry_block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
vfsHDD_Entry entry; vfsHDD_Entry entry;
@ -479,7 +533,7 @@ s32 vfsHDD::OpenDir(const std::string& name)
m_cur_dir_block = entry.data_block; m_cur_dir_block = entry.data_block;
ReadEntry(m_cur_dir_block, m_cur_dir); ReadEntry(m_cur_dir_block, m_cur_dir);
return 0; return HDD_OK;
} }
bool vfsHDD::Rename(const std::string& from, const std::string& to) bool vfsHDD::Rename(const std::string& from, const std::string& to)
@ -501,7 +555,7 @@ u64 vfsHDD::FindFreeBlock()
{ {
vfsHDD_Block block_info; vfsHDD_Block block_info;
for (u64 i = 0; i<m_hdd_info.block_count; ++i) for (u64 i = 0; i < m_hdd_info.block_count; ++i)
{ {
ReadBlock(i, block_info); ReadBlock(i, block_info);
@ -516,97 +570,97 @@ u64 vfsHDD::FindFreeBlock()
s32 vfsHDD::WriteBlock(u64 block, const vfsHDD_Block& data) s32 vfsHDD::WriteBlock(u64 block, const vfsHDD_Block& data)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "WriteBlock seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "WriteBlock seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd_file.Write(&data, sizeof(vfsHDD_Block)); m_hdd_file.Write(&data, sizeof(vfsHDD_Block));
return 0; return HDD_OK;
} }
s32 vfsHDD::ReadBlock(u64 block, vfsHDD_Block& data) s32 vfsHDD::ReadBlock(u64 block, vfsHDD_Block& data)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "ReadBlock seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "ReadBlock seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd_file.Read(&data, sizeof(vfsHDD_Block)); m_hdd_file.Read(&data, sizeof(vfsHDD_Block));
return 0; return HDD_OK;
} }
s32 vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data) s32 vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd_file.Write(&data, sizeof(vfsHDD_Entry)); m_hdd_file.Write(&data, sizeof(vfsHDD_Entry));
return 0; return HDD_OK;
} }
s32 vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data) s32 vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd_file.Read(&data, sizeof(vfsHDD_Entry)); m_hdd_file.Read(&data, sizeof(vfsHDD_Entry));
return 0; return HDD_OK;
} }
s32 vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name) s32 vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd_file.Read(&data, sizeof(vfsHDD_Entry)); m_hdd_file.Read(&data, sizeof(vfsHDD_Entry));
name.resize(GetMaxNameLen()); name.resize(GetMaxNameLen());
m_hdd_file.Read(&name.front(), GetMaxNameLen()); m_hdd_file.Read(&name.front(), GetMaxNameLen());
return 0; return HDD_OK;
} }
s32 vfsHDD::ReadEntry(u64 block, std::string& name) s32 vfsHDD::ReadEntry(u64 block, std::string& name)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) < 0) if (m_hdd_file.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) < HDD_OK)
{ {
LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)); LOG_ERROR(HLE, "ReadEntry seek to %u failed.", block * m_hdd_info.block_size + sizeof(vfsHDD_Entry));
return -1; return HDD_SEEK_FAILURE;
} }
name.resize(GetMaxNameLen()); name.resize(GetMaxNameLen());
m_hdd_file.Read(&name.front(), GetMaxNameLen()); m_hdd_file.Read(&name.front(), GetMaxNameLen());
return 0; return HDD_OK;
} }
s32 vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name) s32 vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name)
{ {
if (m_hdd_file.Seek(block * m_hdd_info.block_size) < 0) if (m_hdd_file.Seek(block * m_hdd_info.block_size) < HDD_OK)
{ {
LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size); LOG_ERROR(HLE, "WriteEntry seek to %u failed.", block * m_hdd_info.block_size);
return -1; return HDD_SEEK_FAILURE;
} }
m_hdd_file.Write(&data, sizeof(vfsHDD_Entry)); m_hdd_file.Write(&data, sizeof(vfsHDD_Entry));
m_hdd_file.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1)); m_hdd_file.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1));
return 0; return HDD_OK;
} }
bool vfsHDD::Create(vfsHDD_EntryType type, const std::string& name) bool vfsHDD::Create(vfsHDD_EntryType type, const std::string& name)

View File

@ -5,6 +5,14 @@
static const u64 g_hdd_magic = *(u64*)"PS3eHDD\0"; static const u64 g_hdd_magic = *(u64*)"PS3eHDD\0";
static const u16 g_hdd_version = 0x0001; static const u16 g_hdd_version = 0x0001;
// Return codes
enum
{
HDD_OK = 0,
HDD_SEEK_FAILURE = 0x400,
HDD_ENTRY_NOT_FOUND = 0x401,
};
struct vfsHDD_Block struct vfsHDD_Block
{ {
struct struct
@ -114,7 +122,7 @@ public:
return m_cur_block * m_hdd_info.block_size + m_position; // ??? return m_cur_block * m_hdd_info.block_size + m_position; // ???
} }
void SaveInfo(); s32 SaveInfo();
u64 Read(void* dst, u64 size); u64 Read(void* dst, u64 size);

View File

@ -116,7 +116,7 @@ std::string CgBinaryDisasm::GetSRCDisasm(const u32 n)
if (swizzle != f) ret += '.' + swizzle; if (swizzle != f) ret += '.' + swizzle;
bool abs; bool abs = false;
switch (n) switch (n)
{ {

View File

@ -48,6 +48,7 @@ Emulator::Emulator()
: m_status(Stopped) : m_status(Stopped)
, m_mode(DisAsm) , m_mode(DisAsm)
, m_rsx_callback(0) , m_rsx_callback(0)
, m_cpu_thr_stop(0)
, m_thread_manager(new CPUThreadManager()) , m_thread_manager(new CPUThreadManager())
, m_pad_manager(new PadManager()) , m_pad_manager(new PadManager())
, m_keyboard_manager(new KeyboardManager()) , m_keyboard_manager(new KeyboardManager())
@ -453,6 +454,7 @@ void Emulator::Stop()
} }
m_rsx_callback = 0; m_rsx_callback = 0;
m_cpu_thr_stop = 0;
// TODO: check finalization order // TODO: check finalization order