source: git/omalloc/omMmap.c @ 08a955

spielwiese
Last change on this file since 08a955 was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 1.1 KB
Line 
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 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 int omVfreeMmap(void* addr, size_t size)
44{
45  return munmap(addr, size);
46}
Note: See TracBrowser for help on using the repository browser.