1
0
mirror of https://github.com/golang/go synced 2024-11-24 23:57:57 -07:00

cgo: enable cgo on netbsd/386 and netbsd/amd64

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6261056
This commit is contained in:
Joel Sing 2012-06-05 01:43:04 +10:00
parent b945b741e1
commit 5131deeeb2
8 changed files with 207 additions and 4 deletions

View File

@ -40,6 +40,11 @@ c_go_cgo="
if [ "$goos" == "freebsd" ]; then if [ "$goos" == "freebsd" ]; then
c_go_cgo="cgo3 cgo4" c_go_cgo="cgo3 cgo4"
fi 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=" timeout="
timeout1 timeout1

View File

@ -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]))

View File

@ -213,11 +213,13 @@ var Default Context = defaultContext()
var cgoEnabled = map[string]bool{ var cgoEnabled = map[string]bool{
"darwin/386": true, "darwin/386": true,
"darwin/amd64": true, "darwin/amd64": true,
"freebsd/386": true,
"freebsd/amd64": true,
"linux/386": true, "linux/386": true,
"linux/amd64": true, "linux/amd64": true,
"linux/arm": true, "linux/arm": true,
"freebsd/386": true, "netbsd/386": true,
"freebsd/amd64": true, "netbsd/amd64": true,
"windows/386": true, "windows/386": true,
"windows/amd64": true, "windows/amd64": true,
} }

20
src/pkg/net/cgo_netbsd.go Normal file
View File

@ -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
}

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build darwin freebsd linux // +build darwin freebsd linux netbsd
package net package net

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build darwin freebsd linux // +build darwin freebsd linux netbsd
// +build cgo // +build cgo
package user package user

View File

@ -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;
}

View File

@ -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;
}