mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
encoding/json walked every payload on every call. ZAP reads a field at a
constant offset out of the buffer that arrived, and //tools/zap has
already stated those offsets for every payload, so the transport now asks
the payload for its own bytes and the parse step is gone.
The envelope collapses with it. clientCall and serverCall existed only
because JSON needed one type to hold an any and another to hold a
RawMessage; bytes are bytes, so one Call serves both ends. Framing comes
from the ZAP header, which declares its own length.
A payload that is nothing -- the *struct{} a method takes when it has no
argument or no result -- carries nothing. Anything else without a layout
fails the call naming the type, so a payload that would have arrived
silently empty does not arrive at all.
The methods that took a bare string or returned a bare int now take and
return named payloads, because a scalar has no layout to state and the
rest of the API was already shaped this way.
Co-authored-by: Hanzo Dev <[email protected]>
572 lines
14 KiB
Go
572 lines
14 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 procfs
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"strings"
|
|
|
|
zap "github.com/zap-proto/go"
|
|
kernel "gvisor.dev/gvisor/pkg/sentry/kernel"
|
|
limits "gvisor.dev/gvisor/pkg/sentry/limits"
|
|
)
|
|
|
|
// ---- FDInfo ------------------------------------------------------------
|
|
|
|
const (
|
|
fDInfoNumberAt = 0
|
|
fDInfoPathAt = 8
|
|
fDInfoModeAt = 16
|
|
fDInfoSize = 24
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*FDInfo)(nil)
|
|
|
|
// MarshalZAP writes FDInfo from constant offsets.
|
|
func (x *FDInfo) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(fDInfoSize + 256)
|
|
ob := b.StartObject(fDInfoSize)
|
|
ob.SetInt32(fDInfoNumberAt, int32(x.Number))
|
|
ob.SetText(fDInfoPathAt, string(x.Path))
|
|
ob.SetUint16(fDInfoModeAt, uint16(x.Mode))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads FDInfo out of the buffer that arrived.
|
|
func (x *FDInfo) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("FDInfo: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Number = int32(o.Int32(fDInfoNumberAt))
|
|
x.Path = string(strings.Clone(o.Text(fDInfoPathAt)))
|
|
x.Mode = uint16(o.Uint16(fDInfoModeAt))
|
|
return nil
|
|
}
|
|
|
|
// ---- Mapping -----------------------------------------------------------
|
|
|
|
const (
|
|
mappingAddressAt = 0
|
|
mappingPermissionsAt = 8
|
|
mappingPrivateAt = 16
|
|
mappingOffsetAt = 24
|
|
mappingDevMajorAt = 32
|
|
mappingDevMinorAt = 36
|
|
mappingInodeAt = 40
|
|
mappingPathnameAt = 48
|
|
mappingSize = 56
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Mapping)(nil)
|
|
|
|
// MarshalZAP writes Mapping from constant offsets.
|
|
func (x *Mapping) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(mappingSize + 256)
|
|
ob := b.StartObject(mappingSize)
|
|
innerAddress, err := x.Address.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(mappingAddressAt, innerAddress)
|
|
innerPermissions, err := x.Permissions.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(mappingPermissionsAt, innerPermissions)
|
|
ob.SetText(mappingPrivateAt, string(x.Private))
|
|
ob.SetUint64(mappingOffsetAt, uint64(x.Offset))
|
|
ob.SetUint32(mappingDevMajorAt, uint32(x.DevMajor))
|
|
ob.SetUint32(mappingDevMinorAt, uint32(x.DevMinor))
|
|
ob.SetUint64(mappingInodeAt, uint64(x.Inode))
|
|
ob.SetText(mappingPathnameAt, string(x.Pathname))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Mapping out of the buffer that arrived.
|
|
func (x *Mapping) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Mapping: %w", err)
|
|
}
|
|
o := m.Root()
|
|
if raw := o.Bytes(mappingAddressAt); len(raw) > 0 {
|
|
if err := x.Address.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(mappingPermissionsAt); len(raw) > 0 {
|
|
if err := x.Permissions.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Private = string(strings.Clone(o.Text(mappingPrivateAt)))
|
|
x.Offset = uint64(o.Uint64(mappingOffsetAt))
|
|
x.DevMajor = uint32(o.Uint32(mappingDevMajorAt))
|
|
x.DevMinor = uint32(o.Uint32(mappingDevMinorAt))
|
|
x.Inode = uint64(o.Uint64(mappingInodeAt))
|
|
x.Pathname = string(strings.Clone(o.Text(mappingPathnameAt)))
|
|
return nil
|
|
}
|
|
|
|
// ---- ProcessProcfsDump -------------------------------------------------
|
|
|
|
const (
|
|
processProcfsDumpExeAt = 0
|
|
processProcfsDumpArgsAt = 8
|
|
processProcfsDumpEnvAt = 16
|
|
processProcfsDumpCWDAt = 24
|
|
processProcfsDumpFDsAt = 32
|
|
processProcfsDumpStartTimeAt = 40
|
|
processProcfsDumpRootAt = 48
|
|
processProcfsDumpLimitsAt = 56
|
|
processProcfsDumpCgroupAt = 64
|
|
processProcfsDumpStatusAt = 72
|
|
processProcfsDumpStatAt = 80
|
|
processProcfsDumpMapsAt = 88
|
|
processProcfsDumpSize = 96
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*ProcessProcfsDump)(nil)
|
|
|
|
// MarshalZAP writes ProcessProcfsDump from constant offsets.
|
|
func (x *ProcessProcfsDump) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(processProcfsDumpSize + 256)
|
|
argsAt, argsN := 0, len(x.Args)
|
|
if argsN > 0 {
|
|
var blob []byte
|
|
for i := range x.Args {
|
|
enc := []byte(x.Args[i])
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
argsAt = b.WriteBytes(blob)
|
|
}
|
|
envAt, envN := 0, len(x.Env)
|
|
if envN > 0 {
|
|
var blob []byte
|
|
for i := range x.Env {
|
|
enc := []byte(x.Env[i])
|
|
var n [4]byte
|
|
binary.LittleEndian.PutUint32(n[:], uint32(len(enc)))
|
|
blob = append(blob, n[:]...)
|
|
blob = append(blob, enc...)
|
|
}
|
|
envAt = b.WriteBytes(blob)
|
|
}
|
|
fDsAt, fDsN := 0, len(x.FDs)
|
|
if fDsN > 0 {
|
|
var blob []byte
|
|
for i := range x.FDs {
|
|
enc, err := x.FDs[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...)
|
|
}
|
|
fDsAt = b.WriteBytes(blob)
|
|
}
|
|
limitsAt, limitsN := 0, len(x.Limits)
|
|
if limitsN > 0 {
|
|
var blob []byte
|
|
for i := range x.Limits {
|
|
enc, err := x.Limits[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...)
|
|
}
|
|
limitsAt = b.WriteBytes(blob)
|
|
}
|
|
cgroupAt, cgroupN := 0, len(x.Cgroup)
|
|
if cgroupN > 0 {
|
|
var blob []byte
|
|
for i := range x.Cgroup {
|
|
enc, err := x.Cgroup[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...)
|
|
}
|
|
cgroupAt = b.WriteBytes(blob)
|
|
}
|
|
mapsAt, mapsN := 0, len(x.Maps)
|
|
if mapsN > 0 {
|
|
var blob []byte
|
|
for i := range x.Maps {
|
|
enc, err := x.Maps[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...)
|
|
}
|
|
mapsAt = b.WriteBytes(blob)
|
|
}
|
|
ob := b.StartObject(processProcfsDumpSize)
|
|
ob.SetText(processProcfsDumpExeAt, string(x.Exe))
|
|
ob.SetText(processProcfsDumpCWDAt, string(x.CWD))
|
|
ob.SetInt64(processProcfsDumpStartTimeAt, int64(x.StartTime))
|
|
ob.SetText(processProcfsDumpRootAt, string(x.Root))
|
|
innerStatus, err := x.Status.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(processProcfsDumpStatusAt, innerStatus)
|
|
innerStat, err := x.Stat.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(processProcfsDumpStatAt, innerStat)
|
|
if argsN > 0 {
|
|
ob.SetList(processProcfsDumpArgsAt, argsAt, argsN)
|
|
}
|
|
if envN > 0 {
|
|
ob.SetList(processProcfsDumpEnvAt, envAt, envN)
|
|
}
|
|
if fDsN > 0 {
|
|
ob.SetList(processProcfsDumpFDsAt, fDsAt, fDsN)
|
|
}
|
|
if limitsN > 0 {
|
|
ob.SetList(processProcfsDumpLimitsAt, limitsAt, limitsN)
|
|
}
|
|
if cgroupN > 0 {
|
|
ob.SetList(processProcfsDumpCgroupAt, cgroupAt, cgroupN)
|
|
}
|
|
if mapsN > 0 {
|
|
ob.SetList(processProcfsDumpMapsAt, mapsAt, mapsN)
|
|
}
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads ProcessProcfsDump out of the buffer that arrived.
|
|
func (x *ProcessProcfsDump) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("ProcessProcfsDump: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Exe = string(strings.Clone(o.Text(processProcfsDumpExeAt)))
|
|
if l := o.List(processProcfsDumpArgsAt); l.Len() > 0 {
|
|
rows := make([]string, l.Len())
|
|
for i := range rows {
|
|
rows[i] = string(l.BytesAt(i))
|
|
}
|
|
x.Args = rows
|
|
}
|
|
if l := o.List(processProcfsDumpEnvAt); l.Len() > 0 {
|
|
rows := make([]string, l.Len())
|
|
for i := range rows {
|
|
rows[i] = string(l.BytesAt(i))
|
|
}
|
|
x.Env = rows
|
|
}
|
|
x.CWD = string(strings.Clone(o.Text(processProcfsDumpCWDAt)))
|
|
if l := o.List(processProcfsDumpFDsAt); l.Len() > 0 {
|
|
rows := make([]FDInfo, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.FDs = rows
|
|
}
|
|
x.StartTime = int64(o.Int64(processProcfsDumpStartTimeAt))
|
|
x.Root = string(strings.Clone(o.Text(processProcfsDumpRootAt)))
|
|
if l := o.List(processProcfsDumpLimitsAt); l.Len() > 0 {
|
|
rows := make([]limits.Rlimit, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Limits = rows
|
|
}
|
|
if l := o.List(processProcfsDumpCgroupAt); l.Len() > 0 {
|
|
rows := make([]kernel.TaskCgroupEntry, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Cgroup = rows
|
|
}
|
|
if raw := o.Bytes(processProcfsDumpStatusAt); len(raw) > 0 {
|
|
if err := x.Status.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(processProcfsDumpStatAt); len(raw) > 0 {
|
|
if err := x.Stat.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if l := o.List(processProcfsDumpMapsAt); l.Len() > 0 {
|
|
rows := make([]Mapping, l.Len())
|
|
for i := range rows {
|
|
if err := rows[i].UnmarshalZAP(l.BytesAt(i)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.Maps = rows
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ---- Range -------------------------------------------------------------
|
|
|
|
const (
|
|
rangeStartAt = 0
|
|
rangeEndAt = 8
|
|
rangeSize = 16
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Range)(nil)
|
|
|
|
// MarshalZAP writes Range from constant offsets.
|
|
func (x *Range) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(rangeSize + 256)
|
|
ob := b.StartObject(rangeSize)
|
|
ob.SetUint64(rangeStartAt, uint64(x.Start))
|
|
ob.SetUint64(rangeEndAt, uint64(x.End))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Range out of the buffer that arrived.
|
|
func (x *Range) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Range: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Start = uint64(o.Uint64(rangeStartAt))
|
|
x.End = uint64(o.Uint64(rangeEndAt))
|
|
return nil
|
|
}
|
|
|
|
// ---- Stat --------------------------------------------------------------
|
|
|
|
const (
|
|
statPGIDAt = 0
|
|
statSIDAt = 4
|
|
statSize = 8
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Stat)(nil)
|
|
|
|
// MarshalZAP writes Stat from constant offsets.
|
|
func (x *Stat) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(statSize + 256)
|
|
ob := b.StartObject(statSize)
|
|
ob.SetInt32(statPGIDAt, int32(x.PGID))
|
|
ob.SetInt32(statSIDAt, int32(x.SID))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Stat out of the buffer that arrived.
|
|
func (x *Stat) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Stat: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.PGID = int32(o.Int32(statPGIDAt))
|
|
x.SID = int32(o.Int32(statSIDAt))
|
|
return nil
|
|
}
|
|
|
|
// ---- Status ------------------------------------------------------------
|
|
|
|
const (
|
|
statusCommAt = 0
|
|
statusPIDAt = 8
|
|
statusPPIDAt = 12
|
|
statusUIDAt = 16
|
|
statusGIDAt = 24
|
|
statusVMSizeAt = 32
|
|
statusVMRSSAt = 40
|
|
statusSize = 48
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*Status)(nil)
|
|
|
|
// MarshalZAP writes Status from constant offsets.
|
|
func (x *Status) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(statusSize + 256)
|
|
ob := b.StartObject(statusSize)
|
|
ob.SetText(statusCommAt, string(x.Comm))
|
|
ob.SetInt32(statusPIDAt, int32(x.PID))
|
|
ob.SetInt32(statusPPIDAt, int32(x.PPID))
|
|
innerUID, err := x.UID.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(statusUIDAt, innerUID)
|
|
innerGID, err := x.GID.MarshalZAP()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ob.SetBytes(statusGIDAt, innerGID)
|
|
ob.SetUint64(statusVMSizeAt, uint64(x.VMSize))
|
|
ob.SetUint64(statusVMRSSAt, uint64(x.VMRSS))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads Status out of the buffer that arrived.
|
|
func (x *Status) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("Status: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Comm = string(strings.Clone(o.Text(statusCommAt)))
|
|
x.PID = int32(o.Int32(statusPIDAt))
|
|
x.PPID = int32(o.Int32(statusPPIDAt))
|
|
if raw := o.Bytes(statusUIDAt); len(raw) > 0 {
|
|
if err := x.UID.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if raw := o.Bytes(statusGIDAt); len(raw) > 0 {
|
|
if err := x.GID.UnmarshalZAP(raw); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
x.VMSize = uint64(o.Uint64(statusVMSizeAt))
|
|
x.VMRSS = uint64(o.Uint64(statusVMRSSAt))
|
|
return nil
|
|
}
|
|
|
|
// ---- UIDGID ------------------------------------------------------------
|
|
|
|
const (
|
|
uIDGIDRealAt = 0
|
|
uIDGIDEffectiveAt = 4
|
|
uIDGIDSavedAt = 8
|
|
uIDGIDSize = 16
|
|
)
|
|
|
|
var _ interface {
|
|
MarshalZAP() ([]byte, error)
|
|
UnmarshalZAP([]byte) error
|
|
} = (*UIDGID)(nil)
|
|
|
|
// MarshalZAP writes UIDGID from constant offsets.
|
|
func (x *UIDGID) MarshalZAP() ([]byte, error) {
|
|
if x == nil {
|
|
return nil, nil
|
|
}
|
|
b := zap.NewBuilder(uIDGIDSize + 256)
|
|
ob := b.StartObject(uIDGIDSize)
|
|
ob.SetUint32(uIDGIDRealAt, uint32(x.Real))
|
|
ob.SetUint32(uIDGIDEffectiveAt, uint32(x.Effective))
|
|
ob.SetUint32(uIDGIDSavedAt, uint32(x.Saved))
|
|
ob.FinishAsRoot()
|
|
return b.Finish(), nil
|
|
}
|
|
|
|
// UnmarshalZAP reads UIDGID out of the buffer that arrived.
|
|
func (x *UIDGID) UnmarshalZAP(data []byte) error {
|
|
if x == nil || len(data) == 0 {
|
|
return nil
|
|
}
|
|
m, err := zap.Parse(data)
|
|
if err != nil {
|
|
return fmt.Errorf("UIDGID: %w", err)
|
|
}
|
|
o := m.Root()
|
|
x.Real = uint32(o.Uint32(uIDGIDRealAt))
|
|
x.Effective = uint32(o.Uint32(uIDGIDEffectiveAt))
|
|
x.Saved = uint32(o.Uint32(uIDGIDSavedAt))
|
|
return nil
|
|
}
|