- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ N T M a p M e m o r y %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Mmap() emulates the Unix method of the same name.
%
% The format of the NTMapMemory method is:
%
% MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
% int access,int file,MagickOffsetType offset)
%
*/
MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
int flags,int file,MagickOffsetType offset)
{
DWORD
access_mode,
high_length,
high_offset,
low_length,
low_offset,
protection_mode;
HANDLE
file_handle,
map_handle;
void
*map;
(void) address;
access_mode=0;
file_handle=INVALID_HANDLE_VALUE;
low_length=(DWORD) (length & 0xFFFFFFFFUL);
high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
map_handle=INVALID_HANDLE_VALUE;
map=(void *) NULL;
low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
protection_mode=0;
if (protection & PROT_WRITE)
{
access_mode=FILE_MAP_WRITE;
if (!(flags & MAP_PRIVATE))
protection_mode=PAGE_READWRITE;
else
{
access_mode=FILE_MAP_COPY;
protection_mode=PAGE_WRITECOPY;
}
}
else
if (protection & PROT_READ)
{
access_mode=FILE_MAP_READ;
protection_mode=PAGE_READONLY;
}
if ((file == -1) && (flags & MAP_ANONYMOUS))
file_handle=INVALID_HANDLE_VALUE;
else
file_handle=(HANDLE) _get_osfhandle(file);
map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
low_length,0);
if (map_handle)
{
map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
length);
CloseHandle(map_handle);
}
if (map == (void *) NULL)
return((void *) ((char *) MAP_FAILED));
return((void *) ((char *) map));
}
Мумуляция «mmap» в «Винде». Это даже работает, если пофиксить две строчки (кто угадает, какие именно, тому ничего).
Отсюда:
https://github.com/ImageMagick/ImageMagick/blob/master/MagickCore/nt-base.c