From patchwork Tue Jun 15 14:15:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 55673 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 63399B7D6D for ; Wed, 16 Jun 2010 00:16:27 +1000 (EST) Received: (qmail 19611 invoked by alias); 15 Jun 2010 14:16:24 -0000 Received: (qmail 19596 invoked by uid 22791); 15 Jun 2010 14:16:22 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Jun 2010 14:16:16 +0000 Received: from hpaq12.eem.corp.google.com (hpaq12.eem.corp.google.com [172.25.149.12]) by smtp-out.google.com with ESMTP id o5FEGB73002037 for ; Tue, 15 Jun 2010 07:16:14 -0700 Received: from pwi6 (pwi6.prod.google.com [10.241.219.6]) by hpaq12.eem.corp.google.com with ESMTP id o5FEFA4h000441 for ; Tue, 15 Jun 2010 07:16:10 -0700 Received: by pwi6 with SMTP id 6so3373175pwi.40 for ; Tue, 15 Jun 2010 07:16:10 -0700 (PDT) Received: by 10.115.28.1 with SMTP id f1mr5776446waj.181.1276611369736; Tue, 15 Jun 2010 07:16:09 -0700 (PDT) Received: from coign.google.com ([67.218.105.233]) by mx.google.com with ESMTPS id n32sm68802291wae.22.2010.06.15.07.16.07 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 15 Jun 2010 07:16:08 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [gccgo] In absence of mmap, use posix_memalign and not malloc From: Ian Lance Taylor Date: Tue, 15 Jun 2010 07:15:56 -0700 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch from Vinu Rajashekhar fixes libgo to use posix_memalign rather than malloc when mmap is not available. Otherwise the alignment expected by malloc is not available. Committed to gccgo branch. Ian diff -r 6462cc9e6b81 libgo/Makefile.am --- a/libgo/Makefile.am Sun Jun 13 23:12:53 2010 -0700 +++ b/libgo/Makefile.am Tue Jun 15 07:13:56 2010 -0700 @@ -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 \ diff -r 6462cc9e6b81 libgo/configure.ac --- a/libgo/configure.ac Sun Jun 13 23:12:53 2010 -0700 +++ b/libgo/configure.ac Tue Jun 15 07:13:56 2010 -0700 @@ -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 diff -r 6462cc9e6b81 libgo/runtime/mem_posix_memalign.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgo/runtime/mem_posix_memalign.c Tue Jun 15 07:13:56 2010 -0700 @@ -0,0 +1,35 @@ +#include + +#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 +} + diff -r 6462cc9e6b81 libgo/runtime/runtime.h --- a/libgo/runtime/runtime.h Sun Jun 13 23:12:53 2010 -0700 +++ b/libgo/runtime/runtime.h Tue Jun 15 07:13:56 2010 -0700 @@ -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)