diff options
author | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
---|---|---|
committer | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
commit | f154da9e12608589e8d5f0508f908a0c3e88a1bb (patch) | |
tree | f8255d51e10c6f1e0ed69702200b966c9556a431 /src/pkg/runtime/cgo | |
parent | 8d8329ed5dfb9622c82a9fbec6fd99a580f9c9f6 (diff) | |
download | golang-upstream/1.4.tar.gz |
Imported Upstream version 1.4upstream/1.4
Diffstat (limited to 'src/pkg/runtime/cgo')
35 files changed, 0 insertions, 2207 deletions
diff --git a/src/pkg/runtime/cgo/asm_386.s b/src/pkg/runtime/cgo/asm_386.s deleted file mode 100644 index ab2f1d17a..000000000 --- a/src/pkg/runtime/cgo/asm_386.s +++ /dev/null @@ -1,31 +0,0 @@ -// 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 "../../../cmd/ld/textflag.h" - -/* - * void crosscall2(void (*fn)(void*, int32), void*, int32) - * Save registers and call fn with two arguments. - */ -TEXT crosscall2(SB),NOSPLIT,$0 - PUSHL BP - MOVL SP, BP - PUSHL BX - PUSHL SI - PUSHL DI - - SUBL $8, SP - MOVL 16(BP), AX - MOVL AX, 4(SP) - MOVL 12(BP), AX - MOVL AX, 0(SP) - MOVL 8(BP), AX - CALL AX - ADDL $8, SP - - POPL DI - POPL SI - POPL BX - POPL BP - RET diff --git a/src/pkg/runtime/cgo/asm_amd64.s b/src/pkg/runtime/cgo/asm_amd64.s deleted file mode 100644 index 64f719ab1..000000000 --- a/src/pkg/runtime/cgo/asm_amd64.s +++ /dev/null @@ -1,47 +0,0 @@ -// 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 "../../../cmd/ld/textflag.h" - -/* - * void crosscall2(void (*fn)(void*, int32), void*, int32) - * Save registers and call fn with two arguments. - */ -TEXT crosscall2(SB),NOSPLIT,$0 - SUBQ $0x58, SP /* keeps stack pointer 32-byte aligned */ - MOVQ BX, 0x10(SP) - MOVQ BP, 0x18(SP) - MOVQ R12, 0x20(SP) - MOVQ R13, 0x28(SP) - MOVQ R14, 0x30(SP) - MOVQ R15, 0x38(SP) - -#ifdef GOOS_windows - // Win64 save RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15 - MOVQ DI, 0x40(SP) - MOVQ SI, 0x48(SP) - - MOVQ DX, 0(SP) /* arg */ - MOVQ R8, 8(SP) /* argsize (includes padding) */ - - CALL CX /* fn */ - - MOVQ 0x40(SP), DI - MOVQ 0x48(SP), SI -#else - MOVQ SI, 0(SP) /* arg */ - MOVQ DX, 8(SP) /* argsize (includes padding) */ - - CALL DI /* fn */ -#endif - - MOVQ 0x10(SP), BX - MOVQ 0x18(SP), BP - MOVQ 0x20(SP), R12 - MOVQ 0x28(SP), R13 - MOVQ 0x30(SP), R14 - MOVQ 0x38(SP), R15 - - ADDQ $0x58, SP - RET diff --git a/src/pkg/runtime/cgo/asm_arm.s b/src/pkg/runtime/cgo/asm_arm.s deleted file mode 100644 index 850b1c6b6..000000000 --- a/src/pkg/runtime/cgo/asm_arm.s +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2012 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 "../../../cmd/ld/textflag.h" - -/* - * void crosscall2(void (*fn)(void*, int32), void*, int32) - * Save registers and call fn with two arguments. - */ -TEXT crosscall2(SB),NOSPLIT,$-4 - /* - * We still need to save all callee save register as before, and then - * push 2 args for fn (R1 and R2). - * Also note that at procedure entry in 5c/5g world, 4(R13) will be the - * first arg, so we must push another dummy reg (R0) for 0(R13). - * Additionally, runtime·load_gm will clobber R0, so we need to save R0 - * nevertheless. - */ - MOVM.WP [R0, R1, R2, R4, R5, R6, R7, R8, m, g, R11, R12, R14], (R13) - BL runtime·load_gm(SB) - MOVW PC, R14 - MOVW 0(R13), PC - MOVM.IAW (R13), [R0, R1, R2, R4, R5, R6, R7, R8, m, g, R11, R12, PC] diff --git a/src/pkg/runtime/cgo/asm_nacl_amd64p32.s b/src/pkg/runtime/cgo/asm_nacl_amd64p32.s deleted file mode 100644 index 377cf72a3..000000000 --- a/src/pkg/runtime/cgo/asm_nacl_amd64p32.s +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2013 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 "../../../cmd/ld/textflag.h" - -/* - * void crosscall2(void (*fn)(void*, int32), void*, int32) - * Save registers and call fn with two arguments. - */ -TEXT crosscall2(SB),NOSPLIT,$0 - INT $3 - RET diff --git a/src/pkg/runtime/cgo/callbacks.c b/src/pkg/runtime/cgo/callbacks.c deleted file mode 100644 index e91c8bf8a..000000000 --- a/src/pkg/runtime/cgo/callbacks.c +++ /dev/null @@ -1,102 +0,0 @@ -// 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. - -#include "../runtime.h" -#include "../cgocall.h" -#include "../../../cmd/ld/textflag.h" - -// These utility functions are available to be called from code -// compiled with gcc via crosscall2. - -// The declaration of crosscall2 is: -// void crosscall2(void (*fn)(void *, int), void *, int); -// -// We need to export the symbol crosscall2 in order to support -// callbacks from shared libraries. This applies regardless of -// linking mode. -#pragma cgo_export_static crosscall2 -#pragma cgo_export_dynamic crosscall2 - -// Allocate memory. This allocates the requested number of bytes in -// memory controlled by the Go runtime. The allocated memory will be -// zeroed. You are responsible for ensuring that the Go garbage -// collector can see a pointer to the allocated memory for as long as -// it is valid, e.g., by storing a pointer in a local variable in your -// C function, or in memory allocated by the Go runtime. If the only -// pointers are in a C global variable or in memory allocated via -// malloc, then the Go garbage collector may collect the memory. - -// Call like this in code compiled with gcc: -// struct { size_t len; void *ret; } a; -// a.len = /* number of bytes to allocate */; -// crosscall2(_cgo_allocate, &a, sizeof a); -// /* Here a.ret is a pointer to the allocated memory. */ - -static void -_cgo_allocate_internal(uintptr len, byte *ret) -{ - CgoMal *c; - - ret = runtime·mal(len); - c = runtime·mal(sizeof(*c)); - c->next = m->cgomal; - c->alloc = ret; - m->cgomal = c; - FLUSH(&ret); -} - -#pragma cgo_export_static _cgo_allocate -#pragma cgo_export_dynamic _cgo_allocate -#pragma textflag NOSPLIT -void -_cgo_allocate(void *a, int32 n) -{ - runtime·cgocallback((void(*)(void))_cgo_allocate_internal, a, n); -} - -// Panic. The argument is converted into a Go string. - -// Call like this in code compiled with gcc: -// struct { const char *p; } a; -// a.p = /* string to pass to panic */; -// crosscall2(_cgo_panic, &a, sizeof a); -// /* The function call will not return. */ - -extern void ·cgoStringToEface(String, Eface*); - -static void -_cgo_panic_internal(byte *p) -{ - String s; - Eface err; - - s = runtime·gostring(p); - ·cgoStringToEface(s, &err); - runtime·panic(err); -} - -#pragma cgo_export_static _cgo_panic -#pragma cgo_export_dynamic _cgo_panic -#pragma textflag NOSPLIT -void -_cgo_panic(void *a, int32 n) -{ - runtime·cgocallback((void(*)(void))_cgo_panic_internal, a, n); -} - -#pragma cgo_import_static x_cgo_init -extern void x_cgo_init(G*); -void (*_cgo_init)(G*) = x_cgo_init; - -#pragma cgo_import_static x_cgo_malloc -extern void x_cgo_malloc(void*); -void (*_cgo_malloc)(void*) = x_cgo_malloc; - -#pragma cgo_import_static x_cgo_free -extern void x_cgo_free(void*); -void (*_cgo_free)(void*) = x_cgo_free; - -#pragma cgo_import_static x_cgo_thread_start -extern void x_cgo_thread_start(void*); -void (*_cgo_thread_start)(void*) = x_cgo_thread_start; diff --git a/src/pkg/runtime/cgo/cgo.go b/src/pkg/runtime/cgo/cgo.go deleted file mode 100644 index 258b6fba1..000000000 --- a/src/pkg/runtime/cgo/cgo.go +++ /dev/null @@ -1,32 +0,0 @@ -// 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. - -/* -Package cgo contains runtime support for code generated -by the cgo tool. See the documentation for the cgo command -for details on using cgo. -*/ -package cgo - -/* - -#cgo darwin LDFLAGS: -lpthread -#cgo dragonfly LDFLAGS: -lpthread -#cgo freebsd LDFLAGS: -lpthread -#cgo linux LDFLAGS: -lpthread -#cgo netbsd LDFLAGS: -lpthread -#cgo openbsd LDFLAGS: -lpthread -#cgo windows LDFLAGS: -lm -mthreads - -#cgo CFLAGS: -Wall -Werror - -*/ -import "C" - -// Supports _cgo_panic by converting a string constant to an empty -// interface. - -func cgoStringToEface(s string, ret *interface{}) { - *ret = s -} diff --git a/src/pkg/runtime/cgo/dragonfly.c b/src/pkg/runtime/cgo/dragonfly.c deleted file mode 100644 index acf53e265..000000000 --- a/src/pkg/runtime/cgo/dragonfly.c +++ /dev/null @@ -1,13 +0,0 @@ -// 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/freebsd.c b/src/pkg/runtime/cgo/freebsd.c deleted file mode 100644 index dfcfa3a21..000000000 --- a/src/pkg/runtime/cgo/freebsd.c +++ /dev/null @@ -1,13 +0,0 @@ -// 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 FreeBSD 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_386.S b/src/pkg/runtime/cgo/gcc_386.S deleted file mode 100644 index bf4142793..000000000 --- a/src/pkg/runtime/cgo/gcc_386.S +++ /dev/null @@ -1,45 +0,0 @@ -// 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. - -/* - * Apple still insists on underscore prefixes for C function names. - */ -#if defined(__APPLE__) || defined(_WIN32) -#define EXT(s) _##s -#else -#define EXT(s) s -#endif - -/* - * void crosscall_386(void (*fn)(void)) - * - * Calling into the 8c tool chain, where all registers are caller save. - * Called from standard x86 ABI, where %ebp, %ebx, %esi, - * and %edi are callee-save, so they must be saved explicitly. - */ -.globl EXT(crosscall_386) -EXT(crosscall_386): - pushl %ebp - movl %esp, %ebp - pushl %ebx - pushl %esi - pushl %edi - - movl 8(%ebp), %eax /* fn */ - call *%eax - - popl %edi - popl %esi - popl %ebx - popl %ebp - ret - -.globl EXT(__stack_chk_fail_local) -EXT(__stack_chk_fail_local): -1: - jmp 1b - -#ifdef __ELF__ -.section .note.GNU-stack,"",@progbits -#endif diff --git a/src/pkg/runtime/cgo/gcc_amd64.S b/src/pkg/runtime/cgo/gcc_amd64.S deleted file mode 100644 index 32d0200cf..000000000 --- a/src/pkg/runtime/cgo/gcc_amd64.S +++ /dev/null @@ -1,48 +0,0 @@ -// 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. - -/* - * Apple still insists on underscore prefixes for C function names. - */ -#if defined(__APPLE__) -#define EXT(s) _##s -#else -#define EXT(s) s -#endif - -/* - * void crosscall_amd64(void (*fn)(void)) - * - * Calling into the 6c tool chain, where all registers are caller save. - * Called from standard x86-64 ABI, where %rbx, %rbp, %r12-%r15 - * are callee-save so they must be saved explicitly. - * The standard x86-64 ABI passes the three arguments m, g, fn - * in %rdi, %rsi, %rdx. - */ -.globl EXT(crosscall_amd64) -EXT(crosscall_amd64): - pushq %rbx - pushq %rbp - pushq %r12 - pushq %r13 - pushq %r14 - pushq %r15 - -#if defined(_WIN64) - call *%rcx /* fn */ -#else - call *%rdi /* fn */ -#endif - - popq %r15 - popq %r14 - popq %r13 - popq %r12 - popq %rbp - popq %rbx - ret - -#ifdef __ELF__ -.section .note.GNU-stack,"",@progbits -#endif diff --git a/src/pkg/runtime/cgo/gcc_arm.S b/src/pkg/runtime/cgo/gcc_arm.S deleted file mode 100644 index 17e98d91f..000000000 --- a/src/pkg/runtime/cgo/gcc_arm.S +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2012 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. - -/* - * Apple still insists on underscore prefixes for C function names. - */ -#if defined(__APPLE__) -#define EXT(s) _##s -#else -#define EXT(s) s -#endif - -/* - * Because the assembler might target an earlier revision of the ISA - * by default, we must explicitly specify the ISA revision to ensure - * BLX is recognized as a valid instruction. - */ -.arch armv5t - -/* - * void crosscall_arm2(void (*fn)(void), void (*setmg_gcc)(void *m, void *g), void *m, void *g) - * - * Calling into the 5c tool chain, where all registers are caller save. - * Called from standard ARM EABI, where r4-r11 are callee-save, so they - * must be saved explicitly. - */ -.globl EXT(crosscall_arm2) -EXT(crosscall_arm2): - push {r4, r5, r6, r7, r8, r9, r10, r11, ip, lr} - mov r4, r0 - mov r5, r1 - mov r0, r2 - mov r1, r3 - blx r5 // setmg(m, g) - blx r4 // fn() - pop {r4, r5, r6, r7, r8, r9, r10, r11, ip, pc} - -.globl EXT(__stack_chk_fail_local) -EXT(__stack_chk_fail_local): -1: - b 1b - -#ifdef __ELF__ -.section .note.GNU-stack,"",%progbits -#endif diff --git a/src/pkg/runtime/cgo/gcc_darwin_386.c b/src/pkg/runtime/cgo/gcc_darwin_386.c deleted file mode 100644 index ad9fb5abf..000000000 --- a/src/pkg/runtime/cgo/gcc_darwin_386.c +++ /dev/null @@ -1,165 +0,0 @@ -// 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 <string.h> /* for strerror */ -#include <pthread.h> -#include <signal.h> -#include "libcgo.h" - -static void* threadentry(void*); -static pthread_key_t k1, k2; - -#define magic1 (0x23581321U) - -static void -inittls(void) -{ - uint32 x, y; - pthread_key_t tofree[128], k; - int i, ntofree; - int havek1, havek2; - - /* - * Allocate thread-local storage slots for m, g. - * The key numbers start at 0x100, and we expect to be - * one of the early calls to pthread_key_create, so we - * should be able to get pretty low numbers. - * - * In Darwin/386 pthreads, %gs points at the thread - * structure, and each key is an index into the thread-local - * storage array that begins at offset 0x48 within in that structure. - * It may happen that we are not quite the first function to try - * to allocate thread-local storage keys, so instead of depending - * on getting 0x100 and 0x101, we try for 0x108 and 0x109, - * allocating keys until we get the ones we want and then freeing - * the ones we didn't want. - * - * Thus the final offsets to use in %gs references are - * 0x48+4*0x108 = 0x468 and 0x48+4*0x109 = 0x46c. - * - * The linker and runtime hard-code these constant offsets - * from %gs where we expect to find m and g. - * Known to ../../../cmd/8l/obj.c:/468 - * and to ../sys_darwin_386.s:/468 - * - * This is truly disgusting and a bit fragile, but taking care - * of it here protects the rest of the system from damage. - * The alternative would be to use a global variable that - * held the offset and refer to that variable each time we - * need a %gs variable (m or g). That approach would - * require an extra instruction and memory reference in - * every stack growth prolog and would also require - * rewriting the code that 8c generates for extern registers. - * - * Things get more disgusting on OS X 10.7 Lion. - * The 0x48 base mentioned above is the offset of the tsd - * array within the per-thread structure on Leopard and Snow Leopard. - * On Lion, the base moved a little, so while the math above - * still applies, the base is different. Thus, we cannot - * look for specific key values if we want to build binaries - * that run on both systems. Instead, forget about the - * specific key values and just allocate and initialize per-thread - * storage until we find a key that writes to the memory location - * we want. Then keep that key. - */ - havek1 = 0; - havek2 = 0; - ntofree = 0; - while(!havek1 || !havek2) { - if(pthread_key_create(&k, nil) < 0) { - fprintf(stderr, "runtime/cgo: pthread_key_create failed\n"); - abort(); - } - pthread_setspecific(k, (void*)magic1); - asm volatile("movl %%gs:0x468, %0" : "=r"(x)); - asm volatile("movl %%gs:0x46c, %0" : "=r"(y)); - if(x == magic1) { - havek1 = 1; - k1 = k; - } else if(y == magic1) { - havek2 = 1; - k2 = k; - } else { - if(ntofree >= nelem(tofree)) { - fprintf(stderr, "runtime/cgo: could not obtain pthread_keys\n"); - fprintf(stderr, "\ttried"); - for(i=0; i<ntofree; i++) - fprintf(stderr, " %#x", (unsigned)tofree[i]); - fprintf(stderr, "\n"); - abort(); - } - tofree[ntofree++] = k; - } - pthread_setspecific(k, 0); - } - - /* - * We got the keys we wanted. Free the others. - */ - for(i=0; i<ntofree; i++) - pthread_key_delete(tofree[i]); -} - -void -x_cgo_init(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); - - inittls(); -} - - -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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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; - - pthread_setspecific(k1, (void*)ts.g); - pthread_setspecific(k2, (void*)ts.m); - - crosscall_386(ts.fn); - return nil; -} diff --git a/src/pkg/runtime/cgo/gcc_darwin_amd64.c b/src/pkg/runtime/cgo/gcc_darwin_amd64.c deleted file mode 100644 index 65d381633..000000000 --- a/src/pkg/runtime/cgo/gcc_darwin_amd64.c +++ /dev/null @@ -1,135 +0,0 @@ -// 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 <string.h> /* for strerror */ -#include <pthread.h> -#include <signal.h> -#include "libcgo.h" - -static void* threadentry(void*); -static pthread_key_t k1, k2; - -#define magic1 (0x23581321345589ULL) - -static void -inittls(void) -{ - uint64 x, y; - pthread_key_t tofree[128], k; - int i, ntofree; - int havek1, havek2; - - /* - * Same logic, code as darwin_386.c:/inittls, except that words - * are 8 bytes long now, and the thread-local storage starts - * at 0x60 on Leopard / Snow Leopard. So the offsets are - * 0x60+8*0x108 = 0x8a0 and 0x60+8*0x109 = 0x8a8. - * - * The linker and runtime hard-code these constant offsets - * from %gs where we expect to find m and g. - * Known to ../../../cmd/6l/obj.c:/8a0 - * and to ../sys_darwin_amd64.s:/8a0 - * - * As disgusting as on the 386; same justification. - */ - havek1 = 0; - havek2 = 0; - ntofree = 0; - while(!havek1 || !havek2) { - if(pthread_key_create(&k, nil) < 0) { - fprintf(stderr, "runtime/cgo: pthread_key_create failed\n"); - abort(); - } - pthread_setspecific(k, (void*)magic1); - asm volatile("movq %%gs:0x8a0, %0" : "=r"(x)); - asm volatile("movq %%gs:0x8a8, %0" : "=r"(y)); - if(x == magic1) { - havek1 = 1; - k1 = k; - } else if(y == magic1) { - havek2 = 1; - k2 = k; - } else { - if(ntofree >= nelem(tofree)) { - fprintf(stderr, "runtime/cgo: could not obtain pthread_keys\n"); - fprintf(stderr, "\ttried"); - for(i=0; i<ntofree; i++) - fprintf(stderr, " %#x", (unsigned)tofree[i]); - fprintf(stderr, "\n"); - abort(); - } - tofree[ntofree++] = k; - } - pthread_setspecific(k, 0); - } - - /* - * We got the keys we wanted. Free the others. - */ - for(i=0; i<ntofree; i++) - pthread_key_delete(tofree[i]); -} - -void -x_cgo_init(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); - - inittls(); -} - - -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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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; - - pthread_setspecific(k1, (void*)ts.g); - pthread_setspecific(k2, (void*)ts.m); - - crosscall_amd64(ts.fn); - return nil; -} diff --git a/src/pkg/runtime/cgo/gcc_dragonfly_386.c b/src/pkg/runtime/cgo/gcc_dragonfly_386.c deleted file mode 100644 index 695c16634..000000000 --- a/src/pkg/runtime/cgo/gcc_dragonfly_386.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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 deleted file mode 100644 index a46c121ad..000000000 --- a/src/pkg/runtime/cgo/gcc_dragonfly_amd64.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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_freebsd_386.c b/src/pkg/runtime/cgo/gcc_freebsd_386.c deleted file mode 100644 index 695c16634..000000000 --- a/src/pkg/runtime/cgo/gcc_freebsd_386.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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_freebsd_amd64.c b/src/pkg/runtime/cgo/gcc_freebsd_amd64.c deleted file mode 100644 index a46c121ad..000000000 --- a/src/pkg/runtime/cgo/gcc_freebsd_amd64.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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_freebsd_arm.c b/src/pkg/runtime/cgo/gcc_freebsd_arm.c deleted file mode 100644 index 6175e1d9c..000000000 --- a/src/pkg/runtime/cgo/gcc_freebsd_arm.c +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2012 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 <machine/sysarch.h> -#include <sys/signalvar.h> -#include <pthread.h> -#include <signal.h> -#include <string.h> -#include "libcgo.h" - -#ifdef ARM_TP_ADDRESS -// ARM_TP_ADDRESS is (ARM_VECTORS_HIGH + 0x1000) or 0xffff1000 -// and is known to runtime.read_tls_fallback. Verify it with -// cpp. -#if ARM_TP_ADDRESS != 0xffff1000 -#error Wrong ARM_TP_ADDRESS! -#endif -#endif - -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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - // Not sure why the memset is necessary here, - // but without it, we get a bogus stack size - // out of pthread_attr_getstacksize. C'est la Linux. - memset(&attr, 0, sizeof attr); - pthread_attr_init(&attr); - size = 0; - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(SIG_SETMASK, &oset, nil); - - if (err != 0) { - fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err)); - abort(); - } -} - -extern void crosscall_arm2(void (*fn)(void), void (*setmg_gcc)(void*, void*), void *g, void *m); -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 * 2; - - crosscall_arm2(ts.fn, setmg_gcc, (void*)ts.m, (void*)ts.g); - return nil; -} diff --git a/src/pkg/runtime/cgo/gcc_linux_386.c b/src/pkg/runtime/cgo/gcc_linux_386.c deleted file mode 100644 index 0a46c9b7a..000000000 --- a/src/pkg/runtime/cgo/gcc_linux_386.c +++ /dev/null @@ -1,80 +0,0 @@ -// 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 <pthread.h> -#include <string.h> -#include <signal.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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - // Not sure why the memset is necessary here, - // but without it, we get a bogus stack size - // out of pthread_attr_getstacksize. C'est la Linux. - memset(&attr, 0, sizeof attr); - pthread_attr_init(&attr); - size = 0; - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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_linux_amd64.c b/src/pkg/runtime/cgo/gcc_linux_amd64.c deleted file mode 100644 index c530183b7..000000000 --- a/src/pkg/runtime/cgo/gcc_linux_amd64.c +++ /dev/null @@ -1,75 +0,0 @@ -// 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 <pthread.h> -#include <string.h> // strerror -#include <signal.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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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_linux_arm.c b/src/pkg/runtime/cgo/gcc_linux_arm.c deleted file mode 100644 index 032568155..000000000 --- a/src/pkg/runtime/cgo/gcc_linux_arm.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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. - -#include <pthread.h> -#include <string.h> -#include <signal.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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - // Not sure why the memset is necessary here, - // but without it, we get a bogus stack size - // out of pthread_attr_getstacksize. C'est la Linux. - memset(&attr, 0, sizeof attr); - pthread_attr_init(&attr); - size = 0; - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(SIG_SETMASK, &oset, nil); - - if (err != 0) { - fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err)); - abort(); - } -} - -extern void crosscall_arm2(void (*fn)(void), void (*setmg_gcc)(void*, void*), void*, void*); -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 * 2; - - crosscall_arm2(ts.fn, setmg_gcc, (void*)ts.m, (void*)ts.g); - return nil; -} diff --git a/src/pkg/runtime/cgo/gcc_netbsd_386.c b/src/pkg/runtime/cgo/gcc_netbsd_386.c deleted file mode 100644 index 28690ccbd..000000000 --- a/src/pkg/runtime/cgo/gcc_netbsd_386.c +++ /dev/null @@ -1,76 +0,0 @@ -// 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 <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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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_netbsd_amd64.c b/src/pkg/runtime/cgo/gcc_netbsd_amd64.c deleted file mode 100644 index 6e0482d5b..000000000 --- a/src/pkg/runtime/cgo/gcc_netbsd_amd64.c +++ /dev/null @@ -1,77 +0,0 @@ -// 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 <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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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_netbsd_arm.c b/src/pkg/runtime/cgo/gcc_netbsd_arm.c deleted file mode 100644 index ba2ae2568..000000000 --- a/src/pkg/runtime/cgo/gcc_netbsd_arm.c +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2013 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 <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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(SIG_SETMASK, &oset, nil); - - if (err != 0) { - fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err)); - abort(); - } -} - -extern void crosscall_arm2(void (*fn)(void), void (*setmg_gcc)(void*, void*), void *g, void *m); -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 * 2; - - crosscall_arm2(ts.fn, setmg_gcc, (void*)ts.m, (void*)ts.g); - return nil; -} diff --git a/src/pkg/runtime/cgo/gcc_openbsd_386.c b/src/pkg/runtime/cgo/gcc_openbsd_386.c deleted file mode 100644 index e682c3725..000000000 --- a/src/pkg/runtime/cgo/gcc_openbsd_386.c +++ /dev/null @@ -1,165 +0,0 @@ -// 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 <dlfcn.h> -#include <errno.h> -#include <pthread.h> -#include <signal.h> -#include <string.h> -#include "libcgo.h" - -static void* threadentry(void*); -static void (*setmg_gcc)(void*, void*); - -// TCB_SIZE is sizeof(struct thread_control_block), -// as defined in /usr/src/lib/librthread/tcb.h -#define TCB_SIZE (4 * sizeof(void *)) -#define TLS_SIZE (2 * sizeof(void *)) - -void *__get_tcb(void); -void __set_tcb(void *); - -static int (*sys_pthread_create)(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg); - -struct thread_args { - void *(*func)(void *); - void *arg; -}; - -static void -tcb_fixup(int mainthread) -{ - void *newtcb, *oldtcb; - - // The OpenBSD ld.so(1) does not currently support PT_TLS. As a result, - // we need to allocate our own TLS space while preserving the existing - // TCB that has been setup via librthread. - - newtcb = malloc(TCB_SIZE + TLS_SIZE); - if(newtcb == NULL) - abort(); - - // The signal trampoline expects the TLS slots to be zeroed. - bzero(newtcb, TLS_SIZE); - - oldtcb = __get_tcb(); - bcopy(oldtcb, newtcb + TLS_SIZE, TCB_SIZE); - __set_tcb(newtcb + TLS_SIZE); - - // NOTE(jsing, minux): we can't free oldtcb without causing double-free - // problem. so newtcb will be memory leaks. Get rid of this when OpenBSD - // has proper support for PT_TLS. -} - -static void * -thread_start_wrapper(void *arg) -{ - struct thread_args args = *(struct thread_args *)arg; - - free(arg); - tcb_fixup(0); - - return args.func(args.arg); -} - -int -pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg) -{ - struct thread_args *p; - - p = malloc(sizeof(*p)); - if(p == NULL) { - errno = ENOMEM; - return -1; - } - p->func = start_routine; - p->arg = arg; - - return sys_pthread_create(thread, attr, thread_start_wrapper, p); -} - -void -x_cgo_init(G *g, void (*setmg)(void*, void*)) -{ - pthread_attr_t attr; - size_t size; - void *handle; - - setmg_gcc = setmg; - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - g->stackguard = (uintptr)&attr - size + 4096; - pthread_attr_destroy(&attr); - - // Locate symbol for the system pthread_create function. - handle = dlopen("libpthread.so", RTLD_LAZY); - if(handle == NULL) { - fprintf(stderr, "dlopen: failed to load libpthread: %s\n", dlerror()); - abort(); - } - sys_pthread_create = dlsym(handle, "pthread_create"); - if(sys_pthread_create == NULL) { - fprintf(stderr, "dlsym: failed to find pthread_create: %s\n", dlerror()); - abort(); - } - dlclose(handle); - - tcb_fixup(1); -} - - -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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - ts->g->stackguard = size; - err = sys_pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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; - - tcb_fixup(0); - - 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_openbsd_amd64.c b/src/pkg/runtime/cgo/gcc_openbsd_amd64.c deleted file mode 100644 index 64d29a935..000000000 --- a/src/pkg/runtime/cgo/gcc_openbsd_amd64.c +++ /dev/null @@ -1,166 +0,0 @@ -// 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 <dlfcn.h> -#include <errno.h> -#include <pthread.h> -#include <signal.h> -#include <string.h> -#include "libcgo.h" - -static void* threadentry(void*); -static void (*setmg_gcc)(void*, void*); - -// TCB_SIZE is sizeof(struct thread_control_block), -// as defined in /usr/src/lib/librthread/tcb.h -#define TCB_SIZE (4 * sizeof(void *)) -#define TLS_SIZE (2 * sizeof(void *)) - -void *__get_tcb(void); -void __set_tcb(void *); - -static int (*sys_pthread_create)(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg); - -struct thread_args { - void *(*func)(void *); - void *arg; -}; - -static void -tcb_fixup(int mainthread) -{ - void *newtcb, *oldtcb; - - // The OpenBSD ld.so(1) does not currently support PT_TLS. As a result, - // we need to allocate our own TLS space while preserving the existing - // TCB that has been setup via librthread. - - newtcb = malloc(TCB_SIZE + TLS_SIZE); - if(newtcb == NULL) - abort(); - - // The signal trampoline expects the TLS slots to be zeroed. - bzero(newtcb, TLS_SIZE); - - oldtcb = __get_tcb(); - bcopy(oldtcb, newtcb + TLS_SIZE, TCB_SIZE); - __set_tcb(newtcb + TLS_SIZE); - - // NOTE(jsing, minux): we can't free oldtcb without causing double-free - // problem. so newtcb will be memory leaks. Get rid of this when OpenBSD - // has proper support for PT_TLS. -} - -static void * -thread_start_wrapper(void *arg) -{ - struct thread_args args = *(struct thread_args *)arg; - - free(arg); - tcb_fixup(0); - - return args.func(args.arg); -} - -int -pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg) -{ - struct thread_args *p; - - p = malloc(sizeof(*p)); - if(p == NULL) { - errno = ENOMEM; - return -1; - } - p->func = start_routine; - p->arg = arg; - - return sys_pthread_create(thread, attr, thread_start_wrapper, p); -} - -void -x_cgo_init(G *g, void (*setmg)(void*, void*)) -{ - pthread_attr_t attr; - size_t size; - void *handle; - - setmg_gcc = setmg; - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - g->stackguard = (uintptr)&attr - size + 4096; - pthread_attr_destroy(&attr); - - // Locate symbol for the system pthread_create function. - handle = dlopen("libpthread.so", RTLD_LAZY); - if(handle == NULL) { - fprintf(stderr, "dlopen: failed to load libpthread: %s\n", dlerror()); - abort(); - } - sys_pthread_create = dlsym(handle, "pthread_create"); - if(sys_pthread_create == NULL) { - fprintf(stderr, "dlsym: failed to find pthread_create: %s\n", dlerror()); - abort(); - } - dlclose(handle); - - tcb_fixup(1); -} - - -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); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - - ts->g->stackguard = size; - err = sys_pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(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; - - tcb_fixup(0); - - 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 deleted file mode 100644 index 8b128b946..000000000 --- a/src/pkg/runtime/cgo/gcc_setenv.c +++ /dev/null @@ -1,16 +0,0 @@ -// 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 darwin dragonfly freebsd linux netbsd openbsd - -#include "libcgo.h" - -#include <stdlib.h> - -/* Stub for calling setenv */ -void -x_cgo_setenv(char **arg) -{ - setenv(arg[0], arg[1], 1); -} diff --git a/src/pkg/runtime/cgo/gcc_util.c b/src/pkg/runtime/cgo/gcc_util.c deleted file mode 100644 index 143734e94..000000000 --- a/src/pkg/runtime/cgo/gcc_util.c +++ /dev/null @@ -1,47 +0,0 @@ -// 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 "libcgo.h" - -/* Stub for calling malloc from Go */ -void -x_cgo_malloc(void *p) -{ - struct a { - long long n; - void *ret; - } *a = p; - - a->ret = malloc(a->n); - if(a->ret == NULL && a->n == 0) - a->ret = malloc(1); -} - -/* Stub for calling free from Go */ -void -x_cgo_free(void *p) -{ - struct a { - void *arg; - } *a = p; - - free(a->arg); -} - -/* Stub for creating a new thread */ -void -x_cgo_thread_start(ThreadStart *arg) -{ - ThreadStart *ts; - - /* Make our own copy that can persist after we return. */ - ts = malloc(sizeof *ts); - if(ts == nil) { - fprintf(stderr, "runtime/cgo: out of memory in thread_start\n"); - abort(); - } - *ts = *arg; - - _cgo_sys_thread_start(ts); /* OS-dependent half */ -} diff --git a/src/pkg/runtime/cgo/gcc_windows_386.c b/src/pkg/runtime/cgo/gcc_windows_386.c deleted file mode 100644 index cdc866468..000000000 --- a/src/pkg/runtime/cgo/gcc_windows_386.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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. - -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#include <process.h> -#include <stdlib.h> -#include <stdio.h> -#include "libcgo.h" - -static void threadentry(void*); - -/* 1MB is default stack size for 32-bit Windows. - Allocation granularity on Windows is typically 64 KB. - The constant is also hardcoded in cmd/ld/pe.c (keep synchronized). */ -#define STACKSIZE (1*1024*1024) - -void -x_cgo_init(G *g) -{ - int tmp; - g->stackguard = (uintptr)&tmp - STACKSIZE + 8*1024; -} - - -void -_cgo_sys_thread_start(ThreadStart *ts) -{ - uintptr_t thandle; - - thandle = _beginthread(threadentry, 0, ts); - if(thandle == -1) { - fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno); - abort(); - } -} - -static void -threadentry(void *v) -{ - ThreadStart ts; - - ts = *(ThreadStart*)v; - free(v); - - ts.g->stackbase = (uintptr)&ts; - ts.g->stackguard = (uintptr)&ts - STACKSIZE + 8*1024; - - /* - * Set specific keys in thread local storage. - */ - asm volatile ( - "movl %0, %%fs:0x14\n" // MOVL tls0, 0x14(FS) - "movl %%fs:0x14, %%eax\n" // MOVL 0x14(FS), tmp - "movl %1, 0(%%eax)\n" // MOVL g, 0(FS) - "movl %2, 4(%%eax)\n" // MOVL m, 4(FS) - :: "r"(ts.tls), "r"(ts.g), "r"(ts.m) : "%eax" - ); - - crosscall_386(ts.fn); -} diff --git a/src/pkg/runtime/cgo/gcc_windows_amd64.c b/src/pkg/runtime/cgo/gcc_windows_amd64.c deleted file mode 100644 index d8dd69b4a..000000000 --- a/src/pkg/runtime/cgo/gcc_windows_amd64.c +++ /dev/null @@ -1,62 +0,0 @@ -// 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. - -#define WIN64_LEAN_AND_MEAN -#include <windows.h> -#include <process.h> -#include <stdlib.h> -#include <stdio.h> -#include "libcgo.h" - -static void threadentry(void*); - -/* 2MB is default stack size for 64-bit Windows. - Allocation granularity on Windows is typically 64 KB. - The constant is also hardcoded in cmd/ld/pe.c (keep synchronized). */ -#define STACKSIZE (2*1024*1024) - -void -x_cgo_init(G *g) -{ - int tmp; - g->stackguard = (uintptr)&tmp - STACKSIZE + 8*1024; -} - - -void -_cgo_sys_thread_start(ThreadStart *ts) -{ - uintptr_t thandle; - - thandle = _beginthread(threadentry, 0, ts); - if(thandle == -1) { - fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno); - abort(); - } -} - -static void -threadentry(void *v) -{ - ThreadStart ts; - - ts = *(ThreadStart*)v; - free(v); - - ts.g->stackbase = (uintptr)&ts; - ts.g->stackguard = (uintptr)&ts - STACKSIZE + 8*1024; - - /* - * Set specific keys in thread local storage. - */ - asm volatile ( - "movq %0, %%gs:0x28\n" // MOVL tls0, 0x28(GS) - "movq %%gs:0x28, %%rax\n" // MOVQ 0x28(GS), tmp - "movq %1, 0(%%rax)\n" // MOVQ g, 0(GS) - "movq %2, 8(%%rax)\n" // MOVQ m, 8(GS) - :: "r"(ts.tls), "r"(ts.g), "r"(ts.m) : "%rax" - ); - - crosscall_amd64(ts.fn); -} diff --git a/src/pkg/runtime/cgo/iscgo.c b/src/pkg/runtime/cgo/iscgo.c deleted file mode 100644 index 0907a1958..000000000 --- a/src/pkg/runtime/cgo/iscgo.c +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -// The runtime package contains an uninitialized definition -// for runtime·iscgo. Override it to tell the runtime we're here. -// There are various function pointers that should be set too, -// but those depend on dynamic linker magic to get initialized -// correctly, and sometimes they break. This variable is a -// backup: it depends only on old C style static linking rules. - -#include "../runtime.h" - -bool runtime·iscgo = 1; -uint32 runtime·needextram = 1; // create an extra M on first cgo call diff --git a/src/pkg/runtime/cgo/libcgo.h b/src/pkg/runtime/cgo/libcgo.h deleted file mode 100644 index 65ea3f372..000000000 --- a/src/pkg/runtime/cgo/libcgo.h +++ /dev/null @@ -1,61 +0,0 @@ -// 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 <stdint.h> -#include <stdlib.h> -#include <stdio.h> - -#define nil ((void*)0) -#define nelem(x) (sizeof(x)/sizeof((x)[0])) - -typedef uint32_t uint32; -typedef uint64_t uint64; -typedef uintptr_t uintptr; - -/* - * The beginning of the per-goroutine structure, - * as defined in ../pkg/runtime/runtime.h. - * Just enough to edit these two fields. - */ -typedef struct G G; -struct G -{ - uintptr stackguard; - uintptr stackbase; -}; - -/* - * Arguments to the _cgo_thread_start call. - * Also known to ../pkg/runtime/runtime.h. - */ -typedef struct ThreadStart ThreadStart; -struct ThreadStart -{ - uintptr m; - G *g; - uintptr *tls; - void (*fn)(void); -}; - -/* - * Called by 5c/6c/8c world. - * Makes a local copy of the ThreadStart and - * calls _cgo_sys_thread_start(ts). - */ -extern void (*_cgo_thread_start)(ThreadStart *ts); - -/* - * Creates the new operating system thread (OS, arch dependent). - */ -void _cgo_sys_thread_start(ThreadStart *ts); - -/* - * Call fn in the 6c world. - */ -void crosscall_amd64(void (*fn)(void)); - -/* - * Call fn in the 8c world. - */ -void crosscall_386(void (*fn)(void)); diff --git a/src/pkg/runtime/cgo/netbsd.c b/src/pkg/runtime/cgo/netbsd.c deleted file mode 100644 index b6403f686..000000000 --- a/src/pkg/runtime/cgo/netbsd.c +++ /dev/null @@ -1,13 +0,0 @@ -// 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 NetBSD 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/openbsd.c b/src/pkg/runtime/cgo/openbsd.c deleted file mode 100644 index 84e9f9eff..000000000 --- a/src/pkg/runtime/cgo/openbsd.c +++ /dev/null @@ -1,21 +0,0 @@ -// 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, __progname and __guard_local, because -// we don't link against the standard OpenBSD crt0.o and -// the libc dynamic library needs them. - -char *environ[1]; -char *__progname; -long __guard_local; - -#pragma dynexport environ environ -#pragma dynexport __progname __progname - -// This is normally marked as hidden and placed in the -// .openbsd.randomdata section. -#pragma dynexport __guard_local __guard_local - -// We override pthread_create to support PT_TLS. -#pragma dynexport pthread_create pthread_create diff --git a/src/pkg/runtime/cgo/setenv.c b/src/pkg/runtime/cgo/setenv.c deleted file mode 100644 index 2d03db09f..000000000 --- a/src/pkg/runtime/cgo/setenv.c +++ /dev/null @@ -1,10 +0,0 @@ -// 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 darwin dragonfly freebsd linux netbsd openbsd - -#pragma cgo_import_static x_cgo_setenv - -void x_cgo_setenv(char**); -void (*_cgo_setenv)(char**) = x_cgo_setenv; |