mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 13:31:27 +12:00
Replace most returns with CHECK_ASSERTION
Also fix some Seek methods return types being unsigned, while returning negative errors. Added the CHECK_ASSERTION macro checks in a couple more places. Simplified CHECK_ASSERTION macro usage.
This commit is contained in:
parent
9c2f48cd1d
commit
5d5a4f804b
14 changed files with 159 additions and 394 deletions
|
@ -327,13 +327,7 @@ int OSCopyFile(const char* source, const char* destination, bool overwrite)
|
|||
//sendfile will work with non-socket output (i.e. regular file) on Linux 2.6.33+
|
||||
off_t bytesCopied = 0;
|
||||
struct stat fileinfo = { 0 };
|
||||
|
||||
s32 ret = fstat(input, &fileinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
fstat(input, &fileinfo);
|
||||
int result = sendfile(output, input, &bytesCopied, fileinfo.st_size) == -1 ? -1 : 0;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -17,55 +17,29 @@ namespace memory_helper
|
|||
{
|
||||
#ifdef _WIN32
|
||||
void* ret = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
|
||||
if (ret == NULL)
|
||||
{
|
||||
LOG_ERROR(HLE, "reserve_memory VirtualAlloc failed.");
|
||||
return (void*)VM_FAILURE;
|
||||
}
|
||||
CHECK_ASSERTION(ret != NULL);
|
||||
#else
|
||||
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.");
|
||||
}
|
||||
CHECK_ASSERTION(ret != 0);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 commit_page_memory(void* pointer, size_t page_size)
|
||||
void commit_page_memory(void* pointer, size_t page_size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (VirtualAlloc((u8*)pointer, page_size, MEM_COMMIT, PAGE_READWRITE) == NULL)
|
||||
{
|
||||
LOG_ERROR(HLE, "commit_page_memory VirtualAlloc failed.");
|
||||
return VM_FAILURE;
|
||||
}
|
||||
CHECK_ASSERTION(VirtualAlloc((u8*)pointer, page_size, MEM_COMMIT, PAGE_READWRITE) != NULL);
|
||||
#else
|
||||
s32 ret = mprotect((u8*)pointer, page_size, PROT_READ | PROT_WRITE);
|
||||
if (ret < VM_SUCCESS)
|
||||
{
|
||||
LOG_ERROR(HLE, "commit_page_memory mprotect failed. (%d)", ret);
|
||||
return VM_FAILURE;
|
||||
}
|
||||
CHECK_ASSERTION(mprotect((u8*)pointer, page_size, PROT_READ | PROT_WRITE) != -1);
|
||||
#endif
|
||||
return VM_SUCCESS;
|
||||
}
|
||||
|
||||
s32 free_reserved_memory(void* pointer, size_t size)
|
||||
void free_reserved_memory(void* pointer, size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (VirtualFree(pointer, 0, MEM_RELEASE) == 0)
|
||||
{
|
||||
LOG_ERROR(HLE, "free_reserved_memory VirtualFree failed.");
|
||||
return VM_FAILURE;
|
||||
}
|
||||
CHECK_ASSERTION(VirtualFree(pointer, 0, MEM_RELEASE) != 0);
|
||||
#else
|
||||
if (munmap(pointer, size) != VM_SUCCESS)
|
||||
{
|
||||
LOG_ERROR(HLE, "free_reserved_memory munmap failed.");
|
||||
return VM_FAILURE;
|
||||
}
|
||||
CHECK_ASSERTION(munmap(pointer, size) == 0);
|
||||
#endif
|
||||
return VM_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
// Failure codes for the functions
|
||||
enum
|
||||
{
|
||||
VM_SUCCESS = 0,
|
||||
VM_FAILURE = -1,
|
||||
};
|
||||
|
||||
namespace memory_helper
|
||||
{
|
||||
/**
|
||||
* Reserve size bytes of virtual memory and returns it.
|
||||
* 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);
|
||||
|
||||
|
@ -22,17 +12,11 @@ namespace memory_helper
|
|||
* Commit page_size bytes of virtual memory starting at pointer.
|
||||
* That is, bake reserved memory with physical memory.
|
||||
* pointer should belong to a range of reserved memory.
|
||||
*
|
||||
* Returns VM_SUCCESS, if successful.
|
||||
* Returns VM_FAILURE, if unsuccessful.
|
||||
*/
|
||||
s32 commit_page_memory(void* pointer, size_t page_size);
|
||||
void commit_page_memory(void* pointer, size_t page_size);
|
||||
|
||||
/**
|
||||
* Free memory alloced via reserve_memory.
|
||||
*
|
||||
* Returns VM_SUCCESS, if successful.
|
||||
* Returns VM_FAILURE, if unsuccessful.
|
||||
*/
|
||||
s32 free_reserved_memory(void* pointer, size_t size);
|
||||
void free_reserved_memory(void* pointer, size_t size);
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#ifndef _WIN32
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "rPlatform.h"
|
||||
|
@ -57,14 +58,9 @@ std::string rPlatform::getConfigDir()
|
|||
dir = "./config";
|
||||
dir = dir + "/rpcs3/";
|
||||
|
||||
s32 ret = mkdir(dir.c_str(), 0777);
|
||||
if (ret == EEXIST)
|
||||
if (mkdir(dir.c_str(), 0777) == -1)
|
||||
{
|
||||
LOG_WARNING(HLE, "Configuration directory already exists. (%s)", dir);
|
||||
}
|
||||
else if (ret < 0)
|
||||
{
|
||||
LOG_ERROR(HLE, "An error occured during the creation of the configuration directory. (%d)", ret);
|
||||
printf("An error occured during the creation of the configuration directory. (%d)", errno);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue