annotate osdep/mmap_anon.c @ 22149:7b4f17dc2689

Avoid calling aspect on each frame and make ass subtitles work better with panscan
author reimar
date Tue, 06 Feb 2007 19:26:58 +0000
parents 936209c39ed1
children 10f268ec0d87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
1 /**
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
2 * \file mmap_anon.c
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
3 * \brief Provide a compatible anonymous space mapping function
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
4 */
21253
f2ddea0632d4 Disable when HAVE_SYS_MMAN_H is not defined, since it can not be compiled then.
reimar
parents: 21248
diff changeset
5 #include "config.h"
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
6
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
7 #include <stdio.h>
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
8 #include <unistd.h>
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
9 #include <fcntl.h>
21489
969de5b130ae fix include clash for mmap_anon on darwin ppc
nplourde
parents: 21253
diff changeset
10 #include <sys/mman.h>
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
11
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
12 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
13 #define MAP_ANONYMOUS MAP_ANON
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
14 #endif
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
15
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
16 /*
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
17 * 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
18 * 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
19 * of the opened /dev/zero.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
20 */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
21
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
22 /**
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
23 * \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
24 * 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
25 * of the opened /dev/zero.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
26 *
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
27 * \param addr address to map at.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
28 * \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
29 * \param prot protections (region accessibility).
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
30 * \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
31 * \param offset start mapping at byte offset.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
32 * \param zerofd
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
33 * \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
34 */
21248
2de480457872 Remove useless fd parameter for mmap_anon
reimar
parents: 21187
diff changeset
35 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
36 {
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
37 int fd;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
38 void *result;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
39
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
40 /* From loader/ext.c:
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
41 * "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
42 * 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
43 * 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
44 #if defined(MAP_SHARED) && defined(MAP_PRIVATE)
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
45 flags = (flags & ~MAP_SHARED) | MAP_PRIVATE;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
46 #endif /* defined(MAP_SHARED) && defined(MAP_PRIVATE) */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
47
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
48 #ifdef MAP_ANONYMOUS
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
49 /* BSD-style anonymous mapping */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
50 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
51 #else
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
52 /* SysV-style anonymous mapping */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
53 fd = open("/dev/zero", O_RDWR);
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
54 if(fd < 0){
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
55 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
56 return NULL;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
57 }
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 result = mmap(addr, len, prot, flags, fd, offset);
21248
2de480457872 Remove useless fd parameter for mmap_anon
reimar
parents: 21187
diff changeset
60 close(fd);
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
61 #endif /* MAP_ANONYMOUS */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
62
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
63 return result;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
64 }