forked from nicocha30/gvisor-ligolo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
netfilter_abi_autogen_unsafe.go
148 lines (128 loc) · 5.06 KB
/
netfilter_abi_autogen_unsafe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Automatically generated marshal implementation. See tools/go_marshal.
package netfilter
import (
"io"
"reflect"
"runtime"
"unsafe"
"github.com/ttpreport/gvisor-ligolo/pkg/abi/linux"
"github.com/ttpreport/gvisor-ligolo/pkg/gohacks"
"github.com/ttpreport/gvisor-ligolo/pkg/hostarch"
"github.com/ttpreport/gvisor-ligolo/pkg/marshal"
)
// Marshallable types used by this file.
var _ marshal.Marshallable = (*linux.NFNATRange)(nil)
var _ marshal.Marshallable = (*linux.XTEntryTarget)(nil)
var _ marshal.Marshallable = (*nfNATTarget)(nil)
// SizeBytes implements marshal.Marshallable.SizeBytes.
func (n *nfNATTarget) SizeBytes() int {
return 0 +
(*linux.XTEntryTarget)(nil).SizeBytes() +
(*linux.NFNATRange)(nil).SizeBytes()
}
// MarshalBytes implements marshal.Marshallable.MarshalBytes.
func (n *nfNATTarget) MarshalBytes(dst []byte) []byte {
dst = n.Target.MarshalUnsafe(dst)
dst = n.Range.MarshalUnsafe(dst)
return dst
}
// UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
func (n *nfNATTarget) UnmarshalBytes(src []byte) []byte {
src = n.Target.UnmarshalUnsafe(src)
src = n.Range.UnmarshalUnsafe(src)
return src
}
// Packed implements marshal.Marshallable.Packed.
//
//go:nosplit
func (n *nfNATTarget) Packed() bool {
return n.Range.Packed() && n.Target.Packed()
}
// MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
func (n *nfNATTarget) MarshalUnsafe(dst []byte) []byte {
if n.Range.Packed() && n.Target.Packed() {
size := n.SizeBytes()
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(n), uintptr(size))
return dst[size:]
}
// Type nfNATTarget doesn't have a packed layout in memory, fallback to MarshalBytes.
return n.MarshalBytes(dst)
}
// UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
func (n *nfNATTarget) UnmarshalUnsafe(src []byte) []byte {
if n.Range.Packed() && n.Target.Packed() {
size := n.SizeBytes()
gohacks.Memmove(unsafe.Pointer(n), unsafe.Pointer(&src[0]), uintptr(size))
return src[size:]
}
// Type nfNATTarget doesn't have a packed layout in memory, fallback to UnmarshalBytes.
return n.UnmarshalBytes(src)
}
// CopyOutN implements marshal.Marshallable.CopyOutN.
func (n *nfNATTarget) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
if !n.Range.Packed() && n.Target.Packed() {
// Type nfNATTarget doesn't have a packed layout in memory, fall back to MarshalBytes.
buf := cc.CopyScratchBuffer(n.SizeBytes()) // escapes: okay.
n.MarshalBytes(buf) // escapes: fallback.
return cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
}
// Construct a slice backed by dst's underlying memory.
var buf []byte
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(n)))
hdr.Len = n.SizeBytes()
hdr.Cap = n.SizeBytes()
length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
// Since we bypassed the compiler's escape analysis, indicate that n
// must live until the use above.
runtime.KeepAlive(n) // escapes: replaced by intrinsic.
return length, err
}
// CopyOut implements marshal.Marshallable.CopyOut.
func (n *nfNATTarget) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
return n.CopyOutN(cc, addr, n.SizeBytes())
}
// CopyIn implements marshal.Marshallable.CopyIn.
func (n *nfNATTarget) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
if !n.Range.Packed() && n.Target.Packed() {
// Type nfNATTarget doesn't have a packed layout in memory, fall back to UnmarshalBytes.
buf := cc.CopyScratchBuffer(n.SizeBytes()) // escapes: okay.
length, err := cc.CopyInBytes(addr, buf) // escapes: okay.
// Unmarshal unconditionally. If we had a short copy-in, this results in a
// partially unmarshalled struct.
n.UnmarshalBytes(buf) // escapes: fallback.
return length, err
}
// Construct a slice backed by dst's underlying memory.
var buf []byte
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(n)))
hdr.Len = n.SizeBytes()
hdr.Cap = n.SizeBytes()
length, err := cc.CopyInBytes(addr, buf) // escapes: okay.
// Since we bypassed the compiler's escape analysis, indicate that n
// must live until the use above.
runtime.KeepAlive(n) // escapes: replaced by intrinsic.
return length, err
}
// WriteTo implements io.WriterTo.WriteTo.
func (n *nfNATTarget) WriteTo(writer io.Writer) (int64, error) {
if !n.Range.Packed() && n.Target.Packed() {
// Type nfNATTarget doesn't have a packed layout in memory, fall back to MarshalBytes.
buf := make([]byte, n.SizeBytes())
n.MarshalBytes(buf)
length, err := writer.Write(buf)
return int64(length), err
}
// Construct a slice backed by dst's underlying memory.
var buf []byte
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(n)))
hdr.Len = n.SizeBytes()
hdr.Cap = n.SizeBytes()
length, err := writer.Write(buf)
// Since we bypassed the compiler's escape analysis, indicate that n
// must live until the use above.
runtime.KeepAlive(n) // escapes: replaced by intrinsic.
return int64(length), err
}