Mercurial > mplayer.hg
annotate osdep/mmap_anon.c @ 32986:983a6e18b80d
Fix MPlayer build after CrystalHD have been accepted in FFmpeg.
Add dummy detection to configure and set it to disabled.
author | iive |
---|---|
date | Fri, 11 Mar 2011 15:50:42 +0000 |
parents | 321e9ea69b9f |
children | 08a90b0e44e1 |
rev | line source |
---|---|
28744 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
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. | |
8 * | |
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. | |
13 * | |
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. | |
17 */ | |
18 | |
21187 | 19 /** |
20 * \file mmap_anon.c | |
21 * \brief Provide a compatible anonymous space mapping function | |
22 */ | |
21253
f2ddea0632d4
Disable when HAVE_SYS_MMAN_H is not defined, since it can not be compiled then.
reimar
parents:
21248
diff
changeset
|
23 #include "config.h" |
21187 | 24 |
25 #include <stdio.h> | |
26 #include <unistd.h> | |
27 #include <fcntl.h> | |
21489 | 28 #include <sys/mman.h> |
21187 | 29 |
30554 | 30 #include "mmap_anon.h" |
31 | |
21187 | 32 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) |
33 #define MAP_ANONYMOUS MAP_ANON | |
34 #endif | |
35 | |
36 /* | |
37 * mmap() anonymous space, depending on the system's mmap() style. On systems | |
38 * that use the /dev/zero mapping idiom, zerofd will be set to the file descriptor | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28744
diff
changeset
|
39 * of the opened /dev/zero. |
21187 | 40 */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28744
diff
changeset
|
41 |
21187 | 42 /** |
43 * \brief mmap() anonymous space, depending on the system's mmap() style. On systems | |
44 * that use the /dev/zero mapping idiom, zerofd will be set to the file descriptor | |
45 * of the opened /dev/zero. | |
46 * | |
47 * \param addr address to map at. | |
48 * \param len number of bytes from addr to be mapped. | |
49 * \param prot protections (region accessibility). | |
50 * \param flags specifies the type of the mapped object. | |
51 * \param offset start mapping at byte offset. | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28744
diff
changeset
|
52 * \param zerofd |
21187 | 53 * \return a pointer to the mapped region upon successful completion, -1 otherwise. |
54 */ | |
21248 | 55 void *mmap_anon(void *addr, size_t len, int prot, int flags, off_t offset) |
21187 | 56 { |
57 void *result; | |
58 | |
59 /* From loader/ext.c: | |
60 * "Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap" | |
61 * Therefore we preserve the same behavior on all platforms, ie. no | |
62 * shared mappings of anon space (if the concepts are supported). */ | |
63 #if defined(MAP_SHARED) && defined(MAP_PRIVATE) | |
64 flags = (flags & ~MAP_SHARED) | MAP_PRIVATE; | |
65 #endif /* defined(MAP_SHARED) && defined(MAP_PRIVATE) */ | |
66 | |
67 #ifdef MAP_ANONYMOUS | |
68 /* BSD-style anonymous mapping */ | |
69 result = mmap(addr, len, prot, flags | MAP_ANONYMOUS, -1, offset); | |
70 #else | |
71 /* SysV-style anonymous mapping */ | |
24174 | 72 int fd; |
21187 | 73 fd = open("/dev/zero", O_RDWR); |
74 if(fd < 0){ | |
75 perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: "); | |
76 return NULL; | |
77 } | |
78 | |
79 result = mmap(addr, len, prot, flags, fd, offset); | |
21248 | 80 close(fd); |
21187 | 81 #endif /* MAP_ANONYMOUS */ |
82 | |
83 return result; | |
84 } |