return 0
}
-// in sys_windows_386.s and sys_windows_amd64.s
-func profileloop()
-
// called from zcallback_windows_*.s to sys_windows_*.s
func callbackasm1()
return nil
}
-func profileloop1(param uintptr) uint32 {
+func profileLoop() {
stdcall2(_SetThreadPriority, currentThread, _THREAD_PRIORITY_HIGHEST)
for {
stdcall2(_WaitForSingleObject, profiletimer, _INFINITE)
first := (*m)(atomic.Loadp(unsafe.Pointer(&allm)))
for mp := first; mp != nil; mp = mp.alllink {
+ if mp == getg().m {
+ // Don't profile ourselves.
+ continue
+ }
+
lock(&mp.threadLock)
// Do not profile threads blocked on Notes,
// this includes idle worker threads,
// Acquire our own handle to the thread.
var thread uintptr
if stdcall7(_DuplicateHandle, currentProcess, mp.thread, currentProcess, uintptr(unsafe.Pointer(&thread)), 0, 0, _DUPLICATE_SAME_ACCESS) == 0 {
- print("runtime.profileloop1: duplicatehandle failed; errno=", getlasterror(), "\n")
- throw("runtime.profileloop1: duplicatehandle failed")
+ print("runtime: duplicatehandle failed; errno=", getlasterror(), "\n")
+ throw("duplicatehandle failed")
}
unlock(&mp.threadLock)
if profiletimer == 0 {
timer := stdcall3(_CreateWaitableTimerA, 0, 0, 0)
atomic.Storeuintptr(&profiletimer, timer)
- thread := stdcall6(_CreateThread, 0, 0, funcPC(profileloop), 0, 0, 0)
- stdcall2(_SetThreadPriority, thread, _THREAD_PRIORITY_HIGHEST)
- stdcall1(_CloseHandle, thread)
+ newm(profileLoop, nil, -1)
}
}
MOVL $runtime·lastcontinuehandler(SB), AX
JMP sigtramp<>(SB)
-// Called by OS using stdcall ABI: uint32 profileloop(void*).
-TEXT runtime·profileloop<ABIInternal>(SB),NOSPLIT,$0
- PUSHL $runtime·profileloop1(SB)
- NOP SP // tell vet SP changed - stop checking offsets
- CALL runtime·externalthreadhandler(SB)
- MOVL 4(SP), CX
- ADDL $12, SP
- JMP CX
-
TEXT runtime·externalthreadhandler<ABIInternal>(SB),NOSPLIT|TOPFRAME,$0
PUSHL BP
MOVL SP, BP
MOVQ $runtime·lastcontinuehandler(SB), AX
JMP sigtramp<>(SB)
-TEXT runtime·profileloop<ABIInternal>(SB),NOSPLIT|NOFRAME,$8
- MOVQ $runtime·profileloop1(SB), CX
- MOVQ CX, 0(SP)
- CALL runtime·externalthreadhandler<ABIInternal>(SB)
- RET
-
TEXT runtime·externalthreadhandler<ABIInternal>(SB),NOSPLIT|NOFRAME|TOPFRAME,$0
PUSHQ BP
MOVQ SP, BP
MOVW $runtime·lastcontinuehandler(SB), R1
B sigtramp<>(SB)
-TEXT runtime·profileloop<ABIInternal>(SB),NOSPLIT|NOFRAME,$0
- MOVW $runtime·profileloop1(SB), R1
- B runtime·externalthreadhandler<ABIInternal>(SB)
-
// int32 externalthreadhandler(uint32 arg, int (*func)(uint32))
// stack layout:
// +----------------+
MOVD $runtime·lastcontinuehandler<ABIInternal>(SB), R1
B sigtramp<>(SB)
-TEXT runtime·profileloop<ABIInternal>(SB),NOSPLIT|NOFRAME,$0
- MOVD $runtime·profileloop1(SB), R1
- B runtime·externalthreadhandler<ABIInternal>(SB)
-
// externalthreadhander called with R0 = uint32 arg, R1 = Go function f.
// Need to call f(arg), which returns a uint32, and return it in R0.
TEXT runtime·externalthreadhandler<ABIInternal>(SB),NOSPLIT|TOPFRAME,$96-0