annotate osdep/mmap_anon.c @ 35211:014d0c671b80

mpcommon: Show more CPU flags Add SSE3, SSE4, SSE4.2, and AVX in CPU flags information. Patch by Josh [joshf87 live com]
author upsuper
date Wed, 31 Oct 2012 04:41:32 +0000
parents 08a90b0e44e1
children
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 /**
33882
08a90b0e44e1 doxygen: drop filename from @file directive
diego
parents: 30554
diff changeset
20 * \file
21187
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
30554
321e9ea69b9f #include corresponding .h files in .c files.
diego
parents: 29263
diff changeset
30 #include "mmap_anon.h"
321e9ea69b9f #include corresponding .h files in .c files.
diego
parents: 29263
diff changeset
31
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
32 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
33 #define MAP_ANONYMOUS MAP_ANON
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
34 #endif
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
35
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
36 /*
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
37 * 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
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
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
40 */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28744
diff changeset
41
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
42 /**
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
43 * \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
44 * 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
45 * of the opened /dev/zero.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
46 *
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
47 * \param addr address to map at.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
48 * \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
49 * \param prot protections (region accessibility).
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
50 * \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
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
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
53 * \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
54 */
21248
2de480457872 Remove useless fd parameter for mmap_anon
reimar
parents: 21187
diff changeset
55 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
56 {
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
57 void *result;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
58
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
59 /* From loader/ext.c:
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
60 * "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
61 * 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
62 * 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
63 #if defined(MAP_SHARED) && defined(MAP_PRIVATE)
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
64 flags = (flags & ~MAP_SHARED) | MAP_PRIVATE;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
65 #endif /* defined(MAP_SHARED) && defined(MAP_PRIVATE) */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
66
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
67 #ifdef MAP_ANONYMOUS
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
68 /* BSD-style anonymous mapping */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
69 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
70 #else
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
71 /* SysV-style anonymous mapping */
24174
10f268ec0d87 warning fix:
diego
parents: 21855
diff changeset
72 int fd;
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
73 fd = open("/dev/zero", O_RDWR);
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
74 if(fd < 0){
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
75 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
76 return NULL;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
77 }
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
78
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
79 result = mmap(addr, len, prot, flags, fd, offset);
21248
2de480457872 Remove useless fd parameter for mmap_anon
reimar
parents: 21187
diff changeset
80 close(fd);
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
81 #endif /* MAP_ANONYMOUS */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
82
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
83 return result;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
84 }