Skip to content

Commit 4480d6a

Browse files
Rahul Chaudhryianlancetaylor
Rahul Chaudhry
authored andcommitted
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 <[email protected]>
1 parent 3a1bed8 commit 4480d6a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/runtime/cgo/gcc_android_arm64.c

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2015 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
#include <pthread.h>
6+
#include <signal.h>
7+
#include <stdio.h>
8+
#include <sys/limits.h>
9+
#include "libcgo.h"
10+
11+
#define magic1 (0x23581321345589ULL)
12+
13+
// inittls allocates a thread-local storage slot for g.
14+
//
15+
// It finds the first available slot using pthread_key_create and uses
16+
// it as the offset value for runtime.tlsg.
17+
static void
18+
inittls(void **tlsg, void **tlsbase)
19+
{
20+
pthread_key_t k;
21+
int i, err;
22+
23+
err = pthread_key_create(&k, nil);
24+
if(err != 0) {
25+
fatalf("pthread_key_create failed: %d", err);
26+
}
27+
pthread_setspecific(k, (void*)magic1);
28+
for (i=0; i<PTHREAD_KEYS_MAX; i++) {
29+
if (*(tlsbase+i) == (void*)magic1) {
30+
*tlsg = (void*)(i*sizeof(void *));
31+
pthread_setspecific(k, 0);
32+
return;
33+
}
34+
}
35+
fatalf("could not find pthread key");
36+
}
37+
38+
void (*x_cgo_inittls)(void **tlsg, void **tlsbase) = inittls;

0 commit comments

Comments
 (0)