Commit c352fc8e authored by R.K.Garcia's avatar R.K.Garcia
Browse files

added win32 copy-on-write implementation, now experiencing windows segfault fun

parent 8506e6b8
......@@ -17,7 +17,7 @@ static int __map_mman_error(const DWORD err, const int deferr)
return err;
}
static DWORD __map_mmap_prot_page(const int prot)
static DWORD __map_mmap_prot_page(const int prot, const int flags)
{
DWORD protect = 0;
......@@ -31,14 +31,17 @@ static DWORD __map_mmap_prot_page(const int prot)
}
else
{
protect = ((prot & PROT_WRITE) != 0) ?
if ((flags & MAP_PRIVATE) != 0)
protect = PAGE_READONLY;
else
protect = ((prot & PROT_WRITE) != 0) ?
PAGE_READWRITE : PAGE_READONLY;
}
return protect;
}
static DWORD __map_mmap_prot_file(const int prot)
static DWORD __map_mmap_prot_file(const int prot, const int flags)
{
DWORD desiredAccess = 0;
......@@ -47,8 +50,13 @@ static DWORD __map_mmap_prot_file(const int prot)
if ((prot & PROT_READ) != 0)
desiredAccess |= FILE_MAP_READ;
if ((prot & PROT_WRITE) != 0)
desiredAccess |= FILE_MAP_WRITE;
if ((prot & PROT_WRITE) != 0)
{
if ((flags & MAP_PRIVATE) != 0)
desiredAccess |= FILE_MAP_COPY;
else
desiredAccess |= FILE_MAP_WRITE;
}
if ((prot & PROT_EXEC) != 0)
desiredAccess |= FILE_MAP_EXECUTE;
......@@ -70,8 +78,8 @@ void* mmap(void *addr, size_t len, int prot, int flags, int fildes, OffsetType o
(DWORD)off : (DWORD)(off & 0xFFFFFFFFL);
const DWORD dwFileOffsetHigh = (sizeof(OffsetType) <= sizeof(DWORD)) ?
(DWORD)0 : (DWORD)((off >> 32) & 0xFFFFFFFFL);
const DWORD protect = __map_mmap_prot_page(prot);
const DWORD desiredAccess = __map_mmap_prot_file(prot);
const DWORD protect = __map_mmap_prot_page(prot, flags);
const DWORD desiredAccess = __map_mmap_prot_file(prot, flags);
const OffsetType maxSize = off + (OffsetType)len;
......@@ -138,7 +146,7 @@ int munmap(void *addr, size_t len)
int _mprotect(void *addr, size_t len, int prot)
{
DWORD newProtect = __map_mmap_prot_page(prot);
DWORD newProtect = __map_mmap_prot_page(prot, 0); // TODO: determine whether flags is needed here
DWORD oldProtect = 0;
if (VirtualProtect(addr, len, newProtect, &oldProtect))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment