[Base] First-pass memory file mapping support

This commit is contained in:
DrChat 2017-12-19 19:25:58 -06:00
parent 0efb08ad74
commit cd2e07f680
1 changed files with 32 additions and 4 deletions

View File

@ -8,7 +8,9 @@
*/
#include "xenia/base/memory.h"
#include "xenia/base/string.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
@ -61,19 +63,45 @@ bool QueryProtect(void* base_address, size_t& length, PageAccess& access_out) {
FileMappingHandle CreateFileMappingHandle(std::wstring path, size_t length,
PageAccess access, bool commit) {
return nullptr;
int oflag;
switch (access) {
case PageAccess::kNoAccess:
oflag = 0;
break;
case PageAccess::kReadOnly:
oflag = O_RDONLY;
break;
case PageAccess::kReadWrite:
oflag = O_RDWR;
break;
default:
assert_always();
return nullptr;
}
oflag |= O_CREAT;
int ret = shm_open(xe::to_string(path).c_str(), oflag, 0777);
if (ret > 0) {
ftruncate64(ret, length);
}
return ret <= 0 ? nullptr : reinterpret_cast<FileMappingHandle>(ret);
}
void CloseFileMappingHandle(FileMappingHandle handle) {}
void CloseFileMappingHandle(FileMappingHandle handle) {
close((intptr_t)handle);
}
void* MapFileView(FileMappingHandle handle, void* base_address, size_t length,
PageAccess access, size_t file_offset) {
return nullptr;
uint32_t prot = ToPosixProtectFlags(access);
return mmap64(base_address, length, prot, MAP_PRIVATE | MAP_ANONYMOUS,
reinterpret_cast<intptr_t>(handle), file_offset);
}
bool UnmapFileView(FileMappingHandle handle, void* base_address,
size_t length) {
return false;
return munmap(base_address, length) == 0;
}
} // namespace memory