1af69d88dSmrg/************************************************************************** 2af69d88dSmrg * 3af69d88dSmrg * Copyright 2011 LunarG, Inc. 4af69d88dSmrg * All Rights Reserved. 5af69d88dSmrg * 6af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a 7af69d88dSmrg * copy of this software and associated documentation files (the 8af69d88dSmrg * "Software"), to deal in the Software without restriction, including 9af69d88dSmrg * without limitation the rights to use, copy, modify, merge, publish, 10af69d88dSmrg * distribute, sub license, and/or sell copies of the Software, and to 11af69d88dSmrg * permit persons to whom the Software is furnished to do so, subject to 12af69d88dSmrg * the following conditions: 13af69d88dSmrg * 14af69d88dSmrg * The above copyright notice and this permission notice (including the 15af69d88dSmrg * next paragraph) shall be included in all copies or substantial portions 16af69d88dSmrg * of the Software. 17af69d88dSmrg * 18af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19af69d88dSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20af69d88dSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22af69d88dSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23af69d88dSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24af69d88dSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25af69d88dSmrg * 26af69d88dSmrg **************************************************************************/ 27af69d88dSmrg 28af69d88dSmrg/** 29af69d88dSmrg * @file 30af69d88dSmrg * OS independent memory mapping (with large file support). 31af69d88dSmrg * 32af69d88dSmrg * @author Chia-I Wu <olvaffe@gmail.com> 33af69d88dSmrg */ 34af69d88dSmrg 35af69d88dSmrg#ifndef _OS_MMAN_H_ 36af69d88dSmrg#define _OS_MMAN_H_ 37af69d88dSmrg 38af69d88dSmrg 39af69d88dSmrg#include "pipe/p_config.h" 40af69d88dSmrg#include "pipe/p_compiler.h" 41af69d88dSmrg 42af69d88dSmrg#if defined(PIPE_OS_UNIX) 43af69d88dSmrg# include <sys/mman.h> 44af69d88dSmrg#else 45af69d88dSmrg# error Unsupported OS 46af69d88dSmrg#endif 47af69d88dSmrg 48af69d88dSmrg#ifdef __cplusplus 49af69d88dSmrgextern "C" { 50af69d88dSmrg#endif 51af69d88dSmrg 52af69d88dSmrg 5301e04c3fSmrg#if defined(PIPE_OS_ANDROID) && !defined(__LP64__) 5401e04c3fSmrg/* 32-bit needs mmap64 for 64-bit offsets */ 5501e04c3fSmrg# define os_mmap(addr, length, prot, flags, fd, offset) \ 5601e04c3fSmrg mmap64(addr, length, prot, flags, fd, offset) 57af69d88dSmrg 5801e04c3fSmrg# define os_munmap(addr, length) \ 5901e04c3fSmrg munmap(addr, length) 60af69d88dSmrg 61af69d88dSmrg#else 62af69d88dSmrg/* assume large file support exists */ 6301e04c3fSmrg# define os_mmap(addr, length, prot, flags, fd, offset) \ 6401e04c3fSmrg mmap(addr, length, prot, flags, fd, offset) 65af69d88dSmrg 6601e04c3fSmrgstatic inline int os_munmap(void *addr, size_t length) 6701e04c3fSmrg{ 6801e04c3fSmrg /* Copied from configure code generated by AC_SYS_LARGEFILE */ 6901e04c3fSmrg#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + \ 7001e04c3fSmrg (((off_t) 1 << 31) << 31)) 7101e04c3fSmrg STATIC_ASSERT(LARGE_OFF_T % 2147483629 == 721 && 7201e04c3fSmrg LARGE_OFF_T % 2147483647 == 1); 7301e04c3fSmrg#undef LARGE_OFF_T 7401e04c3fSmrg 7501e04c3fSmrg return munmap(addr, length); 7601e04c3fSmrg} 7701e04c3fSmrg#endif 78af69d88dSmrg 79af69d88dSmrg 80af69d88dSmrg#ifdef __cplusplus 81af69d88dSmrg} 82af69d88dSmrg#endif 83af69d88dSmrg 84af69d88dSmrg#endif /* _OS_MMAN_H_ */ 85