Intel compiler icc 11.1 supports compilation of internal mp3lib and internal liba52.
[mplayer.git] / osdep / mmap_anon.c
blob727761cb6cf7df614d16afd0476db59b29eb7443
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 /**
20 * \file mmap_anon.c
21 * \brief Provide a compatible anonymous space mapping function
23 #include "config.h"
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <sys/mman.h>
30 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
31 #define MAP_ANONYMOUS MAP_ANON
32 #endif
35 * mmap() anonymous space, depending on the system's mmap() style. On systems
36 * that use the /dev/zero mapping idiom, zerofd will be set to the file descriptor
37 * of the opened /dev/zero.
40 /**
41 * \brief mmap() anonymous space, depending on the system's mmap() style. On systems
42 * that use the /dev/zero mapping idiom, zerofd will be set to the file descriptor
43 * of the opened /dev/zero.
45 * \param addr address to map at.
46 * \param len number of bytes from addr to be mapped.
47 * \param prot protections (region accessibility).
48 * \param flags specifies the type of the mapped object.
49 * \param offset start mapping at byte offset.
50 * \param zerofd
51 * \return a pointer to the mapped region upon successful completion, -1 otherwise.
53 void *mmap_anon(void *addr, size_t len, int prot, int flags, off_t offset)
55 void *result;
57 /* From loader/ext.c:
58 * "Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap"
59 * Therefore we preserve the same behavior on all platforms, ie. no
60 * shared mappings of anon space (if the concepts are supported). */
61 #if defined(MAP_SHARED) && defined(MAP_PRIVATE)
62 flags = (flags & ~MAP_SHARED) | MAP_PRIVATE;
63 #endif /* defined(MAP_SHARED) && defined(MAP_PRIVATE) */
65 #ifdef MAP_ANONYMOUS
66 /* BSD-style anonymous mapping */
67 result = mmap(addr, len, prot, flags | MAP_ANONYMOUS, -1, offset);
68 #else
69 /* SysV-style anonymous mapping */
70 int fd;
71 fd = open("/dev/zero", O_RDWR);
72 if(fd < 0){
73 perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
74 return NULL;
77 result = mmap(addr, len, prot, flags, fd, offset);
78 close(fd);
79 #endif /* MAP_ANONYMOUS */
81 return result;