github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/runtime/mem_posix_memalign.c (about)

     1  #include <errno.h>
     2  
     3  #include "runtime.h"
     4  #include "arch.h"
     5  #include "malloc.h"
     6  
     7  void*
     8  runtime_SysAlloc(uintptr n)
     9  {
    10  	void *p;
    11  
    12  	mstats.sys += n;
    13  	errno = posix_memalign(&p, PageSize, n);
    14  	if (errno > 0) {
    15  		perror("posix_memalign");
    16  		exit(2);
    17  	}
    18  	return p;
    19  }
    20  
    21  void
    22  runtime_SysUnused(void *v, uintptr n)
    23  {
    24  	USED(v);
    25  	USED(n);
    26  	// TODO(rsc): call madvise MADV_DONTNEED
    27  }
    28  
    29  void
    30  runtime_SysFree(void *v, uintptr n)
    31  {
    32  	mstats.sys -= n;
    33  	free(v);
    34  }
    35  
    36  void*
    37  runtime_SysReserve(void *v, uintptr n)
    38  {
    39  	USED(v);
    40  	return runtime_SysAlloc(n);
    41  }
    42  
    43  void
    44  runtime_SysMap(void *v, uintptr n)
    45  {
    46  	USED(v);
    47  	USED(n);
    48  }