Text file src/runtime/go_tls.h

     1  // Copyright 2014 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  #ifdef GOOS_windows
     6  // Offset of the TEB's ThreadLocalStoragePointer field, which points to the
     7  // array of module TLS blocks indexed by _tls_index.
     8  #ifdef GOARCH_386
     9  #define TEB_ThreadLocalStoragePointer 0x2c
    10  #else
    11  #define TEB_ThreadLocalStoragePointer 0x58
    12  #endif
    13  #endif
    14  
    15  #ifdef GOARCH_arm
    16  #define LR R14
    17  #endif
    18  
    19  #ifdef GOARCH_amd64
    20  #ifdef GOOS_windows
    21  // get_tls loads the address of the current thread's g slot into r.
    22  // It clobbers R11; r must differ from R11.
    23  #define get_tls(r) \
    24  	MOVL	_tls_index(SB), r /* 32-bit TLS index, zero-extended to 64 bits. */ \
    25  	MOVQ	TEB_ThreadLocalStoragePointer(GS), R11 /* R11 is volatile in the host ABI. */ \
    26  	MOVQ	(R11)(r*8), r \
    27  	MOVQ	runtimeĀ·tls_g(SB), R11 \
    28  	LEAQ	(r)(R11*1), r
    29  #else
    30  #define	get_tls(r)	MOVQ TLS, r
    31  #endif
    32  #define	g(r)	0(r)(TLS*1)
    33  #endif
    34  
    35  #ifdef GOARCH_386
    36  #ifdef GOOS_windows
    37  // get_tls2 lets callers preserve AX or load the TLS address into AX.
    38  // r and scratch must differ; scratch is clobbered.
    39  #define get_tls2(r, scratch) \
    40  	MOVL	_tls_index(SB), r \
    41  	MOVL	TEB_ThreadLocalStoragePointer(FS), scratch \
    42  	MOVL	(scratch)(r*4), r \
    43  	MOVL	runtimeĀ·tls_g(SB), scratch \
    44  	LEAL	(r)(scratch*1), r
    45  #define get_tls(r) get_tls2(r, AX)
    46  #else
    47  #define	get_tls(r)	MOVL TLS, r
    48  #define	get_tls2(r, scratch)	MOVL TLS, r
    49  #endif
    50  #define	g(r)	0(r)(TLS*1)
    51  #endif
    52  

View as plain text