]> Cypherpunks repositories - gostls13.git/commitdiff
cgo: enable cgo on netbsd/386 and netbsd/amd64
authorJoel Sing <jsing@google.com>
Mon, 4 Jun 2012 15:43:04 +0000 (01:43 +1000)
committerJoel Sing <jsing@google.com>
Mon, 4 Jun 2012 15:43:04 +0000 (01:43 +1000)
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6261056

doc/progs/run
misc/cgo/stdio/stdio_netbsd.go [new file with mode: 0644]
src/pkg/go/build/build.go
src/pkg/net/cgo_netbsd.go [new file with mode: 0644]
src/pkg/net/cgo_unix.go
src/pkg/os/user/lookup_unix.go
src/pkg/runtime/cgo/gcc_netbsd_386.c [new file with mode: 0644]
src/pkg/runtime/cgo/gcc_netbsd_amd64.c [new file with mode: 0644]

index 92c8da5cdcdb1c2001eeb6063e2b33fda3ca0033..48725d3289fde90c76cb3c1c16c4f98c30a8dce0 100755 (executable)
@@ -40,6 +40,11 @@ c_go_cgo="
 if [ "$goos" == "freebsd" ]; then
        c_go_cgo="cgo3 cgo4"
 fi
+# cgo1 and cgo2 don't run on netbsd, srandom has a different signature
+# cgo3 and cgo4 don't run on netbsd, since cgo cannot handle stdout correctly
+if [ "$goos" == "netbsd" ]; then
+       c_go_cgo=""
+fi
 
 timeout="
        timeout1
diff --git a/misc/cgo/stdio/stdio_netbsd.go b/misc/cgo/stdio/stdio_netbsd.go
new file mode 100644 (file)
index 0000000..075c1d0
--- /dev/null
@@ -0,0 +1,16 @@
+// 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.
+
+package stdio
+
+/*
+#include <stdio.h>
+
+extern FILE __sF[3];
+*/
+import "C"
+import "unsafe"
+
+var Stdout = (*File)(unsafe.Pointer(&C.__sF[1]))
+var Stderr = (*File)(unsafe.Pointer(&C.__sF[2]))
index dda4a13eb6bcb4010e636f86a470f1f77bbcd3a2..c3e0e8e69c809574134e92a39163ccf087e88705 100644 (file)
@@ -213,11 +213,13 @@ var Default Context = defaultContext()
 var cgoEnabled = map[string]bool{
        "darwin/386":    true,
        "darwin/amd64":  true,
+       "freebsd/386":   true,
+       "freebsd/amd64": true,
        "linux/386":     true,
        "linux/amd64":   true,
        "linux/arm":     true,
-       "freebsd/386":   true,
-       "freebsd/amd64": true,
+       "netbsd/386":    true,
+       "netbsd/amd64":  true,
        "windows/386":   true,
        "windows/amd64": true,
 }
diff --git a/src/pkg/net/cgo_netbsd.go b/src/pkg/net/cgo_netbsd.go
new file mode 100644 (file)
index 0000000..84ade59
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2011 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.
+
+// +build netbsd
+
+package net
+
+/*
+#include <netdb.h>
+*/
+import "C"
+
+func cgoAddrInfoFlags() C.int {
+<<<<<<< local
+       return C.AI_CANONNAME
+=======
+       return C.AI_CANONNAME | C.AI_V4MAPPED | C.AI_ALL
+>>>>>>> other
+}
index d703df992c51d176ee74e60c86e0f50d0bdcf8da..393fcee88ae7d8e54ee0805c4cf47755e8d9eda5 100644 (file)
@@ -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
+// +build darwin freebsd linux netbsd
 
 package net
 
index 241957c333cc00a5dae14bf394e25d8b65581185..2c53c953634b3cf1d3efd6b4d968afba11d9d1f2 100644 (file)
@@ -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
+// +build darwin freebsd linux netbsd
 // +build cgo
 
 package user
diff --git a/src/pkg/runtime/cgo/gcc_netbsd_386.c b/src/pkg/runtime/cgo/gcc_netbsd_386.c
new file mode 100644 (file)
index 0000000..3b4c750
--- /dev/null
@@ -0,0 +1,80 @@
+// 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 <pthread.h>
+#include <signal.h>
+#include "libcgo.h"
+
+static void* threadentry(void*);
+
+static void
+xinitcgo(G *g)
+{
+       pthread_attr_t attr;
+       size_t size;
+
+       pthread_attr_init(&attr);
+       pthread_attr_getstacksize(&attr, &size);
+       g->stackguard = (uintptr)&attr - size + 4096;
+       pthread_attr_destroy(&attr);
+}
+
+void (*initcgo)(G*) = xinitcgo;
+
+void
+libcgo_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;
+
+       /*
+        * libcgo_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.  On NetBSD/ELF, the thread local storage
+        * is just before %gs:0.  Our dynamic 8.out's reserve 8 bytes
+        * for the two words g and m at %gs:-8 and %gs:-4.
+        */
+       asm volatile (
+               "movl %0, %%gs:-8\n"    // MOVL g, -8(GS)
+               "movl %1, %%gs:-4\n"    // MOVL m, -4(GS)
+               :: "r"(ts.g), "r"(ts.m)
+       );
+
+       crosscall_386(ts.fn);
+       return nil;
+}
diff --git a/src/pkg/runtime/cgo/gcc_netbsd_amd64.c b/src/pkg/runtime/cgo/gcc_netbsd_amd64.c
new file mode 100644 (file)
index 0000000..2afcf02
--- /dev/null
@@ -0,0 +1,80 @@
+// 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 <pthread.h>
+#include <signal.h>
+#include "libcgo.h"
+
+static void* threadentry(void*);
+
+static void
+xinitcgo(G *g)
+{
+       pthread_attr_t attr;
+       size_t size;
+
+       pthread_attr_init(&attr);
+       pthread_attr_getstacksize(&attr, &size);
+       g->stackguard = (uintptr)&attr - size + 4096;
+       pthread_attr_destroy(&attr);
+}
+
+void (*initcgo)(G*) = xinitcgo;
+
+void
+libcgo_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;
+
+       /*
+        * libcgo_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.  On NetBSD/ELF, the thread local storage
+        * is just before %fs:0.  Our dynamic 6.out's reserve 16 bytes
+        * for the two words g and m at %fs:-16 and %fs:-8.
+        */
+       asm volatile (
+               "movq %0, %%fs:-16\n"   // MOVL g, -16(FS)
+               "movq %1, %%fs:-8\n"    // MOVL m, -8(FS)
+               :: "r"(ts.g), "r"(ts.m)
+       );
+       crosscall_amd64(ts.fn);
+       return nil;
+}