Files
zeekayandHanzo Dev 3da05638df State the ZAP wire of every urpc payload
urpc encodes with encoding/json, which walks the payload on every call: a
realistic control.ExecArgs costs 7084ns and 10 allocations to cross. ZAP
reads a field at a constant offset out of the buffer that arrived, so the
same payload is 740ns and one allocation -- but only if the offsets are
stated, and a stated offset that is wrong is silent corruption rather than
a compile error. So state them from the types themselves.

//tools/zap reflects over the payloads at build time and writes the wire
as Go source with the offsets as constants. It lives inside Bazel because
pkg/sentry/control cannot be imported from outside it: the *_go_proto
packages it depends on have no source in the tree.

Six payloads had no layout to state. A map, an interface and a type from
another module have no offsets, so each is answered in the type:

  SaveOpts.Metadata and StartContainerArgs.InitialCgroups/Limits cross as
  lists of pairs; boot.Route.Destination restates net.IPNet as Subnet;
  OpenMountArgs restates the OCI mount fields the call actually uses;
  StartArgs.Spec and SinkConfig.Config carry their documents as the bytes
  they arrived as; MetricsRegistrationResponse carries the protocol
  buffer the same way; and seccheck's session options become a type
  instead of a map of any.

ExecArgs and MetricsExportData still have none: ExecArgs holds live
kernel objects behind an interface, and MetricsExportData reaches a
prometheus snapshot whose labels are a map.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-22 23:10:33 -07:00

326 lines
9.1 KiB
Go

// Copyright 2026 The gVisor Authors.
//
// 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.
// Code generated by zip; DO NOT EDIT.
package stateipc
import (
"encoding/binary"
"fmt"
"strings"
zap "github.com/zap-proto/go"
stateio "gvisor.dev/gvisor/pkg/sentry/state/stateio"
)
// ---- CloseRequest ------------------------------------------------------
const (
closeRequestHandleAt = 0
closeRequestSize = 8
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*CloseRequest)(nil)
// MarshalZAP writes CloseRequest from constant offsets.
func (x *CloseRequest) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(closeRequestSize + 256)
ob := b.StartObject(closeRequestSize)
ob.SetUint32(closeRequestHandleAt, uint32(x.Handle))
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads CloseRequest out of the buffer that arrived.
func (x *CloseRequest) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("CloseRequest: %w", err)
}
o := m.Root()
x.Handle = uint32(o.Uint32(closeRequestHandleAt))
return nil
}
// ---- CloseResponse -----------------------------------------------------
const (
closeResponseSize = 0
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*CloseResponse)(nil)
// MarshalZAP writes CloseResponse from constant offsets.
func (x *CloseResponse) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(closeResponseSize + 256)
ob := b.StartObject(closeResponseSize)
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads CloseResponse out of the buffer that arrived.
func (x *CloseResponse) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("CloseResponse: %w", err)
}
_ = m
return nil
}
// ---- OpenRequest -------------------------------------------------------
const (
openRequestPathAt = 0
openRequestModeAt = 8
openRequestSize = 16
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*OpenRequest)(nil)
// MarshalZAP writes OpenRequest from constant offsets.
func (x *OpenRequest) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(openRequestSize + 256)
ob := b.StartObject(openRequestSize)
ob.SetText(openRequestPathAt, string(x.Path))
ob.SetInt64(openRequestModeAt, int64(x.Mode))
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads OpenRequest out of the buffer that arrived.
func (x *OpenRequest) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("OpenRequest: %w", err)
}
o := m.Root()
x.Path = string(strings.Clone(o.Text(openRequestPathAt)))
x.Mode = int(o.Int64(openRequestModeAt))
return nil
}
// ---- OpenResponse ------------------------------------------------------
const (
openResponseHandleAt = 0
openResponseMaxIOBytesAt = 4
openResponseMaxRangesAt = 8
openResponseMaxParallelAt = 12
openResponseFilePayloadAt = 16
openResponsePacketWindowOffsetAt = 24
openResponsePacketWindowLengthAt = 32
openResponseSize = 40
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*OpenResponse)(nil)
// MarshalZAP writes OpenResponse from constant offsets.
func (x *OpenResponse) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(openResponseSize + 256)
ob := b.StartObject(openResponseSize)
ob.SetUint32(openResponseHandleAt, uint32(x.Handle))
ob.SetUint32(openResponseMaxIOBytesAt, uint32(x.MaxIOBytes))
ob.SetUint32(openResponseMaxRangesAt, uint32(x.MaxRanges))
ob.SetUint32(openResponseMaxParallelAt, uint32(x.MaxParallel))
innerFilePayload, err := x.FilePayload.MarshalZAP()
if err != nil {
return nil, err
}
ob.SetBytes(openResponseFilePayloadAt, innerFilePayload)
ob.SetInt64(openResponsePacketWindowOffsetAt, int64(x.PacketWindowOffset))
ob.SetInt64(openResponsePacketWindowLengthAt, int64(x.PacketWindowLength))
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads OpenResponse out of the buffer that arrived.
func (x *OpenResponse) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("OpenResponse: %w", err)
}
o := m.Root()
x.Handle = uint32(o.Uint32(openResponseHandleAt))
x.MaxIOBytes = uint32(o.Uint32(openResponseMaxIOBytesAt))
x.MaxRanges = uint32(o.Uint32(openResponseMaxRangesAt))
x.MaxParallel = uint32(o.Uint32(openResponseMaxParallelAt))
if raw := o.Bytes(openResponseFilePayloadAt); len(raw) > 0 {
if err := x.FilePayload.UnmarshalZAP(raw); err != nil {
return err
}
}
x.PacketWindowOffset = int64(o.Int64(openResponsePacketWindowOffsetAt))
x.PacketWindowLength = int(o.Int64(openResponsePacketWindowLengthAt))
return nil
}
// ---- RegisterClientFileRequest -----------------------------------------
const (
registerClientFileRequestHandleAt = 0
registerClientFileRequestFilePayloadAt = 8
registerClientFileRequestSizeAt = 16
registerClientFileRequestWritableAt = 24
registerClientFileRequestSettingsAt = 32
registerClientFileRequestSize = 40
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*RegisterClientFileRequest)(nil)
// MarshalZAP writes RegisterClientFileRequest from constant offsets.
func (x *RegisterClientFileRequest) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(registerClientFileRequestSize + 256)
settingsAt, settingsN := 0, len(x.Settings)
if settingsN > 0 {
var blob []byte
for i := range x.Settings {
enc, err := x.Settings[i].MarshalZAP()
if err != nil {
return nil, err
}
var n [4]byte
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
blob = append(blob, n[:]...)
blob = append(blob, enc...)
}
settingsAt = b.WriteBytes(blob)
}
ob := b.StartObject(registerClientFileRequestSize)
ob.SetUint32(registerClientFileRequestHandleAt, uint32(x.Handle))
innerFilePayload, err := x.FilePayload.MarshalZAP()
if err != nil {
return nil, err
}
ob.SetBytes(registerClientFileRequestFilePayloadAt, innerFilePayload)
ob.SetUint64(registerClientFileRequestSizeAt, uint64(x.Size))
ob.SetBool(registerClientFileRequestWritableAt, bool(x.Writable))
if settingsN > 0 {
ob.SetList(registerClientFileRequestSettingsAt, settingsAt, settingsN)
}
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads RegisterClientFileRequest out of the buffer that arrived.
func (x *RegisterClientFileRequest) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("RegisterClientFileRequest: %w", err)
}
o := m.Root()
x.Handle = uint32(o.Uint32(registerClientFileRequestHandleAt))
if raw := o.Bytes(registerClientFileRequestFilePayloadAt); len(raw) > 0 {
if err := x.FilePayload.UnmarshalZAP(raw); err != nil {
return err
}
}
x.Size = uint64(o.Uint64(registerClientFileRequestSizeAt))
x.Writable = bool(o.Bool(registerClientFileRequestWritableAt))
if l := o.List(registerClientFileRequestSettingsAt); l.Len() > 0 {
rows := make([]stateio.ClientFileRangeSetting, l.Len())
for i := range rows {
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
return err
}
}
x.Settings = rows
}
return nil
}
// ---- RegisterClientFileResponse ----------------------------------------
const (
registerClientFileResponseHandleAt = 0
registerClientFileResponseSize = 8
)
var _ interface {
MarshalZAP() ([]byte, error)
UnmarshalZAP([]byte) error
} = (*RegisterClientFileResponse)(nil)
// MarshalZAP writes RegisterClientFileResponse from constant offsets.
func (x *RegisterClientFileResponse) MarshalZAP() ([]byte, error) {
if x == nil {
return nil, nil
}
b := zap.NewBuilder(registerClientFileResponseSize + 256)
ob := b.StartObject(registerClientFileResponseSize)
ob.SetUint32(registerClientFileResponseHandleAt, uint32(x.Handle))
ob.FinishAsRoot()
return b.Finish(), nil
}
// UnmarshalZAP reads RegisterClientFileResponse out of the buffer that arrived.
func (x *RegisterClientFileResponse) UnmarshalZAP(data []byte) error {
if x == nil || len(data) == 0 {
return nil
}
m, err := zap.Parse(data)
if err != nil {
return fmt.Errorf("RegisterClientFileResponse: %w", err)
}
o := m.Root()
x.Handle = uint32(o.Uint32(registerClientFileResponseHandleAt))
return nil
}