My Project
Loading...
Searching...
No Matches
Functions
omMmap.c File Reference
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>

Go to the source code of this file.

Functions

static void * omVallocMmap (size_t size)
 
static int omVfreeMmap (void *addr, size_t size)
 

Function Documentation

◆ omVallocMmap()

static void * omVallocMmap ( size_t  size)
inlinestatic

Definition at line 15 of file omMmap.c.

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}
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
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

◆ omVfreeMmap()

static int omVfreeMmap ( void *  addr,
size_t  size 
)
inlinestatic

Definition at line 43 of file omMmap.c.

44{
45 return munmap(addr, size);
46}