2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid
[] = "@(#)db_os_mmap.c 10.4 (Sleepycat) 6/28/97";
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
26 * Map in some shared memory backed by a file descriptor.
28 * PUBLIC: int __db_mmap __P((int, size_t, int, int, void *));
31 __db_mmap(fd
, len
, is_private
, rdonly
, addr
)
32 int fd
, is_private
, rdonly
;
37 /* We have not implemented copy-on-write here */
39 HANDLE hFile
= (HANDLE
)_get_osfhandle(fd
);
40 HANDLE hMemory
= CreateFileMapping(
43 (rdonly
? PAGE_READONLY
: PAGE_READWRITE
),
45 len
, /* This code fails if the library is ever compiled on a 64-bit machine */
52 pMemory
= MapViewOfFile(
54 (rdonly
? FILE_MAP_READ
: FILE_MAP_ALL_ACCESS
),
60 *(void **)addr
= pMemory
;
68 flags
= is_private
? MAP_PRIVATE
: MAP_SHARED
;
69 #ifdef MAP_HASSEMAPHORE
70 flags
+= MAP_HASSEMAPHORE
;
72 prot
= PROT_READ
| (rdonly
? 0 : PROT_WRITE
);
74 #ifndef MAP_FAILED /* XXX: Mmap(2) failure return. */
78 mmap(NULL
, len
, prot
, flags
, fd
, (off_t
)0)) == (void *)MAP_FAILED
)
88 * Release the specified shared memory.
90 * PUBLIC: int __db_munmap __P((void *, size_t));
93 __db_munmap(addr
, len
)
99 * The argument len is always the same length as was mapped.
102 return (!UnmapViewOfFile(addr
) ? errno
: 0);
104 return (munmap(addr
, len
) ? errno
: 0);