1
0
mirror of https://github.com/rancher/os.git synced 2025-09-05 16:52:20 +00:00

Add defered syslog hook

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit
2017-07-12 14:18:02 +10:00
parent 43c620c4d8
commit bb20e96a98
27 changed files with 777 additions and 254 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2016 VMware, Inc. All Rights Reserved.
// Copyright 2016-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.
@@ -15,7 +15,6 @@
package bdoor
const (
BackdoorMagic = uint64(0x564D5868)
BackdoorPort = uint16(0x5658)
BackdoorHighBWPort = uint16(0x5659)
@@ -26,109 +25,80 @@ const (
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)
p.DX.AsUInt32().Low = BackdoorPort
p.AX.SetValue(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(),
p.AX.Value(),
p.BX.Value(),
p.CX.Value(),
p.DX.Value(),
p.SI.Value(),
p.DI.Value(),
p.BP.Value(),
)
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)
ret.AX.SetValue(retax)
ret.BX.SetValue(retbx)
ret.CX.SetValue(retcx)
ret.DX.SetValue(retdx)
ret.SI.SetValue(retsi)
ret.DI.SetValue(retdi)
ret.BP.SetValue(retbp)
return ret
}
func (p *BackdoorProto) HighBandwidthOut() *BackdoorProto {
p.DX.Low.Low = BackdoorHighBWPort
p.AX.SetQuad(BackdoorMagic)
p.DX.AsUInt32().Low = BackdoorHighBWPort
p.AX.SetValue(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(),
p.AX.Value(),
p.BX.Value(),
p.CX.Value(),
p.DX.Value(),
p.SI.Value(),
p.DI.Value(),
p.BP.Value(),
)
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)
ret.AX.SetValue(retax)
ret.BX.SetValue(retbx)
ret.CX.SetValue(retcx)
ret.DX.SetValue(retdx)
ret.SI.SetValue(retsi)
ret.DI.SetValue(retdi)
ret.BP.SetValue(retbp)
return ret
}
func (p *BackdoorProto) HighBandwidthIn() *BackdoorProto {
p.DX.Low.Low = BackdoorHighBWPort
p.AX.SetQuad(BackdoorMagic)
p.DX.AsUInt32().Low = BackdoorHighBWPort
p.AX.SetValue(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(),
p.AX.Value(),
p.BX.Value(),
p.CX.Value(),
p.DX.Value(),
p.SI.Value(),
p.DI.Value(),
p.BP.Value(),
)
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)
ret.AX.SetValue(retax)
ret.BX.SetValue(retbx)
ret.CX.SetValue(retcx)
ret.DX.SetValue(retdx)
ret.SI.SetValue(retsi)
ret.DI.SetValue(retdi)
ret.BP.SetValue(retbp)
return ret
}

View File

@@ -0,0 +1,48 @@
// Copyright 2016-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.
package bdoor
const (
BackdoorMagic = uint32(0x564D5868)
)
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 UInt32
size uint32
}
func bdoor_inout(ax, bx, cx, dx, si, di, bp uint32) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint32)
func bdoor_hbout(ax, bx, cx, dx, si, di, bp uint32) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint32)
func bdoor_hbin(ax, bx, cx, dx, si, di, bp uint32) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint32)
func bdoor_inout_test(ax, bx, cx, dx, si, di, bp uint32) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint32)

View 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 uint32) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint32)
TEXT ·bdoor_inout(SB), NOSPLIT|WRAPPER, $0
MOVL ax+0(FP), AX
MOVL bx+4(FP), BX
MOVL cx+8(FP), CX
MOVL dx+12(FP), DX
MOVL si+16(FP), SI
MOVL di+20(FP), DI
MOVL bp+24(FP), BP
// IN to DX from EAX
INL
MOVL AX, retax+28(FP)
MOVL BX, retbx+32(FP)
MOVL CX, retcx+36(FP)
MOVL DX, retdx+40(FP)
MOVL SI, retsi+44(FP)
MOVL DI, retdi+48(FP)
MOVL BP, retbp+52(FP)
RET
// func bdoor_hbout(ax, bx, cx, dx, si, di, bp uint32) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint32)
TEXT ·bdoor_hbout(SB), NOSPLIT|WRAPPER, $0
MOVL ax+0(FP), AX
MOVL bx+4(FP), BX
MOVL cx+8(FP), CX
MOVL dx+12(FP), DX
MOVL si+16(FP), SI
MOVL di+20(FP), DI
MOVL bp+24(FP), BP
CLD; REP; OUTSB
MOVL AX, retax+28(FP)
MOVL BX, retbx+32(FP)
MOVL CX, retcx+36(FP)
MOVL DX, retdx+40(FP)
MOVL SI, retsi+44(FP)
MOVL DI, retdi+48(FP)
MOVL BP, retbp+52(FP)
RET
// func bdoor_hbin(ax, bx, cx, dx, si, di, bp uint32) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint32)
TEXT ·bdoor_hbin(SB), NOSPLIT|WRAPPER, $0
MOVL ax+0(FP), AX
MOVL bx+4(FP), BX
MOVL cx+8(FP), CX
MOVL dx+12(FP), DX
MOVL si+16(FP), SI
MOVL di+20(FP), DI
MOVL bp+24(FP), BP
CLD; REP; INSB
MOVL AX, retax+28(FP)
MOVL BX, retbx+32(FP)
MOVL CX, retcx+40(FP)
MOVL DX, retdx+44(FP)
MOVL SI, retsi+48(FP)
MOVL DI, retdi+52(FP)
MOVL BP, retbp+56(FP)
RET
// func bdoor_inout_test(ax, bx, cx, dx, si, di, bp uint32) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint32)
TEXT ·bdoor_inout_test(SB), NOSPLIT|WRAPPER, $0
MOVL ax+0(FP), AX
MOVL bx+4(FP), BX
MOVL cx+8(FP), CX
MOVL dx+12(FP), DX
MOVL si+16(FP), SI
MOVL di+20(FP), DI
MOVL bp+24(FP), BP
MOVL AX, retax+28(FP)
MOVL BX, retbx+32(FP)
MOVL CX, retcx+36(FP)
MOVL DX, retdx+40(FP)
MOVL SI, retsi+44(FP)
MOVL DI, retdi+48(FP)
MOVL BP, retbp+52(FP)
RET

View File

@@ -0,0 +1,48 @@
// Copyright 2016-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.
package bdoor
const (
BackdoorMagic = uint64(0x564D5868)
)
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)

View File

@@ -1,4 +1,4 @@
// Copyright 2016 VMware, Inc. All Rights Reserved.
// Copyright 2016-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.
@@ -14,6 +14,8 @@
package bdoor
import "unsafe"
type UInt32 struct {
High uint16
Low uint16
@@ -28,6 +30,22 @@ func (u *UInt32) SetWord(w uint32) {
u.Low = uint16(w)
}
func (u *UInt32) AsUInt32() *UInt32 {
return u
}
func (u *UInt32) Value() uint32 {
return u.Word()
}
func (u *UInt32) SetValue(val uint32) {
u.SetWord(val)
}
func (u *UInt32) SetPointer(p unsafe.Pointer) {
u.SetWord(uint32(uintptr(p)))
}
type UInt64 struct {
High UInt32
Low UInt32
@@ -41,3 +59,19 @@ func (u *UInt64) SetQuad(w uint64) {
u.High.SetWord(uint32(w >> 32))
u.Low.SetWord(uint32(w))
}
func (u *UInt64) AsUInt32() *UInt32 {
return &u.Low
}
func (u *UInt64) Value() uint64 {
return u.Quad()
}
func (u *UInt64) SetValue(val uint64) {
u.SetQuad(val)
}
func (u *UInt64) SetPointer(p unsafe.Pointer) {
u.SetQuad(uint64(uintptr(p)))
}

View File

@@ -1,4 +1,4 @@
// Copyright 2016 VMware, Inc. All Rights Reserved.
// Copyright 2016-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.
@@ -66,12 +66,12 @@ func NewChannel(proto uint32) (*Channel, error) {
retry:
bp := &bdoor.BackdoorProto{}
bp.BX.Low.SetWord(proto | flags)
bp.CX.Low.High = messageTypeOpen
bp.CX.Low.Low = bdoor.CommandMessage
bp.BX.AsUInt32().SetWord(proto | flags)
bp.CX.AsUInt32().High = messageTypeOpen
bp.CX.AsUInt32().Low = bdoor.CommandMessage
out := bp.InOut()
if (out.CX.Low.High & messageStatusSuccess) == 0 {
if (out.CX.AsUInt32().High & messageStatusSuccess) == 0 {
if flags != 0 {
flags = 0
goto retry
@@ -82,9 +82,9 @@ retry:
}
ch := &Channel{}
ch.id = out.DX.Low.High
ch.cookie.High.SetWord(out.SI.Low.Word())
ch.cookie.Low.SetWord(out.DI.Low.Word())
ch.id = out.DX.AsUInt32().High
ch.cookie.High.SetWord(out.SI.AsUInt32().Word())
ch.cookie.Low.SetWord(out.DI.AsUInt32().Word())
Debugf("Opened channel %d", ch.id)
return ch, nil
@@ -93,15 +93,15 @@ retry:
func (c *Channel) Close() error {
bp := &bdoor.BackdoorProto{}
bp.CX.Low.High = messageTypeClose
bp.CX.Low.Low = bdoor.CommandMessage
bp.CX.AsUInt32().High = messageTypeClose
bp.CX.AsUInt32().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.DX.AsUInt32().High = c.id
bp.SI.AsUInt32().SetWord(c.cookie.High.Word())
bp.DI.AsUInt32().SetWord(c.cookie.Low.Word())
out := bp.InOut()
if (out.CX.Low.High & messageStatusSuccess) == 0 {
if (out.CX.AsUInt32().High & messageStatusSuccess) == 0 {
Errorf("Message: Unable to close communication channel %d", c.id)
return ErrChannelClose
}
@@ -113,18 +113,18 @@ func (c *Channel) Close() error {
func (c *Channel) Send(buf []byte) error {
retry:
bp := &bdoor.BackdoorProto{}
bp.CX.Low.High = messageTypeSendSize
bp.CX.Low.Low = bdoor.CommandMessage
bp.CX.AsUInt32().High = messageTypeSendSize
bp.CX.AsUInt32().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.DX.AsUInt32().High = c.id
bp.SI.AsUInt32().SetWord(c.cookie.High.Word())
bp.DI.AsUInt32().SetWord(c.cookie.Low.Word())
bp.BX.Low.SetWord(uint32(len(buf)))
bp.BX.AsUInt32().SetWord(uint32(len(buf)))
// send the size
out := bp.InOut()
if (out.CX.Low.High & messageStatusSuccess) == 0 {
if (out.CX.AsUInt32().High & messageStatusSuccess) == 0 {
Errorf("Message: Unable to send a message over the communication channel %d", c.id)
return ErrRpciSend
}
@@ -134,20 +134,20 @@ retry:
return nil
}
if !c.forceLowBW && (out.CX.Low.High&messageStatusHighBW) == messageStatusHighBW {
if !c.forceLowBW && (out.CX.AsUInt32().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]))))
hbbp.BX.AsUInt32().Low = bdoor.CommandHighBWMessage
hbbp.BX.AsUInt32().High = messageStatusSuccess
hbbp.DX.AsUInt32().High = c.id
hbbp.BP.AsUInt32().SetWord(c.cookie.High.Word())
hbbp.DI.AsUInt32().SetWord(c.cookie.Low.Word())
hbbp.CX.AsUInt32().SetWord(uint32(len(buf)))
hbbp.SI.SetPointer(unsafe.Pointer(&buf[0]))
out := hbbp.HighBandwidthOut()
if (out.BX.Low.High & messageStatusSuccess) == 0 {
if (out.BX.Low.High & messageStatusCheckPoint) != 0 {
if (out.BX.AsUInt32().High & messageStatusSuccess) == 0 {
if (out.BX.AsUInt32().High & messageStatusCheckPoint) != 0 {
Debugf("A checkpoint occurred. Retrying the operation")
goto retry
}
@@ -156,7 +156,7 @@ retry:
return ErrRpciSend
}
} else {
bp.CX.Low.High = messageTypeSendPayload
bp.CX.AsUInt32().High = messageTypeSendPayload
bbuf := bytes.NewBuffer(buf)
for {
@@ -169,17 +169,17 @@ retry:
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]}))
bp.BX.AsUInt32().SetWord(binary.LittleEndian.Uint32([]byte{0x0, words[2], words[1], words[0]}))
case 2:
bp.BX.Low.SetWord(uint32(binary.LittleEndian.Uint16(words)))
bp.BX.AsUInt32().SetWord(uint32(binary.LittleEndian.Uint16(words)))
case 1:
bp.BX.Low.SetWord(uint32(words[0]))
bp.BX.AsUInt32().SetWord(uint32(words[0]))
default:
bp.BX.Low.SetWord(binary.LittleEndian.Uint32(words))
bp.BX.AsUInt32().SetWord(binary.LittleEndian.Uint32(words))
}
out = bp.InOut()
if (out.CX.Low.High & messageStatusSuccess) == 0 {
if (out.CX.AsUInt32().High & messageStatusSuccess) == 0 {
Errorf("Message: Unable to send a message over the communication channel %d", c.id)
return ErrRpciSend
}
@@ -193,50 +193,50 @@ 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.CX.AsUInt32().High = messageTypeReceiveSize
bp.CX.AsUInt32().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.DX.AsUInt32().High = c.id
bp.SI.AsUInt32().SetWord(c.cookie.High.Word())
bp.DI.AsUInt32().SetWord(c.cookie.Low.Word())
out := bp.InOut()
if (out.CX.Low.High & messageStatusSuccess) == 0 {
if (out.CX.AsUInt32().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 {
if (out.CX.AsUInt32().High & messageStatusDoRecieve) == 0 {
Debugf("No message to retrieve")
return nil, nil
}
// Receive the size.
if out.DX.Low.High != messageTypeSendSize {
if out.DX.AsUInt32().High != messageTypeSendSize {
Errorf("Message: Protocol error. Expected a MESSAGE_TYPE_SENDSIZE request from vmware")
return nil, ErrRpciReceive
}
size := out.BX.Quad()
size := out.BX.Value()
var buf []byte
if size != 0 {
if !c.forceLowBW && (out.CX.Low.High&messageStatusHighBW == messageStatusHighBW) {
if !c.forceLowBW && (out.CX.AsUInt32().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]))))
hbbp.BX.AsUInt32().Low = bdoor.CommandHighBWMessage
hbbp.BX.AsUInt32().High = messageStatusSuccess
hbbp.DX.AsUInt32().High = c.id
hbbp.SI.AsUInt32().SetWord(c.cookie.High.Word())
hbbp.BP.AsUInt32().SetWord(c.cookie.Low.Word())
hbbp.CX.AsUInt32().SetWord(uint32(len(buf)))
hbbp.DI.SetPointer(unsafe.Pointer(&buf[0]))
out := hbbp.HighBandwidthIn()
if (out.BX.Low.High & messageStatusSuccess) == 0 {
if (out.BX.AsUInt32().High & messageStatusSuccess) == 0 {
Errorf("Message: Unable to send a message over the communication channel %d", c.id)
c.reply(messageTypeReceivePayload, messageStatusFail)
return nil, ErrRpciReceive
@@ -249,12 +249,12 @@ retry:
break
}
bp.CX.Low.High = messageTypeReceivePayload
bp.BX.Low.Low = messageStatusSuccess
bp.CX.AsUInt32().High = messageTypeReceivePayload
bp.BX.AsUInt32().Low = messageStatusSuccess
out = bp.InOut()
if (out.CX.Low.High & messageStatusSuccess) == 0 {
if (out.CX.Low.High & messageStatusCheckPoint) != 0 {
if (out.CX.AsUInt32().High & messageStatusSuccess) == 0 {
if (out.CX.AsUInt32().High & messageStatusCheckPoint) != 0 {
Debugf("A checkpoint occurred. Retrying the operation")
goto retry
}
@@ -264,34 +264,34 @@ retry:
return nil, ErrRpciReceive
}
if out.DX.Low.High != messageTypeSendPayload {
if out.DX.AsUInt32().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())
Debugf("Received %#v", out.BX.AsUInt32().Word())
switch size {
case 1:
err = binary.Write(b, binary.LittleEndian, uint8(out.BX.Low.Low))
err = binary.Write(b, binary.LittleEndian, uint8(out.BX.AsUInt32().Low))
size = size - 1
case 2:
err = binary.Write(b, binary.LittleEndian, uint16(out.BX.Low.Low))
err = binary.Write(b, binary.LittleEndian, uint16(out.BX.AsUInt32().Low))
size = size - 2
case 3:
err = binary.Write(b, binary.LittleEndian, uint16(out.BX.Low.Low))
err = binary.Write(b, binary.LittleEndian, uint16(out.BX.AsUInt32().Low))
if err != nil {
c.reply(messageTypeReceivePayload, messageStatusFail)
return nil, ErrRpciReceive
}
err = binary.Write(b, binary.LittleEndian, uint8(out.BX.Low.High))
err = binary.Write(b, binary.LittleEndian, uint8(out.BX.AsUInt32().High))
size = size - 3
default:
err = binary.Write(b, binary.LittleEndian, out.BX.Low.Word())
err = binary.Write(b, binary.LittleEndian, out.BX.AsUInt32().Word())
size = size - 4
}
@@ -314,17 +314,17 @@ retry:
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())
bp.BX.AsUInt32().Low = messageStatus
bp.CX.AsUInt32().High = messageType
bp.CX.AsUInt32().Low = bdoor.CommandMessage
bp.DX.AsUInt32().High = c.id
bp.SI.AsUInt32().SetWord(c.cookie.High.Word())
bp.DI.AsUInt32().SetWord(c.cookie.Low.Word())
out := bp.InOut()
/* OUT: Status */
if (out.CX.Low.High & messageStatusSuccess) == 0 {
if (out.CX.AsUInt32().High & messageStatusSuccess) == 0 {
if messageStatus == messageStatusSuccess {
Errorf("reply Message: Unable to send a message over the communication channel %d", c.id)
} else {