Commit 16ce2f93 authored by Wei Guangjing's avatar Wei Guangjing Committed by Russ Cox

os: Process.handle use syscall.Handle

R=golang-dev, alex.brainman, rsc
CC=golang-dev
https://golang.org/cl/5605050
parent cdabb3d3
...@@ -12,11 +12,11 @@ import ( ...@@ -12,11 +12,11 @@ import (
// Process stores the information about a process created by StartProcess. // Process stores the information about a process created by StartProcess.
type Process struct { type Process struct {
Pid int Pid int
handle int handle uintptr
done bool // process has been successfuly waited on done bool // process has been successfuly waited on
} }
func newProcess(pid, handle int) *Process { func newProcess(pid int, handle uintptr) *Process {
p := &Process{Pid: pid, handle: handle} p := &Process{Pid: pid, handle: handle}
runtime.SetFinalizer(p, (*Process).Release) runtime.SetFinalizer(p, (*Process).Release)
return p return p
......
...@@ -46,14 +46,14 @@ func (p *Process) Signal(sig Signal) error { ...@@ -46,14 +46,14 @@ func (p *Process) Signal(sig Signal) error {
// Release releases any resources associated with the Process. // Release releases any resources associated with the Process.
func (p *Process) Release() error { func (p *Process) Release() error {
if p.handle == -1 { if p.handle == uintptr(syscall.InvalidHandle) {
return EINVAL return EINVAL
} }
e := syscall.CloseHandle(syscall.Handle(p.handle)) e := syscall.CloseHandle(syscall.Handle(p.handle))
if e != nil { if e != nil {
return NewSyscallError("CloseHandle", e) return NewSyscallError("CloseHandle", e)
} }
p.handle = -1 p.handle = uintptr(syscall.InvalidHandle)
// no need for a finalizer anymore // no need for a finalizer anymore
runtime.SetFinalizer(p, nil) runtime.SetFinalizer(p, nil)
return nil return nil
...@@ -66,7 +66,7 @@ func findProcess(pid int) (p *Process, err error) { ...@@ -66,7 +66,7 @@ func findProcess(pid int) (p *Process, err error) {
if e != nil { if e != nil {
return nil, NewSyscallError("OpenProcess", e) return nil, NewSyscallError("OpenProcess", e)
} }
return newProcess(pid, int(h)), nil return newProcess(pid, uintptr(h)), nil
} }
func init() { func init() {
......
...@@ -483,7 +483,7 @@ func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) ...@@ -483,7 +483,7 @@ func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
} }
// StartProcess wraps ForkExec for package os. // StartProcess wraps ForkExec for package os.
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, err error) { func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
pid, err = forkExec(argv0, argv, attr) pid, err = forkExec(argv0, argv, attr)
return pid, 0, err return pid, 0, err
} }
......
...@@ -208,7 +208,7 @@ func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) ...@@ -208,7 +208,7 @@ func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
} }
// StartProcess wraps ForkExec for package os. // StartProcess wraps ForkExec for package os.
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, err error) { func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
pid, err = forkExec(argv0, argv, attr) pid, err = forkExec(argv0, argv, attr)
return pid, 0, err return pid, 0, err
} }
......
...@@ -232,7 +232,7 @@ type SysProcAttr struct { ...@@ -232,7 +232,7 @@ type SysProcAttr struct {
var zeroProcAttr ProcAttr var zeroProcAttr ProcAttr
var zeroSysProcAttr SysProcAttr var zeroSysProcAttr SysProcAttr
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, err error) { func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
if len(argv0) == 0 { if len(argv0) == 0 {
return 0, 0, EWINDOWS return 0, 0, EWINDOWS
} }
...@@ -319,7 +319,7 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, ...@@ -319,7 +319,7 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int,
} }
defer CloseHandle(Handle(pi.Thread)) defer CloseHandle(Handle(pi.Thread))
return int(pi.ProcessId), int(pi.Process), nil return int(pi.ProcessId), uintptr(pi.Process), nil
} }
func Exec(argv0 string, argv []string, envv []string) (err error) { func Exec(argv0 string, argv []string, envv []string) (err error) {
......
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