]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: support Getpid() on Windows
authorShenghou Ma <minux.ma@gmail.com>
Tue, 10 Apr 2012 14:34:31 +0000 (22:34 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Tue, 10 Apr 2012 14:34:31 +0000 (22:34 +0800)
        Fixes #3379.

R=golang-dev, alex.brainman, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5909043

src/pkg/syscall/syscall_windows.go
src/pkg/syscall/zsyscall_windows_386.go
src/pkg/syscall/zsyscall_windows_amd64.go

index 47209da8fecd7a436306c1153108d5906910124a..978da92ec2e2c63d01835cc6bbd2b1f87a222e33 100644 (file)
@@ -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  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  GetCurrentProcessId() (pid uint32) = kernel32.GetCurrentProcessId
 
 // syscall interface implementation for other packages
 
@@ -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 }
 
-// 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 Fchdir(fd Handle) (err error)                        { return EWINDOWS }
index 8e6afcf0a859c2ce2092c1f0fac45e6adc26624d..dd97f7fcd2fc3ff18935ecbb99ec016bdc603d57 100644 (file)
@@ -142,6 +142,7 @@ var (
        procOpenProcessToken                 = modadvapi32.NewProc("OpenProcessToken")
        procGetTokenInformation              = modadvapi32.NewProc("GetTokenInformation")
        procGetUserProfileDirectoryW         = moduserenv.NewProc("GetUserProfileDirectoryW")
+       procGetCurrentProcessId              = modkernel32.NewProc("GetCurrentProcessId")
 )
 
 func GetLastError() (lasterr error) {
@@ -1600,3 +1601,9 @@ func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
        }
        return
 }
+
+func GetCurrentProcessId() (pid uint32) {
+       r0, _, _ := Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
+       pid = uint32(r0)
+       return
+}
index c6ff6fe02e228c7d651b97a3713f52b616ef593e..a45c61defd1178378702b966a208bbf09072667f 100644 (file)
@@ -142,6 +142,7 @@ var (
        procOpenProcessToken                 = modadvapi32.NewProc("OpenProcessToken")
        procGetTokenInformation              = modadvapi32.NewProc("GetTokenInformation")
        procGetUserProfileDirectoryW         = moduserenv.NewProc("GetUserProfileDirectoryW")
+       procGetCurrentProcessId              = modkernel32.NewProc("GetCurrentProcessId")
 )
 
 func GetLastError() (lasterr error) {
@@ -1600,3 +1601,9 @@ func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
        }
        return
 }
+
+func GetCurrentProcessId() (pid uint32) {
+       r0, _, _ := Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
+       pid = uint32(r0)
+       return
+}