diff options
Diffstat (limited to 'src/pkg/runtime/cgo')
-rw-r--r-- | src/pkg/runtime/cgo/cgo.go | 1 | ||||
-rw-r--r-- | src/pkg/runtime/cgo/dragonfly.c | 13 | ||||
-rw-r--r-- | src/pkg/runtime/cgo/gcc_dragonfly_386.c | 77 | ||||
-rw-r--r-- | src/pkg/runtime/cgo/gcc_dragonfly_amd64.c | 77 | ||||
-rw-r--r-- | src/pkg/runtime/cgo/gcc_setenv.c | 2 | ||||
-rw-r--r-- | src/pkg/runtime/cgo/setenv.c | 2 |
6 files changed, 170 insertions, 2 deletions
diff --git a/src/pkg/runtime/cgo/cgo.go b/src/pkg/runtime/cgo/cgo.go index e0d538668..258b6fba1 100644 --- a/src/pkg/runtime/cgo/cgo.go +++ b/src/pkg/runtime/cgo/cgo.go @@ -12,6 +12,7 @@ package cgo /* #cgo darwin LDFLAGS: -lpthread +#cgo dragonfly LDFLAGS: -lpthread #cgo freebsd LDFLAGS: -lpthread #cgo linux LDFLAGS: -lpthread #cgo netbsd LDFLAGS: -lpthread diff --git a/src/pkg/runtime/cgo/dragonfly.c b/src/pkg/runtime/cgo/dragonfly.c new file mode 100644 index 000000000..acf53e265 --- /dev/null +++ b/src/pkg/runtime/cgo/dragonfly.c @@ -0,0 +1,13 @@ +// Copyright 2010 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. + +// Supply environ and __progname, because we don't +// link against the standard DragonFly crt0.o and the +// libc dynamic library needs them. + +char *environ[1]; +char *__progname; + +#pragma dynexport environ environ +#pragma dynexport __progname __progname diff --git a/src/pkg/runtime/cgo/gcc_dragonfly_386.c b/src/pkg/runtime/cgo/gcc_dragonfly_386.c new file mode 100644 index 000000000..6797824c6 --- /dev/null +++ b/src/pkg/runtime/cgo/gcc_dragonfly_386.c @@ -0,0 +1,77 @@ +// 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 <sys/types.h> +#include <sys/signalvar.h> +#include <pthread.h> +#include <signal.h> +#include <string.h> +#include "libcgo.h" + +static void* threadentry(void*); +static void (*setmg_gcc)(void*, void*); + +void +x_cgo_init(G *g, void (*setmg)(void*, void*)) +{ + pthread_attr_t attr; + size_t size; + + setmg_gcc = setmg; + pthread_attr_init(&attr); + pthread_attr_getstacksize(&attr, &size); + g->stackguard = (uintptr)&attr - size + 4096; + pthread_attr_destroy(&attr); +} + + +void +_cgo_sys_thread_start(ThreadStart *ts) +{ + pthread_attr_t attr; + sigset_t ign, oset; + pthread_t p; + size_t size; + int err; + + SIGFILLSET(ign); + sigprocmask(SIG_SETMASK, &ign, &oset); + + pthread_attr_init(&attr); + pthread_attr_getstacksize(&attr, &size); + ts->g->stackguard = size; + err = pthread_create(&p, &attr, threadentry, ts); + + sigprocmask(SIG_SETMASK, &oset, nil); + + if (err != 0) { + fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err)); + abort(); + } +} + +static void* +threadentry(void *v) +{ + ThreadStart ts; + + ts = *(ThreadStart*)v; + free(v); + + ts.g->stackbase = (uintptr)&ts; + + /* + * _cgo_sys_thread_start set stackguard to stack size; + * change to actual guard pointer. + */ + ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096; + + /* + * Set specific keys. + */ + setmg_gcc((void*)ts.m, (void*)ts.g); + + crosscall_386(ts.fn); + return nil; +} diff --git a/src/pkg/runtime/cgo/gcc_dragonfly_amd64.c b/src/pkg/runtime/cgo/gcc_dragonfly_amd64.c new file mode 100644 index 000000000..eb342a2ff --- /dev/null +++ b/src/pkg/runtime/cgo/gcc_dragonfly_amd64.c @@ -0,0 +1,77 @@ +// 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 <sys/types.h> +#include <sys/signalvar.h> +#include <pthread.h> +#include <signal.h> +#include <string.h> +#include "libcgo.h" + +static void* threadentry(void*); +static void (*setmg_gcc)(void*, void*); + +void +x_cgo_init(G *g, void (*setmg)(void*, void*)) +{ + pthread_attr_t attr; + size_t size; + + setmg_gcc = setmg; + pthread_attr_init(&attr); + pthread_attr_getstacksize(&attr, &size); + g->stackguard = (uintptr)&attr - size + 4096; + pthread_attr_destroy(&attr); +} + +void +_cgo_sys_thread_start(ThreadStart *ts) +{ + pthread_attr_t attr; + sigset_t ign, oset; + pthread_t p; + size_t size; + int err; + + SIGFILLSET(ign); + sigprocmask(SIG_SETMASK, &ign, &oset); + + pthread_attr_init(&attr); + pthread_attr_getstacksize(&attr, &size); + + ts->g->stackguard = size; + err = pthread_create(&p, &attr, threadentry, ts); + + sigprocmask(SIG_SETMASK, &oset, nil); + + if (err != 0) { + fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err)); + abort(); + } +} + +static void* +threadentry(void *v) +{ + ThreadStart ts; + + ts = *(ThreadStart*)v; + free(v); + + ts.g->stackbase = (uintptr)&ts; + + /* + * _cgo_sys_thread_start set stackguard to stack size; + * change to actual guard pointer. + */ + ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096; + + /* + * Set specific keys. + */ + setmg_gcc((void*)ts.m, (void*)ts.g); + + crosscall_amd64(ts.fn); + return nil; +} diff --git a/src/pkg/runtime/cgo/gcc_setenv.c b/src/pkg/runtime/cgo/gcc_setenv.c index a0938166d..8b128b946 100644 --- a/src/pkg/runtime/cgo/gcc_setenv.c +++ b/src/pkg/runtime/cgo/gcc_setenv.c @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin freebsd linux netbsd openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd #include "libcgo.h" diff --git a/src/pkg/runtime/cgo/setenv.c b/src/pkg/runtime/cgo/setenv.c index 4c47cdb00..2d03db09f 100644 --- a/src/pkg/runtime/cgo/setenv.c +++ b/src/pkg/runtime/cgo/setenv.c @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin freebsd linux netbsd openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd #pragma cgo_import_static x_cgo_setenv |