diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libgo/runtime/go-trampoline.c | |
download | cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.bz2 cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libgo/runtime/go-trampoline.c')
-rw-r--r-- | libgo/runtime/go-trampoline.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/libgo/runtime/go-trampoline.c b/libgo/runtime/go-trampoline.c new file mode 100644 index 000000000..43003e81c --- /dev/null +++ b/libgo/runtime/go-trampoline.c @@ -0,0 +1,53 @@ +/* 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; +} |