mirror of
https://github.com/rancher/os.git
synced 2025-09-03 07:44:21 +00:00
cloudinit tests pass :)
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
202
vendor/github.com/vmware/vmw-guestinfo/LICENSE
generated
vendored
Normal file
202
vendor/github.com/vmware/vmw-guestinfo/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2017 VMware, Inc. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
3
vendor/github.com/vmware/vmw-guestinfo/README
generated
vendored
Normal file
3
vendor/github.com/vmware/vmw-guestinfo/README
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
This package provides access to the guestinfo variables exposed to a VMware virtual machine.
|
||||
|
||||
see examples/main.go for an example
|
134
vendor/github.com/vmware/vmw-guestinfo/bdoor/bdoor.go
generated
vendored
Normal file
134
vendor/github.com/vmware/vmw-guestinfo/bdoor/bdoor.go
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bdoor
|
||||
|
||||
const (
|
||||
BackdoorMagic = uint64(0x564D5868)
|
||||
BackdoorPort = uint16(0x5658)
|
||||
BackdoorHighBWPort = uint16(0x5659)
|
||||
|
||||
CommandGetVersion = uint32(10)
|
||||
|
||||
CommandMessage = uint16(0x1e)
|
||||
CommandHighBWMessage = uint16(0)
|
||||
CommandFlagCookie = uint32(0x80000000)
|
||||
)
|
||||
|
||||
type BackdoorProto struct {
|
||||
// typedef union {
|
||||
// struct {
|
||||
// DECLARE_REG_NAMED_STRUCT(ax);
|
||||
// size_t size; /* Register bx. */
|
||||
// DECLARE_REG_NAMED_STRUCT(cx);
|
||||
// DECLARE_REG_NAMED_STRUCT(dx);
|
||||
// DECLARE_REG_NAMED_STRUCT(si);
|
||||
// DECLARE_REG_NAMED_STRUCT(di);
|
||||
// } in;
|
||||
// struct {
|
||||
// DECLARE_REG_NAMED_STRUCT(ax);
|
||||
// DECLARE_REG_NAMED_STRUCT(bx);
|
||||
// DECLARE_REG_NAMED_STRUCT(cx);
|
||||
// DECLARE_REG_NAMED_STRUCT(dx);
|
||||
// DECLARE_REG_NAMED_STRUCT(si);
|
||||
// DECLARE_REG_NAMED_STRUCT(di);
|
||||
// } out;
|
||||
// } proto;
|
||||
|
||||
AX, BX, CX, DX, SI, DI, BP UInt64
|
||||
size uint32
|
||||
}
|
||||
|
||||
func bdoor_inout(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
|
||||
func bdoor_hbout(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
|
||||
func bdoor_hbin(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
|
||||
func bdoor_inout_test(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
|
||||
|
||||
func (p *BackdoorProto) InOut() *BackdoorProto {
|
||||
p.DX.Low.Low = BackdoorPort
|
||||
p.AX.SetQuad(BackdoorMagic)
|
||||
|
||||
retax, retbx, retcx, retdx, retsi, retdi, retbp := bdoor_inout(
|
||||
p.AX.Quad(),
|
||||
p.BX.Quad(),
|
||||
p.CX.Quad(),
|
||||
p.DX.Quad(),
|
||||
p.SI.Quad(),
|
||||
p.DI.Quad(),
|
||||
p.BP.Quad(),
|
||||
)
|
||||
|
||||
ret := &BackdoorProto{}
|
||||
ret.AX.SetQuad(retax)
|
||||
ret.BX.SetQuad(retbx)
|
||||
ret.CX.SetQuad(retcx)
|
||||
ret.DX.SetQuad(retdx)
|
||||
ret.SI.SetQuad(retsi)
|
||||
ret.DI.SetQuad(retdi)
|
||||
ret.BP.SetQuad(retbp)
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *BackdoorProto) HighBandwidthOut() *BackdoorProto {
|
||||
p.DX.Low.Low = BackdoorHighBWPort
|
||||
p.AX.SetQuad(BackdoorMagic)
|
||||
|
||||
retax, retbx, retcx, retdx, retsi, retdi, retbp := bdoor_hbout(
|
||||
p.AX.Quad(),
|
||||
p.BX.Quad(),
|
||||
p.CX.Quad(),
|
||||
p.DX.Quad(),
|
||||
p.SI.Quad(),
|
||||
p.DI.Quad(),
|
||||
p.BP.Quad(),
|
||||
)
|
||||
|
||||
ret := &BackdoorProto{}
|
||||
ret.AX.SetQuad(retax)
|
||||
ret.BX.SetQuad(retbx)
|
||||
ret.CX.SetQuad(retcx)
|
||||
ret.DX.SetQuad(retdx)
|
||||
ret.SI.SetQuad(retsi)
|
||||
ret.DI.SetQuad(retdi)
|
||||
ret.BP.SetQuad(retbp)
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *BackdoorProto) HighBandwidthIn() *BackdoorProto {
|
||||
p.DX.Low.Low = BackdoorHighBWPort
|
||||
p.AX.SetQuad(BackdoorMagic)
|
||||
|
||||
retax, retbx, retcx, retdx, retsi, retdi, retbp := bdoor_hbin(
|
||||
p.AX.Quad(),
|
||||
p.BX.Quad(),
|
||||
p.CX.Quad(),
|
||||
p.DX.Quad(),
|
||||
p.SI.Quad(),
|
||||
p.DI.Quad(),
|
||||
p.BP.Quad(),
|
||||
)
|
||||
|
||||
ret := &BackdoorProto{}
|
||||
ret.AX.SetQuad(retax)
|
||||
ret.BX.SetQuad(retbx)
|
||||
ret.CX.SetQuad(retcx)
|
||||
ret.DX.SetQuad(retdx)
|
||||
ret.SI.SetQuad(retsi)
|
||||
ret.DI.SetQuad(retdi)
|
||||
ret.BP.SetQuad(retbp)
|
||||
|
||||
return ret
|
||||
}
|
112
vendor/github.com/vmware/vmw-guestinfo/bdoor/bdoor_amd64.s
generated
vendored
Normal file
112
vendor/github.com/vmware/vmw-guestinfo/bdoor/bdoor_amd64.s
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
#include "textflag.h"
|
||||
|
||||
// Doc of the golang plan9 assembler
|
||||
// http://p9.nyx.link/labs/sys/doc/asm.html
|
||||
//
|
||||
// A good primer of how to write golang with some plan9 flavored assembly
|
||||
// http://www.doxsey.net/blog/go-and-assembly
|
||||
//
|
||||
// Some x86 references
|
||||
// http://www.eecg.toronto.edu/~amza/www.mindsec.com/files/x86regs.html
|
||||
// https://cseweb.ucsd.edu/classes/sp10/cse141/pdf/02/S01_x86_64.key.pdf
|
||||
// https://en.wikibooks.org/wiki/X86_Assembly/Other_Instructions
|
||||
//
|
||||
// (This one is invaluable. Has a working example of how a standard function
|
||||
// call looks on the stack with the associated assembly.)
|
||||
// https://www.recurse.com/blog/7-understanding-c-by-learning-assembly
|
||||
//
|
||||
// Reference with raw form of the Opcode
|
||||
// http://x86.renejeschke.de/html/file_module_x86_id_139.html
|
||||
//
|
||||
// Massive x86_64 reference
|
||||
// http://ref.x86asm.net/coder64.html#xED
|
||||
//
|
||||
// Adding instructions to the go assembler
|
||||
// https://blog.klauspost.com/adding-unsupported-instructions-in-golang-assembler/
|
||||
//
|
||||
// Backdoor commands
|
||||
// https://sites.google.com/site/chitchatvmback/backdoor
|
||||
|
||||
// func bdoor_inout(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
|
||||
TEXT ·bdoor_inout(SB), NOSPLIT|WRAPPER, $0
|
||||
MOVQ ax+0(FP), AX
|
||||
MOVQ bx+8(FP), BX
|
||||
MOVQ cx+16(FP), CX
|
||||
MOVQ dx+24(FP), DX
|
||||
MOVQ si+32(FP), SI
|
||||
MOVQ di+40(FP), DI
|
||||
MOVQ bp+48(FP), BP
|
||||
|
||||
// IN to DX from EAX
|
||||
INL
|
||||
|
||||
MOVQ AX, retax+56(FP)
|
||||
MOVQ BX, retbx+64(FP)
|
||||
MOVQ CX, retcx+72(FP)
|
||||
MOVQ DX, retdx+80(FP)
|
||||
MOVQ SI, retsi+88(FP)
|
||||
MOVQ DI, retdi+96(FP)
|
||||
MOVQ BP, retbp+104(FP)
|
||||
RET
|
||||
|
||||
// func bdoor_hbout(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
|
||||
TEXT ·bdoor_hbout(SB), NOSPLIT|WRAPPER, $0
|
||||
MOVQ ax+0(FP), AX
|
||||
MOVQ bx+8(FP), BX
|
||||
MOVQ cx+16(FP), CX
|
||||
MOVQ dx+24(FP), DX
|
||||
MOVQ si+32(FP), SI
|
||||
MOVQ di+40(FP), DI
|
||||
MOVQ bp+48(FP), BP
|
||||
|
||||
CLD; REP; OUTSB
|
||||
|
||||
MOVQ AX, retax+56(FP)
|
||||
MOVQ BX, retbx+64(FP)
|
||||
MOVQ CX, retcx+72(FP)
|
||||
MOVQ DX, retdx+80(FP)
|
||||
MOVQ SI, retsi+88(FP)
|
||||
MOVQ DI, retdi+96(FP)
|
||||
MOVQ BP, retbp+104(FP)
|
||||
RET
|
||||
|
||||
// func bdoor_hbin(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
|
||||
TEXT ·bdoor_hbin(SB), NOSPLIT|WRAPPER, $0
|
||||
MOVQ ax+0(FP), AX
|
||||
MOVQ bx+8(FP), BX
|
||||
MOVQ cx+16(FP), CX
|
||||
MOVQ dx+24(FP), DX
|
||||
MOVQ si+32(FP), SI
|
||||
MOVQ di+40(FP), DI
|
||||
MOVQ bp+48(FP), BP
|
||||
|
||||
CLD; REP; INSB
|
||||
|
||||
MOVQ AX, retax+56(FP)
|
||||
MOVQ BX, retbx+64(FP)
|
||||
MOVQ CX, retcx+72(FP)
|
||||
MOVQ DX, retdx+80(FP)
|
||||
MOVQ SI, retsi+88(FP)
|
||||
MOVQ DI, retdi+96(FP)
|
||||
MOVQ BP, retbp+104(FP)
|
||||
RET
|
||||
|
||||
// func bdoor_inout_test(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
|
||||
TEXT ·bdoor_inout_test(SB), NOSPLIT|WRAPPER, $0
|
||||
MOVQ ax+0(FP), AX
|
||||
MOVQ bx+8(FP), BX
|
||||
MOVQ cx+16(FP), CX
|
||||
MOVQ dx+24(FP), DX
|
||||
MOVQ si+32(FP), SI
|
||||
MOVQ di+40(FP), DI
|
||||
MOVQ bp+48(FP), BP
|
||||
|
||||
MOVQ AX, retax+56(FP)
|
||||
MOVQ BX, retbx+64(FP)
|
||||
MOVQ CX, retcx+72(FP)
|
||||
MOVQ DX, retdx+80(FP)
|
||||
MOVQ SI, retsi+88(FP)
|
||||
MOVQ DI, retdi+96(FP)
|
||||
MOVQ BP, retbp+104(FP)
|
||||
RET
|
||||
|
43
vendor/github.com/vmware/vmw-guestinfo/bdoor/word.go
generated
vendored
Normal file
43
vendor/github.com/vmware/vmw-guestinfo/bdoor/word.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bdoor
|
||||
|
||||
type UInt32 struct {
|
||||
High uint16
|
||||
Low uint16
|
||||
}
|
||||
|
||||
func (u *UInt32) Word() uint32 {
|
||||
return uint32(u.High)<<16 + uint32(u.Low)
|
||||
}
|
||||
|
||||
func (u *UInt32) SetWord(w uint32) {
|
||||
u.High = uint16(w >> 16)
|
||||
u.Low = uint16(w)
|
||||
}
|
||||
|
||||
type UInt64 struct {
|
||||
High UInt32
|
||||
Low UInt32
|
||||
}
|
||||
|
||||
func (u *UInt64) Quad() uint64 {
|
||||
return uint64(u.High.Word())<<32 + uint64(u.Low.Word())
|
||||
}
|
||||
|
||||
func (u *UInt64) SetQuad(w uint64) {
|
||||
u.High.SetWord(uint32(w >> 32))
|
||||
u.Low.SetWord(uint32(w))
|
||||
}
|
61
vendor/github.com/vmware/vmw-guestinfo/message/log.go
generated
vendored
Normal file
61
vendor/github.com/vmware/vmw-guestinfo/message/log.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package message
|
||||
|
||||
import "log"
|
||||
|
||||
var DefaultLogger Logger
|
||||
|
||||
type Logger interface {
|
||||
Errorf(format string, args ...interface{})
|
||||
Debugf(format string, args ...interface{})
|
||||
Infof(format string, args ...interface{})
|
||||
}
|
||||
|
||||
func init() {
|
||||
DefaultLogger = &logger{}
|
||||
}
|
||||
|
||||
type logger struct {
|
||||
DebugLevel bool
|
||||
}
|
||||
|
||||
func (l *logger) Errorf(format string, args ...interface{}) {
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
|
||||
func (l *logger) Debugf(format string, args ...interface{}) {
|
||||
if !l.DebugLevel {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
|
||||
func (l *logger) Infof(format string, args ...interface{}) {
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
|
||||
func Errorf(format string, args ...interface{}) {
|
||||
DefaultLogger.Errorf(format, args...)
|
||||
}
|
||||
|
||||
func Debugf(format string, args ...interface{}) {
|
||||
DefaultLogger.Debugf(format, args...)
|
||||
}
|
||||
|
||||
func Infof(format string, args ...interface{}) {
|
||||
DefaultLogger.Infof(format, args...)
|
||||
}
|
334
vendor/github.com/vmware/vmw-guestinfo/message/message.go
generated
vendored
Normal file
334
vendor/github.com/vmware/vmw-guestinfo/message/message.go
generated
vendored
Normal file
@@ -0,0 +1,334 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package message
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"unsafe"
|
||||
|
||||
"github.com/vmware/vmw-guestinfo/bdoor"
|
||||
)
|
||||
|
||||
const (
|
||||
messageTypeOpen = iota
|
||||
messageTypeSendSize
|
||||
messageTypeSendPayload
|
||||
messageTypeReceiveSize
|
||||
messageTypeReceivePayload
|
||||
messageTypeReceiveStatus
|
||||
messageTypeClose
|
||||
|
||||
messageStatusFail = uint16(0x0000)
|
||||
messageStatusSuccess = uint16(0x0001)
|
||||
messageStatusDoRecieve = uint16(0x0002)
|
||||
messageStatusCheckPoint = uint16(0x0010)
|
||||
messageStatusHighBW = uint16(0x0080)
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrChannelOpen represents a failure to open a channel
|
||||
ErrChannelOpen = errors.New("could not open channel")
|
||||
// ErrChannelClose represents a failure to close a channel
|
||||
ErrChannelClose = errors.New("could not close channel")
|
||||
// ErrRpciSend represents a failure to send a message
|
||||
ErrRpciSend = errors.New("unable to send RPCI command")
|
||||
// ErrRpciReceive represents a failure to receive a message
|
||||
ErrRpciReceive = errors.New("unable to receive RPCI command result")
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
id uint16
|
||||
|
||||
forceLowBW bool
|
||||
buf []byte
|
||||
|
||||
cookie bdoor.UInt64
|
||||
}
|
||||
|
||||
// NewChannel opens a new Channel
|
||||
func NewChannel(proto uint32) (*Channel, error) {
|
||||
flags := bdoor.CommandFlagCookie
|
||||
|
||||
retry:
|
||||
bp := &bdoor.BackdoorProto{}
|
||||
|
||||
bp.BX.Low.SetWord(proto | flags)
|
||||
bp.CX.Low.High = messageTypeOpen
|
||||
bp.CX.Low.Low = bdoor.CommandMessage
|
||||
|
||||
out := bp.InOut()
|
||||
if (out.CX.Low.High & messageStatusSuccess) == 0 {
|
||||
if flags != 0 {
|
||||
flags = 0
|
||||
goto retry
|
||||
}
|
||||
|
||||
Errorf("Message: Unable to open communication channel")
|
||||
return nil, ErrChannelOpen
|
||||
}
|
||||
|
||||
ch := &Channel{}
|
||||
ch.id = out.DX.Low.High
|
||||
ch.cookie.High.SetWord(out.SI.Low.Word())
|
||||
ch.cookie.Low.SetWord(out.DI.Low.Word())
|
||||
|
||||
Debugf("Opened channel %d", ch.id)
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (c *Channel) Close() error {
|
||||
bp := &bdoor.BackdoorProto{}
|
||||
|
||||
bp.CX.Low.High = messageTypeClose
|
||||
bp.CX.Low.Low = bdoor.CommandMessage
|
||||
|
||||
bp.DX.Low.High = c.id
|
||||
bp.SI.Low.SetWord(c.cookie.High.Word())
|
||||
bp.DI.Low.SetWord(c.cookie.Low.Word())
|
||||
|
||||
out := bp.InOut()
|
||||
if (out.CX.Low.High & messageStatusSuccess) == 0 {
|
||||
Errorf("Message: Unable to close communication channel %d", c.id)
|
||||
return ErrChannelClose
|
||||
}
|
||||
|
||||
Debugf("Closed channel %d", c.id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Channel) Send(buf []byte) error {
|
||||
retry:
|
||||
bp := &bdoor.BackdoorProto{}
|
||||
bp.CX.Low.High = messageTypeSendSize
|
||||
bp.CX.Low.Low = bdoor.CommandMessage
|
||||
|
||||
bp.DX.Low.High = c.id
|
||||
bp.SI.Low.SetWord(c.cookie.High.Word())
|
||||
bp.DI.Low.SetWord(c.cookie.Low.Word())
|
||||
|
||||
bp.BX.Low.SetWord(uint32(len(buf)))
|
||||
|
||||
// send the size
|
||||
out := bp.InOut()
|
||||
if (out.CX.Low.High & messageStatusSuccess) == 0 {
|
||||
Errorf("Message: Unable to send a message over the communication channel %d", c.id)
|
||||
return ErrRpciSend
|
||||
}
|
||||
|
||||
// size of buf 0 is fine, just return
|
||||
if len(buf) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !c.forceLowBW && (out.CX.Low.High&messageStatusHighBW) == messageStatusHighBW {
|
||||
hbbp := &bdoor.BackdoorProto{}
|
||||
|
||||
hbbp.BX.Low.Low = bdoor.CommandHighBWMessage
|
||||
hbbp.BX.Low.High = messageStatusSuccess
|
||||
hbbp.DX.Low.High = c.id
|
||||
hbbp.BP.Low.SetWord(c.cookie.High.Word())
|
||||
hbbp.DI.Low.SetWord(c.cookie.Low.Word())
|
||||
hbbp.CX.Low.SetWord(uint32(len(buf)))
|
||||
hbbp.SI.SetQuad(uint64(uintptr(unsafe.Pointer(&buf[0]))))
|
||||
|
||||
out := hbbp.HighBandwidthOut()
|
||||
if (out.BX.Low.High & messageStatusSuccess) == 0 {
|
||||
if (out.BX.Low.High & messageStatusCheckPoint) != 0 {
|
||||
Debugf("A checkpoint occurred. Retrying the operation")
|
||||
goto retry
|
||||
}
|
||||
|
||||
Errorf("Message: Unable to send a message over the communication channel %d", c.id)
|
||||
return ErrRpciSend
|
||||
}
|
||||
} else {
|
||||
bp.CX.Low.High = messageTypeSendPayload
|
||||
|
||||
bbuf := bytes.NewBuffer(buf)
|
||||
for {
|
||||
// read 4 bytes at a time
|
||||
words := bbuf.Next(4)
|
||||
if len(words) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
Debugf("sending %q over %d", string(words), c.id)
|
||||
switch len(words) {
|
||||
case 3:
|
||||
bp.BX.Low.SetWord(binary.LittleEndian.Uint32([]byte{0x0, words[2], words[1], words[0]}))
|
||||
case 2:
|
||||
bp.BX.Low.SetWord(uint32(binary.LittleEndian.Uint16(words)))
|
||||
case 1:
|
||||
bp.BX.Low.SetWord(uint32(words[0]))
|
||||
default:
|
||||
bp.BX.Low.SetWord(binary.LittleEndian.Uint32(words))
|
||||
}
|
||||
|
||||
out = bp.InOut()
|
||||
if (out.CX.Low.High & messageStatusSuccess) == 0 {
|
||||
Errorf("Message: Unable to send a message over the communication channel %d", c.id)
|
||||
return ErrRpciSend
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Channel) Receive() ([]byte, error) {
|
||||
retry:
|
||||
var err error
|
||||
bp := &bdoor.BackdoorProto{}
|
||||
bp.CX.Low.High = messageTypeReceiveSize
|
||||
bp.CX.Low.Low = bdoor.CommandMessage
|
||||
|
||||
bp.DX.Low.High = c.id
|
||||
bp.SI.Low.SetWord(c.cookie.High.Word())
|
||||
bp.DI.Low.SetWord(c.cookie.Low.Word())
|
||||
|
||||
out := bp.InOut()
|
||||
if (out.CX.Low.High & messageStatusSuccess) == 0 {
|
||||
Errorf("Message: Unable to poll for messages over the communication channel %d", c.id)
|
||||
return nil, ErrRpciReceive
|
||||
}
|
||||
|
||||
if (out.CX.Low.High & messageStatusDoRecieve) == 0 {
|
||||
Debugf("No message to retrieve")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Receive the size.
|
||||
if out.DX.Low.High != messageTypeSendSize {
|
||||
Errorf("Message: Protocol error. Expected a MESSAGE_TYPE_SENDSIZE request from vmware")
|
||||
return nil, ErrRpciReceive
|
||||
}
|
||||
|
||||
size := out.BX.Quad()
|
||||
|
||||
var buf []byte
|
||||
|
||||
if size != 0 {
|
||||
if !c.forceLowBW && (out.CX.Low.High&messageStatusHighBW == messageStatusHighBW) {
|
||||
buf = make([]byte, size)
|
||||
|
||||
hbbp := &bdoor.BackdoorProto{}
|
||||
|
||||
hbbp.BX.Low.Low = bdoor.CommandHighBWMessage
|
||||
hbbp.BX.Low.High = messageStatusSuccess
|
||||
hbbp.DX.Low.High = c.id
|
||||
hbbp.SI.Low.SetWord(c.cookie.High.Word())
|
||||
hbbp.BP.Low.SetWord(c.cookie.Low.Word())
|
||||
hbbp.CX.Low.SetWord(uint32(len(buf)))
|
||||
hbbp.DI.SetQuad(uint64(uintptr(unsafe.Pointer(&buf[0]))))
|
||||
|
||||
out := hbbp.HighBandwidthIn()
|
||||
if (out.BX.Low.High & messageStatusSuccess) == 0 {
|
||||
Errorf("Message: Unable to send a message over the communication channel %d", c.id)
|
||||
c.reply(messageTypeReceivePayload, messageStatusFail)
|
||||
return nil, ErrRpciReceive
|
||||
}
|
||||
} else {
|
||||
b := bytes.NewBuffer(make([]byte, 0, size))
|
||||
|
||||
for {
|
||||
if size == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
bp.CX.Low.High = messageTypeReceivePayload
|
||||
bp.BX.Low.Low = messageStatusSuccess
|
||||
|
||||
out = bp.InOut()
|
||||
if (out.CX.Low.High & messageStatusSuccess) == 0 {
|
||||
if (out.CX.Low.High & messageStatusCheckPoint) != 0 {
|
||||
Debugf("A checkpoint occurred. Retrying the operation")
|
||||
goto retry
|
||||
}
|
||||
|
||||
Errorf("Message: Unable to receive a message over the communication channel %d", c.id)
|
||||
c.reply(messageTypeReceivePayload, messageStatusFail)
|
||||
return nil, ErrRpciReceive
|
||||
}
|
||||
|
||||
if out.DX.Low.High != messageTypeSendPayload {
|
||||
Errorf("Message: Protocol error. Expected a MESSAGE_TYPE_SENDPAYLOAD from vmware")
|
||||
c.reply(messageTypeReceivePayload, messageStatusFail)
|
||||
return nil, ErrRpciReceive
|
||||
}
|
||||
|
||||
Debugf("Received %#v", out.BX.Low.Word())
|
||||
|
||||
switch size {
|
||||
case 1:
|
||||
err = binary.Write(b, binary.LittleEndian, uint8(out.BX.Low.Low))
|
||||
size = size - 1
|
||||
|
||||
case 2:
|
||||
err = binary.Write(b, binary.LittleEndian, uint16(out.BX.Low.Low))
|
||||
size = size - 2
|
||||
|
||||
case 3:
|
||||
err = binary.Write(b, binary.LittleEndian, uint16(out.BX.Low.Low))
|
||||
if err != nil {
|
||||
c.reply(messageTypeReceivePayload, messageStatusFail)
|
||||
return nil, ErrRpciReceive
|
||||
}
|
||||
err = binary.Write(b, binary.LittleEndian, uint8(out.BX.Low.High))
|
||||
size = size - 3
|
||||
|
||||
default:
|
||||
err = binary.Write(b, binary.LittleEndian, out.BX.Low.Word())
|
||||
size = size - 4
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
Errorf(err.Error())
|
||||
c.reply(messageTypeReceivePayload, messageStatusFail)
|
||||
return nil, ErrRpciReceive
|
||||
}
|
||||
}
|
||||
|
||||
buf = b.Bytes()
|
||||
}
|
||||
}
|
||||
|
||||
c.reply(messageTypeReceiveStatus, messageStatusSuccess)
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (c *Channel) reply(messageType, messageStatus uint16) {
|
||||
bp := &bdoor.BackdoorProto{}
|
||||
|
||||
bp.BX.Low.Low = messageStatus
|
||||
bp.CX.Low.High = messageType
|
||||
bp.CX.Low.Low = bdoor.CommandMessage
|
||||
bp.DX.Low.High = c.id
|
||||
bp.SI.Low.SetWord(c.cookie.High.Word())
|
||||
bp.DI.Low.SetWord(c.cookie.Low.Word())
|
||||
|
||||
out := bp.InOut()
|
||||
|
||||
/* OUT: Status */
|
||||
if (out.CX.Low.High & messageStatusSuccess) == 0 {
|
||||
if messageStatus == messageStatusSuccess {
|
||||
Errorf("reply Message: Unable to send a message over the communication channel %d", c.id)
|
||||
} else {
|
||||
Errorf("reply Message: Unable to signal an error of reception over the communication channel %d", c.id)
|
||||
}
|
||||
}
|
||||
}
|
93
vendor/github.com/vmware/vmw-guestinfo/rpcout/rpcout.go
generated
vendored
Normal file
93
vendor/github.com/vmware/vmw-guestinfo/rpcout/rpcout.go
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright 2016 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package rpcout
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/vmw-guestinfo/message"
|
||||
)
|
||||
|
||||
// ErrRpciFormat represents an invalid result format
|
||||
var ErrRpciFormat = errors.New("invalid format for RPCI command result")
|
||||
|
||||
const rpciProtocolNum uint32 = 0x49435052
|
||||
|
||||
// SendOne is a command-oriented wrapper for SendOneRaw
|
||||
func SendOne(format string, a ...interface{}) (reply []byte, ok bool, err error) {
|
||||
request := fmt.Sprintf(format, a...)
|
||||
return SendOneRaw([]byte(request))
|
||||
}
|
||||
|
||||
// SendOneRaw uses a throw-away RPCOut to send a request
|
||||
func SendOneRaw(request []byte) (reply []byte, ok bool, err error) {
|
||||
out := &RPCOut{}
|
||||
if err = out.Start(); err != nil {
|
||||
return
|
||||
}
|
||||
if reply, ok, err = out.Send(request); err != nil {
|
||||
return
|
||||
}
|
||||
if err = out.Stop(); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// RPCOut is an ougoing connection from the VM to the hypervisor
|
||||
type RPCOut struct {
|
||||
channel *message.Channel
|
||||
}
|
||||
|
||||
// Start opens the connection
|
||||
func (out *RPCOut) Start() error {
|
||||
channel, err := message.NewChannel(rpciProtocolNum)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out.channel = channel
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop closes the connection
|
||||
func (out *RPCOut) Stop() error {
|
||||
err := out.channel.Close()
|
||||
out.channel = nil
|
||||
return err
|
||||
}
|
||||
|
||||
// Send emits a request and receives a response
|
||||
func (out *RPCOut) Send(request []byte) (reply []byte, ok bool, err error) {
|
||||
if err = out.channel.Send(request); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var resp []byte
|
||||
if resp, err = out.channel.Receive(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch string(resp[:2]) {
|
||||
case "0 ":
|
||||
reply = resp[2:]
|
||||
case "1 ":
|
||||
reply = resp[2:]
|
||||
ok = true
|
||||
default:
|
||||
err = ErrRpciFormat
|
||||
}
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user