gcc/libgo/runtime/go-trampoline.c
Ian Lance Taylor 7a9389330e Add Go frontend, libgo library, and Go testsuite.
gcc/:
	* gcc.c (default_compilers): Add entry for ".go".
	* common.opt: Add -static-libgo as a driver option.
	* doc/install.texi (Configuration): Mention libgo as an option for
	--enable-shared.  Mention go as an option for --enable-languages.
	* doc/invoke.texi (Overall Options): Mention .go as a file name
	suffix.  Mention go as a -x option.
	* doc/frontends.texi (G++ and GCC): Mention Go as a supported
	language.
	* doc/sourcebuild.texi (Top Level): Mention libgo.
	* doc/standards.texi (Standards): Add section on Go language.
	Move references for other languages into their own section.
	* doc/contrib.texi (Contributors): Mention that I contributed the
	Go frontend.
gcc/testsuite/:
	* lib/go.exp: New file.
	* lib/go-dg.exp: New file.
	* lib/go-torture.exp: New file.
	* lib/target-supports.exp (check_compile): Match // Go.

From-SVN: r167407
2010-12-03 04:34:57 +00:00

54 lines
1.4 KiB
C

/* go-trampoline.c -- allocate a trampoline for a nested function.
Copyright 2009 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
#include "config.h"
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#include "go-alloc.h"
#include "go-assert.h"
/* In order to build a trampoline we need space which is both writable
and executable. We currently just allocate a whole page. This
needs to be more system dependent. */
void *
__go_allocate_trampoline (size_t size, void *closure)
{
unsigned int page_size;
void *ret;
size_t off;
page_size = getpagesize ();
__go_assert (page_size >= size);
ret = __go_alloc (2 * page_size - 1);
ret = (void *) (((uintptr_t) ret + page_size - 1)
& ~ ((uintptr_t) page_size - 1));
/* Because the garbage collector only looks at correct address
offsets, we need to ensure that it will see the closure
address. */
off = ((size + sizeof (void *) - 1) / sizeof (void *)) * sizeof (void *);
__go_assert (size + off + sizeof (void *) <= page_size);
__builtin_memcpy (ret + off, &closure, sizeof (void *));
#ifdef HAVE_SYS_MMAN_H
{
int i;
i = mprotect (ret, size, PROT_READ | PROT_WRITE | PROT_EXEC);
__go_assert (i == 0);
}
#endif
return ret;
}