Skip to content

Commit

Permalink
pid: fix for go1.14 asyncpreemption
Browse files Browse the repository at this point in the history
Signed-off-by: Cholerae Hu <[email protected]>
  • Loading branch information
choleraehyq committed Mar 3, 2020
1 parent 58707fa commit 2a44ce9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion os_darwin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package goid

type sigset uint32
type sigset uint32
2 changes: 1 addition & 1 deletion os_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package goid

type sigset [2]uint32
type sigset [2]uint32
26 changes: 13 additions & 13 deletions p_m_go1.12.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ type mutex struct {

type p struct {
lock mutex
id int32 // Here is pid
id int32 // Here is pid
}

type m struct {
g0 uintptr // goroutine with scheduling stack
morebuf gobuf // gobuf arg to morestack
divmod uint32 // div/mod denominator for arm - known to liblink
g0 uintptr // goroutine with scheduling stack
morebuf gobuf // gobuf arg to morestack
divmod uint32 // div/mod denominator for arm - known to liblink

// Fields not known to debuggers.
procid uint64 // for debuggers, but offset not hard-coded
gsignal uintptr // signal-handling g
goSigStack gsignalStack // Go-allocated signal handling stack
sigmask sigset // storage for saved signal mask
tls [6]uintptr // thread-local storage (for x86 extern register)
mstartfn func()
curg uintptr // current running goroutine
caughtsig uintptr // goroutine running during fatal signal
p *p // attached p for executing go code (nil if not executing go code)
procid uint64 // for debuggers, but offset not hard-coded
gsignal uintptr // signal-handling g
goSigStack gsignalStack // Go-allocated signal handling stack
sigmask sigset // storage for saved signal mask
tls [6]uintptr // thread-local storage (for x86 extern register)
mstartfn func()
curg uintptr // current running goroutine
caughtsig uintptr // goroutine running during fatal signal
p *p // attached p for executing go code (nil if not executing go code)
}
24 changes: 12 additions & 12 deletions p_m_go1.13.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ type p struct {
}

type m struct {
g0 uintptr // goroutine with scheduling stack
morebuf gobuf // gobuf arg to morestack
divmod uint32 // div/mod denominator for arm - known to liblink
g0 uintptr // goroutine with scheduling stack
morebuf gobuf // gobuf arg to morestack
divmod uint32 // div/mod denominator for arm - known to liblink

// Fields not known to debuggers.
procid uint64 // for debuggers, but offset not hard-coded
gsignal uintptr // signal-handling g
goSigStack gsignalStack // Go-allocated signal handling stack
sigmask sigset // storage for saved signal mask
tls [6]uintptr // thread-local storage (for x86 extern register)
mstartfn func()
curg uintptr // current running goroutine
caughtsig uintptr // goroutine running during fatal signal
p *p // attached p for executing go code (nil if not executing go code)
procid uint64 // for debuggers, but offset not hard-coded
gsignal uintptr // signal-handling g
goSigStack gsignalStack // Go-allocated signal handling stack
sigmask sigset // storage for saved signal mask
tls [6]uintptr // thread-local storage (for x86 extern register)
mstartfn func()
curg uintptr // current running goroutine
caughtsig uintptr // goroutine running during fatal signal
p *p // attached p for executing go code (nil if not executing go code)
}
10 changes: 7 additions & 3 deletions pid_go1.5_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@

package goid

import "unsafe"
import (
"unsafe"
)

var _ = unsafe.Sizeof(0)

//go:nosplit
func getM() uintptr
func getPid() uintptr

//go:nosplit
func GetPid() int {
return int((*m)(unsafe.Pointer(getM())).p.id)
return int(getPid())
}

//go:linkname procPin runtime.procPin
Expand Down
6 changes: 4 additions & 2 deletions pid_go1.5_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
#include "go_asm.h"
#include "textflag.h"

// func getM() int64
TEXT ·getM(SB),NOSPLIT,$0-8
// func getPid() int64
TEXT ·getPid(SB),NOSPLIT,$0-8
MOVQ (TLS), R14
MOVQ g_m(R14), R13
MOVQ m_p(R13), R14
MOVL p_id(R14), R13
MOVQ R13, ret+0(FP)
RET
4 changes: 2 additions & 2 deletions pid_go1.5_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestPid(t *testing.T) {
p1 := GetPid()
p2 := getTID()
if GetPid() != getTID() {
t.Fatalf("The result of GetPid %d is not equal to procPin %d!", p1, p2)
if p1 != p2 {
t.Fatalf("The result of GetPid %d procPin %d are not equal!", p1, p2)
}
}

0 comments on commit 2a44ce9

Please sign in to comment.