OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [os/] [exec_windows.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package os
6
 
7
import (
8
        "errors"
9
        "runtime"
10
        "syscall"
11
        "unsafe"
12
)
13
 
14
// Wait waits for the Process to exit or stop, and then returns a
15
// Waitmsg describing its status and an error, if any.
16
func (p *Process) Wait(options int) (w *Waitmsg, err error) {
17
        s, e := syscall.WaitForSingleObject(syscall.Handle(p.handle), syscall.INFINITE)
18
        switch s {
19
        case syscall.WAIT_OBJECT_0:
20
                break
21
        case syscall.WAIT_FAILED:
22
                return nil, NewSyscallError("WaitForSingleObject", e)
23
        default:
24
                return nil, errors.New("os: unexpected result from WaitForSingleObject")
25
        }
26
        var ec uint32
27
        e = syscall.GetExitCodeProcess(syscall.Handle(p.handle), &ec)
28
        if e != nil {
29
                return nil, NewSyscallError("GetExitCodeProcess", e)
30
        }
31
        p.done = true
32
        return &Waitmsg{p.Pid, syscall.WaitStatus{Status: s, ExitCode: ec}, new(syscall.Rusage)}, nil
33
}
34
 
35
// Signal sends a signal to the Process.
36
func (p *Process) Signal(sig Signal) error {
37
        if p.done {
38
                return errors.New("os: process already finished")
39
        }
40
        if us, ok := sig.(UnixSignal); ok && us == syscall.SIGKILL {
41
                e := syscall.TerminateProcess(syscall.Handle(p.handle), 1)
42
                return NewSyscallError("TerminateProcess", e)
43
        }
44
        return syscall.Errno(syscall.EWINDOWS)
45
}
46
 
47
// Release releases any resources associated with the Process.
48
func (p *Process) Release() error {
49
        if p.handle == uintptr(syscall.InvalidHandle) {
50
                return EINVAL
51
        }
52
        e := syscall.CloseHandle(syscall.Handle(p.handle))
53
        if e != nil {
54
                return NewSyscallError("CloseHandle", e)
55
        }
56
        p.handle = uintptr(syscall.InvalidHandle)
57
        // no need for a finalizer anymore
58
        runtime.SetFinalizer(p, nil)
59
        return nil
60
}
61
 
62
func findProcess(pid int) (p *Process, err error) {
63
        const da = syscall.STANDARD_RIGHTS_READ |
64
                syscall.PROCESS_QUERY_INFORMATION | syscall.SYNCHRONIZE
65
        h, e := syscall.OpenProcess(da, false, uint32(pid))
66
        if e != nil {
67
                return nil, NewSyscallError("OpenProcess", e)
68
        }
69
        return newProcess(pid, uintptr(h)), nil
70
}
71
 
72
func init() {
73
        var argc int32
74
        cmd := syscall.GetCommandLine()
75
        argv, e := syscall.CommandLineToArgv(cmd, &argc)
76
        if e != nil {
77
                return
78
        }
79
        defer syscall.LocalFree(syscall.Handle(uintptr(unsafe.Pointer(argv))))
80
        Args = make([]string, argc)
81
        for i, v := range (*argv)[:argc] {
82
                Args[i] = string(syscall.UTF16ToString((*v)[:]))
83
        }
84
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.