1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2011 LunarG, Inc. 4848b8605Smrg * All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the 8848b8605Smrg * "Software"), to deal in the Software without restriction, including 9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 12848b8605Smrg * the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice (including the 15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 16848b8605Smrg * of the Software. 17848b8605Smrg * 18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25848b8605Smrg * 26848b8605Smrg **************************************************************************/ 27848b8605Smrg 28848b8605Smrg/** 29848b8605Smrg * @file 30848b8605Smrg * OS independent memory mapping (with large file support). 31848b8605Smrg * 32848b8605Smrg * @author Chia-I Wu <olvaffe@gmail.com> 33848b8605Smrg */ 34848b8605Smrg 35848b8605Smrg#ifndef _OS_MMAN_H_ 36848b8605Smrg#define _OS_MMAN_H_ 37848b8605Smrg 38848b8605Smrg 39848b8605Smrg#include "pipe/p_config.h" 40848b8605Smrg#include "pipe/p_compiler.h" 41848b8605Smrg 42848b8605Smrg#if defined(PIPE_OS_UNIX) 43848b8605Smrg# include <sys/mman.h> 44848b8605Smrg#else 45848b8605Smrg# error Unsupported OS 46848b8605Smrg#endif 47848b8605Smrg 48848b8605Smrg#ifdef __cplusplus 49848b8605Smrgextern "C" { 50848b8605Smrg#endif 51848b8605Smrg 52848b8605Smrg 53b8e80941Smrg#if defined(PIPE_OS_ANDROID) && !defined(__LP64__) 54b8e80941Smrg/* 32-bit needs mmap64 for 64-bit offsets */ 55b8e80941Smrg# define os_mmap(addr, length, prot, flags, fd, offset) \ 56b8e80941Smrg mmap64(addr, length, prot, flags, fd, offset) 57848b8605Smrg 58b8e80941Smrg# define os_munmap(addr, length) \ 59b8e80941Smrg munmap(addr, length) 60848b8605Smrg 61848b8605Smrg#else 62848b8605Smrg/* assume large file support exists */ 63b8e80941Smrg# define os_mmap(addr, length, prot, flags, fd, offset) \ 64b8e80941Smrg mmap(addr, length, prot, flags, fd, offset) 65848b8605Smrg 66b8e80941Smrgstatic inline int os_munmap(void *addr, size_t length) 67b8e80941Smrg{ 68b8e80941Smrg /* Copied from configure code generated by AC_SYS_LARGEFILE */ 69b8e80941Smrg#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + \ 70b8e80941Smrg (((off_t) 1 << 31) << 31)) 71b8e80941Smrg STATIC_ASSERT(LARGE_OFF_T % 2147483629 == 721 && 72b8e80941Smrg LARGE_OFF_T % 2147483647 == 1); 73b8e80941Smrg#undef LARGE_OFF_T 74b8e80941Smrg 75b8e80941Smrg return munmap(addr, length); 76b8e80941Smrg} 77b8e80941Smrg#endif 78848b8605Smrg 79848b8605Smrg 80848b8605Smrg#ifdef __cplusplus 81848b8605Smrg} 82848b8605Smrg#endif 83848b8605Smrg 84848b8605Smrg#endif /* _OS_MMAN_H_ */ 85