File: msbrk.c

package info (click to toggle)
gcl27 2.7.1-13
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 30,888 kB
  • sloc: lisp: 211,946; ansic: 52,944; sh: 9,347; makefile: 647; tcl: 53; awk: 52
file content (77 lines) | stat: -rw-r--r-- 1,412 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#define _GNU_SOURCE
#include <sys/mman.h>

#include "include.h"

static void *m;
static ufixnum sz,mps;

int
msbrk_end(void) {

  sz+=(ufixnum)m;
  mps=sz;
  m=NULL;

  return 0;

}

#if !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__)/*FIXME*/

static void *
new_map(void *v,ufixnum s) {
  return mmap(v,s,PROT_READ|PROT_WRITE|PROT_EXEC,MAP_PRIVATE|MAP_ANON|MAP_FIXED,-1,0);
}

#if defined(DARWIN)
/*This initial heap must be large enough to initialize the raw image,
  but not so large that the Mac linker ignores the segment designation
  and creates a __huge section under __DATA for this and other
  variables.  We enlarge this on unexec.*/
asm (".zerofill __HEAP,__heap,__end,0x70000000\n\t.globl __end");
#endif

int
msbrk_init(void) {

  if (!m) {

    extern int gcl_alloc_initialized;
    extern fixnum _end;
    void *v;

    v=gcl_alloc_initialized ? core_end : (void *)ROUNDUP((void *)&_end,getpagesize());
    m=(void *)ROUNDUP((ufixnum)v,PAGESIZE);
    massert(!gcl_alloc_initialized || v==m);

    if (v!=m)
      massert(new_map(v,m-v)!=(void *)-1);
    mps=sz=0;

  }
  
  return 0;

}

void *
msbrk(intptr_t inc) {

  size_t p2=ROUNDUP(sz+inc,PAGESIZE);

  if (mps<p2) {
    if (m+mps!=new_map(m+mps,p2-mps))
      return (void *)-1;
#ifdef HAVE_MADVISE_HUGEPAGE
    massert(!madvise(m,p2,MADV_HUGEPAGE));
#endif
    mps=p2;
  }

  sz+=inc;
  return m+sz-inc;

}

#endif