diff --git a/Pal/src/host/Linux/db_files.c b/Pal/src/host/Linux/db_files.c index 52efff4c..169eadab 100644 --- a/Pal/src/host/Linux/db_files.c +++ b/Pal/src/host/Linux/db_files.c @@ -153,7 +153,7 @@ static int file_map (PAL_HANDLE handle, void ** addr, int prot, { int fd = handle->file.fd; void * mem = *addr; - if (mem && _DkCheckMemoryMappable(mem, size)) + if (mem && !_DkCheckMemoryMappable(mem, size)) return -PAL_ERROR_DENIED; /* diff --git a/Pal/src/host/Linux/db_memory.c b/Pal/src/host/Linux/db_memory.c index e306ccf5..e4ccebca 100644 --- a/Pal/src/host/Linux/db_memory.c +++ b/Pal/src/host/Linux/db_memory.c @@ -34,7 +34,7 @@ bool _DkCheckMemoryMappable (const void * addr, size_t size) { - return (addr < DATA_END && addr + size > TEXT_START); + return (addr >= DATA_END || addr + size <= TEXT_START); } int _DkVirtualMemoryAlloc (void ** paddr, size_t size, int alloc_type, @@ -42,7 +42,7 @@ int _DkVirtualMemoryAlloc (void ** paddr, size_t size, int alloc_type, { void * addr = *paddr, * mem = addr; - if (addr && _DkCheckMemoryMappable(addr, size)) + if (addr && !_DkCheckMemoryMappable(addr, size)) return -PAL_ERROR_DENIED; int flags = HOST_FLAGS(alloc_type, prot|PAL_PROT_WRITECOPY); @@ -60,7 +60,7 @@ int _DkVirtualMemoryAlloc (void ** paddr, size_t size, int alloc_type, int _DkVirtualMemoryFree (void * addr, size_t size) { - if (_DkCheckMemoryMappable(addr, size)) + if (!_DkCheckMemoryMappable(addr, size)) return -PAL_ERROR_DENIED; int ret = INLINE_SYSCALL(munmap, 2, addr, size); @@ -70,7 +70,7 @@ int _DkVirtualMemoryFree (void * addr, size_t size) int _DkVirtualMemoryProtect (void * addr, size_t size, int prot) { - if (_DkCheckMemoryMappable(addr, size)) + if (!_DkCheckMemoryMappable(addr, size)) return -PAL_ERROR_DENIED; int ret = INLINE_SYSCALL(mprotect, 3, addr, size, HOST_PROT(prot)); diff --git a/Pal/src/host/Linux/db_streams.c b/Pal/src/host/Linux/db_streams.c index 85b7a176..7ecebf49 100644 --- a/Pal/src/host/Linux/db_streams.c +++ b/Pal/src/host/Linux/db_streams.c @@ -82,7 +82,7 @@ int handle_set_cloexec(PAL_HANDLE handle, bool enable) { /* _DkStreamUnmap for internal use. Unmap stream at certain memory address. The memory is unmapped as a whole.*/ int _DkStreamUnmap(void* addr, uint64_t size) { - if (_DkCheckMemoryMappable(addr, size)) + if (!_DkCheckMemoryMappable(addr, size)) return -PAL_ERROR_DENIED; /* Just let the kernel tell us if the mapping isn't good. */