diff options
| author | Rahul Chaudhry <rahulchaudhry@chromium.org> | 2015-11-25 17:31:57 -0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2015-12-02 21:59:52 +0000 |
| commit | 4480d6a9272cdf90ff958163fcdc3819216e8889 (patch) | |
| tree | 3b3aaae9a04fa84d2eeb1ae34b8c3bf134dc21a9 /src/runtime/cgo | |
| parent | 3a1bed82a66c9ff4bf659e5603a8f7c0120435c3 (diff) | |
| download | go-git-4480d6a9272cdf90ff958163fcdc3819216e8889.tar.gz | |
runtime/cgo: define x_cgo_inittls() for android/arm64.
On android, runtime.tls_g is a normal variable.
TLS offset is computed in x_cgo_inittls.
Change-Id: I64cfd3543040776dcdf73cad8dba54fc6aaf6f35
Reviewed-on: https://go-review.googlesource.com/17245
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Diffstat (limited to 'src/runtime/cgo')
| -rw-r--r-- | src/runtime/cgo/gcc_android_arm64.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/runtime/cgo/gcc_android_arm64.c b/src/runtime/cgo/gcc_android_arm64.c new file mode 100644 index 0000000000..5d4cefee60 --- /dev/null +++ b/src/runtime/cgo/gcc_android_arm64.c @@ -0,0 +1,38 @@ +// Copyright 2015 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 <signal.h> +#include <stdio.h> +#include <sys/limits.h> +#include "libcgo.h" + +#define magic1 (0x23581321345589ULL) + +// inittls allocates a thread-local storage slot for g. +// +// It finds the first available slot using pthread_key_create and uses +// it as the offset value for runtime.tlsg. +static void +inittls(void **tlsg, void **tlsbase) +{ + pthread_key_t k; + int i, err; + + err = pthread_key_create(&k, nil); + if(err != 0) { + fatalf("pthread_key_create failed: %d", err); + } + pthread_setspecific(k, (void*)magic1); + for (i=0; i<PTHREAD_KEYS_MAX; i++) { + if (*(tlsbase+i) == (void*)magic1) { + *tlsg = (void*)(i*sizeof(void *)); + pthread_setspecific(k, 0); + return; + } + } + fatalf("could not find pthread key"); +} + +void (*x_cgo_inittls)(void **tlsg, void **tlsbase) = inittls; |
