Mercurial > mplayer.hg
annotate osdep/mmap_anon.c @ 21805:924da043b8ce
Use av_d2q to produce the fps fraction, this usually produces more sane fractions
and works right also for extreme values that otherwise would over- or underflow.
author | reimar |
---|---|
date | Thu, 04 Jan 2007 19:41:41 +0000 |
parents | 969de5b130ae |
children | 936209c39ed1 |
rev | line source |
---|---|
21187 | 1 /** |
2 * \file mmap_anon.c | |
3 * \brief Provide a compatible anonymous space mapping function | |
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" |
f2ddea0632d4
Disable when HAVE_SYS_MMAN_H is not defined, since it can not be compiled then.
reimar
parents:
21248
diff
changeset
|
6 #ifdef HAVE_SYS_MMAN_H |
21187 | 7 |
8 #include <stdio.h> | |
9 #include <unistd.h> | |
10 #include <fcntl.h> | |
21489 | 11 #include <sys/mman.h> |
21187 | 12 |
13 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) | |
14 #define MAP_ANONYMOUS MAP_ANON | |
15 #endif | |
16 | |
17 /* | |
18 * mmap() anonymous space, depending on the system's mmap() style. On systems | |
19 * that use the /dev/zero mapping idiom, zerofd will be set to the file descriptor | |
20 * of the opened /dev/zero. | |
21 */ | |
22 | |
23 /** | |
24 * \brief mmap() anonymous space, depending on the system's mmap() style. On systems | |
25 * that use the /dev/zero mapping idiom, zerofd will be set to the file descriptor | |
26 * of the opened /dev/zero. | |
27 * | |
28 * \param addr address to map at. | |
29 * \param len number of bytes from addr to be mapped. | |
30 * \param prot protections (region accessibility). | |
31 * \param flags specifies the type of the mapped object. | |
32 * \param offset start mapping at byte offset. | |
33 * \param zerofd | |
34 * \return a pointer to the mapped region upon successful completion, -1 otherwise. | |
35 */ | |
21248 | 36 void *mmap_anon(void *addr, size_t len, int prot, int flags, off_t offset) |
21187 | 37 { |
38 int fd; | |
39 void *result; | |
40 | |
41 /* From loader/ext.c: | |
42 * "Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap" | |
43 * Therefore we preserve the same behavior on all platforms, ie. no | |
44 * shared mappings of anon space (if the concepts are supported). */ | |
45 #if defined(MAP_SHARED) && defined(MAP_PRIVATE) | |
46 flags = (flags & ~MAP_SHARED) | MAP_PRIVATE; | |
47 #endif /* defined(MAP_SHARED) && defined(MAP_PRIVATE) */ | |
48 | |
49 #ifdef MAP_ANONYMOUS | |
50 /* BSD-style anonymous mapping */ | |
51 result = mmap(addr, len, prot, flags | MAP_ANONYMOUS, -1, offset); | |
52 #else | |
53 /* SysV-style anonymous mapping */ | |
54 fd = open("/dev/zero", O_RDWR); | |
55 if(fd < 0){ | |
56 perror( "Cannot open /dev/zero for READ+WRITE. Check permissions! error: "); | |
57 return NULL; | |
58 } | |
59 | |
60 result = mmap(addr, len, prot, flags, fd, offset); | |
21248 | 61 close(fd); |
21187 | 62 #endif /* MAP_ANONYMOUS */ |
63 | |
64 return result; | |
65 } | |
66 | |
21253
f2ddea0632d4
Disable when HAVE_SYS_MMAN_H is not defined, since it can not be compiled then.
reimar
parents:
21248
diff
changeset
|
67 #endif /* HAVE_SYS_MMAN_H */ |