2 * Copyright 2008 Extreme Engineering Solutions, Inc.
4 * mmap/munmap implementation derived from:
5 * Clamav Native Windows Port : mmap win32 compatibility layer
6 * Copyright (c) 2005-2006 Gianluigi Tiesi <sherpya@netfarm.it>
7 * Parts by Kees Zeelenberg <kzlg@users.sourceforge.net> (LibGW32C)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this software; if not, write to the
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "mingw_support.h"
35 void *mmap(void *addr, size_t len, int prot, int flags, int fd, int offset)
38 HANDLE handle = INVALID_HANDLE_VALUE;
39 DWORD cfm_flags = 0, mvf_flags = 0;
42 case PROT_READ | PROT_WRITE:
43 cfm_flags = PAGE_READWRITE;
44 mvf_flags = FILE_MAP_ALL_ACCESS;
47 cfm_flags = PAGE_READWRITE;
48 mvf_flags = FILE_MAP_WRITE;
51 cfm_flags = PAGE_READONLY;
52 mvf_flags = FILE_MAP_READ;
58 handle = CreateFileMappingA((HANDLE) _get_osfhandle(fd), NULL,
59 cfm_flags, HIDWORD(len), LODWORD(len), NULL);
63 map = MapViewOfFile(handle, mvf_flags, HIDWORD(offset),
64 LODWORD(offset), len);
73 int munmap(void *addr, size_t len)
75 if (!UnmapViewOfFile(addr))