Back to index

plt-scheme  4.2.1
Functions | Variables
vm_mmap.c File Reference
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include "alloc_cache.c"
#include "rlimit_heapsize.c"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static void os_vm_free_pages (void *p, size_t len)
static voidos_vm_alloc_pages (size_t len)
static void vm_protect_pages (void *p, size_t len, int writeable)

Variables

static long page_size

Function Documentation

static void* os_vm_alloc_pages ( size_t  len) [static]

Definition at line 27 of file vm_mmap.c.

{
  void *r;

#ifndef MAP_ANON
  static int fd;
  static int fd_created;

  if (!fd_created) {
    fd_created = 1;
    fd = open("/dev/zero", O_RDWR);
  }
#endif

  /* Round up to nearest page: */
  if (len & (page_size - 1))
    len += page_size - (len & (page_size - 1));

#ifdef MAP_ANON
  r = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
#else
  r = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
#endif

  if (r  == (void *)-1)
    return NULL;

  return r;
}

Here is the caller graph for this function:

static void os_vm_free_pages ( void p,
size_t  len 
) [static]

Definition at line 20 of file vm_mmap.c.

{
  if (munmap(p, len)) {
    GCPRINT(GCOUTF, "Unmap warning: %lx, %ld, %d\n", (long)p, (long)len, errno);
  }
}

Here is the caller graph for this function:

static void vm_protect_pages ( void p,
size_t  len,
int  writeable 
) [static]

Definition at line 58 of file vm_mmap.c.

{
  if (len & (page_size - 1)) {
    len += page_size - (len & (page_size - 1));
  }

  mprotect(p, len, (writeable ? (PROT_READ | PROT_WRITE) : PROT_READ));
}

Variable Documentation

long page_size [static]

Definition at line 18 of file vm_mmap.c.