Commit ae382129 authored by Shenghou Ma's avatar Shenghou Ma

syscall: support Getpid() on Windows

        Fixes #3379.

R=golang-dev, alex.brainman, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5909043
parent edf8b03f
...@@ -199,6 +199,7 @@ func NewCallback(fn interface{}) uintptr ...@@ -199,6 +199,7 @@ func NewCallback(fn interface{}) uintptr
//sys RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) = advapi32.RegQueryInfoKeyW //sys RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) = advapi32.RegQueryInfoKeyW
//sys RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) = advapi32.RegEnumKeyExW //sys RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) = advapi32.RegEnumKeyExW
//sys RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegQueryValueExW //sys RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegQueryValueExW
//sys GetCurrentProcessId() (pid uint32) = kernel32.GetCurrentProcessId
// syscall interface implementation for other packages // syscall interface implementation for other packages
...@@ -681,9 +682,9 @@ func SetsockoptIPMreq(fd Handle, level, opt int, mreq *IPMreq) (err error) { ...@@ -681,9 +682,9 @@ func SetsockoptIPMreq(fd Handle, level, opt int, mreq *IPMreq) (err error) {
} }
func SetsockoptIPv6Mreq(fd Handle, level, opt int, mreq *IPv6Mreq) (err error) { return EWINDOWS } func SetsockoptIPv6Mreq(fd Handle, level, opt int, mreq *IPv6Mreq) (err error) { return EWINDOWS }
// TODO(brainman): fix all needed for os func Getpid() (pid int) { return int(GetCurrentProcessId()) }
func Getpid() (pid int) { return -1 } // TODO(brainman): fix all needed for os
func Getppid() (ppid int) { return -1 } func Getppid() (ppid int) { return -1 }
func Fchdir(fd Handle) (err error) { return EWINDOWS } func Fchdir(fd Handle) (err error) { return EWINDOWS }
......
...@@ -142,6 +142,7 @@ var ( ...@@ -142,6 +142,7 @@ var (
procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken") procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation") procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation")
procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW") procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
) )
func GetLastError() (lasterr error) { func GetLastError() (lasterr error) {
...@@ -1600,3 +1601,9 @@ func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) { ...@@ -1600,3 +1601,9 @@ func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
} }
return return
} }
func GetCurrentProcessId() (pid uint32) {
r0, _, _ := Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
pid = uint32(r0)
return
}
...@@ -142,6 +142,7 @@ var ( ...@@ -142,6 +142,7 @@ var (
procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken") procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation") procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation")
procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW") procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
) )
func GetLastError() (lasterr error) { func GetLastError() (lasterr error) {
...@@ -1600,3 +1601,9 @@ func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) { ...@@ -1600,3 +1601,9 @@ func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
} }
return return
} }
func GetCurrentProcessId() (pid uint32) {
r0, _, _ := Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
pid = uint32(r0)
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment