mirror of
https://github.com/containers/podman.git
synced 2025-06-19 16:33:24 +08:00
Vendor in latest containers/storage
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com> Closes: #1061 Approved by: baude
This commit is contained in:

committed by
Atomic Bot

parent
5a8e5a2b17
commit
f661e1d21d
@ -11,7 +11,7 @@ github.com/containerd/continuity master
|
|||||||
github.com/containernetworking/cni v0.6.0
|
github.com/containernetworking/cni v0.6.0
|
||||||
github.com/containernetworking/plugins 1fb94a4222eafc6f948eacdca9c9f2158b427e53
|
github.com/containernetworking/plugins 1fb94a4222eafc6f948eacdca9c9f2158b427e53
|
||||||
github.com/containers/image 5144ced37a1b21b63c6ef605e56811e29a687528
|
github.com/containers/image 5144ced37a1b21b63c6ef605e56811e29a687528
|
||||||
github.com/containers/storage 51f1f85c2b7863b2fd361471f05b937fd8059124
|
github.com/containers/storage 90d0a58ffabb324042e074d33d1f6fbf3185c789
|
||||||
github.com/coreos/go-systemd v14
|
github.com/coreos/go-systemd v14
|
||||||
github.com/cri-o/ocicni master
|
github.com/cri-o/ocicni master
|
||||||
github.com/cyphar/filepath-securejoin v0.2.1
|
github.com/cyphar/filepath-securejoin v0.2.1
|
||||||
|
3
vendor/github.com/containers/storage/README.md
generated
vendored
3
vendor/github.com/containers/storage/README.md
generated
vendored
@ -41,3 +41,6 @@ memory and stored along with the library's own bookkeeping information.
|
|||||||
Additionally, the library can store one or more of what it calls *big data* for
|
Additionally, the library can store one or more of what it calls *big data* for
|
||||||
images and containers. This is a named chunk of larger data, which is only in
|
images and containers. This is a named chunk of larger data, which is only in
|
||||||
memory when it is being read from or being written to its own disk file.
|
memory when it is being read from or being written to its own disk file.
|
||||||
|
|
||||||
|
**[Contributing](CONTRIBUTING.md)**
|
||||||
|
Information about contributing to this project.
|
||||||
|
85
vendor/github.com/containers/storage/drivers/overlay/overlay.go
generated
vendored
85
vendor/github.com/containers/storage/drivers/overlay/overlay.go
generated
vendored
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/containers/storage/pkg/idtools"
|
"github.com/containers/storage/pkg/idtools"
|
||||||
"github.com/containers/storage/pkg/locker"
|
"github.com/containers/storage/pkg/locker"
|
||||||
"github.com/containers/storage/pkg/mount"
|
"github.com/containers/storage/pkg/mount"
|
||||||
|
"github.com/containers/storage/pkg/ostree"
|
||||||
"github.com/containers/storage/pkg/parsers"
|
"github.com/containers/storage/pkg/parsers"
|
||||||
"github.com/containers/storage/pkg/system"
|
"github.com/containers/storage/pkg/system"
|
||||||
units "github.com/docker/go-units"
|
units "github.com/docker/go-units"
|
||||||
@ -84,6 +85,9 @@ type overlayOptions struct {
|
|||||||
overrideKernelCheck bool
|
overrideKernelCheck bool
|
||||||
imageStores []string
|
imageStores []string
|
||||||
quota quota.Quota
|
quota quota.Quota
|
||||||
|
fuseProgram string
|
||||||
|
ostreeRepo string
|
||||||
|
skipMountHome bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver contains information about the home directory and the list of active mounts that are created using this driver.
|
// Driver contains information about the home directory and the list of active mounts that are created using this driver.
|
||||||
@ -98,6 +102,7 @@ type Driver struct {
|
|||||||
naiveDiff graphdriver.DiffDriver
|
naiveDiff graphdriver.DiffDriver
|
||||||
supportsDType bool
|
supportsDType bool
|
||||||
locker *locker.Locker
|
locker *locker.Locker
|
||||||
|
convert map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -147,15 +152,28 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
supportsDType, err := supportsOverlay(home, fsMagic, rootUID, rootGID)
|
var supportsDType bool
|
||||||
if err != nil {
|
if opts.fuseProgram != "" {
|
||||||
os.Remove(filepath.Join(home, linkDir))
|
supportsDType = true
|
||||||
os.Remove(home)
|
} else {
|
||||||
return nil, errors.Wrap(err, "kernel does not support overlay fs")
|
supportsDType, err = supportsOverlay(home, fsMagic, rootUID, rootGID)
|
||||||
|
if err != nil {
|
||||||
|
os.Remove(filepath.Join(home, linkDir))
|
||||||
|
os.Remove(home)
|
||||||
|
return nil, errors.Wrap(err, "kernel does not support overlay fs")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := mount.MakePrivate(home); err != nil {
|
if !opts.skipMountHome {
|
||||||
return nil, err
|
if err := mount.MakePrivate(home); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.ostreeRepo != "" {
|
||||||
|
if err := ostree.CreateOSTreeRepository(opts.ostreeRepo, rootUID, rootGID); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d := &Driver{
|
d := &Driver{
|
||||||
@ -167,6 +185,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
|||||||
supportsDType: supportsDType,
|
supportsDType: supportsDType,
|
||||||
locker: locker.New(),
|
locker: locker.New(),
|
||||||
options: *opts,
|
options: *opts,
|
||||||
|
convert: make(map[string]bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
d.naiveDiff = graphdriver.NewNaiveDiffDriver(d, d)
|
d.naiveDiff = graphdriver.NewNaiveDiffDriver(d, d)
|
||||||
@ -227,6 +246,25 @@ func parseOptions(options []string) (*overlayOptions, error) {
|
|||||||
}
|
}
|
||||||
o.imageStores = append(o.imageStores, store)
|
o.imageStores = append(o.imageStores, store)
|
||||||
}
|
}
|
||||||
|
case ".fuse_program", "overlay.fuse_program", "overlay2.fuse_program":
|
||||||
|
logrus.Debugf("overlay: fuse_program=%s", val)
|
||||||
|
_, err := os.Stat(val)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("overlay: can't stat FUSE program %s: %v", val, err)
|
||||||
|
}
|
||||||
|
o.fuseProgram = val
|
||||||
|
case "overlay2.ostree_repo", "overlay.ostree_repo", ".ostree_repo":
|
||||||
|
logrus.Debugf("overlay: ostree_repo=%s", val)
|
||||||
|
if !ostree.OstreeSupport() {
|
||||||
|
return nil, fmt.Errorf("overlay: ostree_repo specified but support for ostree is missing")
|
||||||
|
}
|
||||||
|
o.ostreeRepo = val
|
||||||
|
case "overlay2.skip_mount_home", "overlay.skip_mount_home", ".skip_mount_home":
|
||||||
|
logrus.Debugf("overlay: skip_mount_home=%s", val)
|
||||||
|
o.skipMountHome, err = strconv.ParseBool(val)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("overlay: Unknown option %s", key)
|
return nil, fmt.Errorf("overlay: Unknown option %s", key)
|
||||||
}
|
}
|
||||||
@ -236,6 +274,7 @@ func parseOptions(options []string) (*overlayOptions, error) {
|
|||||||
|
|
||||||
func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGID int) (supportsDType bool, err error) {
|
func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGID int) (supportsDType bool, err error) {
|
||||||
// We can try to modprobe overlay first
|
// We can try to modprobe overlay first
|
||||||
|
|
||||||
exec.Command("modprobe", "overlay").Run()
|
exec.Command("modprobe", "overlay").Run()
|
||||||
|
|
||||||
layerDir, err := ioutil.TempDir(home, "compat")
|
layerDir, err := ioutil.TempDir(home, "compat")
|
||||||
@ -380,6 +419,11 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) (retErr
|
|||||||
return fmt.Errorf("--storage-opt size is only supported for ReadWrite Layers")
|
return fmt.Errorf("--storage-opt size is only supported for ReadWrite Layers")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.options.ostreeRepo != "" {
|
||||||
|
d.convert[id] = true
|
||||||
|
}
|
||||||
|
|
||||||
return d.create(id, parent, opts)
|
return d.create(id, parent, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,6 +591,12 @@ func (d *Driver) getLowerDirs(id string) ([]string, error) {
|
|||||||
func (d *Driver) Remove(id string) error {
|
func (d *Driver) Remove(id string) error {
|
||||||
d.locker.Lock(id)
|
d.locker.Lock(id)
|
||||||
defer d.locker.Unlock(id)
|
defer d.locker.Unlock(id)
|
||||||
|
|
||||||
|
// Ignore errors, we don't want to fail if the ostree branch doesn't exist,
|
||||||
|
if d.options.ostreeRepo != "" {
|
||||||
|
ostree.DeleteOSTree(d.options.ostreeRepo, id)
|
||||||
|
}
|
||||||
|
|
||||||
dir := d.dir(id)
|
dir := d.dir(id)
|
||||||
lid, err := ioutil.ReadFile(path.Join(dir, "link"))
|
lid, err := ioutil.ReadFile(path.Join(dir, "link"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -663,7 +713,7 @@ func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) {
|
|||||||
// the page size. The mount syscall fails if the mount data cannot
|
// the page size. The mount syscall fails if the mount data cannot
|
||||||
// fit within a page and relative links make the mount data much
|
// fit within a page and relative links make the mount data much
|
||||||
// smaller at the expense of requiring a fork exec to chroot.
|
// smaller at the expense of requiring a fork exec to chroot.
|
||||||
if len(mountData) > pageSize {
|
if len(mountData) > pageSize || d.options.fuseProgram != "" {
|
||||||
//FIXME: We need to figure out to get this to work with additional stores
|
//FIXME: We need to figure out to get this to work with additional stores
|
||||||
opts = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(relLowers, ":"), path.Join(id, "diff"), path.Join(id, "work"))
|
opts = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(relLowers, ":"), path.Join(id, "diff"), path.Join(id, "work"))
|
||||||
mountData = label.FormatMountLabel(opts, mountLabel)
|
mountData = label.FormatMountLabel(opts, mountLabel)
|
||||||
@ -671,8 +721,16 @@ func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) {
|
|||||||
return "", fmt.Errorf("cannot mount layer, mount label too large %d", len(mountData))
|
return "", fmt.Errorf("cannot mount layer, mount label too large %d", len(mountData))
|
||||||
}
|
}
|
||||||
|
|
||||||
mount = func(source string, target string, mType string, flags uintptr, label string) error {
|
if d.options.fuseProgram != "" {
|
||||||
return mountFrom(d.home, source, target, mType, flags, label)
|
mount = func(source string, target string, mType string, flags uintptr, label string) error {
|
||||||
|
cmdRootless := exec.Command(d.options.fuseProgram, "-o", label, target)
|
||||||
|
cmdRootless.Dir = d.home
|
||||||
|
return cmdRootless.Run()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mount = func(source string, target string, mType string, flags uintptr, label string) error {
|
||||||
|
return mountFrom(d.home, source, target, mType, flags, label)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mountTarget = path.Join(id, "merged")
|
mountTarget = path.Join(id, "merged")
|
||||||
}
|
}
|
||||||
@ -764,6 +822,13 @@ func (d *Driver) ApplyDiff(id string, idMappings *idtools.IDMappings, parent str
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, convert := d.convert[id]
|
||||||
|
if convert {
|
||||||
|
if err := ostree.ConvertToOSTree(d.options.ostreeRepo, applyDir, id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return directory.Size(applyDir)
|
return directory.Size(applyDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
54
vendor/github.com/containers/storage/drivers/vfs/driver.go
generated
vendored
54
vendor/github.com/containers/storage/drivers/vfs/driver.go
generated
vendored
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/containers/storage/drivers"
|
"github.com/containers/storage/drivers"
|
||||||
"github.com/containers/storage/pkg/chrootarchive"
|
"github.com/containers/storage/pkg/chrootarchive"
|
||||||
"github.com/containers/storage/pkg/idtools"
|
"github.com/containers/storage/pkg/idtools"
|
||||||
|
"github.com/containers/storage/pkg/ostree"
|
||||||
"github.com/containers/storage/pkg/system"
|
"github.com/containers/storage/pkg/system"
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
)
|
)
|
||||||
@ -42,6 +43,27 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
|||||||
d.homes = append(d.homes, strings.Split(option[12:], ",")...)
|
d.homes = append(d.homes, strings.Split(option[12:], ",")...)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(option, "vfs.ostree_repo=") {
|
||||||
|
if !ostree.OstreeSupport() {
|
||||||
|
return nil, fmt.Errorf("vfs: ostree_repo specified but support for ostree is missing")
|
||||||
|
}
|
||||||
|
d.ostreeRepo = option[16:]
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(option, ".ostree_repo=") {
|
||||||
|
if !ostree.OstreeSupport() {
|
||||||
|
return nil, fmt.Errorf("vfs: ostree_repo specified but support for ostree is missing")
|
||||||
|
}
|
||||||
|
d.ostreeRepo = option[13:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if d.ostreeRepo != "" {
|
||||||
|
rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := ostree.CreateOSTreeRepository(d.ostreeRepo, rootUID, rootGID); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return graphdriver.NewNaiveDiffDriver(d, graphdriver.NewNaiveLayerIDMapUpdater(d)), nil
|
return graphdriver.NewNaiveDiffDriver(d, graphdriver.NewNaiveLayerIDMapUpdater(d)), nil
|
||||||
}
|
}
|
||||||
@ -53,6 +75,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
|||||||
type Driver struct {
|
type Driver struct {
|
||||||
homes []string
|
homes []string
|
||||||
idMappings *idtools.IDMappings
|
idMappings *idtools.IDMappings
|
||||||
|
ostreeRepo string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) String() string {
|
func (d *Driver) String() string {
|
||||||
@ -77,11 +100,15 @@ func (d *Driver) Cleanup() error {
|
|||||||
// CreateReadWrite creates a layer that is writable for use as a container
|
// CreateReadWrite creates a layer that is writable for use as a container
|
||||||
// file system.
|
// file system.
|
||||||
func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error {
|
func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error {
|
||||||
return d.Create(id, parent, opts)
|
return d.create(id, parent, opts, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create prepares the filesystem for the VFS driver and copies the directory for the given id under the parent.
|
// Create prepares the filesystem for the VFS driver and copies the directory for the given id under the parent.
|
||||||
func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
|
func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
|
||||||
|
return d.create(id, parent, opts, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts, ro bool) error {
|
||||||
if opts != nil && len(opts.StorageOpt) != 0 {
|
if opts != nil && len(opts.StorageOpt) != 0 {
|
||||||
return fmt.Errorf("--storage-opt is not supported for vfs")
|
return fmt.Errorf("--storage-opt is not supported for vfs")
|
||||||
}
|
}
|
||||||
@ -106,14 +133,23 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
|
|||||||
if _, mountLabel, err := label.InitLabels(labelOpts); err == nil {
|
if _, mountLabel, err := label.InitLabels(labelOpts); err == nil {
|
||||||
label.SetFileLabel(dir, mountLabel)
|
label.SetFileLabel(dir, mountLabel)
|
||||||
}
|
}
|
||||||
if parent == "" {
|
if parent != "" {
|
||||||
return nil
|
parentDir, err := d.Get(parent, "")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%s: %s", parent, err)
|
||||||
|
}
|
||||||
|
if err := CopyWithTar(parentDir, dir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
parentDir, err := d.Get(parent, "")
|
|
||||||
if err != nil {
|
if ro && d.ostreeRepo != "" {
|
||||||
return fmt.Errorf("%s: %s", parent, err)
|
if err := ostree.ConvertToOSTree(d.ostreeRepo, dir, id); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return CopyWithTar(parentDir, dir)
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) dir(id string) string {
|
func (d *Driver) dir(id string) string {
|
||||||
@ -132,6 +168,10 @@ func (d *Driver) dir(id string) string {
|
|||||||
|
|
||||||
// Remove deletes the content from the directory for a given id.
|
// Remove deletes the content from the directory for a given id.
|
||||||
func (d *Driver) Remove(id string) error {
|
func (d *Driver) Remove(id string) error {
|
||||||
|
if d.ostreeRepo != "" {
|
||||||
|
// Ignore errors, we don't want to fail if the ostree branch doesn't exist,
|
||||||
|
ostree.DeleteOSTree(d.ostreeRepo, id)
|
||||||
|
}
|
||||||
return system.EnsureRemoveAll(d.dir(id))
|
return system.EnsureRemoveAll(d.dir(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
97
vendor/github.com/containers/storage/pkg/archive/example_changes.go
generated
vendored
Normal file
97
vendor/github.com/containers/storage/pkg/archive/example_changes.go
generated
vendored
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
// +build ignore
|
||||||
|
|
||||||
|
// Simple tool to create an archive stream from an old and new directory
|
||||||
|
//
|
||||||
|
// By default it will stream the comparison of two temporary directories with junk files
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"github.com/containers/storage/pkg/archive"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
flDebug = flag.Bool("D", false, "debugging output")
|
||||||
|
flNewDir = flag.String("newdir", "", "")
|
||||||
|
flOldDir = flag.String("olddir", "", "")
|
||||||
|
log = logrus.New()
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Println("Produce a tar from comparing two directory paths. By default a demo tar is created of around 200 files (including hardlinks)")
|
||||||
|
fmt.Printf("%s [OPTIONS]\n", os.Args[0])
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
|
flag.Parse()
|
||||||
|
log.Out = os.Stderr
|
||||||
|
if (len(os.Getenv("DEBUG")) > 0) || *flDebug {
|
||||||
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
}
|
||||||
|
var newDir, oldDir string
|
||||||
|
|
||||||
|
if len(*flNewDir) == 0 {
|
||||||
|
var err error
|
||||||
|
newDir, err = ioutil.TempDir("", "storage-test-newDir")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(newDir)
|
||||||
|
if _, err := prepareUntarSourceDirectory(100, newDir, true); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newDir = *flNewDir
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(*flOldDir) == 0 {
|
||||||
|
oldDir, err := ioutil.TempDir("", "storage-test-oldDir")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(oldDir)
|
||||||
|
} else {
|
||||||
|
oldDir = *flOldDir
|
||||||
|
}
|
||||||
|
|
||||||
|
changes, err := archive.ChangesDirs(newDir, oldDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a, err := archive.ExportChanges(newDir, changes)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer a.Close()
|
||||||
|
|
||||||
|
i, err := io.Copy(os.Stdout, a)
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "wrote archive of %d bytes", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func prepareUntarSourceDirectory(numberOfFiles int, targetPath string, makeLinks bool) (int, error) {
|
||||||
|
fileData := []byte("fooo")
|
||||||
|
for n := 0; n < numberOfFiles; n++ {
|
||||||
|
fileName := fmt.Sprintf("file-%d", n)
|
||||||
|
if err := ioutil.WriteFile(path.Join(targetPath, fileName), fileData, 0700); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if makeLinks {
|
||||||
|
if err := os.Link(path.Join(targetPath, fileName), path.Join(targetPath, fileName+"-link")); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalSize := numberOfFiles * len(fileData)
|
||||||
|
return totalSize, nil
|
||||||
|
}
|
19
vendor/github.com/containers/storage/pkg/ostree/no_ostree.go
generated
vendored
Normal file
19
vendor/github.com/containers/storage/pkg/ostree/no_ostree.go
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// +build !ostree
|
||||||
|
|
||||||
|
package ostree
|
||||||
|
|
||||||
|
func OstreeSupport() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteOSTree(repoLocation, id string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateOSTreeRepository(repoLocation string, rootUID int, rootGID int) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertToOSTree(repoLocation, root, id string) error {
|
||||||
|
return nil
|
||||||
|
}
|
198
vendor/github.com/containers/storage/pkg/ostree/ostree.go
generated
vendored
Normal file
198
vendor/github.com/containers/storage/pkg/ostree/ostree.go
generated
vendored
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
// +build ostree
|
||||||
|
|
||||||
|
package ostree
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/containers/storage/pkg/idtools"
|
||||||
|
"github.com/containers/storage/pkg/system"
|
||||||
|
glib "github.com/ostreedev/ostree-go/pkg/glibobject"
|
||||||
|
"github.com/ostreedev/ostree-go/pkg/otbuiltin"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// #cgo pkg-config: glib-2.0 gobject-2.0 ostree-1
|
||||||
|
// #include <glib.h>
|
||||||
|
// #include <glib-object.h>
|
||||||
|
// #include <gio/gio.h>
|
||||||
|
// #include <stdlib.h>
|
||||||
|
// #include <ostree.h>
|
||||||
|
// #include <gio/ginputstream.h>
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
func OstreeSupport() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func fixFiles(dir string, usermode bool) (bool, []string, error) {
|
||||||
|
var SkipOstree = errors.New("skip ostree deduplication")
|
||||||
|
|
||||||
|
var whiteouts []string
|
||||||
|
|
||||||
|
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if info.Mode()&(os.ModeNamedPipe|os.ModeSocket|os.ModeDevice) != 0 {
|
||||||
|
if !usermode {
|
||||||
|
stat, ok := info.Sys().(*syscall.Stat_t)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not syscall.Stat_t")
|
||||||
|
}
|
||||||
|
|
||||||
|
if stat.Rdev == 0 && (stat.Mode&unix.S_IFCHR) != 0 {
|
||||||
|
whiteouts = append(whiteouts, path)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Skip the ostree deduplication if we encounter a file type that
|
||||||
|
// ostree does not manage.
|
||||||
|
return SkipOstree
|
||||||
|
}
|
||||||
|
if info.IsDir() {
|
||||||
|
if usermode {
|
||||||
|
if err := os.Chmod(path, info.Mode()|0700); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if usermode && (info.Mode().IsRegular()) {
|
||||||
|
if err := os.Chmod(path, info.Mode()|0600); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err == SkipOstree {
|
||||||
|
return true, nil, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, err
|
||||||
|
}
|
||||||
|
return false, whiteouts, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create prepares the filesystem for the OSTREE driver and copies the directory for the given id under the parent.
|
||||||
|
func ConvertToOSTree(repoLocation, root, id string) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
repo, err := otbuiltin.OpenRepo(repoLocation)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "could not open the OSTree repository")
|
||||||
|
}
|
||||||
|
|
||||||
|
skip, whiteouts, err := fixFiles(root, os.Getuid() != 0)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "could not prepare the OSTree directory")
|
||||||
|
}
|
||||||
|
if skip {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := repo.PrepareTransaction(); err != nil {
|
||||||
|
return errors.Wrap(err, "could not prepare the OSTree transaction")
|
||||||
|
}
|
||||||
|
|
||||||
|
if skip {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
commitOpts := otbuiltin.NewCommitOptions()
|
||||||
|
commitOpts.Timestamp = time.Now()
|
||||||
|
commitOpts.LinkCheckoutSpeedup = true
|
||||||
|
commitOpts.Parent = "0000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
branch := fmt.Sprintf("containers-storage/%s", id)
|
||||||
|
|
||||||
|
for _, w := range whiteouts {
|
||||||
|
if err := os.Remove(w); err != nil {
|
||||||
|
return errors.Wrap(err, "could not delete whiteout file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := repo.Commit(root, branch, commitOpts); err != nil {
|
||||||
|
return errors.Wrap(err, "could not commit the layer")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := repo.CommitTransaction(); err != nil {
|
||||||
|
return errors.Wrap(err, "could not complete the OSTree transaction")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := system.EnsureRemoveAll(root); err != nil {
|
||||||
|
return errors.Wrap(err, "could not delete layer")
|
||||||
|
}
|
||||||
|
|
||||||
|
checkoutOpts := otbuiltin.NewCheckoutOptions()
|
||||||
|
checkoutOpts.RequireHardlinks = true
|
||||||
|
checkoutOpts.Whiteouts = false
|
||||||
|
if err := otbuiltin.Checkout(repoLocation, root, branch, checkoutOpts); err != nil {
|
||||||
|
return errors.Wrap(err, "could not checkout from OSTree")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, w := range whiteouts {
|
||||||
|
if err := unix.Mknod(w, unix.S_IFCHR, 0); err != nil {
|
||||||
|
return errors.Wrap(err, "could not recreate whiteout file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateOSTreeRepository(repoLocation string, rootUID int, rootGID int) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
_, err := os.Stat(repoLocation)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
} else if err != nil {
|
||||||
|
if err := idtools.MkdirAllAs(repoLocation, 0700, rootUID, rootGID); err != nil {
|
||||||
|
return errors.Wrap(err, "could not create OSTree repository directory: %v")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := otbuiltin.Init(repoLocation, otbuiltin.NewInitOptions()); err != nil {
|
||||||
|
return errors.Wrap(err, "could not create OSTree repository")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func openRepo(path string) (*C.struct_OstreeRepo, error) {
|
||||||
|
var cerr *C.GError
|
||||||
|
cpath := C.CString(path)
|
||||||
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
|
pathc := C.g_file_new_for_path(cpath)
|
||||||
|
defer C.g_object_unref(C.gpointer(pathc))
|
||||||
|
repo := C.ostree_repo_new(pathc)
|
||||||
|
r := glib.GoBool(glib.GBoolean(C.ostree_repo_open(repo, nil, &cerr)))
|
||||||
|
if !r {
|
||||||
|
C.g_object_unref(C.gpointer(repo))
|
||||||
|
return nil, glib.ConvertGError(glib.ToGError(unsafe.Pointer(cerr)))
|
||||||
|
}
|
||||||
|
return repo, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteOSTree(repoLocation, id string) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
repo, err := openRepo(repoLocation)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer C.g_object_unref(C.gpointer(repo))
|
||||||
|
|
||||||
|
branch := fmt.Sprintf("containers-storage/%s", id)
|
||||||
|
|
||||||
|
cbranch := C.CString(branch)
|
||||||
|
defer C.free(unsafe.Pointer(cbranch))
|
||||||
|
|
||||||
|
var cerr *C.GError
|
||||||
|
r := glib.GoBool(glib.GBoolean(C.ostree_repo_set_ref_immediate(repo, nil, cbranch, nil, nil, &cerr)))
|
||||||
|
if !r {
|
||||||
|
return glib.ConvertGError(glib.ToGError(unsafe.Pointer(cerr)))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
11
vendor/github.com/containers/storage/store.go
generated
vendored
11
vendor/github.com/containers/storage/store.go
generated
vendored
@ -2987,6 +2987,11 @@ type OptionsConfig struct {
|
|||||||
RemapGroup string `toml:"remap-group"`
|
RemapGroup string `toml:"remap-group"`
|
||||||
// Thinpool container options to be handed to thinpool drivers
|
// Thinpool container options to be handed to thinpool drivers
|
||||||
Thinpool struct{ ThinpoolOptionsConfig } `toml:"thinpool"`
|
Thinpool struct{ ThinpoolOptionsConfig } `toml:"thinpool"`
|
||||||
|
// OSTree repository
|
||||||
|
OstreeRepo string `toml:"ostree_repo"`
|
||||||
|
|
||||||
|
// Do not create a bind mount on the storage home
|
||||||
|
SkipMountHome string `toml:"skip_mount_home"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOML-friendly explicit tables used for conversions.
|
// TOML-friendly explicit tables used for conversions.
|
||||||
@ -3077,6 +3082,12 @@ func init() {
|
|||||||
if config.Storage.Options.Size != "" {
|
if config.Storage.Options.Size != "" {
|
||||||
DefaultStoreOptions.GraphDriverOptions = append(DefaultStoreOptions.GraphDriverOptions, fmt.Sprintf("%s.size=%s", config.Storage.Driver, config.Storage.Options.Size))
|
DefaultStoreOptions.GraphDriverOptions = append(DefaultStoreOptions.GraphDriverOptions, fmt.Sprintf("%s.size=%s", config.Storage.Driver, config.Storage.Options.Size))
|
||||||
}
|
}
|
||||||
|
if config.Storage.Options.OstreeRepo != "" {
|
||||||
|
DefaultStoreOptions.GraphDriverOptions = append(DefaultStoreOptions.GraphDriverOptions, fmt.Sprintf("%s.ostree_repo=%s", config.Storage.Driver, config.Storage.Options.OstreeRepo))
|
||||||
|
}
|
||||||
|
if config.Storage.Options.SkipMountHome != "" {
|
||||||
|
DefaultStoreOptions.GraphDriverOptions = append(DefaultStoreOptions.GraphDriverOptions, fmt.Sprintf("%s.skip_mount_home=%s", config.Storage.Driver, config.Storage.Options.SkipMountHome))
|
||||||
|
}
|
||||||
if config.Storage.Options.OverrideKernelCheck != "" {
|
if config.Storage.Options.OverrideKernelCheck != "" {
|
||||||
DefaultStoreOptions.GraphDriverOptions = append(DefaultStoreOptions.GraphDriverOptions, fmt.Sprintf("%s.override_kernel_check=%s", config.Storage.Driver, config.Storage.Options.OverrideKernelCheck))
|
DefaultStoreOptions.GraphDriverOptions = append(DefaultStoreOptions.GraphDriverOptions, fmt.Sprintf("%s.override_kernel_check=%s", config.Storage.Driver, config.Storage.Options.OverrideKernelCheck))
|
||||||
}
|
}
|
||||||
|
1
vendor/github.com/containers/storage/vendor.conf
generated
vendored
1
vendor/github.com/containers/storage/vendor.conf
generated
vendored
@ -20,3 +20,4 @@ github.com/tchap/go-patricia v2.2.6
|
|||||||
github.com/vbatts/tar-split v0.10.2
|
github.com/vbatts/tar-split v0.10.2
|
||||||
golang.org/x/net 7dcfb8076726a3fdd9353b6b8a1f1b6be6811bd6
|
golang.org/x/net 7dcfb8076726a3fdd9353b6b8a1f1b6be6811bd6
|
||||||
golang.org/x/sys 07c182904dbd53199946ba614a412c61d3c548f5
|
golang.org/x/sys 07c182904dbd53199946ba614a412c61d3c548f5
|
||||||
|
github.com/ostreedev/ostree-go aeb02c6b6aa2889db3ef62f7855650755befd460
|
||||||
|
38
vendor/golang.org/x/sys/cpu/cpu.go
generated
vendored
38
vendor/golang.org/x/sys/cpu/cpu.go
generated
vendored
@ -1,38 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package cpu implements processor feature detection for
|
|
||||||
// various CPU architectures.
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
// CacheLinePad is used to pad structs to avoid false sharing.
|
|
||||||
type CacheLinePad struct{ _ [cacheLineSize]byte }
|
|
||||||
|
|
||||||
// X86 contains the supported CPU features of the
|
|
||||||
// current X86/AMD64 platform. If the current platform
|
|
||||||
// is not X86/AMD64 then all feature flags are false.
|
|
||||||
//
|
|
||||||
// X86 is padded to avoid false sharing. Further the HasAVX
|
|
||||||
// and HasAVX2 are only set if the OS supports XMM and YMM
|
|
||||||
// registers in addition to the CPUID feature bit being set.
|
|
||||||
var X86 struct {
|
|
||||||
_ CacheLinePad
|
|
||||||
HasAES bool // AES hardware implementation (AES NI)
|
|
||||||
HasADX bool // Multi-precision add-carry instruction extensions
|
|
||||||
HasAVX bool // Advanced vector extension
|
|
||||||
HasAVX2 bool // Advanced vector extension 2
|
|
||||||
HasBMI1 bool // Bit manipulation instruction set 1
|
|
||||||
HasBMI2 bool // Bit manipulation instruction set 2
|
|
||||||
HasERMS bool // Enhanced REP for MOVSB and STOSB
|
|
||||||
HasFMA bool // Fused-multiply-add instructions
|
|
||||||
HasOSXSAVE bool // OS supports XSAVE/XRESTOR for saving/restoring XMM registers.
|
|
||||||
HasPCLMULQDQ bool // PCLMULQDQ instruction - most often used for AES-GCM
|
|
||||||
HasPOPCNT bool // Hamming weight instruction POPCNT.
|
|
||||||
HasSSE2 bool // Streaming SIMD extension 2 (always available on amd64)
|
|
||||||
HasSSE3 bool // Streaming SIMD extension 3
|
|
||||||
HasSSSE3 bool // Supplemental streaming SIMD extension 3
|
|
||||||
HasSSE41 bool // Streaming SIMD extension 4 and 4.1
|
|
||||||
HasSSE42 bool // Streaming SIMD extension 4 and 4.2
|
|
||||||
_ CacheLinePad
|
|
||||||
}
|
|
7
vendor/golang.org/x/sys/cpu/cpu_arm.go
generated
vendored
7
vendor/golang.org/x/sys/cpu/cpu_arm.go
generated
vendored
@ -1,7 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
const cacheLineSize = 32
|
|
7
vendor/golang.org/x/sys/cpu/cpu_arm64.go
generated
vendored
7
vendor/golang.org/x/sys/cpu/cpu_arm64.go
generated
vendored
@ -1,7 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
const cacheLineSize = 64
|
|
16
vendor/golang.org/x/sys/cpu/cpu_gc_x86.go
generated
vendored
16
vendor/golang.org/x/sys/cpu/cpu_gc_x86.go
generated
vendored
@ -1,16 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
// +build !gccgo
|
|
||||||
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
// cpuid is implemented in cpu_x86.s for gc compiler
|
|
||||||
// and in cpu_gccgo.c for gccgo.
|
|
||||||
func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)
|
|
||||||
|
|
||||||
// xgetbv with ecx = 0 is implemented in cpu_x86.s for gc compiler
|
|
||||||
// and in cpu_gccgo.c for gccgo.
|
|
||||||
func xgetbv() (eax, edx uint32)
|
|
43
vendor/golang.org/x/sys/cpu/cpu_gccgo.c
generated
vendored
43
vendor/golang.org/x/sys/cpu/cpu_gccgo.c
generated
vendored
@ -1,43 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
// +build gccgo
|
|
||||||
|
|
||||||
#include <cpuid.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
// Need to wrap __get_cpuid_count because it's declared as static.
|
|
||||||
int
|
|
||||||
gccgoGetCpuidCount(uint32_t leaf, uint32_t subleaf,
|
|
||||||
uint32_t *eax, uint32_t *ebx,
|
|
||||||
uint32_t *ecx, uint32_t *edx)
|
|
||||||
{
|
|
||||||
return __get_cpuid_count(leaf, subleaf, eax, ebx, ecx, edx);
|
|
||||||
}
|
|
||||||
|
|
||||||
// xgetbv reads the contents of an XCR (Extended Control Register)
|
|
||||||
// specified in the ECX register into registers EDX:EAX.
|
|
||||||
// Currently, the only supported value for XCR is 0.
|
|
||||||
//
|
|
||||||
// TODO: Replace with a better alternative:
|
|
||||||
//
|
|
||||||
// #include <xsaveintrin.h>
|
|
||||||
//
|
|
||||||
// #pragma GCC target("xsave")
|
|
||||||
//
|
|
||||||
// void gccgoXgetbv(uint32_t *eax, uint32_t *edx) {
|
|
||||||
// unsigned long long x = _xgetbv(0);
|
|
||||||
// *eax = x & 0xffffffff;
|
|
||||||
// *edx = (x >> 32) & 0xffffffff;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Note that _xgetbv is defined starting with GCC 8.
|
|
||||||
void
|
|
||||||
gccgoXgetbv(uint32_t *eax, uint32_t *edx)
|
|
||||||
{
|
|
||||||
__asm(" xorl %%ecx, %%ecx\n"
|
|
||||||
" xgetbv"
|
|
||||||
: "=a"(*eax), "=d"(*edx));
|
|
||||||
}
|
|
26
vendor/golang.org/x/sys/cpu/cpu_gccgo.go
generated
vendored
26
vendor/golang.org/x/sys/cpu/cpu_gccgo.go
generated
vendored
@ -1,26 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
// +build gccgo
|
|
||||||
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
//extern gccgoGetCpuidCount
|
|
||||||
func gccgoGetCpuidCount(eaxArg, ecxArg uint32, eax, ebx, ecx, edx *uint32)
|
|
||||||
|
|
||||||
func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) {
|
|
||||||
var a, b, c, d uint32
|
|
||||||
gccgoGetCpuidCount(eaxArg, ecxArg, &a, &b, &c, &d)
|
|
||||||
return a, b, c, d
|
|
||||||
}
|
|
||||||
|
|
||||||
//extern gccgoXgetbv
|
|
||||||
func gccgoXgetbv(eax, edx *uint32)
|
|
||||||
|
|
||||||
func xgetbv() (eax, edx uint32) {
|
|
||||||
var a, d uint32
|
|
||||||
gccgoXgetbv(&a, &d)
|
|
||||||
return a, d
|
|
||||||
}
|
|
9
vendor/golang.org/x/sys/cpu/cpu_mips64x.go
generated
vendored
9
vendor/golang.org/x/sys/cpu/cpu_mips64x.go
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build mips64 mips64le
|
|
||||||
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
const cacheLineSize = 32
|
|
9
vendor/golang.org/x/sys/cpu/cpu_mipsx.go
generated
vendored
9
vendor/golang.org/x/sys/cpu/cpu_mipsx.go
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build mips mipsle
|
|
||||||
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
const cacheLineSize = 32
|
|
9
vendor/golang.org/x/sys/cpu/cpu_ppc64x.go
generated
vendored
9
vendor/golang.org/x/sys/cpu/cpu_ppc64x.go
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build ppc64 ppc64le
|
|
||||||
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
const cacheLineSize = 128
|
|
7
vendor/golang.org/x/sys/cpu/cpu_s390x.go
generated
vendored
7
vendor/golang.org/x/sys/cpu/cpu_s390x.go
generated
vendored
@ -1,7 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
const cacheLineSize = 256
|
|
55
vendor/golang.org/x/sys/cpu/cpu_x86.go
generated
vendored
55
vendor/golang.org/x/sys/cpu/cpu_x86.go
generated
vendored
@ -1,55 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
|
|
||||||
package cpu
|
|
||||||
|
|
||||||
const cacheLineSize = 64
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
maxID, _, _, _ := cpuid(0, 0)
|
|
||||||
|
|
||||||
if maxID < 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, _, ecx1, edx1 := cpuid(1, 0)
|
|
||||||
X86.HasSSE2 = isSet(26, edx1)
|
|
||||||
|
|
||||||
X86.HasSSE3 = isSet(0, ecx1)
|
|
||||||
X86.HasPCLMULQDQ = isSet(1, ecx1)
|
|
||||||
X86.HasSSSE3 = isSet(9, ecx1)
|
|
||||||
X86.HasFMA = isSet(12, ecx1)
|
|
||||||
X86.HasSSE41 = isSet(19, ecx1)
|
|
||||||
X86.HasSSE42 = isSet(20, ecx1)
|
|
||||||
X86.HasPOPCNT = isSet(23, ecx1)
|
|
||||||
X86.HasAES = isSet(25, ecx1)
|
|
||||||
X86.HasOSXSAVE = isSet(27, ecx1)
|
|
||||||
|
|
||||||
osSupportsAVX := false
|
|
||||||
// For XGETBV, OSXSAVE bit is required and sufficient.
|
|
||||||
if X86.HasOSXSAVE {
|
|
||||||
eax, _ := xgetbv()
|
|
||||||
// Check if XMM and YMM registers have OS support.
|
|
||||||
osSupportsAVX = isSet(1, eax) && isSet(2, eax)
|
|
||||||
}
|
|
||||||
|
|
||||||
X86.HasAVX = isSet(28, ecx1) && osSupportsAVX
|
|
||||||
|
|
||||||
if maxID < 7 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, ebx7, _, _ := cpuid(7, 0)
|
|
||||||
X86.HasBMI1 = isSet(3, ebx7)
|
|
||||||
X86.HasAVX2 = isSet(5, ebx7) && osSupportsAVX
|
|
||||||
X86.HasBMI2 = isSet(8, ebx7)
|
|
||||||
X86.HasERMS = isSet(9, ebx7)
|
|
||||||
X86.HasADX = isSet(19, ebx7)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isSet(bitpos uint, value uint32) bool {
|
|
||||||
return value&(1<<bitpos) != 0
|
|
||||||
}
|
|
27
vendor/golang.org/x/sys/cpu/cpu_x86.s
generated
vendored
27
vendor/golang.org/x/sys/cpu/cpu_x86.s
generated
vendored
@ -1,27 +0,0 @@
|
|||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
// +build !gccgo
|
|
||||||
|
|
||||||
#include "textflag.h"
|
|
||||||
|
|
||||||
// func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)
|
|
||||||
TEXT ·cpuid(SB), NOSPLIT, $0-24
|
|
||||||
MOVL eaxArg+0(FP), AX
|
|
||||||
MOVL ecxArg+4(FP), CX
|
|
||||||
CPUID
|
|
||||||
MOVL AX, eax+8(FP)
|
|
||||||
MOVL BX, ebx+12(FP)
|
|
||||||
MOVL CX, ecx+16(FP)
|
|
||||||
MOVL DX, edx+20(FP)
|
|
||||||
RET
|
|
||||||
|
|
||||||
// func xgetbv() (eax, edx uint32)
|
|
||||||
TEXT ·xgetbv(SB),NOSPLIT,$0-8
|
|
||||||
MOVL $0, CX
|
|
||||||
XGETBV
|
|
||||||
MOVL AX, eax+0(FP)
|
|
||||||
MOVL DX, edx+4(FP)
|
|
||||||
RET
|
|
8
vendor/golang.org/x/sys/plan9/asm.s
generated
vendored
8
vendor/golang.org/x/sys/plan9/asm.s
generated
vendored
@ -1,8 +0,0 @@
|
|||||||
// Copyright 2014 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "textflag.h"
|
|
||||||
|
|
||||||
TEXT ·use(SB),NOSPLIT,$0
|
|
||||||
RET
|
|
30
vendor/golang.org/x/sys/plan9/asm_plan9_386.s
generated
vendored
30
vendor/golang.org/x/sys/plan9/asm_plan9_386.s
generated
vendored
@ -1,30 +0,0 @@
|
|||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "textflag.h"
|
|
||||||
|
|
||||||
//
|
|
||||||
// System call support for 386, Plan 9
|
|
||||||
//
|
|
||||||
|
|
||||||
// Just jump to package syscall's implementation for all these functions.
|
|
||||||
// The runtime may know about them.
|
|
||||||
|
|
||||||
TEXT ·Syscall(SB),NOSPLIT,$0-32
|
|
||||||
JMP syscall·Syscall(SB)
|
|
||||||
|
|
||||||
TEXT ·Syscall6(SB),NOSPLIT,$0-44
|
|
||||||
JMP syscall·Syscall6(SB)
|
|
||||||
|
|
||||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-28
|
|
||||||
JMP syscall·RawSyscall(SB)
|
|
||||||
|
|
||||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
|
|
||||||
JMP syscall·RawSyscall6(SB)
|
|
||||||
|
|
||||||
TEXT ·seek(SB),NOSPLIT,$0-36
|
|
||||||
JMP syscall·seek(SB)
|
|
||||||
|
|
||||||
TEXT ·exit(SB),NOSPLIT,$4-4
|
|
||||||
JMP syscall·exit(SB)
|
|
30
vendor/golang.org/x/sys/plan9/asm_plan9_amd64.s
generated
vendored
30
vendor/golang.org/x/sys/plan9/asm_plan9_amd64.s
generated
vendored
@ -1,30 +0,0 @@
|
|||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "textflag.h"
|
|
||||||
|
|
||||||
//
|
|
||||||
// System call support for amd64, Plan 9
|
|
||||||
//
|
|
||||||
|
|
||||||
// Just jump to package syscall's implementation for all these functions.
|
|
||||||
// The runtime may know about them.
|
|
||||||
|
|
||||||
TEXT ·Syscall(SB),NOSPLIT,$0-64
|
|
||||||
JMP syscall·Syscall(SB)
|
|
||||||
|
|
||||||
TEXT ·Syscall6(SB),NOSPLIT,$0-88
|
|
||||||
JMP syscall·Syscall6(SB)
|
|
||||||
|
|
||||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
|
|
||||||
JMP syscall·RawSyscall(SB)
|
|
||||||
|
|
||||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
|
|
||||||
JMP syscall·RawSyscall6(SB)
|
|
||||||
|
|
||||||
TEXT ·seek(SB),NOSPLIT,$0-56
|
|
||||||
JMP syscall·seek(SB)
|
|
||||||
|
|
||||||
TEXT ·exit(SB),NOSPLIT,$8-8
|
|
||||||
JMP syscall·exit(SB)
|
|
25
vendor/golang.org/x/sys/plan9/asm_plan9_arm.s
generated
vendored
25
vendor/golang.org/x/sys/plan9/asm_plan9_arm.s
generated
vendored
@ -1,25 +0,0 @@
|
|||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "textflag.h"
|
|
||||||
|
|
||||||
// System call support for plan9 on arm
|
|
||||||
|
|
||||||
// Just jump to package syscall's implementation for all these functions.
|
|
||||||
// The runtime may know about them.
|
|
||||||
|
|
||||||
TEXT ·Syscall(SB),NOSPLIT,$0-32
|
|
||||||
JMP syscall·Syscall(SB)
|
|
||||||
|
|
||||||
TEXT ·Syscall6(SB),NOSPLIT,$0-44
|
|
||||||
JMP syscall·Syscall6(SB)
|
|
||||||
|
|
||||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-28
|
|
||||||
JMP syscall·RawSyscall(SB)
|
|
||||||
|
|
||||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
|
|
||||||
JMP syscall·RawSyscall6(SB)
|
|
||||||
|
|
||||||
TEXT ·seek(SB),NOSPLIT,$0-36
|
|
||||||
JMP syscall·exit(SB)
|
|
70
vendor/golang.org/x/sys/plan9/const_plan9.go
generated
vendored
70
vendor/golang.org/x/sys/plan9/const_plan9.go
generated
vendored
@ -1,70 +0,0 @@
|
|||||||
package plan9
|
|
||||||
|
|
||||||
// Plan 9 Constants
|
|
||||||
|
|
||||||
// Open modes
|
|
||||||
const (
|
|
||||||
O_RDONLY = 0
|
|
||||||
O_WRONLY = 1
|
|
||||||
O_RDWR = 2
|
|
||||||
O_TRUNC = 16
|
|
||||||
O_CLOEXEC = 32
|
|
||||||
O_EXCL = 0x1000
|
|
||||||
)
|
|
||||||
|
|
||||||
// Rfork flags
|
|
||||||
const (
|
|
||||||
RFNAMEG = 1 << 0
|
|
||||||
RFENVG = 1 << 1
|
|
||||||
RFFDG = 1 << 2
|
|
||||||
RFNOTEG = 1 << 3
|
|
||||||
RFPROC = 1 << 4
|
|
||||||
RFMEM = 1 << 5
|
|
||||||
RFNOWAIT = 1 << 6
|
|
||||||
RFCNAMEG = 1 << 10
|
|
||||||
RFCENVG = 1 << 11
|
|
||||||
RFCFDG = 1 << 12
|
|
||||||
RFREND = 1 << 13
|
|
||||||
RFNOMNT = 1 << 14
|
|
||||||
)
|
|
||||||
|
|
||||||
// Qid.Type bits
|
|
||||||
const (
|
|
||||||
QTDIR = 0x80
|
|
||||||
QTAPPEND = 0x40
|
|
||||||
QTEXCL = 0x20
|
|
||||||
QTMOUNT = 0x10
|
|
||||||
QTAUTH = 0x08
|
|
||||||
QTTMP = 0x04
|
|
||||||
QTFILE = 0x00
|
|
||||||
)
|
|
||||||
|
|
||||||
// Dir.Mode bits
|
|
||||||
const (
|
|
||||||
DMDIR = 0x80000000
|
|
||||||
DMAPPEND = 0x40000000
|
|
||||||
DMEXCL = 0x20000000
|
|
||||||
DMMOUNT = 0x10000000
|
|
||||||
DMAUTH = 0x08000000
|
|
||||||
DMTMP = 0x04000000
|
|
||||||
DMREAD = 0x4
|
|
||||||
DMWRITE = 0x2
|
|
||||||
DMEXEC = 0x1
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
STATMAX = 65535
|
|
||||||
ERRMAX = 128
|
|
||||||
STATFIXLEN = 49
|
|
||||||
)
|
|
||||||
|
|
||||||
// Mount and bind flags
|
|
||||||
const (
|
|
||||||
MREPL = 0x0000
|
|
||||||
MBEFORE = 0x0001
|
|
||||||
MAFTER = 0x0002
|
|
||||||
MORDER = 0x0003
|
|
||||||
MCREATE = 0x0004
|
|
||||||
MCACHE = 0x0010
|
|
||||||
MMASK = 0x0017
|
|
||||||
)
|
|
212
vendor/golang.org/x/sys/plan9/dir_plan9.go
generated
vendored
212
vendor/golang.org/x/sys/plan9/dir_plan9.go
generated
vendored
@ -1,212 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Plan 9 directory marshalling. See intro(5).
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrShortStat = errors.New("stat buffer too short")
|
|
||||||
ErrBadStat = errors.New("malformed stat buffer")
|
|
||||||
ErrBadName = errors.New("bad character in file name")
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Qid represents a 9P server's unique identification for a file.
|
|
||||||
type Qid struct {
|
|
||||||
Path uint64 // the file server's unique identification for the file
|
|
||||||
Vers uint32 // version number for given Path
|
|
||||||
Type uint8 // the type of the file (plan9.QTDIR for example)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A Dir contains the metadata for a file.
|
|
||||||
type Dir struct {
|
|
||||||
// system-modified data
|
|
||||||
Type uint16 // server type
|
|
||||||
Dev uint32 // server subtype
|
|
||||||
|
|
||||||
// file data
|
|
||||||
Qid Qid // unique id from server
|
|
||||||
Mode uint32 // permissions
|
|
||||||
Atime uint32 // last read time
|
|
||||||
Mtime uint32 // last write time
|
|
||||||
Length int64 // file length
|
|
||||||
Name string // last element of path
|
|
||||||
Uid string // owner name
|
|
||||||
Gid string // group name
|
|
||||||
Muid string // last modifier name
|
|
||||||
}
|
|
||||||
|
|
||||||
var nullDir = Dir{
|
|
||||||
Type: ^uint16(0),
|
|
||||||
Dev: ^uint32(0),
|
|
||||||
Qid: Qid{
|
|
||||||
Path: ^uint64(0),
|
|
||||||
Vers: ^uint32(0),
|
|
||||||
Type: ^uint8(0),
|
|
||||||
},
|
|
||||||
Mode: ^uint32(0),
|
|
||||||
Atime: ^uint32(0),
|
|
||||||
Mtime: ^uint32(0),
|
|
||||||
Length: ^int64(0),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Null assigns special "don't touch" values to members of d to
|
|
||||||
// avoid modifying them during plan9.Wstat.
|
|
||||||
func (d *Dir) Null() { *d = nullDir }
|
|
||||||
|
|
||||||
// Marshal encodes a 9P stat message corresponding to d into b
|
|
||||||
//
|
|
||||||
// If there isn't enough space in b for a stat message, ErrShortStat is returned.
|
|
||||||
func (d *Dir) Marshal(b []byte) (n int, err error) {
|
|
||||||
n = STATFIXLEN + len(d.Name) + len(d.Uid) + len(d.Gid) + len(d.Muid)
|
|
||||||
if n > len(b) {
|
|
||||||
return n, ErrShortStat
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range d.Name {
|
|
||||||
if c == '/' {
|
|
||||||
return n, ErrBadName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b = pbit16(b, uint16(n)-2)
|
|
||||||
b = pbit16(b, d.Type)
|
|
||||||
b = pbit32(b, d.Dev)
|
|
||||||
b = pbit8(b, d.Qid.Type)
|
|
||||||
b = pbit32(b, d.Qid.Vers)
|
|
||||||
b = pbit64(b, d.Qid.Path)
|
|
||||||
b = pbit32(b, d.Mode)
|
|
||||||
b = pbit32(b, d.Atime)
|
|
||||||
b = pbit32(b, d.Mtime)
|
|
||||||
b = pbit64(b, uint64(d.Length))
|
|
||||||
b = pstring(b, d.Name)
|
|
||||||
b = pstring(b, d.Uid)
|
|
||||||
b = pstring(b, d.Gid)
|
|
||||||
b = pstring(b, d.Muid)
|
|
||||||
|
|
||||||
return n, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalDir decodes a single 9P stat message from b and returns the resulting Dir.
|
|
||||||
//
|
|
||||||
// If b is too small to hold a valid stat message, ErrShortStat is returned.
|
|
||||||
//
|
|
||||||
// If the stat message itself is invalid, ErrBadStat is returned.
|
|
||||||
func UnmarshalDir(b []byte) (*Dir, error) {
|
|
||||||
if len(b) < STATFIXLEN {
|
|
||||||
return nil, ErrShortStat
|
|
||||||
}
|
|
||||||
size, buf := gbit16(b)
|
|
||||||
if len(b) != int(size)+2 {
|
|
||||||
return nil, ErrBadStat
|
|
||||||
}
|
|
||||||
b = buf
|
|
||||||
|
|
||||||
var d Dir
|
|
||||||
d.Type, b = gbit16(b)
|
|
||||||
d.Dev, b = gbit32(b)
|
|
||||||
d.Qid.Type, b = gbit8(b)
|
|
||||||
d.Qid.Vers, b = gbit32(b)
|
|
||||||
d.Qid.Path, b = gbit64(b)
|
|
||||||
d.Mode, b = gbit32(b)
|
|
||||||
d.Atime, b = gbit32(b)
|
|
||||||
d.Mtime, b = gbit32(b)
|
|
||||||
|
|
||||||
n, b := gbit64(b)
|
|
||||||
d.Length = int64(n)
|
|
||||||
|
|
||||||
var ok bool
|
|
||||||
if d.Name, b, ok = gstring(b); !ok {
|
|
||||||
return nil, ErrBadStat
|
|
||||||
}
|
|
||||||
if d.Uid, b, ok = gstring(b); !ok {
|
|
||||||
return nil, ErrBadStat
|
|
||||||
}
|
|
||||||
if d.Gid, b, ok = gstring(b); !ok {
|
|
||||||
return nil, ErrBadStat
|
|
||||||
}
|
|
||||||
if d.Muid, b, ok = gstring(b); !ok {
|
|
||||||
return nil, ErrBadStat
|
|
||||||
}
|
|
||||||
|
|
||||||
return &d, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// pbit8 copies the 8-bit number v to b and returns the remaining slice of b.
|
|
||||||
func pbit8(b []byte, v uint8) []byte {
|
|
||||||
b[0] = byte(v)
|
|
||||||
return b[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// pbit16 copies the 16-bit number v to b in little-endian order and returns the remaining slice of b.
|
|
||||||
func pbit16(b []byte, v uint16) []byte {
|
|
||||||
b[0] = byte(v)
|
|
||||||
b[1] = byte(v >> 8)
|
|
||||||
return b[2:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// pbit32 copies the 32-bit number v to b in little-endian order and returns the remaining slice of b.
|
|
||||||
func pbit32(b []byte, v uint32) []byte {
|
|
||||||
b[0] = byte(v)
|
|
||||||
b[1] = byte(v >> 8)
|
|
||||||
b[2] = byte(v >> 16)
|
|
||||||
b[3] = byte(v >> 24)
|
|
||||||
return b[4:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// pbit64 copies the 64-bit number v to b in little-endian order and returns the remaining slice of b.
|
|
||||||
func pbit64(b []byte, v uint64) []byte {
|
|
||||||
b[0] = byte(v)
|
|
||||||
b[1] = byte(v >> 8)
|
|
||||||
b[2] = byte(v >> 16)
|
|
||||||
b[3] = byte(v >> 24)
|
|
||||||
b[4] = byte(v >> 32)
|
|
||||||
b[5] = byte(v >> 40)
|
|
||||||
b[6] = byte(v >> 48)
|
|
||||||
b[7] = byte(v >> 56)
|
|
||||||
return b[8:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// pstring copies the string s to b, prepending it with a 16-bit length in little-endian order, and
|
|
||||||
// returning the remaining slice of b..
|
|
||||||
func pstring(b []byte, s string) []byte {
|
|
||||||
b = pbit16(b, uint16(len(s)))
|
|
||||||
n := copy(b, s)
|
|
||||||
return b[n:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// gbit8 reads an 8-bit number from b and returns it with the remaining slice of b.
|
|
||||||
func gbit8(b []byte) (uint8, []byte) {
|
|
||||||
return uint8(b[0]), b[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// gbit16 reads a 16-bit number in little-endian order from b and returns it with the remaining slice of b.
|
|
||||||
func gbit16(b []byte) (uint16, []byte) {
|
|
||||||
return uint16(b[0]) | uint16(b[1])<<8, b[2:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// gbit32 reads a 32-bit number in little-endian order from b and returns it with the remaining slice of b.
|
|
||||||
func gbit32(b []byte) (uint32, []byte) {
|
|
||||||
return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24, b[4:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// gbit64 reads a 64-bit number in little-endian order from b and returns it with the remaining slice of b.
|
|
||||||
func gbit64(b []byte) (uint64, []byte) {
|
|
||||||
lo := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
|
|
||||||
hi := uint32(b[4]) | uint32(b[5])<<8 | uint32(b[6])<<16 | uint32(b[7])<<24
|
|
||||||
return uint64(lo) | uint64(hi)<<32, b[8:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// gstring reads a string from b, prefixed with a 16-bit length in little-endian order.
|
|
||||||
// It returns the string with the remaining slice of b and a boolean. If the length is
|
|
||||||
// greater than the number of bytes in b, the boolean will be false.
|
|
||||||
func gstring(b []byte) (string, []byte, bool) {
|
|
||||||
n, b := gbit16(b)
|
|
||||||
if int(n) > len(b) {
|
|
||||||
return "", b, false
|
|
||||||
}
|
|
||||||
return string(b[:n]), b[n:], true
|
|
||||||
}
|
|
31
vendor/golang.org/x/sys/plan9/env_plan9.go
generated
vendored
31
vendor/golang.org/x/sys/plan9/env_plan9.go
generated
vendored
@ -1,31 +0,0 @@
|
|||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Plan 9 environment variables.
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Getenv(key string) (value string, found bool) {
|
|
||||||
return syscall.Getenv(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Setenv(key, value string) error {
|
|
||||||
return syscall.Setenv(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Clearenv() {
|
|
||||||
syscall.Clearenv()
|
|
||||||
}
|
|
||||||
|
|
||||||
func Environ() []string {
|
|
||||||
return syscall.Environ()
|
|
||||||
}
|
|
||||||
|
|
||||||
func Unsetenv(key string) error {
|
|
||||||
return syscall.Unsetenv(key)
|
|
||||||
}
|
|
50
vendor/golang.org/x/sys/plan9/errors_plan9.go
generated
vendored
50
vendor/golang.org/x/sys/plan9/errors_plan9.go
generated
vendored
@ -1,50 +0,0 @@
|
|||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
const (
|
|
||||||
// Invented values to support what package os expects.
|
|
||||||
O_CREAT = 0x02000
|
|
||||||
O_APPEND = 0x00400
|
|
||||||
O_NOCTTY = 0x00000
|
|
||||||
O_NONBLOCK = 0x00000
|
|
||||||
O_SYNC = 0x00000
|
|
||||||
O_ASYNC = 0x00000
|
|
||||||
|
|
||||||
S_IFMT = 0x1f000
|
|
||||||
S_IFIFO = 0x1000
|
|
||||||
S_IFCHR = 0x2000
|
|
||||||
S_IFDIR = 0x4000
|
|
||||||
S_IFBLK = 0x6000
|
|
||||||
S_IFREG = 0x8000
|
|
||||||
S_IFLNK = 0xa000
|
|
||||||
S_IFSOCK = 0xc000
|
|
||||||
)
|
|
||||||
|
|
||||||
// Errors
|
|
||||||
var (
|
|
||||||
EINVAL = syscall.NewError("bad arg in system call")
|
|
||||||
ENOTDIR = syscall.NewError("not a directory")
|
|
||||||
EISDIR = syscall.NewError("file is a directory")
|
|
||||||
ENOENT = syscall.NewError("file does not exist")
|
|
||||||
EEXIST = syscall.NewError("file already exists")
|
|
||||||
EMFILE = syscall.NewError("no free file descriptors")
|
|
||||||
EIO = syscall.NewError("i/o error")
|
|
||||||
ENAMETOOLONG = syscall.NewError("file name too long")
|
|
||||||
EINTR = syscall.NewError("interrupted")
|
|
||||||
EPERM = syscall.NewError("permission denied")
|
|
||||||
EBUSY = syscall.NewError("no free devices")
|
|
||||||
ETIMEDOUT = syscall.NewError("connection timed out")
|
|
||||||
EPLAN9 = syscall.NewError("not supported by plan 9")
|
|
||||||
|
|
||||||
// The following errors do not correspond to any
|
|
||||||
// Plan 9 system messages. Invented to support
|
|
||||||
// what package os and others expect.
|
|
||||||
EACCES = syscall.NewError("access permission denied")
|
|
||||||
EAFNOSUPPORT = syscall.NewError("address family not supported by protocol")
|
|
||||||
)
|
|
21
vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go
generated
vendored
21
vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go
generated
vendored
@ -1,21 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build go1.5
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
func fixwd() {
|
|
||||||
syscall.Fixwd()
|
|
||||||
}
|
|
||||||
|
|
||||||
func Getwd() (wd string, err error) {
|
|
||||||
return syscall.Getwd()
|
|
||||||
}
|
|
||||||
|
|
||||||
func Chdir(path string) error {
|
|
||||||
return syscall.Chdir(path)
|
|
||||||
}
|
|
23
vendor/golang.org/x/sys/plan9/pwd_plan9.go
generated
vendored
23
vendor/golang.org/x/sys/plan9/pwd_plan9.go
generated
vendored
@ -1,23 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build !go1.5
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
func fixwd() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func Getwd() (wd string, err error) {
|
|
||||||
fd, err := open(".", O_RDONLY)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer Close(fd)
|
|
||||||
return Fd2path(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Chdir(path string) error {
|
|
||||||
return chdir(path)
|
|
||||||
}
|
|
30
vendor/golang.org/x/sys/plan9/race.go
generated
vendored
30
vendor/golang.org/x/sys/plan9/race.go
generated
vendored
@ -1,30 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build plan9,race
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import (
|
|
||||||
"runtime"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const raceenabled = true
|
|
||||||
|
|
||||||
func raceAcquire(addr unsafe.Pointer) {
|
|
||||||
runtime.RaceAcquire(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func raceReleaseMerge(addr unsafe.Pointer) {
|
|
||||||
runtime.RaceReleaseMerge(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func raceReadRange(addr unsafe.Pointer, len int) {
|
|
||||||
runtime.RaceReadRange(addr, len)
|
|
||||||
}
|
|
||||||
|
|
||||||
func raceWriteRange(addr unsafe.Pointer, len int) {
|
|
||||||
runtime.RaceWriteRange(addr, len)
|
|
||||||
}
|
|
25
vendor/golang.org/x/sys/plan9/race0.go
generated
vendored
25
vendor/golang.org/x/sys/plan9/race0.go
generated
vendored
@ -1,25 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build plan9,!race
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import (
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const raceenabled = false
|
|
||||||
|
|
||||||
func raceAcquire(addr unsafe.Pointer) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func raceReleaseMerge(addr unsafe.Pointer) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func raceReadRange(addr unsafe.Pointer, len int) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func raceWriteRange(addr unsafe.Pointer, len int) {
|
|
||||||
}
|
|
22
vendor/golang.org/x/sys/plan9/str.go
generated
vendored
22
vendor/golang.org/x/sys/plan9/str.go
generated
vendored
@ -1,22 +0,0 @@
|
|||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build plan9
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
func itoa(val int) string { // do it here rather than with fmt to avoid dependency
|
|
||||||
if val < 0 {
|
|
||||||
return "-" + itoa(-val)
|
|
||||||
}
|
|
||||||
var buf [32]byte // big enough for int64
|
|
||||||
i := len(buf) - 1
|
|
||||||
for val >= 10 {
|
|
||||||
buf[i] = byte(val%10 + '0')
|
|
||||||
i--
|
|
||||||
val /= 10
|
|
||||||
}
|
|
||||||
buf[i] = byte(val + '0')
|
|
||||||
return string(buf[i:])
|
|
||||||
}
|
|
77
vendor/golang.org/x/sys/plan9/syscall.go
generated
vendored
77
vendor/golang.org/x/sys/plan9/syscall.go
generated
vendored
@ -1,77 +0,0 @@
|
|||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build plan9
|
|
||||||
|
|
||||||
// Package plan9 contains an interface to the low-level operating system
|
|
||||||
// primitives. OS details vary depending on the underlying system, and
|
|
||||||
// by default, godoc will display the OS-specific documentation for the current
|
|
||||||
// system. If you want godoc to display documentation for another
|
|
||||||
// system, set $GOOS and $GOARCH to the desired system. For example, if
|
|
||||||
// you want to view documentation for freebsd/arm on linux/amd64, set $GOOS
|
|
||||||
// to freebsd and $GOARCH to arm.
|
|
||||||
//
|
|
||||||
// The primary use of this package is inside other packages that provide a more
|
|
||||||
// portable interface to the system, such as "os", "time" and "net". Use
|
|
||||||
// those packages rather than this one if you can.
|
|
||||||
//
|
|
||||||
// For details of the functions and data types in this package consult
|
|
||||||
// the manuals for the appropriate operating system.
|
|
||||||
//
|
|
||||||
// These calls return err == nil to indicate success; otherwise
|
|
||||||
// err represents an operating system error describing the failure and
|
|
||||||
// holds a value of type syscall.ErrorString.
|
|
||||||
package plan9 // import "golang.org/x/sys/plan9"
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
// ByteSliceFromString returns a NUL-terminated slice of bytes
|
|
||||||
// containing the text of s. If s contains a NUL byte at any
|
|
||||||
// location, it returns (nil, EINVAL).
|
|
||||||
func ByteSliceFromString(s string) ([]byte, error) {
|
|
||||||
for i := 0; i < len(s); i++ {
|
|
||||||
if s[i] == 0 {
|
|
||||||
return nil, EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
a := make([]byte, len(s)+1)
|
|
||||||
copy(a, s)
|
|
||||||
return a, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BytePtrFromString returns a pointer to a NUL-terminated array of
|
|
||||||
// bytes containing the text of s. If s contains a NUL byte at any
|
|
||||||
// location, it returns (nil, EINVAL).
|
|
||||||
func BytePtrFromString(s string) (*byte, error) {
|
|
||||||
a, err := ByteSliceFromString(s)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &a[0], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Single-word zero for use when we need a valid pointer to 0 bytes.
|
|
||||||
// See mksyscall.pl.
|
|
||||||
var _zero uintptr
|
|
||||||
|
|
||||||
func (ts *Timespec) Unix() (sec int64, nsec int64) {
|
|
||||||
return int64(ts.Sec), int64(ts.Nsec)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tv *Timeval) Unix() (sec int64, nsec int64) {
|
|
||||||
return int64(tv.Sec), int64(tv.Usec) * 1000
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ts *Timespec) Nano() int64 {
|
|
||||||
return int64(ts.Sec)*1e9 + int64(ts.Nsec)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tv *Timeval) Nano() int64 {
|
|
||||||
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
|
|
||||||
}
|
|
||||||
|
|
||||||
// use is a no-op, but the compiler cannot see that it is.
|
|
||||||
// Calling use(p) ensures that p is kept live until that point.
|
|
||||||
//go:noescape
|
|
||||||
func use(p unsafe.Pointer)
|
|
349
vendor/golang.org/x/sys/plan9/syscall_plan9.go
generated
vendored
349
vendor/golang.org/x/sys/plan9/syscall_plan9.go
generated
vendored
@ -1,349 +0,0 @@
|
|||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Plan 9 system calls.
|
|
||||||
// This file is compiled as ordinary Go code,
|
|
||||||
// but it is also input to mksyscall,
|
|
||||||
// which parses the //sys lines and generates system call stubs.
|
|
||||||
// Note that sometimes we use a lowercase //sys name and
|
|
||||||
// wrap it in our own nicer implementation.
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Note is a string describing a process note.
|
|
||||||
// It implements the os.Signal interface.
|
|
||||||
type Note string
|
|
||||||
|
|
||||||
func (n Note) Signal() {}
|
|
||||||
|
|
||||||
func (n Note) String() string {
|
|
||||||
return string(n)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
Stdin = 0
|
|
||||||
Stdout = 1
|
|
||||||
Stderr = 2
|
|
||||||
)
|
|
||||||
|
|
||||||
// For testing: clients can set this flag to force
|
|
||||||
// creation of IPv6 sockets to return EAFNOSUPPORT.
|
|
||||||
var SocketDisableIPv6 bool
|
|
||||||
|
|
||||||
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.ErrorString)
|
|
||||||
func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.ErrorString)
|
|
||||||
func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
|
|
||||||
func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
|
|
||||||
|
|
||||||
func atoi(b []byte) (n uint) {
|
|
||||||
n = 0
|
|
||||||
for i := 0; i < len(b); i++ {
|
|
||||||
n = n*10 + uint(b[i]-'0')
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func cstring(s []byte) string {
|
|
||||||
i := bytes.IndexByte(s, 0)
|
|
||||||
if i == -1 {
|
|
||||||
i = len(s)
|
|
||||||
}
|
|
||||||
return string(s[:i])
|
|
||||||
}
|
|
||||||
|
|
||||||
func errstr() string {
|
|
||||||
var buf [ERRMAX]byte
|
|
||||||
|
|
||||||
RawSyscall(SYS_ERRSTR, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)), 0)
|
|
||||||
|
|
||||||
buf[len(buf)-1] = 0
|
|
||||||
return cstring(buf[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implemented in assembly to import from runtime.
|
|
||||||
func exit(code int)
|
|
||||||
|
|
||||||
func Exit(code int) { exit(code) }
|
|
||||||
|
|
||||||
func readnum(path string) (uint, error) {
|
|
||||||
var b [12]byte
|
|
||||||
|
|
||||||
fd, e := Open(path, O_RDONLY)
|
|
||||||
if e != nil {
|
|
||||||
return 0, e
|
|
||||||
}
|
|
||||||
defer Close(fd)
|
|
||||||
|
|
||||||
n, e := Pread(fd, b[:], 0)
|
|
||||||
|
|
||||||
if e != nil {
|
|
||||||
return 0, e
|
|
||||||
}
|
|
||||||
|
|
||||||
m := 0
|
|
||||||
for ; m < n && b[m] == ' '; m++ {
|
|
||||||
}
|
|
||||||
|
|
||||||
return atoi(b[m : n-1]), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Getpid() (pid int) {
|
|
||||||
n, _ := readnum("#c/pid")
|
|
||||||
return int(n)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Getppid() (ppid int) {
|
|
||||||
n, _ := readnum("#c/ppid")
|
|
||||||
return int(n)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Read(fd int, p []byte) (n int, err error) {
|
|
||||||
return Pread(fd, p, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Write(fd int, p []byte) (n int, err error) {
|
|
||||||
return Pwrite(fd, p, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ioSync int64
|
|
||||||
|
|
||||||
//sys fd2path(fd int, buf []byte) (err error)
|
|
||||||
func Fd2path(fd int) (path string, err error) {
|
|
||||||
var buf [512]byte
|
|
||||||
|
|
||||||
e := fd2path(fd, buf[:])
|
|
||||||
if e != nil {
|
|
||||||
return "", e
|
|
||||||
}
|
|
||||||
return cstring(buf[:]), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys pipe(p *[2]int32) (err error)
|
|
||||||
func Pipe(p []int) (err error) {
|
|
||||||
if len(p) != 2 {
|
|
||||||
return syscall.ErrorString("bad arg in system call")
|
|
||||||
}
|
|
||||||
var pp [2]int32
|
|
||||||
err = pipe(&pp)
|
|
||||||
p[0] = int(pp[0])
|
|
||||||
p[1] = int(pp[1])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Underlying system call writes to newoffset via pointer.
|
|
||||||
// Implemented in assembly to avoid allocation.
|
|
||||||
func seek(placeholder uintptr, fd int, offset int64, whence int) (newoffset int64, err string)
|
|
||||||
|
|
||||||
func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
|
|
||||||
newoffset, e := seek(0, fd, offset, whence)
|
|
||||||
|
|
||||||
if newoffset == -1 {
|
|
||||||
err = syscall.ErrorString(e)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func Mkdir(path string, mode uint32) (err error) {
|
|
||||||
fd, err := Create(path, O_RDONLY, DMDIR|mode)
|
|
||||||
|
|
||||||
if fd != -1 {
|
|
||||||
Close(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type Waitmsg struct {
|
|
||||||
Pid int
|
|
||||||
Time [3]uint32
|
|
||||||
Msg string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w Waitmsg) Exited() bool { return true }
|
|
||||||
func (w Waitmsg) Signaled() bool { return false }
|
|
||||||
|
|
||||||
func (w Waitmsg) ExitStatus() int {
|
|
||||||
if len(w.Msg) == 0 {
|
|
||||||
// a normal exit returns no message
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys await(s []byte) (n int, err error)
|
|
||||||
func Await(w *Waitmsg) (err error) {
|
|
||||||
var buf [512]byte
|
|
||||||
var f [5][]byte
|
|
||||||
|
|
||||||
n, err := await(buf[:])
|
|
||||||
|
|
||||||
if err != nil || w == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
nf := 0
|
|
||||||
p := 0
|
|
||||||
for i := 0; i < n && nf < len(f)-1; i++ {
|
|
||||||
if buf[i] == ' ' {
|
|
||||||
f[nf] = buf[p:i]
|
|
||||||
p = i + 1
|
|
||||||
nf++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f[nf] = buf[p:]
|
|
||||||
nf++
|
|
||||||
|
|
||||||
if nf != len(f) {
|
|
||||||
return syscall.ErrorString("invalid wait message")
|
|
||||||
}
|
|
||||||
w.Pid = int(atoi(f[0]))
|
|
||||||
w.Time[0] = uint32(atoi(f[1]))
|
|
||||||
w.Time[1] = uint32(atoi(f[2]))
|
|
||||||
w.Time[2] = uint32(atoi(f[3]))
|
|
||||||
w.Msg = cstring(f[4])
|
|
||||||
if w.Msg == "''" {
|
|
||||||
// await() returns '' for no error
|
|
||||||
w.Msg = ""
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func Unmount(name, old string) (err error) {
|
|
||||||
fixwd()
|
|
||||||
oldp, err := BytePtrFromString(old)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
oldptr := uintptr(unsafe.Pointer(oldp))
|
|
||||||
|
|
||||||
var r0 uintptr
|
|
||||||
var e syscall.ErrorString
|
|
||||||
|
|
||||||
// bind(2) man page: If name is zero, everything bound or mounted upon old is unbound or unmounted.
|
|
||||||
if name == "" {
|
|
||||||
r0, _, e = Syscall(SYS_UNMOUNT, _zero, oldptr, 0)
|
|
||||||
} else {
|
|
||||||
namep, err := BytePtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
r0, _, e = Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(namep)), oldptr, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func Fchdir(fd int) (err error) {
|
|
||||||
path, err := Fd2path(fd)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return Chdir(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Timespec struct {
|
|
||||||
Sec int32
|
|
||||||
Nsec int32
|
|
||||||
}
|
|
||||||
|
|
||||||
type Timeval struct {
|
|
||||||
Sec int32
|
|
||||||
Usec int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func NsecToTimeval(nsec int64) (tv Timeval) {
|
|
||||||
nsec += 999 // round up to microsecond
|
|
||||||
tv.Usec = int32(nsec % 1e9 / 1e3)
|
|
||||||
tv.Sec = int32(nsec / 1e9)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func nsec() int64 {
|
|
||||||
var scratch int64
|
|
||||||
|
|
||||||
r0, _, _ := Syscall(SYS_NSEC, uintptr(unsafe.Pointer(&scratch)), 0, 0)
|
|
||||||
// TODO(aram): remove hack after I fix _nsec in the pc64 kernel.
|
|
||||||
if r0 == 0 {
|
|
||||||
return scratch
|
|
||||||
}
|
|
||||||
return int64(r0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Gettimeofday(tv *Timeval) error {
|
|
||||||
nsec := nsec()
|
|
||||||
*tv = NsecToTimeval(nsec)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Getpagesize() int { return 0x1000 }
|
|
||||||
|
|
||||||
func Getegid() (egid int) { return -1 }
|
|
||||||
func Geteuid() (euid int) { return -1 }
|
|
||||||
func Getgid() (gid int) { return -1 }
|
|
||||||
func Getuid() (uid int) { return -1 }
|
|
||||||
|
|
||||||
func Getgroups() (gids []int, err error) {
|
|
||||||
return make([]int, 0), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys open(path string, mode int) (fd int, err error)
|
|
||||||
func Open(path string, mode int) (fd int, err error) {
|
|
||||||
fixwd()
|
|
||||||
return open(path, mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys create(path string, mode int, perm uint32) (fd int, err error)
|
|
||||||
func Create(path string, mode int, perm uint32) (fd int, err error) {
|
|
||||||
fixwd()
|
|
||||||
return create(path, mode, perm)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys remove(path string) (err error)
|
|
||||||
func Remove(path string) error {
|
|
||||||
fixwd()
|
|
||||||
return remove(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys stat(path string, edir []byte) (n int, err error)
|
|
||||||
func Stat(path string, edir []byte) (n int, err error) {
|
|
||||||
fixwd()
|
|
||||||
return stat(path, edir)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys bind(name string, old string, flag int) (err error)
|
|
||||||
func Bind(name string, old string, flag int) (err error) {
|
|
||||||
fixwd()
|
|
||||||
return bind(name, old, flag)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys mount(fd int, afd int, old string, flag int, aname string) (err error)
|
|
||||||
func Mount(fd int, afd int, old string, flag int, aname string) (err error) {
|
|
||||||
fixwd()
|
|
||||||
return mount(fd, afd, old, flag, aname)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys wstat(path string, edir []byte) (err error)
|
|
||||||
func Wstat(path string, edir []byte) (err error) {
|
|
||||||
fixwd()
|
|
||||||
return wstat(path, edir)
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys chdir(path string) (err error)
|
|
||||||
//sys Dup(oldfd int, newfd int) (fd int, err error)
|
|
||||||
//sys Pread(fd int, p []byte, offset int64) (n int, err error)
|
|
||||||
//sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
|
|
||||||
//sys Close(fd int) (err error)
|
|
||||||
//sys Fstat(fd int, edir []byte) (n int, err error)
|
|
||||||
//sys Fwstat(fd int, edir []byte) (err error)
|
|
292
vendor/golang.org/x/sys/plan9/zsyscall_plan9_386.go
generated
vendored
292
vendor/golang.org/x/sys/plan9/zsyscall_plan9_386.go
generated
vendored
@ -1,292 +0,0 @@
|
|||||||
// mksyscall.pl -l32 -plan9 syscall_plan9.go
|
|
||||||
// Code generated by the command above; DO NOT EDIT.
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func fd2path(fd int, buf []byte) (err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(buf) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func pipe(p *[2]int32) (err error) {
|
|
||||||
r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func await(s []byte) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(s) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&s[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func open(path string, mode int) (fd int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
fd = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func create(path string, mode int, perm uint32) (fd int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
fd = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func remove(path string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func stat(path string, edir []byte) (n int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func bind(name string, old string, flag int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = BytePtrFromString(old)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flag))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func mount(fd int, afd int, old string, flag int, aname string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(old)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = BytePtrFromString(aname)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(_p0)), uintptr(flag), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func wstat(path string, edir []byte) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func chdir(path string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Dup(oldfd int, newfd int) (fd int, err error) {
|
|
||||||
r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
|
|
||||||
fd = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Pread(fd int, p []byte, offset int64) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(p) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&p[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(p) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&p[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Close(fd int) (err error) {
|
|
||||||
r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Fstat(fd int, edir []byte) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Fwstat(fd int, edir []byte) (err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
292
vendor/golang.org/x/sys/plan9/zsyscall_plan9_amd64.go
generated
vendored
292
vendor/golang.org/x/sys/plan9/zsyscall_plan9_amd64.go
generated
vendored
@ -1,292 +0,0 @@
|
|||||||
// mksyscall.pl -l32 -plan9 syscall_plan9.go
|
|
||||||
// Code generated by the command above; DO NOT EDIT.
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func fd2path(fd int, buf []byte) (err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(buf) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func pipe(p *[2]int32) (err error) {
|
|
||||||
r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func await(s []byte) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(s) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&s[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func open(path string, mode int) (fd int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
fd = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func create(path string, mode int, perm uint32) (fd int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
fd = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func remove(path string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func stat(path string, edir []byte) (n int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func bind(name string, old string, flag int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = BytePtrFromString(old)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flag))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func mount(fd int, afd int, old string, flag int, aname string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(old)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = BytePtrFromString(aname)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(_p0)), uintptr(flag), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
use(unsafe.Pointer(_p1))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func wstat(path string, edir []byte) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func chdir(path string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
|
||||||
use(unsafe.Pointer(_p0))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Dup(oldfd int, newfd int) (fd int, err error) {
|
|
||||||
r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
|
|
||||||
fd = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Pread(fd int, p []byte, offset int64) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(p) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&p[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(p) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&p[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Close(fd int) (err error) {
|
|
||||||
r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Fstat(fd int, edir []byte) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Fwstat(fd int, edir []byte) (err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
284
vendor/golang.org/x/sys/plan9/zsyscall_plan9_arm.go
generated
vendored
284
vendor/golang.org/x/sys/plan9/zsyscall_plan9_arm.go
generated
vendored
@ -1,284 +0,0 @@
|
|||||||
// mksyscall.pl -l32 -plan9 -tags plan9,arm syscall_plan9.go
|
|
||||||
// Code generated by the command above; DO NOT EDIT.
|
|
||||||
|
|
||||||
// +build plan9,arm
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func fd2path(fd int, buf []byte) (err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(buf) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&buf[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func pipe(p *[2]int32) (err error) {
|
|
||||||
r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func await(s []byte) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(s) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&s[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func open(path string, mode int) (fd int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
|
|
||||||
fd = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func create(path string, mode int, perm uint32) (fd int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
|
|
||||||
fd = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func remove(path string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func stat(path string, edir []byte) (n int, err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func bind(name string, old string, flag int) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = BytePtrFromString(old)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flag))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func mount(fd int, afd int, old string, flag int, aname string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(old)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 *byte
|
|
||||||
_p1, err = BytePtrFromString(aname)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(_p0)), uintptr(flag), uintptr(unsafe.Pointer(_p1)), 0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func wstat(path string, edir []byte) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var _p1 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p1 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p1 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func chdir(path string) (err error) {
|
|
||||||
var _p0 *byte
|
|
||||||
_p0, err = BytePtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Dup(oldfd int, newfd int) (fd int, err error) {
|
|
||||||
r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
|
|
||||||
fd = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Pread(fd int, p []byte, offset int64) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(p) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&p[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(p) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&p[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Close(fd int) (err error) {
|
|
||||||
r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Fstat(fd int, edir []byte) (n int, err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
|
|
||||||
n = int(r0)
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
||||||
|
|
||||||
func Fwstat(fd int, edir []byte) (err error) {
|
|
||||||
var _p0 unsafe.Pointer
|
|
||||||
if len(edir) > 0 {
|
|
||||||
_p0 = unsafe.Pointer(&edir[0])
|
|
||||||
} else {
|
|
||||||
_p0 = unsafe.Pointer(&_zero)
|
|
||||||
}
|
|
||||||
r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
|
|
||||||
if int32(r0) == -1 {
|
|
||||||
err = e1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
49
vendor/golang.org/x/sys/plan9/zsysnum_plan9.go
generated
vendored
49
vendor/golang.org/x/sys/plan9/zsysnum_plan9.go
generated
vendored
@ -1,49 +0,0 @@
|
|||||||
// mksysnum_plan9.sh /opt/plan9/sys/src/libc/9syscall/sys.h
|
|
||||||
// MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT
|
|
||||||
|
|
||||||
package plan9
|
|
||||||
|
|
||||||
const (
|
|
||||||
SYS_SYSR1 = 0
|
|
||||||
SYS_BIND = 2
|
|
||||||
SYS_CHDIR = 3
|
|
||||||
SYS_CLOSE = 4
|
|
||||||
SYS_DUP = 5
|
|
||||||
SYS_ALARM = 6
|
|
||||||
SYS_EXEC = 7
|
|
||||||
SYS_EXITS = 8
|
|
||||||
SYS_FAUTH = 10
|
|
||||||
SYS_SEGBRK = 12
|
|
||||||
SYS_OPEN = 14
|
|
||||||
SYS_OSEEK = 16
|
|
||||||
SYS_SLEEP = 17
|
|
||||||
SYS_RFORK = 19
|
|
||||||
SYS_PIPE = 21
|
|
||||||
SYS_CREATE = 22
|
|
||||||
SYS_FD2PATH = 23
|
|
||||||
SYS_BRK_ = 24
|
|
||||||
SYS_REMOVE = 25
|
|
||||||
SYS_NOTIFY = 28
|
|
||||||
SYS_NOTED = 29
|
|
||||||
SYS_SEGATTACH = 30
|
|
||||||
SYS_SEGDETACH = 31
|
|
||||||
SYS_SEGFREE = 32
|
|
||||||
SYS_SEGFLUSH = 33
|
|
||||||
SYS_RENDEZVOUS = 34
|
|
||||||
SYS_UNMOUNT = 35
|
|
||||||
SYS_SEMACQUIRE = 37
|
|
||||||
SYS_SEMRELEASE = 38
|
|
||||||
SYS_SEEK = 39
|
|
||||||
SYS_FVERSION = 40
|
|
||||||
SYS_ERRSTR = 41
|
|
||||||
SYS_STAT = 42
|
|
||||||
SYS_FSTAT = 43
|
|
||||||
SYS_WSTAT = 44
|
|
||||||
SYS_FWSTAT = 45
|
|
||||||
SYS_MOUNT = 46
|
|
||||||
SYS_AWAIT = 47
|
|
||||||
SYS_PREAD = 50
|
|
||||||
SYS_PWRITE = 51
|
|
||||||
SYS_TSEMACQUIRE = 52
|
|
||||||
SYS_NSEC = 53
|
|
||||||
)
|
|
198
vendor/golang.org/x/sys/windows/registry/key.go
generated
vendored
198
vendor/golang.org/x/sys/windows/registry/key.go
generated
vendored
@ -1,198 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
// Package registry provides access to the Windows registry.
|
|
||||||
//
|
|
||||||
// Here is a simple example, opening a registry key and reading a string value from it.
|
|
||||||
//
|
|
||||||
// k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
|
|
||||||
// if err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
// }
|
|
||||||
// defer k.Close()
|
|
||||||
//
|
|
||||||
// s, _, err := k.GetStringValue("SystemRoot")
|
|
||||||
// if err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
// }
|
|
||||||
// fmt.Printf("Windows system root is %q\n", s)
|
|
||||||
//
|
|
||||||
package registry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Registry key security and access rights.
|
|
||||||
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724878.aspx
|
|
||||||
// for details.
|
|
||||||
ALL_ACCESS = 0xf003f
|
|
||||||
CREATE_LINK = 0x00020
|
|
||||||
CREATE_SUB_KEY = 0x00004
|
|
||||||
ENUMERATE_SUB_KEYS = 0x00008
|
|
||||||
EXECUTE = 0x20019
|
|
||||||
NOTIFY = 0x00010
|
|
||||||
QUERY_VALUE = 0x00001
|
|
||||||
READ = 0x20019
|
|
||||||
SET_VALUE = 0x00002
|
|
||||||
WOW64_32KEY = 0x00200
|
|
||||||
WOW64_64KEY = 0x00100
|
|
||||||
WRITE = 0x20006
|
|
||||||
)
|
|
||||||
|
|
||||||
// Key is a handle to an open Windows registry key.
|
|
||||||
// Keys can be obtained by calling OpenKey; there are
|
|
||||||
// also some predefined root keys such as CURRENT_USER.
|
|
||||||
// Keys can be used directly in the Windows API.
|
|
||||||
type Key syscall.Handle
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Windows defines some predefined root keys that are always open.
|
|
||||||
// An application can use these keys as entry points to the registry.
|
|
||||||
// Normally these keys are used in OpenKey to open new keys,
|
|
||||||
// but they can also be used anywhere a Key is required.
|
|
||||||
CLASSES_ROOT = Key(syscall.HKEY_CLASSES_ROOT)
|
|
||||||
CURRENT_USER = Key(syscall.HKEY_CURRENT_USER)
|
|
||||||
LOCAL_MACHINE = Key(syscall.HKEY_LOCAL_MACHINE)
|
|
||||||
USERS = Key(syscall.HKEY_USERS)
|
|
||||||
CURRENT_CONFIG = Key(syscall.HKEY_CURRENT_CONFIG)
|
|
||||||
PERFORMANCE_DATA = Key(syscall.HKEY_PERFORMANCE_DATA)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Close closes open key k.
|
|
||||||
func (k Key) Close() error {
|
|
||||||
return syscall.RegCloseKey(syscall.Handle(k))
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenKey opens a new key with path name relative to key k.
|
|
||||||
// It accepts any open key, including CURRENT_USER and others,
|
|
||||||
// and returns the new key and an error.
|
|
||||||
// The access parameter specifies desired access rights to the
|
|
||||||
// key to be opened.
|
|
||||||
func OpenKey(k Key, path string, access uint32) (Key, error) {
|
|
||||||
p, err := syscall.UTF16PtrFromString(path)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
var subkey syscall.Handle
|
|
||||||
err = syscall.RegOpenKeyEx(syscall.Handle(k), p, 0, access, &subkey)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return Key(subkey), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenRemoteKey opens a predefined registry key on another
|
|
||||||
// computer pcname. The key to be opened is specified by k, but
|
|
||||||
// can only be one of LOCAL_MACHINE, PERFORMANCE_DATA or USERS.
|
|
||||||
// If pcname is "", OpenRemoteKey returns local computer key.
|
|
||||||
func OpenRemoteKey(pcname string, k Key) (Key, error) {
|
|
||||||
var err error
|
|
||||||
var p *uint16
|
|
||||||
if pcname != "" {
|
|
||||||
p, err = syscall.UTF16PtrFromString(`\\` + pcname)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var remoteKey syscall.Handle
|
|
||||||
err = regConnectRegistry(p, syscall.Handle(k), &remoteKey)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return Key(remoteKey), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadSubKeyNames returns the names of subkeys of key k.
|
|
||||||
// The parameter n controls the number of returned names,
|
|
||||||
// analogous to the way os.File.Readdirnames works.
|
|
||||||
func (k Key) ReadSubKeyNames(n int) ([]string, error) {
|
|
||||||
names := make([]string, 0)
|
|
||||||
// Registry key size limit is 255 bytes and described there:
|
|
||||||
// https://msdn.microsoft.com/library/windows/desktop/ms724872.aspx
|
|
||||||
buf := make([]uint16, 256) //plus extra room for terminating zero byte
|
|
||||||
loopItems:
|
|
||||||
for i := uint32(0); ; i++ {
|
|
||||||
if n > 0 {
|
|
||||||
if len(names) == n {
|
|
||||||
return names, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
l := uint32(len(buf))
|
|
||||||
for {
|
|
||||||
err := syscall.RegEnumKeyEx(syscall.Handle(k), i, &buf[0], &l, nil, nil, nil, nil)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err == syscall.ERROR_MORE_DATA {
|
|
||||||
// Double buffer size and try again.
|
|
||||||
l = uint32(2 * len(buf))
|
|
||||||
buf = make([]uint16, l)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err == _ERROR_NO_MORE_ITEMS {
|
|
||||||
break loopItems
|
|
||||||
}
|
|
||||||
return names, err
|
|
||||||
}
|
|
||||||
names = append(names, syscall.UTF16ToString(buf[:l]))
|
|
||||||
}
|
|
||||||
if n > len(names) {
|
|
||||||
return names, io.EOF
|
|
||||||
}
|
|
||||||
return names, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateKey creates a key named path under open key k.
|
|
||||||
// CreateKey returns the new key and a boolean flag that reports
|
|
||||||
// whether the key already existed.
|
|
||||||
// The access parameter specifies the access rights for the key
|
|
||||||
// to be created.
|
|
||||||
func CreateKey(k Key, path string, access uint32) (newk Key, openedExisting bool, err error) {
|
|
||||||
var h syscall.Handle
|
|
||||||
var d uint32
|
|
||||||
err = regCreateKeyEx(syscall.Handle(k), syscall.StringToUTF16Ptr(path),
|
|
||||||
0, nil, _REG_OPTION_NON_VOLATILE, access, nil, &h, &d)
|
|
||||||
if err != nil {
|
|
||||||
return 0, false, err
|
|
||||||
}
|
|
||||||
return Key(h), d == _REG_OPENED_EXISTING_KEY, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteKey deletes the subkey path of key k and its values.
|
|
||||||
func DeleteKey(k Key, path string) error {
|
|
||||||
return regDeleteKey(syscall.Handle(k), syscall.StringToUTF16Ptr(path))
|
|
||||||
}
|
|
||||||
|
|
||||||
// A KeyInfo describes the statistics of a key. It is returned by Stat.
|
|
||||||
type KeyInfo struct {
|
|
||||||
SubKeyCount uint32
|
|
||||||
MaxSubKeyLen uint32 // size of the key's subkey with the longest name, in Unicode characters, not including the terminating zero byte
|
|
||||||
ValueCount uint32
|
|
||||||
MaxValueNameLen uint32 // size of the key's longest value name, in Unicode characters, not including the terminating zero byte
|
|
||||||
MaxValueLen uint32 // longest data component among the key's values, in bytes
|
|
||||||
lastWriteTime syscall.Filetime
|
|
||||||
}
|
|
||||||
|
|
||||||
// ModTime returns the key's last write time.
|
|
||||||
func (ki *KeyInfo) ModTime() time.Time {
|
|
||||||
return time.Unix(0, ki.lastWriteTime.Nanoseconds())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stat retrieves information about the open key k.
|
|
||||||
func (k Key) Stat() (*KeyInfo, error) {
|
|
||||||
var ki KeyInfo
|
|
||||||
err := syscall.RegQueryInfoKey(syscall.Handle(k), nil, nil, nil,
|
|
||||||
&ki.SubKeyCount, &ki.MaxSubKeyLen, nil, &ki.ValueCount,
|
|
||||||
&ki.MaxValueNameLen, &ki.MaxValueLen, nil, &ki.lastWriteTime)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &ki, nil
|
|
||||||
}
|
|
7
vendor/golang.org/x/sys/windows/registry/mksyscall.go
generated
vendored
7
vendor/golang.org/x/sys/windows/registry/mksyscall.go
generated
vendored
@ -1,7 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package registry
|
|
||||||
|
|
||||||
//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go syscall.go
|
|
32
vendor/golang.org/x/sys/windows/registry/syscall.go
generated
vendored
32
vendor/golang.org/x/sys/windows/registry/syscall.go
generated
vendored
@ -1,32 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package registry
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const (
|
|
||||||
_REG_OPTION_NON_VOLATILE = 0
|
|
||||||
|
|
||||||
_REG_CREATED_NEW_KEY = 1
|
|
||||||
_REG_OPENED_EXISTING_KEY = 2
|
|
||||||
|
|
||||||
_ERROR_NO_MORE_ITEMS syscall.Errno = 259
|
|
||||||
)
|
|
||||||
|
|
||||||
func LoadRegLoadMUIString() error {
|
|
||||||
return procRegLoadMUIStringW.Find()
|
|
||||||
}
|
|
||||||
|
|
||||||
//sys regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) = advapi32.RegCreateKeyExW
|
|
||||||
//sys regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) = advapi32.RegDeleteKeyW
|
|
||||||
//sys regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype uint32, buf *byte, bufsize uint32) (regerrno error) = advapi32.RegSetValueExW
|
|
||||||
//sys regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegEnumValueW
|
|
||||||
//sys regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) = advapi32.RegDeleteValueW
|
|
||||||
//sys regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint32, buflenCopied *uint32, flags uint32, dir *uint16) (regerrno error) = advapi32.RegLoadMUIStringW
|
|
||||||
//sys regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall.Handle) (regerrno error) = advapi32.RegConnectRegistryW
|
|
||||||
|
|
||||||
//sys expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) = kernel32.ExpandEnvironmentStringsW
|
|
384
vendor/golang.org/x/sys/windows/registry/value.go
generated
vendored
384
vendor/golang.org/x/sys/windows/registry/value.go
generated
vendored
@ -1,384 +0,0 @@
|
|||||||
// Copyright 2015 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package registry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"syscall"
|
|
||||||
"unicode/utf16"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Registry value types.
|
|
||||||
NONE = 0
|
|
||||||
SZ = 1
|
|
||||||
EXPAND_SZ = 2
|
|
||||||
BINARY = 3
|
|
||||||
DWORD = 4
|
|
||||||
DWORD_BIG_ENDIAN = 5
|
|
||||||
LINK = 6
|
|
||||||
MULTI_SZ = 7
|
|
||||||
RESOURCE_LIST = 8
|
|
||||||
FULL_RESOURCE_DESCRIPTOR = 9
|
|
||||||
RESOURCE_REQUIREMENTS_LIST = 10
|
|
||||||
QWORD = 11
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// ErrShortBuffer is returned when the buffer was too short for the operation.
|
|
||||||
ErrShortBuffer = syscall.ERROR_MORE_DATA
|
|
||||||
|
|
||||||
// ErrNotExist is returned when a registry key or value does not exist.
|
|
||||||
ErrNotExist = syscall.ERROR_FILE_NOT_FOUND
|
|
||||||
|
|
||||||
// ErrUnexpectedType is returned by Get*Value when the value's type was unexpected.
|
|
||||||
ErrUnexpectedType = errors.New("unexpected key value type")
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetValue retrieves the type and data for the specified value associated
|
|
||||||
// with an open key k. It fills up buffer buf and returns the retrieved
|
|
||||||
// byte count n. If buf is too small to fit the stored value it returns
|
|
||||||
// ErrShortBuffer error along with the required buffer size n.
|
|
||||||
// If no buffer is provided, it returns true and actual buffer size n.
|
|
||||||
// If no buffer is provided, GetValue returns the value's type only.
|
|
||||||
// If the value does not exist, the error returned is ErrNotExist.
|
|
||||||
//
|
|
||||||
// GetValue is a low level function. If value's type is known, use the appropriate
|
|
||||||
// Get*Value function instead.
|
|
||||||
func (k Key) GetValue(name string, buf []byte) (n int, valtype uint32, err error) {
|
|
||||||
pname, err := syscall.UTF16PtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return 0, 0, err
|
|
||||||
}
|
|
||||||
var pbuf *byte
|
|
||||||
if len(buf) > 0 {
|
|
||||||
pbuf = (*byte)(unsafe.Pointer(&buf[0]))
|
|
||||||
}
|
|
||||||
l := uint32(len(buf))
|
|
||||||
err = syscall.RegQueryValueEx(syscall.Handle(k), pname, nil, &valtype, pbuf, &l)
|
|
||||||
if err != nil {
|
|
||||||
return int(l), valtype, err
|
|
||||||
}
|
|
||||||
return int(l), valtype, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (k Key) getValue(name string, buf []byte) (date []byte, valtype uint32, err error) {
|
|
||||||
p, err := syscall.UTF16PtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
var t uint32
|
|
||||||
n := uint32(len(buf))
|
|
||||||
for {
|
|
||||||
err = syscall.RegQueryValueEx(syscall.Handle(k), p, nil, &t, (*byte)(unsafe.Pointer(&buf[0])), &n)
|
|
||||||
if err == nil {
|
|
||||||
return buf[:n], t, nil
|
|
||||||
}
|
|
||||||
if err != syscall.ERROR_MORE_DATA {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
if n <= uint32(len(buf)) {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
buf = make([]byte, n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetStringValue retrieves the string value for the specified
|
|
||||||
// value name associated with an open key k. It also returns the value's type.
|
|
||||||
// If value does not exist, GetStringValue returns ErrNotExist.
|
|
||||||
// If value is not SZ or EXPAND_SZ, it will return the correct value
|
|
||||||
// type and ErrUnexpectedType.
|
|
||||||
func (k Key) GetStringValue(name string) (val string, valtype uint32, err error) {
|
|
||||||
data, typ, err2 := k.getValue(name, make([]byte, 64))
|
|
||||||
if err2 != nil {
|
|
||||||
return "", typ, err2
|
|
||||||
}
|
|
||||||
switch typ {
|
|
||||||
case SZ, EXPAND_SZ:
|
|
||||||
default:
|
|
||||||
return "", typ, ErrUnexpectedType
|
|
||||||
}
|
|
||||||
if len(data) == 0 {
|
|
||||||
return "", typ, nil
|
|
||||||
}
|
|
||||||
u := (*[1 << 29]uint16)(unsafe.Pointer(&data[0]))[:]
|
|
||||||
return syscall.UTF16ToString(u), typ, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMUIStringValue retrieves the localized string value for
|
|
||||||
// the specified value name associated with an open key k.
|
|
||||||
// If the value name doesn't exist or the localized string value
|
|
||||||
// can't be resolved, GetMUIStringValue returns ErrNotExist.
|
|
||||||
// GetMUIStringValue panics if the system doesn't support
|
|
||||||
// regLoadMUIString; use LoadRegLoadMUIString to check if
|
|
||||||
// regLoadMUIString is supported before calling this function.
|
|
||||||
func (k Key) GetMUIStringValue(name string) (string, error) {
|
|
||||||
pname, err := syscall.UTF16PtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := make([]uint16, 1024)
|
|
||||||
var buflen uint32
|
|
||||||
var pdir *uint16
|
|
||||||
|
|
||||||
err = regLoadMUIString(syscall.Handle(k), pname, &buf[0], uint32(len(buf)), &buflen, 0, pdir)
|
|
||||||
if err == syscall.ERROR_FILE_NOT_FOUND { // Try fallback path
|
|
||||||
|
|
||||||
// Try to resolve the string value using the system directory as
|
|
||||||
// a DLL search path; this assumes the string value is of the form
|
|
||||||
// @[path]\dllname,-strID but with no path given, e.g. @tzres.dll,-320.
|
|
||||||
|
|
||||||
// This approach works with tzres.dll but may have to be revised
|
|
||||||
// in the future to allow callers to provide custom search paths.
|
|
||||||
|
|
||||||
var s string
|
|
||||||
s, err = ExpandString("%SystemRoot%\\system32\\")
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
pdir, err = syscall.UTF16PtrFromString(s)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = regLoadMUIString(syscall.Handle(k), pname, &buf[0], uint32(len(buf)), &buflen, 0, pdir)
|
|
||||||
}
|
|
||||||
|
|
||||||
for err == syscall.ERROR_MORE_DATA { // Grow buffer if needed
|
|
||||||
if buflen <= uint32(len(buf)) {
|
|
||||||
break // Buffer not growing, assume race; break
|
|
||||||
}
|
|
||||||
buf = make([]uint16, buflen)
|
|
||||||
err = regLoadMUIString(syscall.Handle(k), pname, &buf[0], uint32(len(buf)), &buflen, 0, pdir)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return syscall.UTF16ToString(buf), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpandString expands environment-variable strings and replaces
|
|
||||||
// them with the values defined for the current user.
|
|
||||||
// Use ExpandString to expand EXPAND_SZ strings.
|
|
||||||
func ExpandString(value string) (string, error) {
|
|
||||||
if value == "" {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
p, err := syscall.UTF16PtrFromString(value)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
r := make([]uint16, 100)
|
|
||||||
for {
|
|
||||||
n, err := expandEnvironmentStrings(p, &r[0], uint32(len(r)))
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if n <= uint32(len(r)) {
|
|
||||||
u := (*[1 << 29]uint16)(unsafe.Pointer(&r[0]))[:]
|
|
||||||
return syscall.UTF16ToString(u), nil
|
|
||||||
}
|
|
||||||
r = make([]uint16, n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetStringsValue retrieves the []string value for the specified
|
|
||||||
// value name associated with an open key k. It also returns the value's type.
|
|
||||||
// If value does not exist, GetStringsValue returns ErrNotExist.
|
|
||||||
// If value is not MULTI_SZ, it will return the correct value
|
|
||||||
// type and ErrUnexpectedType.
|
|
||||||
func (k Key) GetStringsValue(name string) (val []string, valtype uint32, err error) {
|
|
||||||
data, typ, err2 := k.getValue(name, make([]byte, 64))
|
|
||||||
if err2 != nil {
|
|
||||||
return nil, typ, err2
|
|
||||||
}
|
|
||||||
if typ != MULTI_SZ {
|
|
||||||
return nil, typ, ErrUnexpectedType
|
|
||||||
}
|
|
||||||
if len(data) == 0 {
|
|
||||||
return nil, typ, nil
|
|
||||||
}
|
|
||||||
p := (*[1 << 29]uint16)(unsafe.Pointer(&data[0]))[:len(data)/2]
|
|
||||||
if len(p) == 0 {
|
|
||||||
return nil, typ, nil
|
|
||||||
}
|
|
||||||
if p[len(p)-1] == 0 {
|
|
||||||
p = p[:len(p)-1] // remove terminating null
|
|
||||||
}
|
|
||||||
val = make([]string, 0, 5)
|
|
||||||
from := 0
|
|
||||||
for i, c := range p {
|
|
||||||
if c == 0 {
|
|
||||||
val = append(val, string(utf16.Decode(p[from:i])))
|
|
||||||
from = i + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return val, typ, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetIntegerValue retrieves the integer value for the specified
|
|
||||||
// value name associated with an open key k. It also returns the value's type.
|
|
||||||
// If value does not exist, GetIntegerValue returns ErrNotExist.
|
|
||||||
// If value is not DWORD or QWORD, it will return the correct value
|
|
||||||
// type and ErrUnexpectedType.
|
|
||||||
func (k Key) GetIntegerValue(name string) (val uint64, valtype uint32, err error) {
|
|
||||||
data, typ, err2 := k.getValue(name, make([]byte, 8))
|
|
||||||
if err2 != nil {
|
|
||||||
return 0, typ, err2
|
|
||||||
}
|
|
||||||
switch typ {
|
|
||||||
case DWORD:
|
|
||||||
if len(data) != 4 {
|
|
||||||
return 0, typ, errors.New("DWORD value is not 4 bytes long")
|
|
||||||
}
|
|
||||||
return uint64(*(*uint32)(unsafe.Pointer(&data[0]))), DWORD, nil
|
|
||||||
case QWORD:
|
|
||||||
if len(data) != 8 {
|
|
||||||
return 0, typ, errors.New("QWORD value is not 8 bytes long")
|
|
||||||
}
|
|
||||||
return uint64(*(*uint64)(unsafe.Pointer(&data[0]))), QWORD, nil
|
|
||||||
default:
|
|
||||||
return 0, typ, ErrUnexpectedType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetBinaryValue retrieves the binary value for the specified
|
|
||||||
// value name associated with an open key k. It also returns the value's type.
|
|
||||||
// If value does not exist, GetBinaryValue returns ErrNotExist.
|
|
||||||
// If value is not BINARY, it will return the correct value
|
|
||||||
// type and ErrUnexpectedType.
|
|
||||||
func (k Key) GetBinaryValue(name string) (val []byte, valtype uint32, err error) {
|
|
||||||
data, typ, err2 := k.getValue(name, make([]byte, 64))
|
|
||||||
if err2 != nil {
|
|
||||||
return nil, typ, err2
|
|
||||||
}
|
|
||||||
if typ != BINARY {
|
|
||||||
return nil, typ, ErrUnexpectedType
|
|
||||||
}
|
|
||||||
return data, typ, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (k Key) setValue(name string, valtype uint32, data []byte) error {
|
|
||||||
p, err := syscall.UTF16PtrFromString(name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(data) == 0 {
|
|
||||||
return regSetValueEx(syscall.Handle(k), p, 0, valtype, nil, 0)
|
|
||||||
}
|
|
||||||
return regSetValueEx(syscall.Handle(k), p, 0, valtype, &data[0], uint32(len(data)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDWordValue sets the data and type of a name value
|
|
||||||
// under key k to value and DWORD.
|
|
||||||
func (k Key) SetDWordValue(name string, value uint32) error {
|
|
||||||
return k.setValue(name, DWORD, (*[4]byte)(unsafe.Pointer(&value))[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetQWordValue sets the data and type of a name value
|
|
||||||
// under key k to value and QWORD.
|
|
||||||
func (k Key) SetQWordValue(name string, value uint64) error {
|
|
||||||
return k.setValue(name, QWORD, (*[8]byte)(unsafe.Pointer(&value))[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
func (k Key) setStringValue(name string, valtype uint32, value string) error {
|
|
||||||
v, err := syscall.UTF16FromString(value)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
buf := (*[1 << 29]byte)(unsafe.Pointer(&v[0]))[:len(v)*2]
|
|
||||||
return k.setValue(name, valtype, buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStringValue sets the data and type of a name value
|
|
||||||
// under key k to value and SZ. The value must not contain a zero byte.
|
|
||||||
func (k Key) SetStringValue(name, value string) error {
|
|
||||||
return k.setStringValue(name, SZ, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetExpandStringValue sets the data and type of a name value
|
|
||||||
// under key k to value and EXPAND_SZ. The value must not contain a zero byte.
|
|
||||||
func (k Key) SetExpandStringValue(name, value string) error {
|
|
||||||
return k.setStringValue(name, EXPAND_SZ, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStringsValue sets the data and type of a name value
|
|
||||||
// under key k to value and MULTI_SZ. The value strings
|
|
||||||
// must not contain a zero byte.
|
|
||||||
func (k Key) SetStringsValue(name string, value []string) error {
|
|
||||||
ss := ""
|
|
||||||
for _, s := range value {
|
|
||||||
for i := 0; i < len(s); i++ {
|
|
||||||
if s[i] == 0 {
|
|
||||||
return errors.New("string cannot have 0 inside")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ss += s + "\x00"
|
|
||||||
}
|
|
||||||
v := utf16.Encode([]rune(ss + "\x00"))
|
|
||||||
buf := (*[1 << 29]byte)(unsafe.Pointer(&v[0]))[:len(v)*2]
|
|
||||||
return k.setValue(name, MULTI_SZ, buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBinaryValue sets the data and type of a name value
|
|
||||||
// under key k to value and BINARY.
|
|
||||||
func (k Key) SetBinaryValue(name string, value []byte) error {
|
|
||||||
return k.setValue(name, BINARY, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteValue removes a named value from the key k.
|
|
||||||
func (k Key) DeleteValue(name string) error {
|
|
||||||
return regDeleteValue(syscall.Handle(k), syscall.StringToUTF16Ptr(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadValueNames returns the value names of key k.
|
|
||||||
// The parameter n controls the number of returned names,
|
|
||||||
// analogous to the way os.File.Readdirnames works.
|
|
||||||
func (k Key) ReadValueNames(n int) ([]string, error) {
|
|
||||||
ki, err := k.Stat()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
names := make([]string, 0, ki.ValueCount)
|
|
||||||
buf := make([]uint16, ki.MaxValueNameLen+1) // extra room for terminating null character
|
|
||||||
loopItems:
|
|
||||||
for i := uint32(0); ; i++ {
|
|
||||||
if n > 0 {
|
|
||||||
if len(names) == n {
|
|
||||||
return names, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
l := uint32(len(buf))
|
|
||||||
for {
|
|
||||||
err := regEnumValue(syscall.Handle(k), i, &buf[0], &l, nil, nil, nil, nil)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err == syscall.ERROR_MORE_DATA {
|
|
||||||
// Double buffer size and try again.
|
|
||||||
l = uint32(2 * len(buf))
|
|
||||||
buf = make([]uint16, l)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err == _ERROR_NO_MORE_ITEMS {
|
|
||||||
break loopItems
|
|
||||||
}
|
|
||||||
return names, err
|
|
||||||
}
|
|
||||||
names = append(names, syscall.UTF16ToString(buf[:l]))
|
|
||||||
}
|
|
||||||
if n > len(names) {
|
|
||||||
return names, io.EOF
|
|
||||||
}
|
|
||||||
return names, nil
|
|
||||||
}
|
|
120
vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go
generated
vendored
120
vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go
generated
vendored
@ -1,120 +0,0 @@
|
|||||||
// Code generated by 'go generate'; DO NOT EDIT.
|
|
||||||
|
|
||||||
package registry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ unsafe.Pointer
|
|
||||||
|
|
||||||
// Do the interface allocations only once for common
|
|
||||||
// Errno values.
|
|
||||||
const (
|
|
||||||
errnoERROR_IO_PENDING = 997
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
|
|
||||||
)
|
|
||||||
|
|
||||||
// errnoErr returns common boxed Errno values, to prevent
|
|
||||||
// allocations at runtime.
|
|
||||||
func errnoErr(e syscall.Errno) error {
|
|
||||||
switch e {
|
|
||||||
case 0:
|
|
||||||
return nil
|
|
||||||
case errnoERROR_IO_PENDING:
|
|
||||||
return errERROR_IO_PENDING
|
|
||||||
}
|
|
||||||
// TODO: add more here, after collecting data on the common
|
|
||||||
// error values see on Windows. (perhaps when running
|
|
||||||
// all.bat?)
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
|
|
||||||
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
|
||||||
|
|
||||||
procRegCreateKeyExW = modadvapi32.NewProc("RegCreateKeyExW")
|
|
||||||
procRegDeleteKeyW = modadvapi32.NewProc("RegDeleteKeyW")
|
|
||||||
procRegSetValueExW = modadvapi32.NewProc("RegSetValueExW")
|
|
||||||
procRegEnumValueW = modadvapi32.NewProc("RegEnumValueW")
|
|
||||||
procRegDeleteValueW = modadvapi32.NewProc("RegDeleteValueW")
|
|
||||||
procRegLoadMUIStringW = modadvapi32.NewProc("RegLoadMUIStringW")
|
|
||||||
procRegConnectRegistryW = modadvapi32.NewProc("RegConnectRegistryW")
|
|
||||||
procExpandEnvironmentStringsW = modkernel32.NewProc("ExpandEnvironmentStringsW")
|
|
||||||
)
|
|
||||||
|
|
||||||
func regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) {
|
|
||||||
r0, _, _ := syscall.Syscall9(procRegCreateKeyExW.Addr(), 9, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(reserved), uintptr(unsafe.Pointer(class)), uintptr(options), uintptr(desired), uintptr(unsafe.Pointer(sa)), uintptr(unsafe.Pointer(result)), uintptr(unsafe.Pointer(disposition)))
|
|
||||||
if r0 != 0 {
|
|
||||||
regerrno = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) {
|
|
||||||
r0, _, _ := syscall.Syscall(procRegDeleteKeyW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(subkey)), 0)
|
|
||||||
if r0 != 0 {
|
|
||||||
regerrno = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype uint32, buf *byte, bufsize uint32) (regerrno error) {
|
|
||||||
r0, _, _ := syscall.Syscall6(procRegSetValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(valueName)), uintptr(reserved), uintptr(vtype), uintptr(unsafe.Pointer(buf)), uintptr(bufsize))
|
|
||||||
if r0 != 0 {
|
|
||||||
regerrno = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
|
|
||||||
r0, _, _ := syscall.Syscall9(procRegEnumValueW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)), 0)
|
|
||||||
if r0 != 0 {
|
|
||||||
regerrno = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) {
|
|
||||||
r0, _, _ := syscall.Syscall(procRegDeleteValueW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(name)), 0)
|
|
||||||
if r0 != 0 {
|
|
||||||
regerrno = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint32, buflenCopied *uint32, flags uint32, dir *uint16) (regerrno error) {
|
|
||||||
r0, _, _ := syscall.Syscall9(procRegLoadMUIStringW.Addr(), 7, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(unsafe.Pointer(buflenCopied)), uintptr(flags), uintptr(unsafe.Pointer(dir)), 0, 0)
|
|
||||||
if r0 != 0 {
|
|
||||||
regerrno = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall.Handle) (regerrno error) {
|
|
||||||
r0, _, _ := syscall.Syscall(procRegConnectRegistryW.Addr(), 3, uintptr(unsafe.Pointer(machinename)), uintptr(key), uintptr(unsafe.Pointer(result)))
|
|
||||||
if r0 != 0 {
|
|
||||||
regerrno = syscall.Errno(r0)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) {
|
|
||||||
r0, _, e1 := syscall.Syscall(procExpandEnvironmentStringsW.Addr(), 3, uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(dst)), uintptr(size))
|
|
||||||
n = uint32(r0)
|
|
||||||
if n == 0 {
|
|
||||||
if e1 != 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
} else {
|
|
||||||
err = syscall.EINVAL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
56
vendor/golang.org/x/sys/windows/svc/debug/log.go
generated
vendored
56
vendor/golang.org/x/sys/windows/svc/debug/log.go
generated
vendored
@ -1,56 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package debug
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Log interface allows different log implementations to be used.
|
|
||||||
type Log interface {
|
|
||||||
Close() error
|
|
||||||
Info(eid uint32, msg string) error
|
|
||||||
Warning(eid uint32, msg string) error
|
|
||||||
Error(eid uint32, msg string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConsoleLog provides access to the console.
|
|
||||||
type ConsoleLog struct {
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates new ConsoleLog.
|
|
||||||
func New(source string) *ConsoleLog {
|
|
||||||
return &ConsoleLog{Name: source}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes console log l.
|
|
||||||
func (l *ConsoleLog) Close() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ConsoleLog) report(kind string, eid uint32, msg string) error {
|
|
||||||
s := l.Name + "." + kind + "(" + strconv.Itoa(int(eid)) + "): " + msg + "\n"
|
|
||||||
_, err := os.Stdout.Write([]byte(s))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info writes an information event msg with event id eid to the console l.
|
|
||||||
func (l *ConsoleLog) Info(eid uint32, msg string) error {
|
|
||||||
return l.report("info", eid, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warning writes an warning event msg with event id eid to the console l.
|
|
||||||
func (l *ConsoleLog) Warning(eid uint32, msg string) error {
|
|
||||||
return l.report("warn", eid, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error writes an error event msg with event id eid to the console l.
|
|
||||||
func (l *ConsoleLog) Error(eid uint32, msg string) error {
|
|
||||||
return l.report("error", eid, msg)
|
|
||||||
}
|
|
45
vendor/golang.org/x/sys/windows/svc/debug/service.go
generated
vendored
45
vendor/golang.org/x/sys/windows/svc/debug/service.go
generated
vendored
@ -1,45 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
// Package debug provides facilities to execute svc.Handler on console.
|
|
||||||
//
|
|
||||||
package debug
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows/svc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Run executes service name by calling appropriate handler function.
|
|
||||||
// The process is running on console, unlike real service. Use Ctrl+C to
|
|
||||||
// send "Stop" command to your service.
|
|
||||||
func Run(name string, handler svc.Handler) error {
|
|
||||||
cmds := make(chan svc.ChangeRequest)
|
|
||||||
changes := make(chan svc.Status)
|
|
||||||
|
|
||||||
sig := make(chan os.Signal)
|
|
||||||
signal.Notify(sig)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
status := svc.Status{State: svc.Stopped}
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-sig:
|
|
||||||
cmds <- svc.ChangeRequest{Cmd: svc.Stop, CurrentStatus: status}
|
|
||||||
case status = <-changes:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, errno := handler.Execute([]string{name}, cmds, changes)
|
|
||||||
if errno != 0 {
|
|
||||||
return syscall.Errno(errno)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
48
vendor/golang.org/x/sys/windows/svc/event.go
generated
vendored
48
vendor/golang.org/x/sys/windows/svc/event.go
generated
vendored
@ -1,48 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package svc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
)
|
|
||||||
|
|
||||||
// event represents auto-reset, initially non-signaled Windows event.
|
|
||||||
// It is used to communicate between go and asm parts of this package.
|
|
||||||
type event struct {
|
|
||||||
h windows.Handle
|
|
||||||
}
|
|
||||||
|
|
||||||
func newEvent() (*event, error) {
|
|
||||||
h, err := windows.CreateEvent(nil, 0, 0, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &event{h: h}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *event) Close() error {
|
|
||||||
return windows.CloseHandle(e.h)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *event) Set() error {
|
|
||||||
return windows.SetEvent(e.h)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *event) Wait() error {
|
|
||||||
s, err := windows.WaitForSingleObject(e.h, windows.INFINITE)
|
|
||||||
switch s {
|
|
||||||
case windows.WAIT_OBJECT_0:
|
|
||||||
break
|
|
||||||
case windows.WAIT_FAILED:
|
|
||||||
return err
|
|
||||||
default:
|
|
||||||
return errors.New("unexpected result from WaitForSingleObject")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
80
vendor/golang.org/x/sys/windows/svc/eventlog/install.go
generated
vendored
80
vendor/golang.org/x/sys/windows/svc/eventlog/install.go
generated
vendored
@ -1,80 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package eventlog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
"golang.org/x/sys/windows/registry"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Log levels.
|
|
||||||
Info = windows.EVENTLOG_INFORMATION_TYPE
|
|
||||||
Warning = windows.EVENTLOG_WARNING_TYPE
|
|
||||||
Error = windows.EVENTLOG_ERROR_TYPE
|
|
||||||
)
|
|
||||||
|
|
||||||
const addKeyName = `SYSTEM\CurrentControlSet\Services\EventLog\Application`
|
|
||||||
|
|
||||||
// Install modifies PC registry to allow logging with an event source src.
|
|
||||||
// It adds all required keys and values to the event log registry key.
|
|
||||||
// Install uses msgFile as the event message file. If useExpandKey is true,
|
|
||||||
// the event message file is installed as REG_EXPAND_SZ value,
|
|
||||||
// otherwise as REG_SZ. Use bitwise of log.Error, log.Warning and
|
|
||||||
// log.Info to specify events supported by the new event source.
|
|
||||||
func Install(src, msgFile string, useExpandKey bool, eventsSupported uint32) error {
|
|
||||||
appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.CREATE_SUB_KEY)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer appkey.Close()
|
|
||||||
|
|
||||||
sk, alreadyExist, err := registry.CreateKey(appkey, src, registry.SET_VALUE)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer sk.Close()
|
|
||||||
if alreadyExist {
|
|
||||||
return errors.New(addKeyName + `\` + src + " registry key already exists")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = sk.SetDWordValue("CustomSource", 1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if useExpandKey {
|
|
||||||
err = sk.SetExpandStringValue("EventMessageFile", msgFile)
|
|
||||||
} else {
|
|
||||||
err = sk.SetStringValue("EventMessageFile", msgFile)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = sk.SetDWordValue("TypesSupported", eventsSupported)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// InstallAsEventCreate is the same as Install, but uses
|
|
||||||
// %SystemRoot%\System32\EventCreate.exe as the event message file.
|
|
||||||
func InstallAsEventCreate(src string, eventsSupported uint32) error {
|
|
||||||
return Install(src, "%SystemRoot%\\System32\\EventCreate.exe", true, eventsSupported)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove deletes all registry elements installed by the correspondent Install.
|
|
||||||
func Remove(src string) error {
|
|
||||||
appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.SET_VALUE)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer appkey.Close()
|
|
||||||
return registry.DeleteKey(appkey, src)
|
|
||||||
}
|
|
70
vendor/golang.org/x/sys/windows/svc/eventlog/log.go
generated
vendored
70
vendor/golang.org/x/sys/windows/svc/eventlog/log.go
generated
vendored
@ -1,70 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
// Package eventlog implements access to Windows event log.
|
|
||||||
//
|
|
||||||
package eventlog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Log provides access to the system log.
|
|
||||||
type Log struct {
|
|
||||||
Handle windows.Handle
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open retrieves a handle to the specified event log.
|
|
||||||
func Open(source string) (*Log, error) {
|
|
||||||
return OpenRemote("", source)
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenRemote does the same as Open, but on different computer host.
|
|
||||||
func OpenRemote(host, source string) (*Log, error) {
|
|
||||||
if source == "" {
|
|
||||||
return nil, errors.New("Specify event log source")
|
|
||||||
}
|
|
||||||
var s *uint16
|
|
||||||
if host != "" {
|
|
||||||
s = syscall.StringToUTF16Ptr(host)
|
|
||||||
}
|
|
||||||
h, err := windows.RegisterEventSource(s, syscall.StringToUTF16Ptr(source))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Log{Handle: h}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes event log l.
|
|
||||||
func (l *Log) Close() error {
|
|
||||||
return windows.DeregisterEventSource(l.Handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Log) report(etype uint16, eid uint32, msg string) error {
|
|
||||||
ss := []*uint16{syscall.StringToUTF16Ptr(msg)}
|
|
||||||
return windows.ReportEvent(l.Handle, etype, 0, eid, 0, 1, 0, &ss[0], nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info writes an information event msg with event id eid to the end of event log l.
|
|
||||||
// When EventCreate.exe is used, eid must be between 1 and 1000.
|
|
||||||
func (l *Log) Info(eid uint32, msg string) error {
|
|
||||||
return l.report(windows.EVENTLOG_INFORMATION_TYPE, eid, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warning writes an warning event msg with event id eid to the end of event log l.
|
|
||||||
// When EventCreate.exe is used, eid must be between 1 and 1000.
|
|
||||||
func (l *Log) Warning(eid uint32, msg string) error {
|
|
||||||
return l.report(windows.EVENTLOG_WARNING_TYPE, eid, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error writes an error event msg with event id eid to the end of event log l.
|
|
||||||
// When EventCreate.exe is used, eid must be between 1 and 1000.
|
|
||||||
func (l *Log) Error(eid uint32, msg string) error {
|
|
||||||
return l.report(windows.EVENTLOG_ERROR_TYPE, eid, msg)
|
|
||||||
}
|
|
24
vendor/golang.org/x/sys/windows/svc/go12.c
generated
vendored
24
vendor/golang.org/x/sys/windows/svc/go12.c
generated
vendored
@ -1,24 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
// +build !go1.3
|
|
||||||
|
|
||||||
// copied from pkg/runtime
|
|
||||||
typedef unsigned int uint32;
|
|
||||||
typedef unsigned long long int uint64;
|
|
||||||
#ifdef _64BIT
|
|
||||||
typedef uint64 uintptr;
|
|
||||||
#else
|
|
||||||
typedef uint32 uintptr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// from sys_386.s or sys_amd64.s
|
|
||||||
void ·servicemain(void);
|
|
||||||
|
|
||||||
void
|
|
||||||
·getServiceMain(uintptr *r)
|
|
||||||
{
|
|
||||||
*r = (uintptr)·servicemain;
|
|
||||||
}
|
|
11
vendor/golang.org/x/sys/windows/svc/go12.go
generated
vendored
11
vendor/golang.org/x/sys/windows/svc/go12.go
generated
vendored
@ -1,11 +0,0 @@
|
|||||||
// Copyright 2014 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
// +build !go1.3
|
|
||||||
|
|
||||||
package svc
|
|
||||||
|
|
||||||
// from go12.c
|
|
||||||
func getServiceMain(r *uintptr)
|
|
31
vendor/golang.org/x/sys/windows/svc/go13.go
generated
vendored
31
vendor/golang.org/x/sys/windows/svc/go13.go
generated
vendored
@ -1,31 +0,0 @@
|
|||||||
// Copyright 2014 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
// +build go1.3
|
|
||||||
|
|
||||||
package svc
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
const ptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const
|
|
||||||
|
|
||||||
// Should be a built-in for unsafe.Pointer?
|
|
||||||
func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(p) + x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// funcPC returns the entry PC of the function f.
|
|
||||||
// It assumes that f is a func value. Otherwise the behavior is undefined.
|
|
||||||
func funcPC(f interface{}) uintptr {
|
|
||||||
return **(**uintptr)(add(unsafe.Pointer(&f), ptrSize))
|
|
||||||
}
|
|
||||||
|
|
||||||
// from sys_386.s and sys_amd64.s
|
|
||||||
func servicectlhandler(ctl uint32) uintptr
|
|
||||||
func servicemain(argc uint32, argv **uint16)
|
|
||||||
|
|
||||||
func getServiceMain(r *uintptr) {
|
|
||||||
*r = funcPC(servicemain)
|
|
||||||
}
|
|
139
vendor/golang.org/x/sys/windows/svc/mgr/config.go
generated
vendored
139
vendor/golang.org/x/sys/windows/svc/mgr/config.go
generated
vendored
@ -1,139 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package mgr
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unicode/utf16"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Service start types.
|
|
||||||
StartManual = windows.SERVICE_DEMAND_START // the service must be started manually
|
|
||||||
StartAutomatic = windows.SERVICE_AUTO_START // the service will start by itself whenever the computer reboots
|
|
||||||
StartDisabled = windows.SERVICE_DISABLED // the service cannot be started
|
|
||||||
|
|
||||||
// The severity of the error, and action taken,
|
|
||||||
// if this service fails to start.
|
|
||||||
ErrorCritical = windows.SERVICE_ERROR_CRITICAL
|
|
||||||
ErrorIgnore = windows.SERVICE_ERROR_IGNORE
|
|
||||||
ErrorNormal = windows.SERVICE_ERROR_NORMAL
|
|
||||||
ErrorSevere = windows.SERVICE_ERROR_SEVERE
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO(brainman): Password is not returned by windows.QueryServiceConfig, not sure how to get it.
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
ServiceType uint32
|
|
||||||
StartType uint32
|
|
||||||
ErrorControl uint32
|
|
||||||
BinaryPathName string // fully qualified path to the service binary file, can also include arguments for an auto-start service
|
|
||||||
LoadOrderGroup string
|
|
||||||
TagId uint32
|
|
||||||
Dependencies []string
|
|
||||||
ServiceStartName string // name of the account under which the service should run
|
|
||||||
DisplayName string
|
|
||||||
Password string
|
|
||||||
Description string
|
|
||||||
}
|
|
||||||
|
|
||||||
func toString(p *uint16) string {
|
|
||||||
if p == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return syscall.UTF16ToString((*[4096]uint16)(unsafe.Pointer(p))[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
func toStringSlice(ps *uint16) []string {
|
|
||||||
if ps == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
r := make([]string, 0)
|
|
||||||
for from, i, p := 0, 0, (*[1 << 24]uint16)(unsafe.Pointer(ps)); true; i++ {
|
|
||||||
if p[i] == 0 {
|
|
||||||
// empty string marks the end
|
|
||||||
if i <= from {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
r = append(r, string(utf16.Decode(p[from:i])))
|
|
||||||
from = i + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// Config retrieves service s configuration paramteres.
|
|
||||||
func (s *Service) Config() (Config, error) {
|
|
||||||
var p *windows.QUERY_SERVICE_CONFIG
|
|
||||||
n := uint32(1024)
|
|
||||||
for {
|
|
||||||
b := make([]byte, n)
|
|
||||||
p = (*windows.QUERY_SERVICE_CONFIG)(unsafe.Pointer(&b[0]))
|
|
||||||
err := windows.QueryServiceConfig(s.Handle, p, n, &n)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER {
|
|
||||||
return Config{}, err
|
|
||||||
}
|
|
||||||
if n <= uint32(len(b)) {
|
|
||||||
return Config{}, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var p2 *windows.SERVICE_DESCRIPTION
|
|
||||||
n = uint32(1024)
|
|
||||||
for {
|
|
||||||
b := make([]byte, n)
|
|
||||||
p2 = (*windows.SERVICE_DESCRIPTION)(unsafe.Pointer(&b[0]))
|
|
||||||
err := windows.QueryServiceConfig2(s.Handle,
|
|
||||||
windows.SERVICE_CONFIG_DESCRIPTION, &b[0], n, &n)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER {
|
|
||||||
return Config{}, err
|
|
||||||
}
|
|
||||||
if n <= uint32(len(b)) {
|
|
||||||
return Config{}, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Config{
|
|
||||||
ServiceType: p.ServiceType,
|
|
||||||
StartType: p.StartType,
|
|
||||||
ErrorControl: p.ErrorControl,
|
|
||||||
BinaryPathName: toString(p.BinaryPathName),
|
|
||||||
LoadOrderGroup: toString(p.LoadOrderGroup),
|
|
||||||
TagId: p.TagId,
|
|
||||||
Dependencies: toStringSlice(p.Dependencies),
|
|
||||||
ServiceStartName: toString(p.ServiceStartName),
|
|
||||||
DisplayName: toString(p.DisplayName),
|
|
||||||
Description: toString(p2.Description),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateDescription(handle windows.Handle, desc string) error {
|
|
||||||
d := windows.SERVICE_DESCRIPTION{Description: toPtr(desc)}
|
|
||||||
return windows.ChangeServiceConfig2(handle,
|
|
||||||
windows.SERVICE_CONFIG_DESCRIPTION, (*byte)(unsafe.Pointer(&d)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateConfig updates service s configuration parameters.
|
|
||||||
func (s *Service) UpdateConfig(c Config) error {
|
|
||||||
err := windows.ChangeServiceConfig(s.Handle, c.ServiceType, c.StartType,
|
|
||||||
c.ErrorControl, toPtr(c.BinaryPathName), toPtr(c.LoadOrderGroup),
|
|
||||||
nil, toStringBlock(c.Dependencies), toPtr(c.ServiceStartName),
|
|
||||||
toPtr(c.Password), toPtr(c.DisplayName))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return updateDescription(s.Handle, c.Description)
|
|
||||||
}
|
|
162
vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
generated
vendored
162
vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
generated
vendored
@ -1,162 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
// Package mgr can be used to manage Windows service programs.
|
|
||||||
// It can be used to install and remove them. It can also start,
|
|
||||||
// stop and pause them. The package can query / change current
|
|
||||||
// service state and config parameters.
|
|
||||||
//
|
|
||||||
package mgr
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unicode/utf16"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Mgr is used to manage Windows service.
|
|
||||||
type Mgr struct {
|
|
||||||
Handle windows.Handle
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect establishes a connection to the service control manager.
|
|
||||||
func Connect() (*Mgr, error) {
|
|
||||||
return ConnectRemote("")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConnectRemote establishes a connection to the
|
|
||||||
// service control manager on computer named host.
|
|
||||||
func ConnectRemote(host string) (*Mgr, error) {
|
|
||||||
var s *uint16
|
|
||||||
if host != "" {
|
|
||||||
s = syscall.StringToUTF16Ptr(host)
|
|
||||||
}
|
|
||||||
h, err := windows.OpenSCManager(s, nil, windows.SC_MANAGER_ALL_ACCESS)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Mgr{Handle: h}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disconnect closes connection to the service control manager m.
|
|
||||||
func (m *Mgr) Disconnect() error {
|
|
||||||
return windows.CloseServiceHandle(m.Handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
func toPtr(s string) *uint16 {
|
|
||||||
if len(s) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return syscall.StringToUTF16Ptr(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// toStringBlock terminates strings in ss with 0, and then
|
|
||||||
// concatenates them together. It also adds extra 0 at the end.
|
|
||||||
func toStringBlock(ss []string) *uint16 {
|
|
||||||
if len(ss) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
t := ""
|
|
||||||
for _, s := range ss {
|
|
||||||
if s != "" {
|
|
||||||
t += s + "\x00"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if t == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
t += "\x00"
|
|
||||||
return &utf16.Encode([]rune(t))[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateService installs new service name on the system.
|
|
||||||
// The service will be executed by running exepath binary.
|
|
||||||
// Use config c to specify service parameters.
|
|
||||||
// Any args will be passed as command-line arguments when
|
|
||||||
// the service is started; these arguments are distinct from
|
|
||||||
// the arguments passed to Service.Start or via the "Start
|
|
||||||
// parameters" field in the service's Properties dialog box.
|
|
||||||
func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Service, error) {
|
|
||||||
if c.StartType == 0 {
|
|
||||||
c.StartType = StartManual
|
|
||||||
}
|
|
||||||
if c.ErrorControl == 0 {
|
|
||||||
c.ErrorControl = ErrorNormal
|
|
||||||
}
|
|
||||||
if c.ServiceType == 0 {
|
|
||||||
c.ServiceType = windows.SERVICE_WIN32_OWN_PROCESS
|
|
||||||
}
|
|
||||||
s := syscall.EscapeArg(exepath)
|
|
||||||
for _, v := range args {
|
|
||||||
s += " " + syscall.EscapeArg(v)
|
|
||||||
}
|
|
||||||
h, err := windows.CreateService(m.Handle, toPtr(name), toPtr(c.DisplayName),
|
|
||||||
windows.SERVICE_ALL_ACCESS, c.ServiceType,
|
|
||||||
c.StartType, c.ErrorControl, toPtr(s), toPtr(c.LoadOrderGroup),
|
|
||||||
nil, toStringBlock(c.Dependencies), toPtr(c.ServiceStartName), toPtr(c.Password))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if c.Description != "" {
|
|
||||||
err = updateDescription(h, c.Description)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &Service{Name: name, Handle: h}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenService retrieves access to service name, so it can
|
|
||||||
// be interrogated and controlled.
|
|
||||||
func (m *Mgr) OpenService(name string) (*Service, error) {
|
|
||||||
h, err := windows.OpenService(m.Handle, syscall.StringToUTF16Ptr(name), windows.SERVICE_ALL_ACCESS)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Service{Name: name, Handle: h}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListServices enumerates services in the specified
|
|
||||||
// service control manager database m.
|
|
||||||
// If the caller does not have the SERVICE_QUERY_STATUS
|
|
||||||
// access right to a service, the service is silently
|
|
||||||
// omitted from the list of services returned.
|
|
||||||
func (m *Mgr) ListServices() ([]string, error) {
|
|
||||||
var err error
|
|
||||||
var bytesNeeded, servicesReturned uint32
|
|
||||||
var buf []byte
|
|
||||||
for {
|
|
||||||
var p *byte
|
|
||||||
if len(buf) > 0 {
|
|
||||||
p = &buf[0]
|
|
||||||
}
|
|
||||||
err = windows.EnumServicesStatusEx(m.Handle, windows.SC_ENUM_PROCESS_INFO,
|
|
||||||
windows.SERVICE_WIN32, windows.SERVICE_STATE_ALL,
|
|
||||||
p, uint32(len(buf)), &bytesNeeded, &servicesReturned, nil, nil)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != syscall.ERROR_MORE_DATA {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if bytesNeeded <= uint32(len(buf)) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buf = make([]byte, bytesNeeded)
|
|
||||||
}
|
|
||||||
if servicesReturned == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
services := (*[1 << 20]windows.ENUM_SERVICE_STATUS_PROCESS)(unsafe.Pointer(&buf[0]))[:servicesReturned]
|
|
||||||
var names []string
|
|
||||||
for _, s := range services {
|
|
||||||
name := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(s.ServiceName))[:])
|
|
||||||
names = append(names, name)
|
|
||||||
}
|
|
||||||
return names, nil
|
|
||||||
}
|
|
72
vendor/golang.org/x/sys/windows/svc/mgr/service.go
generated
vendored
72
vendor/golang.org/x/sys/windows/svc/mgr/service.go
generated
vendored
@ -1,72 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package mgr
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
"golang.org/x/sys/windows/svc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO(brainman): Use EnumDependentServices to enumerate dependent services.
|
|
||||||
|
|
||||||
// Service is used to access Windows service.
|
|
||||||
type Service struct {
|
|
||||||
Name string
|
|
||||||
Handle windows.Handle
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete marks service s for deletion from the service control manager database.
|
|
||||||
func (s *Service) Delete() error {
|
|
||||||
return windows.DeleteService(s.Handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close relinquish access to the service s.
|
|
||||||
func (s *Service) Close() error {
|
|
||||||
return windows.CloseServiceHandle(s.Handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start starts service s.
|
|
||||||
// args will be passed to svc.Handler.Execute.
|
|
||||||
func (s *Service) Start(args ...string) error {
|
|
||||||
var p **uint16
|
|
||||||
if len(args) > 0 {
|
|
||||||
vs := make([]*uint16, len(args))
|
|
||||||
for i := range vs {
|
|
||||||
vs[i] = syscall.StringToUTF16Ptr(args[i])
|
|
||||||
}
|
|
||||||
p = &vs[0]
|
|
||||||
}
|
|
||||||
return windows.StartService(s.Handle, uint32(len(args)), p)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Control sends state change request c to the servce s.
|
|
||||||
func (s *Service) Control(c svc.Cmd) (svc.Status, error) {
|
|
||||||
var t windows.SERVICE_STATUS
|
|
||||||
err := windows.ControlService(s.Handle, uint32(c), &t)
|
|
||||||
if err != nil {
|
|
||||||
return svc.Status{}, err
|
|
||||||
}
|
|
||||||
return svc.Status{
|
|
||||||
State: svc.State(t.CurrentState),
|
|
||||||
Accepts: svc.Accepted(t.ControlsAccepted),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Query returns current status of service s.
|
|
||||||
func (s *Service) Query() (svc.Status, error) {
|
|
||||||
var t windows.SERVICE_STATUS
|
|
||||||
err := windows.QueryServiceStatus(s.Handle, &t)
|
|
||||||
if err != nil {
|
|
||||||
return svc.Status{}, err
|
|
||||||
}
|
|
||||||
return svc.Status{
|
|
||||||
State: svc.State(t.CurrentState),
|
|
||||||
Accepts: svc.Accepted(t.ControlsAccepted),
|
|
||||||
}, nil
|
|
||||||
}
|
|
62
vendor/golang.org/x/sys/windows/svc/security.go
generated
vendored
62
vendor/golang.org/x/sys/windows/svc/security.go
generated
vendored
@ -1,62 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package svc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
)
|
|
||||||
|
|
||||||
func allocSid(subAuth0 uint32) (*windows.SID, error) {
|
|
||||||
var sid *windows.SID
|
|
||||||
err := windows.AllocateAndInitializeSid(&windows.SECURITY_NT_AUTHORITY,
|
|
||||||
1, subAuth0, 0, 0, 0, 0, 0, 0, 0, &sid)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return sid, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsAnInteractiveSession determines if calling process is running interactively.
|
|
||||||
// It queries the process token for membership in the Interactive group.
|
|
||||||
// http://stackoverflow.com/questions/2668851/how-do-i-detect-that-my-application-is-running-as-service-or-in-an-interactive-s
|
|
||||||
func IsAnInteractiveSession() (bool, error) {
|
|
||||||
interSid, err := allocSid(windows.SECURITY_INTERACTIVE_RID)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
defer windows.FreeSid(interSid)
|
|
||||||
|
|
||||||
serviceSid, err := allocSid(windows.SECURITY_SERVICE_RID)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
defer windows.FreeSid(serviceSid)
|
|
||||||
|
|
||||||
t, err := windows.OpenCurrentProcessToken()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
defer t.Close()
|
|
||||||
|
|
||||||
gs, err := t.GetTokenGroups()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
p := unsafe.Pointer(&gs.Groups[0])
|
|
||||||
groups := (*[2 << 20]windows.SIDAndAttributes)(p)[:gs.GroupCount]
|
|
||||||
for _, g := range groups {
|
|
||||||
if windows.EqualSid(g.Sid, interSid) {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
if windows.EqualSid(g.Sid, serviceSid) {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false, nil
|
|
||||||
}
|
|
363
vendor/golang.org/x/sys/windows/svc/service.go
generated
vendored
363
vendor/golang.org/x/sys/windows/svc/service.go
generated
vendored
@ -1,363 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
// Package svc provides everything required to build Windows service.
|
|
||||||
//
|
|
||||||
package svc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"runtime"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
|
||||||
)
|
|
||||||
|
|
||||||
// State describes service execution state (Stopped, Running and so on).
|
|
||||||
type State uint32
|
|
||||||
|
|
||||||
const (
|
|
||||||
Stopped = State(windows.SERVICE_STOPPED)
|
|
||||||
StartPending = State(windows.SERVICE_START_PENDING)
|
|
||||||
StopPending = State(windows.SERVICE_STOP_PENDING)
|
|
||||||
Running = State(windows.SERVICE_RUNNING)
|
|
||||||
ContinuePending = State(windows.SERVICE_CONTINUE_PENDING)
|
|
||||||
PausePending = State(windows.SERVICE_PAUSE_PENDING)
|
|
||||||
Paused = State(windows.SERVICE_PAUSED)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Cmd represents service state change request. It is sent to a service
|
|
||||||
// by the service manager, and should be actioned upon by the service.
|
|
||||||
type Cmd uint32
|
|
||||||
|
|
||||||
const (
|
|
||||||
Stop = Cmd(windows.SERVICE_CONTROL_STOP)
|
|
||||||
Pause = Cmd(windows.SERVICE_CONTROL_PAUSE)
|
|
||||||
Continue = Cmd(windows.SERVICE_CONTROL_CONTINUE)
|
|
||||||
Interrogate = Cmd(windows.SERVICE_CONTROL_INTERROGATE)
|
|
||||||
Shutdown = Cmd(windows.SERVICE_CONTROL_SHUTDOWN)
|
|
||||||
ParamChange = Cmd(windows.SERVICE_CONTROL_PARAMCHANGE)
|
|
||||||
NetBindAdd = Cmd(windows.SERVICE_CONTROL_NETBINDADD)
|
|
||||||
NetBindRemove = Cmd(windows.SERVICE_CONTROL_NETBINDREMOVE)
|
|
||||||
NetBindEnable = Cmd(windows.SERVICE_CONTROL_NETBINDENABLE)
|
|
||||||
NetBindDisable = Cmd(windows.SERVICE_CONTROL_NETBINDDISABLE)
|
|
||||||
DeviceEvent = Cmd(windows.SERVICE_CONTROL_DEVICEEVENT)
|
|
||||||
HardwareProfileChange = Cmd(windows.SERVICE_CONTROL_HARDWAREPROFILECHANGE)
|
|
||||||
PowerEvent = Cmd(windows.SERVICE_CONTROL_POWEREVENT)
|
|
||||||
SessionChange = Cmd(windows.SERVICE_CONTROL_SESSIONCHANGE)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Accepted is used to describe commands accepted by the service.
|
|
||||||
// Note that Interrogate is always accepted.
|
|
||||||
type Accepted uint32
|
|
||||||
|
|
||||||
const (
|
|
||||||
AcceptStop = Accepted(windows.SERVICE_ACCEPT_STOP)
|
|
||||||
AcceptShutdown = Accepted(windows.SERVICE_ACCEPT_SHUTDOWN)
|
|
||||||
AcceptPauseAndContinue = Accepted(windows.SERVICE_ACCEPT_PAUSE_CONTINUE)
|
|
||||||
AcceptParamChange = Accepted(windows.SERVICE_ACCEPT_PARAMCHANGE)
|
|
||||||
AcceptNetBindChange = Accepted(windows.SERVICE_ACCEPT_NETBINDCHANGE)
|
|
||||||
AcceptHardwareProfileChange = Accepted(windows.SERVICE_ACCEPT_HARDWAREPROFILECHANGE)
|
|
||||||
AcceptPowerEvent = Accepted(windows.SERVICE_ACCEPT_POWEREVENT)
|
|
||||||
AcceptSessionChange = Accepted(windows.SERVICE_ACCEPT_SESSIONCHANGE)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Status combines State and Accepted commands to fully describe running service.
|
|
||||||
type Status struct {
|
|
||||||
State State
|
|
||||||
Accepts Accepted
|
|
||||||
CheckPoint uint32 // used to report progress during a lengthy operation
|
|
||||||
WaitHint uint32 // estimated time required for a pending operation, in milliseconds
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChangeRequest is sent to the service Handler to request service status change.
|
|
||||||
type ChangeRequest struct {
|
|
||||||
Cmd Cmd
|
|
||||||
EventType uint32
|
|
||||||
EventData uintptr
|
|
||||||
CurrentStatus Status
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handler is the interface that must be implemented to build Windows service.
|
|
||||||
type Handler interface {
|
|
||||||
|
|
||||||
// Execute will be called by the package code at the start of
|
|
||||||
// the service, and the service will exit once Execute completes.
|
|
||||||
// Inside Execute you must read service change requests from r and
|
|
||||||
// act accordingly. You must keep service control manager up to date
|
|
||||||
// about state of your service by writing into s as required.
|
|
||||||
// args contains service name followed by argument strings passed
|
|
||||||
// to the service.
|
|
||||||
// You can provide service exit code in exitCode return parameter,
|
|
||||||
// with 0 being "no error". You can also indicate if exit code,
|
|
||||||
// if any, is service specific or not by using svcSpecificEC
|
|
||||||
// parameter.
|
|
||||||
Execute(args []string, r <-chan ChangeRequest, s chan<- Status) (svcSpecificEC bool, exitCode uint32)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
// These are used by asm code.
|
|
||||||
goWaitsH uintptr
|
|
||||||
cWaitsH uintptr
|
|
||||||
ssHandle uintptr
|
|
||||||
sName *uint16
|
|
||||||
sArgc uintptr
|
|
||||||
sArgv **uint16
|
|
||||||
ctlHandlerExProc uintptr
|
|
||||||
cSetEvent uintptr
|
|
||||||
cWaitForSingleObject uintptr
|
|
||||||
cRegisterServiceCtrlHandlerExW uintptr
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
k := syscall.MustLoadDLL("kernel32.dll")
|
|
||||||
cSetEvent = k.MustFindProc("SetEvent").Addr()
|
|
||||||
cWaitForSingleObject = k.MustFindProc("WaitForSingleObject").Addr()
|
|
||||||
a := syscall.MustLoadDLL("advapi32.dll")
|
|
||||||
cRegisterServiceCtrlHandlerExW = a.MustFindProc("RegisterServiceCtrlHandlerExW").Addr()
|
|
||||||
}
|
|
||||||
|
|
||||||
// The HandlerEx prototype also has a context pointer but since we don't use
|
|
||||||
// it at start-up time we don't have to pass it over either.
|
|
||||||
type ctlEvent struct {
|
|
||||||
cmd Cmd
|
|
||||||
eventType uint32
|
|
||||||
eventData uintptr
|
|
||||||
errno uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
// service provides access to windows service api.
|
|
||||||
type service struct {
|
|
||||||
name string
|
|
||||||
h windows.Handle
|
|
||||||
cWaits *event
|
|
||||||
goWaits *event
|
|
||||||
c chan ctlEvent
|
|
||||||
handler Handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func newService(name string, handler Handler) (*service, error) {
|
|
||||||
var s service
|
|
||||||
var err error
|
|
||||||
s.name = name
|
|
||||||
s.c = make(chan ctlEvent)
|
|
||||||
s.handler = handler
|
|
||||||
s.cWaits, err = newEvent()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
s.goWaits, err = newEvent()
|
|
||||||
if err != nil {
|
|
||||||
s.cWaits.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *service) close() error {
|
|
||||||
s.cWaits.Close()
|
|
||||||
s.goWaits.Close()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type exitCode struct {
|
|
||||||
isSvcSpecific bool
|
|
||||||
errno uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *service) updateStatus(status *Status, ec *exitCode) error {
|
|
||||||
if s.h == 0 {
|
|
||||||
return errors.New("updateStatus with no service status handle")
|
|
||||||
}
|
|
||||||
var t windows.SERVICE_STATUS
|
|
||||||
t.ServiceType = windows.SERVICE_WIN32_OWN_PROCESS
|
|
||||||
t.CurrentState = uint32(status.State)
|
|
||||||
if status.Accepts&AcceptStop != 0 {
|
|
||||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_STOP
|
|
||||||
}
|
|
||||||
if status.Accepts&AcceptShutdown != 0 {
|
|
||||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_SHUTDOWN
|
|
||||||
}
|
|
||||||
if status.Accepts&AcceptPauseAndContinue != 0 {
|
|
||||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_PAUSE_CONTINUE
|
|
||||||
}
|
|
||||||
if status.Accepts&AcceptParamChange != 0 {
|
|
||||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_PARAMCHANGE
|
|
||||||
}
|
|
||||||
if status.Accepts&AcceptNetBindChange != 0 {
|
|
||||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_NETBINDCHANGE
|
|
||||||
}
|
|
||||||
if status.Accepts&AcceptHardwareProfileChange != 0 {
|
|
||||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_HARDWAREPROFILECHANGE
|
|
||||||
}
|
|
||||||
if status.Accepts&AcceptPowerEvent != 0 {
|
|
||||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_POWEREVENT
|
|
||||||
}
|
|
||||||
if status.Accepts&AcceptSessionChange != 0 {
|
|
||||||
t.ControlsAccepted |= windows.SERVICE_ACCEPT_SESSIONCHANGE
|
|
||||||
}
|
|
||||||
if ec.errno == 0 {
|
|
||||||
t.Win32ExitCode = windows.NO_ERROR
|
|
||||||
t.ServiceSpecificExitCode = windows.NO_ERROR
|
|
||||||
} else if ec.isSvcSpecific {
|
|
||||||
t.Win32ExitCode = uint32(windows.ERROR_SERVICE_SPECIFIC_ERROR)
|
|
||||||
t.ServiceSpecificExitCode = ec.errno
|
|
||||||
} else {
|
|
||||||
t.Win32ExitCode = ec.errno
|
|
||||||
t.ServiceSpecificExitCode = windows.NO_ERROR
|
|
||||||
}
|
|
||||||
t.CheckPoint = status.CheckPoint
|
|
||||||
t.WaitHint = status.WaitHint
|
|
||||||
return windows.SetServiceStatus(s.h, &t)
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
sysErrSetServiceStatusFailed = uint32(syscall.APPLICATION_ERROR) + iota
|
|
||||||
sysErrNewThreadInCallback
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *service) run() {
|
|
||||||
s.goWaits.Wait()
|
|
||||||
s.h = windows.Handle(ssHandle)
|
|
||||||
argv := (*[100]*int16)(unsafe.Pointer(sArgv))[:sArgc]
|
|
||||||
args := make([]string, len(argv))
|
|
||||||
for i, a := range argv {
|
|
||||||
args[i] = syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(a))[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdsToHandler := make(chan ChangeRequest)
|
|
||||||
changesFromHandler := make(chan Status)
|
|
||||||
exitFromHandler := make(chan exitCode)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
ss, errno := s.handler.Execute(args, cmdsToHandler, changesFromHandler)
|
|
||||||
exitFromHandler <- exitCode{ss, errno}
|
|
||||||
}()
|
|
||||||
|
|
||||||
status := Status{State: Stopped}
|
|
||||||
ec := exitCode{isSvcSpecific: true, errno: 0}
|
|
||||||
var outch chan ChangeRequest
|
|
||||||
inch := s.c
|
|
||||||
var cmd Cmd
|
|
||||||
var evtype uint32
|
|
||||||
var evdata uintptr
|
|
||||||
loop:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case r := <-inch:
|
|
||||||
if r.errno != 0 {
|
|
||||||
ec.errno = r.errno
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
inch = nil
|
|
||||||
outch = cmdsToHandler
|
|
||||||
cmd = r.cmd
|
|
||||||
evtype = r.eventType
|
|
||||||
evdata = r.eventData
|
|
||||||
case outch <- ChangeRequest{cmd, evtype, evdata, status}:
|
|
||||||
inch = s.c
|
|
||||||
outch = nil
|
|
||||||
case c := <-changesFromHandler:
|
|
||||||
err := s.updateStatus(&c, &ec)
|
|
||||||
if err != nil {
|
|
||||||
// best suitable error number
|
|
||||||
ec.errno = sysErrSetServiceStatusFailed
|
|
||||||
if err2, ok := err.(syscall.Errno); ok {
|
|
||||||
ec.errno = uint32(err2)
|
|
||||||
}
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
status = c
|
|
||||||
case ec = <-exitFromHandler:
|
|
||||||
break loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s.updateStatus(&Status{State: Stopped}, &ec)
|
|
||||||
s.cWaits.Set()
|
|
||||||
}
|
|
||||||
|
|
||||||
func newCallback(fn interface{}) (cb uintptr, err error) {
|
|
||||||
defer func() {
|
|
||||||
r := recover()
|
|
||||||
if r == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cb = 0
|
|
||||||
switch v := r.(type) {
|
|
||||||
case string:
|
|
||||||
err = errors.New(v)
|
|
||||||
case error:
|
|
||||||
err = v
|
|
||||||
default:
|
|
||||||
err = errors.New("unexpected panic in syscall.NewCallback")
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return syscall.NewCallback(fn), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BUG(brainman): There is no mechanism to run multiple services
|
|
||||||
// inside one single executable. Perhaps, it can be overcome by
|
|
||||||
// using RegisterServiceCtrlHandlerEx Windows api.
|
|
||||||
|
|
||||||
// Run executes service name by calling appropriate handler function.
|
|
||||||
func Run(name string, handler Handler) error {
|
|
||||||
runtime.LockOSThread()
|
|
||||||
|
|
||||||
tid := windows.GetCurrentThreadId()
|
|
||||||
|
|
||||||
s, err := newService(name, handler)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlHandler := func(ctl uint32, evtype uint32, evdata uintptr, context uintptr) uintptr {
|
|
||||||
e := ctlEvent{cmd: Cmd(ctl), eventType: evtype, eventData: evdata}
|
|
||||||
// We assume that this callback function is running on
|
|
||||||
// the same thread as Run. Nowhere in MS documentation
|
|
||||||
// I could find statement to guarantee that. So putting
|
|
||||||
// check here to verify, otherwise things will go bad
|
|
||||||
// quickly, if ignored.
|
|
||||||
i := windows.GetCurrentThreadId()
|
|
||||||
if i != tid {
|
|
||||||
e.errno = sysErrNewThreadInCallback
|
|
||||||
}
|
|
||||||
s.c <- e
|
|
||||||
// Always return NO_ERROR (0) for now.
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
var svcmain uintptr
|
|
||||||
getServiceMain(&svcmain)
|
|
||||||
t := []windows.SERVICE_TABLE_ENTRY{
|
|
||||||
{ServiceName: syscall.StringToUTF16Ptr(s.name), ServiceProc: svcmain},
|
|
||||||
{ServiceName: nil, ServiceProc: 0},
|
|
||||||
}
|
|
||||||
|
|
||||||
goWaitsH = uintptr(s.goWaits.h)
|
|
||||||
cWaitsH = uintptr(s.cWaits.h)
|
|
||||||
sName = t[0].ServiceName
|
|
||||||
ctlHandlerExProc, err = newCallback(ctlHandler)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
go s.run()
|
|
||||||
|
|
||||||
err = windows.StartServiceCtrlDispatcher(&t[0])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// StatusHandle returns service status handle. It is safe to call this function
|
|
||||||
// from inside the Handler.Execute because then it is guaranteed to be set.
|
|
||||||
// This code will have to change once multiple services are possible per process.
|
|
||||||
func StatusHandle() windows.Handle {
|
|
||||||
return windows.Handle(ssHandle)
|
|
||||||
}
|
|
68
vendor/golang.org/x/sys/windows/svc/sys_386.s
generated
vendored
68
vendor/golang.org/x/sys/windows/svc/sys_386.s
generated
vendored
@ -1,68 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
// func servicemain(argc uint32, argv **uint16)
|
|
||||||
TEXT ·servicemain(SB),7,$0
|
|
||||||
MOVL argc+0(FP), AX
|
|
||||||
MOVL AX, ·sArgc(SB)
|
|
||||||
MOVL argv+4(FP), AX
|
|
||||||
MOVL AX, ·sArgv(SB)
|
|
||||||
|
|
||||||
PUSHL BP
|
|
||||||
PUSHL BX
|
|
||||||
PUSHL SI
|
|
||||||
PUSHL DI
|
|
||||||
|
|
||||||
SUBL $12, SP
|
|
||||||
|
|
||||||
MOVL ·sName(SB), AX
|
|
||||||
MOVL AX, (SP)
|
|
||||||
MOVL $·servicectlhandler(SB), AX
|
|
||||||
MOVL AX, 4(SP)
|
|
||||||
MOVL $0, 8(SP)
|
|
||||||
MOVL ·cRegisterServiceCtrlHandlerExW(SB), AX
|
|
||||||
MOVL SP, BP
|
|
||||||
CALL AX
|
|
||||||
MOVL BP, SP
|
|
||||||
CMPL AX, $0
|
|
||||||
JE exit
|
|
||||||
MOVL AX, ·ssHandle(SB)
|
|
||||||
|
|
||||||
MOVL ·goWaitsH(SB), AX
|
|
||||||
MOVL AX, (SP)
|
|
||||||
MOVL ·cSetEvent(SB), AX
|
|
||||||
MOVL SP, BP
|
|
||||||
CALL AX
|
|
||||||
MOVL BP, SP
|
|
||||||
|
|
||||||
MOVL ·cWaitsH(SB), AX
|
|
||||||
MOVL AX, (SP)
|
|
||||||
MOVL $-1, AX
|
|
||||||
MOVL AX, 4(SP)
|
|
||||||
MOVL ·cWaitForSingleObject(SB), AX
|
|
||||||
MOVL SP, BP
|
|
||||||
CALL AX
|
|
||||||
MOVL BP, SP
|
|
||||||
|
|
||||||
exit:
|
|
||||||
ADDL $12, SP
|
|
||||||
|
|
||||||
POPL DI
|
|
||||||
POPL SI
|
|
||||||
POPL BX
|
|
||||||
POPL BP
|
|
||||||
|
|
||||||
MOVL 0(SP), CX
|
|
||||||
ADDL $12, SP
|
|
||||||
JMP CX
|
|
||||||
|
|
||||||
// I do not know why, but this seems to be the only way to call
|
|
||||||
// ctlHandlerProc on Windows 7.
|
|
||||||
|
|
||||||
// func servicectlhandler(ctl uint32, evtype uint32, evdata uintptr, context uintptr) uintptr {
|
|
||||||
TEXT ·servicectlhandler(SB),7,$0
|
|
||||||
MOVL ·ctlHandlerExProc(SB), CX
|
|
||||||
JMP CX
|
|
42
vendor/golang.org/x/sys/windows/svc/sys_amd64.s
generated
vendored
42
vendor/golang.org/x/sys/windows/svc/sys_amd64.s
generated
vendored
@ -1,42 +0,0 @@
|
|||||||
// Copyright 2012 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
// func servicemain(argc uint32, argv **uint16)
|
|
||||||
TEXT ·servicemain(SB),7,$0
|
|
||||||
MOVL CX, ·sArgc(SB)
|
|
||||||
MOVQ DX, ·sArgv(SB)
|
|
||||||
|
|
||||||
SUBQ $32, SP // stack for the first 4 syscall params
|
|
||||||
|
|
||||||
MOVQ ·sName(SB), CX
|
|
||||||
MOVQ $·servicectlhandler(SB), DX
|
|
||||||
// BUG(pastarmovj): Figure out a way to pass in context in R8.
|
|
||||||
MOVQ ·cRegisterServiceCtrlHandlerExW(SB), AX
|
|
||||||
CALL AX
|
|
||||||
CMPQ AX, $0
|
|
||||||
JE exit
|
|
||||||
MOVQ AX, ·ssHandle(SB)
|
|
||||||
|
|
||||||
MOVQ ·goWaitsH(SB), CX
|
|
||||||
MOVQ ·cSetEvent(SB), AX
|
|
||||||
CALL AX
|
|
||||||
|
|
||||||
MOVQ ·cWaitsH(SB), CX
|
|
||||||
MOVQ $4294967295, DX
|
|
||||||
MOVQ ·cWaitForSingleObject(SB), AX
|
|
||||||
CALL AX
|
|
||||||
|
|
||||||
exit:
|
|
||||||
ADDQ $32, SP
|
|
||||||
RET
|
|
||||||
|
|
||||||
// I do not know why, but this seems to be the only way to call
|
|
||||||
// ctlHandlerProc on Windows 7.
|
|
||||||
|
|
||||||
// func ·servicectlhandler(ctl uint32, evtype uint32, evdata uintptr, context uintptr) uintptr {
|
|
||||||
TEXT ·servicectlhandler(SB),7,$0
|
|
||||||
MOVQ ·ctlHandlerExProc(SB), AX
|
|
||||||
JMP AX
|
|
Reference in New Issue
Block a user