source: git/omalloc/omMmap.c @ e467ae

fieker-DuValspielwiese
Last change on this file since e467ae was e70e45, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* re-added files git-svn-id: file:///usr/local/Singular/svn/trunk@4521 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1017 bytes
Line 
1/*******************************************************************
2 *  File:    omMmap.c
3 *  Purpose: implementing valloc via mmap
4 *  Author:  obachman (Olaf Bachmann)
5 *  Created: 11/99
6 *  Version: $Id: omMmap.c,v 1.3 2000-08-14 12:26:47 obachman Exp $
7 *******************************************************************/
8#include <unistd.h>
9#include <fcntl.h>
10#include <sys/mman.h>
11
12#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
13#define MAP_ANONYMOUS MAP_ANON
14#endif
15
16static void* omVallocMmap(size_t size)
17{
18  void* addr;
19#ifndef MAP_ANONYMOUS
20  static int fd = -1;
21#endif
22
23#ifdef MAP_ANONYMOUS
24  addr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
25#else /* !MAP_ANONYMOUS */
26  if (fd < 0) 
27  {
28    fd = open("/dev/zero", O_RDWR);
29    if (fd < 0) return NULL;
30  }
31  addr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
32#endif
33 
34  if (addr == (void*) -1) return NULL;
35  return addr;
36}
37
38static int omVfreeMmap(void* addr, size_t size)
39{
40  return munmap(addr, size);
41}
42
43
Note: See TracBrowser for help on using the repository browser.