summaryrefslogtreecommitdiff
path: root/src/runtime/cgo/gcc_android_arm.c
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2014-10-22 13:25:37 -0400
committerAustin Clements <austin@google.com>2014-10-22 13:25:37 -0400
commit800a826ae560191d4dbb6c529eea15cf4349a06f (patch)
treec4206bb02365c3b9c66e2946031b86f0ee527faf /src/runtime/cgo/gcc_android_arm.c
parent2c586384223e980fd3303625ea6b02ed5d9fb9c0 (diff)
parent1678ee65674b332e900a703de296eb66fbadcf45 (diff)
downloadgo-800a826ae560191d4dbb6c529eea15cf4349a06f.tar.gz
build: merge the great pkg/ rename into dev.power64
This also removes pkg/runtime/traceback_lr.c, which was ported to Go in an earlier commit and then moved to runtime/traceback.go. Reviewer: rsc@golang.org rsc: LGTM
Diffstat (limited to 'src/runtime/cgo/gcc_android_arm.c')
-rw-r--r--src/runtime/cgo/gcc_android_arm.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/runtime/cgo/gcc_android_arm.c b/src/runtime/cgo/gcc_android_arm.c
new file mode 100644
index 000000000..07f7e72e3
--- /dev/null
+++ b/src/runtime/cgo/gcc_android_arm.c
@@ -0,0 +1,43 @@
+// Copyright 2014 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 (0x23581321U)
+
+// PTHREAD_KEYS_MAX has been added to sys/limits.h at head in bionic:
+// https://android.googlesource.com/platform/bionic/+/master/libc/include/sys/limits.h
+// TODO(crawshaw): remove this definition when a new NDK is released.
+#define PTHREAD_KEYS_MAX 128
+
+// 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;