annotate osdep/mmap_anon.c @ 29335:5f45df619c7c

TS demuxer: make the IDs used by DEMUXER_CTRL_SWITCH_* and DEMUXER_CTRL_IDENTIFY_PROGRAM match those printed as ID_VIDEO_ID/ID_AUDIO_ID and accepted with -vid/-aid
author reimar
date Sun, 21 Jun 2009 10:47:44 +0000
parents 0f1b5b68af32
children 321e9ea69b9f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28744
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
1 /*
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
2 * This file is part of MPlayer.
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
3 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
5 * it under the terms of the GNU General Public License as published by
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
7 * (at your option) any later version.
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
8 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
12 * GNU General Public License for more details.
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
13 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
14 * You should have received a copy of the GNU General Public License along
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
17 */
5cfef41a1771 Add standard license headers to files.
diego
parents: 24174
diff changeset
18
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
19 /**
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
20 * \file mmap_anon.c
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
21 * \brief Provide a compatible anonymous space mapping function
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
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
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
24
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
25 #include <stdio.h>
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
26 #include <unistd.h>
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
27 #include <fcntl.h>
21489
969de5b130ae fix include clash for mmap_anon on darwin ppc
nplourde
parents: 21253
diff changeset
28 #include <sys/mman.h>
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
29
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
30 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
31 #define MAP_ANONYMOUS MAP_ANON
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
32 #endif
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
33
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
34 /*
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
35 * mmap() anonymous space, depending on the system's mmap() style. On systems
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
36 * 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
37 * of the opened /dev/zero.
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
38 */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
39
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
40 /**
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
41 * \brief mmap() anonymous space, depending on the system's mmap() style. On systems
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
42 * that use the /dev/zero mapping idiom, zerofd will be set to the file descriptor
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
43 * of the opened /dev/zero.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
44 *
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
45 * \param addr address to map at.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
46 * \param len number of bytes from addr to be mapped.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
47 * \param prot protections (region accessibility).
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
48 * \param flags specifies the type of the mapped object.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
49 * \param offset start mapping at byte offset.
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
50 * \param zerofd
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
51 * \return a pointer to the mapped region upon successful completion, -1 otherwise.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
52 */
21248
2de480457872 Remove useless fd parameter for mmap_anon
reimar
parents: 21187
diff changeset
53 void *mmap_anon(void *addr, size_t len, int prot, int flags, off_t offset)
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
54 {
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
55 void *result;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
56
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
57 /* From loader/ext.c:
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
58 * "Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap"
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
59 * Therefore we preserve the same behavior on all platforms, ie. no
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
60 * shared mappings of anon space (if the concepts are supported). */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
61 #if defined(MAP_SHARED) && defined(MAP_PRIVATE)
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
62 flags = (flags & ~MAP_SHARED) | MAP_PRIVATE;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
63 #endif /* defined(MAP_SHARED) && defined(MAP_PRIVATE) */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
64
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
65 #ifdef MAP_ANONYMOUS
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
66 /* BSD-style anonymous mapping */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
67 result = mmap(addr, len, prot, flags | MAP_ANONYMOUS, -1, offset);
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
68 #else
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
69 /* SysV-style anonymous mapping */
24174
10f268ec0d87 warning fix:
diego
parents: 21855
diff changeset
70 int fd;
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
71 fd = open("/dev/zero", O_RDWR);
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
72 if(fd < 0){
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
73 perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: ");
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
74 return NULL;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
75 }
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
76
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
77 result = mmap(addr, len, prot, flags, fd, offset);
21248
2de480457872 Remove useless fd parameter for mmap_anon
reimar
parents: 21187
diff changeset
78 close(fd);
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
79 #endif /* MAP_ANONYMOUS */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
80
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
81 return result;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
82 }