aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/go-patches/0010-runtime-allow-for-usleep2HighRes-to-run-without-TLS-.patch
blob: 1c25f5b633302557d632e04d7013ad1287a082f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From 1edac4879e2d4a36d339353c151cb7b9871e135f Mon Sep 17 00:00:00 2001
From: Alex Brainman <alex.brainman@gmail.com>
Date: Sat, 21 Nov 2020 14:56:26 +1100
Subject: [PATCH 10/14] runtime: allow for usleep2HighRes to run without TLS
 setup
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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
---
 src/runtime/sys_windows_386.s   | 11 ++++++++++-
 src/runtime/sys_windows_amd64.s | 11 ++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/runtime/sys_windows_386.s b/src/runtime/sys_windows_386.s
index 4ac1527ab1..310c4008e5 100644
--- a/src/runtime/sys_windows_386.s
+++ b/src/runtime/sys_windows_386.s
@@ -430,12 +430,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
@@ -464,6 +467,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
diff --git a/src/runtime/sys_windows_amd64.s b/src/runtime/sys_windows_amd64.s
index 847542592b..699a6e6ff2 100644
--- a/src/runtime/sys_windows_amd64.s
+++ b/src/runtime/sys_windows_amd64.s
@@ -459,11 +459,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
@@ -489,6 +492,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
-- 
2.29.2