mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-07 15:36:26 +00:00
vm: fix mapping of file's last page
thanks @red_prig for investigation
This commit is contained in:
parent
ea2915467a
commit
e6022c1c4c
6 changed files with 136 additions and 69 deletions
|
|
@ -4,9 +4,18 @@ find_package(Git)
|
|||
|
||||
|
||||
add_library(${PROJECT_NAME} OBJECT
|
||||
src/mem.cpp
|
||||
src/Version.cpp
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
include
|
||||
|
||||
PRIVATE
|
||||
include/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
|
||||
execute_process(COMMAND date +%+4Y%m%d OUTPUT_VARIABLE RAW_VERSION)
|
||||
string(STRIP "${RAW_VERSION}" RAW_VERSION)
|
||||
|
|
|
|||
13
rx/include/rx/mem.hpp
Normal file
13
rx/include/rx/mem.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace rx::mem {
|
||||
extern const std::size_t pageSize;
|
||||
void *map(void *address, std::size_t size, int prot, int flags, int fd = -1,
|
||||
std::ptrdiff_t offset = 0);
|
||||
void *reserve(std::size_t size);
|
||||
bool reserve(void *address, std::size_t size);
|
||||
bool protect(void *address, std::size_t size, int prot);
|
||||
bool unmap(void *address, std::size_t size);
|
||||
} // namespace rx::mem
|
||||
27
rx/src/mem.cpp
Normal file
27
rx/src/mem.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "mem.hpp"
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern const std::size_t rx::mem::pageSize = sysconf(_SC_PAGE_SIZE);
|
||||
|
||||
void *rx::mem::map(void *address, std::size_t size, int prot, int flags,
|
||||
int fd, std::ptrdiff_t offset) {
|
||||
return ::mmap(address, size, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
void *rx::mem::reserve(std::size_t size) {
|
||||
return map(nullptr, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS);
|
||||
}
|
||||
|
||||
bool rx::mem::reserve(void *address, std::size_t size) {
|
||||
return map(address, size, PROT_NONE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED) != MAP_FAILED;
|
||||
}
|
||||
|
||||
bool rx::mem::protect(void *address, std::size_t size, int prot) {
|
||||
return ::mprotect(address, size, prot) == 0;
|
||||
}
|
||||
|
||||
bool rx::mem::unmap(void *address, std::size_t size) {
|
||||
return ::munmap(address, size) == 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue