1 /* mmap replacement for mingw.
3 * Copyright (C) 2011 by Daniel Gillen <gillen (dot) dan (at) pinguin (dot) lu>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
17 #include "hivex-internal.h"
24 hivex__rpl_mmap (hive_h *h,
25 void *p_addr, size_t len, int prot, int flags, int fd, off_t offset)
29 // Check parameters for unsupported values
32 if (prot != PROT_READ)
34 if (flags != MAP_SHARED)
37 // Create file mapping
38 h->p_winmap = CreateFileMapping ((HANDLE)_get_osfhandle(fd),
39 NULL, PAGE_READONLY, 0, 0, NULL);
40 if (h->p_winmap == NULL)
44 p_map = MapViewOfFile (h->p_winmap, FILE_MAP_READ, 0, 0, len);
46 CloseHandle (h->p_winmap);
54 hivex__rpl_munmap (hive_h *h, void *p_addr, size_t len)
56 if (p_addr == NULL || h->p_winmap == NULL)
60 if (UnmapViewOfFile (p_addr) == 0)
64 if (CloseHandle (h->p_winmap) == 0)