Loading...
Searching...
No Matches
omMmap.c
Go to the documentation of this file.
/*******************************************************************
* File: omMmap.c
* Purpose: implementing valloc via mmap
* Author: obachman (Olaf Bachmann)
* Created: 11/99
*******************************************************************/
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS MAP_ANON
#endif
static inline void* omVallocMmap(size_t size)
{
void* addr;
#ifndef MAP_ANONYMOUS
static int fd = -1;
#endif
#ifdef MAP_ANONYMOUS
#ifndef __CYGWIN__
/* under cygwin, MAP_PRIVATE|MAP_ANONYMOUS fails */
addr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
#else
/* however, the following works */
addr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, -1, 0);
#endif
#else /* !MAP_ANONYMOUS */
if (fd < 0)
{
fd = open("/dev/zero", O_RDWR);
if (fd < 0) return NULL;
}
addr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
#endif
if (addr == (void*) -1) return NULL;
return addr;
}
static inline int omVfreeMmap(void* addr, size_t size)
{
return munmap(addr, size);
}
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
NULL
#define NULL
Definition omList.c:12
omVfreeMmap
static int omVfreeMmap(void *addr, size_t size)
Definition omMmap.c:43
omVallocMmap
static void * omVallocMmap(size_t size)
Definition omMmap.c:15
fd
int status int fd
Definition si_signals.h:69
open
int status int void size_t count open
Definition si_signals.h:83