My Project
Loading...
Searching...
No Matches
omMmap.c
Go to the documentation of this file.
1/*******************************************************************
2 * File: omMmap.c
3 * Purpose: implementing valloc via mmap
4 * Author: obachman (Olaf Bachmann)
5 * Created: 11/99
6 *******************************************************************/
7#include <unistd.h>
8#include <fcntl.h>
9#include <sys/mman.h>
10
11#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
12#define MAP_ANONYMOUS MAP_ANON
13#endif
14
15static inline void* omVallocMmap(size_t size)
16{
17 void* addr;
18#ifndef MAP_ANONYMOUS
19 static int fd = -1;
20#endif
21
22#ifdef MAP_ANONYMOUS
23#ifndef __CYGWIN__
24 /* under cygwin, MAP_PRIVATE|MAP_ANONYMOUS fails */
25 addr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
26#else
27 /* however, the following works */
28 addr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, -1, 0);
29#endif
30#else /* !MAP_ANONYMOUS */
31 if (fd < 0)
32 {
33 fd = open("/dev/zero", O_RDWR);
34 if (fd < 0) return NULL;
35 }
36 addr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
37#endif
38
39 if (addr == (void*) -1) return NULL;
40 return addr;
41}
42
43static inline int omVfreeMmap(void* addr, size_t size)
44{
45 return munmap(addr, size);
46}
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define NULL
Definition: omList.c:12
static int omVfreeMmap(void *addr, size_t size)
Definition: omMmap.c:43
static void * omVallocMmap(size_t size)
Definition: omMmap.c:15
int status int void size_t count int const void size_t count open
Definition: si_signals.h:73
int status int fd
Definition: si_signals.h:59