From 5999a28de80cf685b037e53c8dc9a511f11fe7b2 Mon Sep 17 00:00:00 2001
From: Michael Pratt <mpratt@google.com>
Date: Wed, 20 Jul 2022 11:43:30 -0400
Subject: [PATCH] runtime: trivial replacements of _g_ in os files

Change-Id: I7886ea6b94697bafb8ea345508c9cb752c92cadc
Reviewed-on: https://go-review.googlesource.com/c/go/+/418586
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Pratt <mpratt@google.com>
---
 src/runtime/os2_aix.go    | 32 ++++++++++++++++----------------
 src/runtime/os_netbsd.go  | 16 ++++++++--------
 src/runtime/os_openbsd.go |  8 ++++----
 src/runtime/os_plan9.go   |  6 +++---
 4 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/src/runtime/os2_aix.go b/src/runtime/os2_aix.go
index 9ad1caa8161..2efc56554cd 100644
--- a/src/runtime/os2_aix.go
+++ b/src/runtime/os2_aix.go
@@ -388,11 +388,11 @@ func exit1(code int32)
 
 //go:nosplit
 func exit(code int32) {
-	_g_ := getg()
+	gp := getg()
 
 	// Check the validity of g because without a g during
 	// newosproc0.
-	if _g_ != nil {
+	if gp != nil {
 		syscall1(&libc_exit, uintptr(code))
 		return
 	}
@@ -403,11 +403,11 @@ func write2(fd, p uintptr, n int32) int32
 
 //go:nosplit
 func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
-	_g_ := getg()
+	gp := getg()
 
 	// Check the validity of g because without a g during
 	// newosproc0.
-	if _g_ != nil {
+	if gp != nil {
 		r, errno := syscall3(&libc_write, uintptr(fd), uintptr(p), uintptr(n))
 		if int32(r) < 0 {
 			return -int32(errno)
@@ -493,11 +493,11 @@ func sigaction1(sig, new, old uintptr)
 
 //go:nosplit
 func sigaction(sig uintptr, new, old *sigactiont) {
-	_g_ := getg()
+	gp := getg()
 
 	// Check the validity of g because without a g during
 	// runtime.libpreinit.
-	if _g_ != nil {
+	if gp != nil {
 		r, err := syscall3(&libc_sigaction, sig, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
 		if int32(r) == -1 {
 			println("Sigaction failed for sig: ", sig, " with error:", hex(err))
@@ -645,11 +645,11 @@ func pthread_attr_init1(attr uintptr) int32
 
 //go:nosplit
 func pthread_attr_init(attr *pthread_attr) int32 {
-	_g_ := getg()
+	gp := getg()
 
 	// Check the validity of g because without a g during
 	// newosproc0.
-	if _g_ != nil {
+	if gp != nil {
 		r, _ := syscall1(&libpthread_attr_init, uintptr(unsafe.Pointer(attr)))
 		return int32(r)
 	}
@@ -661,11 +661,11 @@ func pthread_attr_setdetachstate1(attr uintptr, state int32) int32
 
 //go:nosplit
 func pthread_attr_setdetachstate(attr *pthread_attr, state int32) int32 {
-	_g_ := getg()
+	gp := getg()
 
 	// Check the validity of g because without a g during
 	// newosproc0.
-	if _g_ != nil {
+	if gp != nil {
 		r, _ := syscall2(&libpthread_attr_setdetachstate, uintptr(unsafe.Pointer(attr)), uintptr(state))
 		return int32(r)
 	}
@@ -689,11 +689,11 @@ func pthread_attr_setstacksize1(attr uintptr, size uint64) int32
 
 //go:nosplit
 func pthread_attr_setstacksize(attr *pthread_attr, size uint64) int32 {
-	_g_ := getg()
+	gp := getg()
 
 	// Check the validity of g because without a g during
 	// newosproc0.
-	if _g_ != nil {
+	if gp != nil {
 		r, _ := syscall2(&libpthread_attr_setstacksize, uintptr(unsafe.Pointer(attr)), uintptr(size))
 		return int32(r)
 	}
@@ -705,11 +705,11 @@ func pthread_create1(tid, attr, fn, arg uintptr) int32
 
 //go:nosplit
 func pthread_create(tid *pthread, attr *pthread_attr, fn *funcDescriptor, arg unsafe.Pointer) int32 {
-	_g_ := getg()
+	gp := getg()
 
 	// Check the validity of g because without a g during
 	// newosproc0.
-	if _g_ != nil {
+	if gp != nil {
 		r, _ := syscall4(&libpthread_create, uintptr(unsafe.Pointer(tid)), uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(fn)), uintptr(arg))
 		return int32(r)
 	}
@@ -723,11 +723,11 @@ func sigprocmask1(how, new, old uintptr)
 
 //go:nosplit
 func sigprocmask(how int32, new, old *sigset) {
-	_g_ := getg()
+	gp := getg()
 
 	// Check the validity of m because it might be called during a cgo
 	// callback early enough where m isn't available yet.
-	if _g_ != nil && _g_.m != nil {
+	if gp != nil && gp.m != nil {
 		r, err := syscall3(&libpthread_sigthreadmask, uintptr(how), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
 		if int32(r) != 0 {
 			println("syscall sigthreadmask failed: ", hex(err))
diff --git a/src/runtime/os_netbsd.go b/src/runtime/os_netbsd.go
index 3cbace38f99..bb23adff076 100644
--- a/src/runtime/os_netbsd.go
+++ b/src/runtime/os_netbsd.go
@@ -152,16 +152,16 @@ func semacreate(mp *m) {
 
 //go:nosplit
 func semasleep(ns int64) int32 {
-	_g_ := getg()
+	gp := getg()
 	var deadline int64
 	if ns >= 0 {
 		deadline = nanotime() + ns
 	}
 
 	for {
-		v := atomic.Load(&_g_.m.waitsemacount)
+		v := atomic.Load(&gp.m.waitsemacount)
 		if v > 0 {
-			if atomic.Cas(&_g_.m.waitsemacount, v, v-1) {
+			if atomic.Cas(&gp.m.waitsemacount, v, v-1) {
 				return 0 // semaphore acquired
 			}
 			continue
@@ -178,7 +178,7 @@ func semasleep(ns int64) int32 {
 			ts.setNsec(wait)
 			tsp = &ts
 		}
-		ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil)
+		ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&gp.m.waitsemacount), nil)
 		if ret == _ETIMEDOUT {
 			return -1
 		}
@@ -289,8 +289,8 @@ func mpreinit(mp *m) {
 // Called to initialize a new m (including the bootstrap m).
 // Called on the new thread, cannot allocate memory.
 func minit() {
-	_g_ := getg()
-	_g_.m.procid = uint64(lwp_self())
+	gp := getg()
+	gp.m.procid = uint64(lwp_self())
 
 	// On NetBSD a thread created by pthread_create inherits the
 	// signal stack of the creating thread. We always create a
@@ -299,8 +299,8 @@ func minit() {
 	// created in C that calls sigaltstack and then calls a Go
 	// function, because we will lose track of the C code's
 	// sigaltstack, but it's the best we can do.
-	signalstack(&_g_.m.gsignal.stack)
-	_g_.m.newSigstack = true
+	signalstack(&gp.m.gsignal.stack)
+	gp.m.newSigstack = true
 
 	minitSignalMask()
 }
diff --git a/src/runtime/os_openbsd.go b/src/runtime/os_openbsd.go
index 2383dc84280..d43414459d2 100644
--- a/src/runtime/os_openbsd.go
+++ b/src/runtime/os_openbsd.go
@@ -84,7 +84,7 @@ func semacreate(mp *m) {
 
 //go:nosplit
 func semasleep(ns int64) int32 {
-	_g_ := getg()
+	gp := getg()
 
 	// Compute sleep deadline.
 	var tsp *timespec
@@ -95,9 +95,9 @@ func semasleep(ns int64) int32 {
 	}
 
 	for {
-		v := atomic.Load(&_g_.m.waitsemacount)
+		v := atomic.Load(&gp.m.waitsemacount)
 		if v > 0 {
-			if atomic.Cas(&_g_.m.waitsemacount, v, v-1) {
+			if atomic.Cas(&gp.m.waitsemacount, v, v-1) {
 				return 0 // semaphore acquired
 			}
 			continue
@@ -110,7 +110,7 @@ func semasleep(ns int64) int32 {
 		// be examined [...] immediately before blocking. If that int
 		// is non-zero then __thrsleep() will immediately return EINTR
 		// without blocking."
-		ret := thrsleep(uintptr(unsafe.Pointer(&_g_.m.waitsemacount)), _CLOCK_MONOTONIC, tsp, 0, &_g_.m.waitsemacount)
+		ret := thrsleep(uintptr(unsafe.Pointer(&gp.m.waitsemacount)), _CLOCK_MONOTONIC, tsp, 0, &gp.m.waitsemacount)
 		if ret == _EWOULDBLOCK {
 			return -1
 		}
diff --git a/src/runtime/os_plan9.go b/src/runtime/os_plan9.go
index b86bd6b3a9f..ab768825f39 100644
--- a/src/runtime/os_plan9.go
+++ b/src/runtime/os_plan9.go
@@ -473,19 +473,19 @@ func semacreate(mp *m) {
 
 //go:nosplit
 func semasleep(ns int64) int {
-	_g_ := getg()
+	gp := getg()
 	if ns >= 0 {
 		ms := timediv(ns, 1000000, nil)
 		if ms == 0 {
 			ms = 1
 		}
-		ret := plan9_tsemacquire(&_g_.m.waitsemacount, ms)
+		ret := plan9_tsemacquire(&gp.m.waitsemacount, ms)
 		if ret == 1 {
 			return 0 // success
 		}
 		return -1 // timeout or interrupted
 	}
-	for plan9_semacquire(&_g_.m.waitsemacount, 1) < 0 {
+	for plan9_semacquire(&gp.m.waitsemacount, 1) < 0 {
 		// interrupted; try again (c.f. lock_sema.go)
 	}
 	return 0 // success
-- 
GitLab