Skip to content

Commit

Permalink
runtime: allow for usleep2HighRes to run without TLS setup
Browse files Browse the repository at this point in the history
This change adjusts usleep2HighRes so it does not crash when TLS is
not configured. When g is not available, usleep2HighRes just calls
usleep2 instead.

Updates #8687

Change-Id: Idbb80f7b71d1da350a6a7df7c49154eb1ffe29a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/271907
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Simon Rozman <simon@rozman.si>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
  • Loading branch information
alexbrainman committed Nov 24, 2020
1 parent 7dc5d90 commit 6965b01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/runtime/sys_windows_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,15 @@ TEXT runtime·usleep2(SB),NOSPLIT,$20

// Runs on OS stack. duration (in 100ns units) is in BX.
TEXT runtime·usleep2HighRes(SB),NOSPLIT,$36
get_tls(CX)
CMPL CX, $0
JE gisnotset

// Want negative 100ns units.
NEGL BX
MOVL $-1, hi-4(SP)
MOVL BX, lo-8(SP)

get_tls(CX)
MOVL g(CX), CX
MOVL g_m(CX), CX
MOVL (m_mOS+mOS_highResTimer)(CX), CX
Expand Down Expand Up @@ -449,6 +452,12 @@ TEXT runtime·usleep2HighRes(SB),NOSPLIT,$36

RET

gisnotset:
// TLS is not configured. Call usleep2 instead.
MOVL $runtime·usleep2(SB), AX
CALL AX
RET

// Runs on OS stack.
TEXT runtime·switchtothread(SB),NOSPLIT,$0
MOVL SP, BP
Expand Down
11 changes: 10 additions & 1 deletion src/runtime/sys_windows_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,14 @@ TEXT runtime·usleep2(SB),NOSPLIT|NOFRAME,$48

// Runs on OS stack. duration (in 100ns units) is in BX.
TEXT runtime·usleep2HighRes(SB),NOSPLIT|NOFRAME,$72
get_tls(CX)
CMPQ CX, $0
JE gisnotset

MOVQ SP, AX
ANDQ $~15, SP // alignment as per Windows requirement
MOVQ AX, 64(SP)

get_tls(CX)
MOVQ g(CX), CX
MOVQ g_m(CX), CX
MOVQ (m_mOS+mOS_highResTimer)(CX), CX // hTimer
Expand All @@ -484,6 +487,12 @@ TEXT runtime·usleep2HighRes(SB),NOSPLIT|NOFRAME,$72
MOVQ 64(SP), SP
RET

gisnotset:
// TLS is not configured. Call usleep2 instead.
MOVQ $runtime·usleep2(SB), AX
CALL AX
RET

// Runs on OS stack.
TEXT runtime·switchtothread(SB),NOSPLIT|NOFRAME,$0
MOVQ SP, AX
Expand Down

0 comments on commit 6965b01

Please sign in to comment.