mirror of
https://github.com/golang/go
synced 2024-11-18 03:04:45 -07:00
runtime: tidy Context allocation
The Context object we pass to GetThreadContext on Windows must be 16 byte-aligned. We also can't allocate in the contexts where we create these, so they must be stack-allocated. There's no great way to do this, but this CL makes the code at least a little clearer, and makes profilem and preemptM more consistent with each other. Change-Id: I5ec47a27d7580ed6003030bf953e668e8cae2cef Reviewed-on: https://go-review.googlesource.com/c/go/+/207967 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
parent
b89f4c6720
commit
2a029b3f26
@ -1027,17 +1027,17 @@ func callbackasm1()
|
||||
var profiletimer uintptr
|
||||
|
||||
func profilem(mp *m, thread uintptr) {
|
||||
var r *context
|
||||
rbuf := make([]byte, unsafe.Sizeof(*r)+15)
|
||||
// Align Context to 16 bytes.
|
||||
var c *context
|
||||
var cbuf [unsafe.Sizeof(*c) + 15]byte
|
||||
c = (*context)(unsafe.Pointer((uintptr(unsafe.Pointer(&cbuf[15]))) &^ 15))
|
||||
|
||||
// align Context to 16 bytes
|
||||
r = (*context)(unsafe.Pointer((uintptr(unsafe.Pointer(&rbuf[15]))) &^ 15))
|
||||
r.contextflags = _CONTEXT_CONTROL
|
||||
stdcall2(_GetThreadContext, thread, uintptr(unsafe.Pointer(r)))
|
||||
c.contextflags = _CONTEXT_CONTROL
|
||||
stdcall2(_GetThreadContext, thread, uintptr(unsafe.Pointer(c)))
|
||||
|
||||
gp := gFromTLS(mp)
|
||||
|
||||
sigprof(r.ip(), r.sp(), r.lr(), gp, mp)
|
||||
sigprof(c.ip(), c.sp(), c.lr(), gp, mp)
|
||||
}
|
||||
|
||||
func gFromTLS(mp *m) *g {
|
||||
@ -1153,10 +1153,9 @@ func preemptM(mp *m) {
|
||||
stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS)
|
||||
unlock(&mp.threadLock)
|
||||
|
||||
// Prepare thread context buffer.
|
||||
// Prepare thread context buffer. This must be aligned to 16 bytes.
|
||||
var c *context
|
||||
cbuf := make([]byte, unsafe.Sizeof(*c)+15)
|
||||
// Align Context to 16 bytes.
|
||||
var cbuf [unsafe.Sizeof(*c) + 15]byte
|
||||
c = (*context)(unsafe.Pointer((uintptr(unsafe.Pointer(&cbuf[15]))) &^ 15))
|
||||
c.contextflags = _CONTEXT_CONTROL
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user