github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/mem_solaris.c (about)

     1  // Copyright 2010 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "runtime.h"
     6  #include "arch_GOARCH.h"
     7  #include "defs_GOOS_GOARCH.h"
     8  #include "os_GOOS.h"
     9  #include "malloc.h"
    10  #include "textflag.h"
    11  
    12  enum
    13  {
    14  	ENOMEM = 12,
    15  };
    16  
    17  #pragma textflag NOSPLIT
    18  void*
    19  runtime·sysAlloc(uintptr n, uint64 *stat)
    20  {
    21  	void *v;
    22  
    23  	v = runtime·mmap(nil, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
    24  	if(v < (void*)4096)
    25  		return nil;
    26  	runtime·xadd64(stat, n);
    27  	return v;
    28  }
    29  
    30  void
    31  runtime·SysUnused(void *v, uintptr n)
    32  {
    33  	USED(v);
    34  	USED(n);
    35  }
    36  
    37  void
    38  runtime·SysUsed(void *v, uintptr n)
    39  {
    40  	USED(v);
    41  	USED(n);
    42  }
    43  
    44  void
    45  runtime·SysFree(void *v, uintptr n, uint64 *stat)
    46  {
    47  	runtime·xadd64(stat, -(uint64)n);
    48  	runtime·munmap(v, n);
    49  }
    50  
    51  void
    52  runtime·SysFault(void *v, uintptr n)
    53  {
    54  	runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
    55  }
    56  
    57  void*
    58  runtime·SysReserve(void *v, uintptr n, bool *reserved)
    59  {
    60  	void *p;
    61  
    62  	// On 64-bit, people with ulimit -v set complain if we reserve too
    63  	// much address space.  Instead, assume that the reservation is okay
    64  	// and check the assumption in SysMap.
    65  	if(sizeof(void*) == 8 && n > 1LL<<32) {
    66  		*reserved = false;
    67  		return v;
    68  	}
    69  	
    70  	p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
    71  	if(p < (void*)4096)
    72  		return nil;
    73  	*reserved = true;
    74  	return p;
    75  }
    76  
    77  void
    78  runtime·SysMap(void *v, uintptr n, bool reserved, uint64 *stat)
    79  {
    80  	void *p;
    81  	
    82  	runtime·xadd64(stat, n);
    83  
    84  	// On 64-bit, we don't actually have v reserved, so tread carefully.
    85  	if(!reserved) {
    86  		p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
    87  		if(p == (void*)ENOMEM)
    88  			runtime·throw("runtime: out of memory");
    89  		if(p != v) {
    90  			runtime·printf("runtime: address space conflict: map(%p) = %p\n", v, p);
    91  			runtime·throw("runtime: address space conflict");
    92  		}
    93  		return;
    94  	}
    95  
    96  	p = runtime·mmap(v, n, PROT_READ|PROT_WRITE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0);
    97  	if(p == (void*)ENOMEM)
    98  		runtime·throw("runtime: out of memory");
    99  	if(p != v)
   100  		runtime·throw("runtime: cannot map pages in arena address space");
   101  }