1
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
#include "mysys_priv.h"
18
#ifdef HAVE_SYS_MMAN_H
21
system msync() only syncs mmap'ed area to fs cache.
22
fsync() is required to really sync to disc
24
int my_msync(int fd, void *addr, size_t len, int flags)
26
msync(addr, len, flags);
27
return my_sync(fd, MYF(0));
32
static SECURITY_ATTRIBUTES mmap_security_attributes=
33
{sizeof(SECURITY_ATTRIBUTES), 0, TRUE};
35
void *my_mmap(void *addr, size_t len, int prot,
36
int flags, File fd, my_off_t offset)
40
HANDLE hFile= (HANDLE)my_get_osfhandle(fd);
41
DBUG_ENTER("my_mmap");
42
DBUG_PRINT("mysys", ("map fd: %d", fd));
44
if (hFile == INVALID_HANDLE_VALUE)
45
DBUG_RETURN(MAP_FAILED);
47
hFileMap=CreateFileMapping(hFile, &mmap_security_attributes,
48
PAGE_READWRITE, 0, (DWORD) len, NULL);
50
DBUG_RETURN(MAP_FAILED);
52
ptr=MapViewOfFile(hFileMap,
53
prot & PROT_WRITE ? FILE_MAP_WRITE : FILE_MAP_READ,
54
(DWORD)(offset >> 32), (DWORD)offset, len);
57
MSDN explicitly states that it's possible to close File Mapping Object
58
even when a view is not unmapped - then the object will be held open
59
implicitly until unmap, as every view stores internally a handler of
60
a corresponding File Mapping Object
62
CloseHandle(hFileMap);
66
DBUG_PRINT("mysys", ("mapped addr: %p", ptr));
70
DBUG_RETURN(MAP_FAILED);
73
int my_munmap(void *addr, size_t len)
75
DBUG_ENTER("my_munmap");
76
DBUG_PRINT("mysys", ("unmap addr: %p", addr));
77
DBUG_RETURN(UnmapViewOfFile(addr) ? 0 : -1);
80
int my_msync(int fd, void *addr, size_t len, int flags)
82
return FlushViewOfFile(addr, len) ? 0 : -1;