andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public
andre@0:  * License, v. 2.0. If a copy of the MPL was not distributed with this
andre@0:  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
andre@0: 
andre@0: /*
andre@0:  *********************************************************************
andre@0:  *
andre@0:  * Memory-mapped files
andre@0:  *
andre@0:  *********************************************************************
andre@0:  */
andre@0: 
andre@0: #include "primpl.h"
andre@0: 
andre@0: PR_IMPLEMENT(PRFileMap *) PR_CreateFileMap(
andre@0:     PRFileDesc *fd,
andre@0:     PRInt64 size,
andre@0:     PRFileMapProtect prot)
andre@0: {
andre@0:     PRFileMap *fmap;
andre@0: 
andre@0:     PR_ASSERT(prot == PR_PROT_READONLY || prot == PR_PROT_READWRITE
andre@0:             || prot == PR_PROT_WRITECOPY);
andre@0:     fmap = PR_NEWZAP(PRFileMap);
andre@0:     if (NULL == fmap) {
andre@0: 	PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
andre@0: 	return NULL;
andre@0:     }
andre@0:     fmap->fd = fd;
andre@0:     fmap->prot = prot;
andre@0:     if (_PR_MD_CREATE_FILE_MAP(fmap, size) == PR_SUCCESS) {
andre@0: 	return fmap;
andre@0:     } else {
andre@0: 	PR_DELETE(fmap);
andre@0: 	return NULL;
andre@0:     }
andre@0: }
andre@0: 
andre@0: PR_IMPLEMENT(PRInt32) PR_GetMemMapAlignment(void)
andre@0: {
andre@0:     return _PR_MD_GET_MEM_MAP_ALIGNMENT();
andre@0: }
andre@0: 
andre@0: PR_IMPLEMENT(void *) PR_MemMap(
andre@0:     PRFileMap *fmap,
andre@0:     PROffset64 offset,
andre@0:     PRUint32 len)
andre@0: {
andre@0:     return _PR_MD_MEM_MAP(fmap, offset, len);
andre@0: }
andre@0: 
andre@0: PR_IMPLEMENT(PRStatus) PR_MemUnmap(void *addr, PRUint32 len)
andre@0: {
andre@0:     return _PR_MD_MEM_UNMAP(addr, len);
andre@0: }
andre@0: 
andre@0: PR_IMPLEMENT(PRStatus) PR_CloseFileMap(PRFileMap *fmap)
andre@0: {
andre@0:     return _PR_MD_CLOSE_FILE_MAP(fmap);
andre@0: }
andre@0: 
andre@0: PR_IMPLEMENT(PRStatus) PR_SyncMemMap(
andre@0:     PRFileDesc *fd,
andre@0:     void *addr,
andre@0:     PRUint32 len)
andre@0: {
andre@0:   return _PR_MD_SYNC_MEM_MAP(fd, addr, len);
andre@0: }