~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/runtime/mem_freebsd.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
#include "os_GOOS.h"
9
9
#include "malloc.h"
10
10
 
 
11
enum
 
12
{
 
13
        ENOMEM = 12,
 
14
};
 
15
 
11
16
void*
12
17
runtime·SysAlloc(uintptr n)
13
18
{
14
19
        void *v;
15
20
 
16
21
        mstats.sys += n;
17
 
        v = runtime·mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
 
22
        v = runtime·mmap(nil, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
18
23
        if(v < (void*)4096)
19
24
                return nil;
20
25
        return v;
23
28
void
24
29
runtime·SysUnused(void *v, uintptr n)
25
30
{
26
 
        USED(v);
27
 
        USED(n);
28
 
        // TODO(rsc): call madvise MADV_DONTNEED
 
31
        runtime·madvise(v, n, MADV_FREE);
29
32
}
30
33
 
31
34
void
38
41
void*
39
42
runtime·SysReserve(void *v, uintptr n)
40
43
{
 
44
        void *p;
 
45
 
41
46
        // On 64-bit, people with ulimit -v set complain if we reserve too
42
47
        // much address space.  Instead, assume that the reservation is okay
43
48
        // and check the assumption in SysMap.
44
49
        if(sizeof(void*) == 8)
45
50
                return v;
46
51
        
47
 
        return runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
 
52
        p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
 
53
        if(p < (void*)4096)
 
54
                return nil;
 
55
        return p;
48
56
}
49
57
 
50
 
enum
51
 
{
52
 
        ENOMEM = 12,
53
 
};
54
 
 
55
58
void
56
59
runtime·SysMap(void *v, uintptr n)
57
60
{
61
64
 
62
65
        // On 64-bit, we don't actually have v reserved, so tread carefully.
63
66
        if(sizeof(void*) == 8) {
64
 
                p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
65
 
                if(p == (void*)-ENOMEM)
 
67
                p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
 
68
                if(p == (void*)ENOMEM)
66
69
                        runtime·throw("runtime: out of memory");
67
70
                if(p != v) {
68
71
                        runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p);
71
74
                return;
72
75
        }
73
76
 
74
 
        p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
75
 
        if(p == (void*)-ENOMEM)
 
77
        p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
 
78
        if(p == (void*)ENOMEM)
76
79
                runtime·throw("runtime: out of memory");
77
80
        if(p != v)
78
81
                runtime·throw("runtime: cannot map pages in arena address space");