Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : /*
7 : *********************************************************************
8 : *
9 : * Memory-mapped files
10 : *
11 : *********************************************************************
12 : */
13 :
14 : #include "primpl.h"
15 :
16 : PR_IMPLEMENT(PRFileMap *) PR_CreateFileMap(
17 : PRFileDesc *fd,
18 : PRInt64 size,
19 : PRFileMapProtect prot)
20 : {
21 : PRFileMap *fmap;
22 :
23 107 : PR_ASSERT(prot == PR_PROT_READONLY || prot == PR_PROT_READWRITE
24 : || prot == PR_PROT_WRITECOPY);
25 107 : fmap = PR_NEWZAP(PRFileMap);
26 107 : if (NULL == fmap) {
27 0 : PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
28 0 : return NULL;
29 : }
30 107 : fmap->fd = fd;
31 107 : fmap->prot = prot;
32 107 : if (_PR_MD_CREATE_FILE_MAP(fmap, size) == PR_SUCCESS) {
33 107 : return fmap;
34 : }
35 0 : PR_DELETE(fmap);
36 0 : return NULL;
37 : }
38 :
39 : PR_IMPLEMENT(PRInt32) PR_GetMemMapAlignment(void)
40 : {
41 1 : return _PR_MD_GET_MEM_MAP_ALIGNMENT();
42 : }
43 :
44 : PR_IMPLEMENT(void *) PR_MemMap(
45 : PRFileMap *fmap,
46 : PROffset64 offset,
47 : PRUint32 len)
48 : {
49 107 : return _PR_MD_MEM_MAP(fmap, offset, len);
50 : }
51 :
52 : PR_IMPLEMENT(PRStatus) PR_MemUnmap(void *addr, PRUint32 len)
53 : {
54 101 : return _PR_MD_MEM_UNMAP(addr, len);
55 : }
56 :
57 : PR_IMPLEMENT(PRStatus) PR_CloseFileMap(PRFileMap *fmap)
58 : {
59 101 : return _PR_MD_CLOSE_FILE_MAP(fmap);
60 : }
61 :
62 : PR_IMPLEMENT(PRStatus) PR_SyncMemMap(
63 : PRFileDesc *fd,
64 : void *addr,
65 : PRUint32 len)
66 : {
67 0 : return _PR_MD_SYNC_MEM_MAP(fd, addr, len);
68 : }
|