@@ -236,6 +236,12 @@
testing/quick.gox \
testing/script.gox
+if HAVE_SYS_MMAN_H
+runtime_mem_file = runtime/mem.c
+else
+runtime_mem_file = runtime/mem_posix_memalign.c
+endif
+
runtime_files = \
runtime/go-bad-index.c \
runtime/go-byte-array-to-string.c \
@@ -313,7 +319,7 @@
runtime/go-unwind.c \
runtime/mcache.c \
runtime/mcentral.c \
- runtime/mem.c \
+ $(runtime_mem_file) \
runtime/mfinal.c \
runtime/mfixalloc.c \
runtime/mgc0.c \
@@ -185,6 +185,7 @@
GCC_CHECK_UNWIND_GETIPINFO
AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/user.h)
+AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes)
AC_CHECK_FUNCS(srandom random strsignal)
CFLAGS_hold=$CFLAGS
@@ -0,0 +1,35 @@
+#include <errno.h>
+
+#include "runtime.h"
+#include "malloc.h"
+
+void*
+SysAlloc(uintptr n)
+{
+ void *p;
+
+ mstats.sys += n;
+ errno = posix_memalign(&p, PageSize, n);
+ if (errno > 0) {
+ perror("posix_memalign");
+ exit(2);
+ }
+ return p;
+}
+
+void
+SysUnused(void *v, uintptr n)
+{
+ USED(v);
+ USED(n);
+ // TODO(rsc): call madvise MADV_DONTNEED
+}
+
+void
+SysFree(void *v, uintptr n)
+{
+ USED(v);
+ USED(n);
+ // TODO(rsc): call munmap
+}
+
@@ -126,12 +126,5 @@
MCache* allocmcache(void);
void free(void *v);
void addfinalizer(void*, void(*fn)(void*), int32);
-
-#ifdef HAVE_SYS_MMAN_H
#define runtime_mmap mmap
-#else
-#define runtime_mmap(start, len, prot, flags, fd, offset) malloc(len)
-#define MAP_FAILED NULL
-#endif
-
#define cas(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)