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
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"
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
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
7
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
8 #include <stdio.h>
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
9 #include <unistd.h>
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
10 #include <fcntl.h>
21489
969de5b130ae fix include clash for mmap_anon on darwin ppc
nplourde
parents: 21253
diff changeset
11 #include <sys/mman.h>
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
12
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
13 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
14 #define MAP_ANONYMOUS MAP_ANON
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
15 #endif
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 /*
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
18 * 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
19 * 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
20 * of the opened /dev/zero.
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 /**
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
24 * \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
25 * 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
26 * of the opened /dev/zero.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
27 *
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
28 * \param addr address to map at.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
29 * \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
30 * \param prot protections (region accessibility).
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
31 * \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
32 * \param offset start mapping at byte offset.
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
33 * \param zerofd
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
34 * \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
35 */
21248
2de480457872 Remove useless fd parameter for mmap_anon
reimar
parents: 21187
diff changeset
36 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
37 {
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
38 int fd;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
39 void *result;
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 /* From loader/ext.c:
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
42 * "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
43 * 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
44 * 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
45 #if defined(MAP_SHARED) && defined(MAP_PRIVATE)
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
46 flags = (flags & ~MAP_SHARED) | MAP_PRIVATE;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
47 #endif /* defined(MAP_SHARED) && defined(MAP_PRIVATE) */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
48
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
49 #ifdef MAP_ANONYMOUS
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
50 /* BSD-style anonymous mapping */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
51 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
52 #else
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
53 /* SysV-style anonymous mapping */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
54 fd = open("/dev/zero", O_RDWR);
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
55 if(fd < 0){
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
56 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
57 return NULL;
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
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
60 result = mmap(addr, len, prot, flags, fd, offset);
21248
2de480457872 Remove useless fd parameter for mmap_anon
reimar
parents: 21187
diff changeset
61 close(fd);
21187
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
62 #endif /* MAP_ANONYMOUS */
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
63
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
64 return result;
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
65 }
d9cedf7b8069 added mmap_anon to osdep lib. Used in loader for now
nplourde
parents:
diff changeset
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 */