github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/kernel/auth/auth_abi_autogen_unsafe.go (about) 1 // Automatically generated marshal implementation. See tools/go_marshal. 2 3 package auth 4 5 import ( 6 "github.com/nicocha30/gvisor-ligolo/pkg/gohacks" 7 "github.com/nicocha30/gvisor-ligolo/pkg/hostarch" 8 "github.com/nicocha30/gvisor-ligolo/pkg/marshal" 9 "io" 10 "reflect" 11 "runtime" 12 "unsafe" 13 ) 14 15 // Marshallable types used by this file. 16 var _ marshal.Marshallable = (*GID)(nil) 17 var _ marshal.Marshallable = (*UID)(nil) 18 19 // SizeBytes implements marshal.Marshallable.SizeBytes. 20 //go:nosplit 21 func (gid *GID) SizeBytes() int { 22 return 4 23 } 24 25 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 26 func (gid *GID) MarshalBytes(dst []byte) []byte { 27 hostarch.ByteOrder.PutUint32(dst[:4], uint32(*gid)) 28 return dst[4:] 29 } 30 31 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 32 func (gid *GID) UnmarshalBytes(src []byte) []byte { 33 *gid = GID(uint32(hostarch.ByteOrder.Uint32(src[:4]))) 34 return src[4:] 35 } 36 37 // Packed implements marshal.Marshallable.Packed. 38 //go:nosplit 39 func (gid *GID) Packed() bool { 40 // Scalar newtypes are always packed. 41 return true 42 } 43 44 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 45 func (gid *GID) MarshalUnsafe(dst []byte) []byte { 46 size := gid.SizeBytes() 47 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(gid), uintptr(size)) 48 return dst[size:] 49 } 50 51 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 52 func (gid *GID) UnmarshalUnsafe(src []byte) []byte { 53 size := gid.SizeBytes() 54 gohacks.Memmove(unsafe.Pointer(gid), unsafe.Pointer(&src[0]), uintptr(size)) 55 return src[size:] 56 } 57 58 // CopyOutN implements marshal.Marshallable.CopyOutN. 59 func (gid *GID) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 60 // Construct a slice backed by dst's underlying memory. 61 var buf []byte 62 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 63 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(gid))) 64 hdr.Len = gid.SizeBytes() 65 hdr.Cap = gid.SizeBytes() 66 67 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 68 // Since we bypassed the compiler's escape analysis, indicate that gid 69 // must live until the use above. 70 runtime.KeepAlive(gid) // escapes: replaced by intrinsic. 71 return length, err 72 } 73 74 // CopyOut implements marshal.Marshallable.CopyOut. 75 func (gid *GID) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 76 return gid.CopyOutN(cc, addr, gid.SizeBytes()) 77 } 78 79 // CopyIn implements marshal.Marshallable.CopyIn. 80 func (gid *GID) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 81 // Construct a slice backed by dst's underlying memory. 82 var buf []byte 83 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 84 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(gid))) 85 hdr.Len = gid.SizeBytes() 86 hdr.Cap = gid.SizeBytes() 87 88 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 89 // Since we bypassed the compiler's escape analysis, indicate that gid 90 // must live until the use above. 91 runtime.KeepAlive(gid) // escapes: replaced by intrinsic. 92 return length, err 93 } 94 95 // WriteTo implements io.WriterTo.WriteTo. 96 func (gid *GID) WriteTo(writer io.Writer) (int64, error) { 97 // Construct a slice backed by dst's underlying memory. 98 var buf []byte 99 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 100 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(gid))) 101 hdr.Len = gid.SizeBytes() 102 hdr.Cap = gid.SizeBytes() 103 104 length, err := writer.Write(buf) 105 // Since we bypassed the compiler's escape analysis, indicate that gid 106 // must live until the use above. 107 runtime.KeepAlive(gid) // escapes: replaced by intrinsic. 108 return int64(length), err 109 } 110 111 // CopyGIDSliceIn copies in a slice of GID objects from the task's memory. 112 func CopyGIDSliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []GID) (int, error) { 113 count := len(dst) 114 if count == 0 { 115 return 0, nil 116 } 117 size := (*GID)(nil).SizeBytes() 118 119 ptr := unsafe.Pointer(&dst) 120 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 121 122 // Construct a slice backed by dst's underlying memory. 123 var buf []byte 124 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 125 hdr.Data = uintptr(val) 126 hdr.Len = size * count 127 hdr.Cap = size * count 128 129 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 130 // Since we bypassed the compiler's escape analysis, indicate that dst 131 // must live until the use above. 132 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 133 return length, err 134 } 135 136 // CopyGIDSliceOut copies a slice of GID objects to the task's memory. 137 func CopyGIDSliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []GID) (int, error) { 138 count := len(src) 139 if count == 0 { 140 return 0, nil 141 } 142 size := (*GID)(nil).SizeBytes() 143 144 ptr := unsafe.Pointer(&src) 145 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 146 147 // Construct a slice backed by dst's underlying memory. 148 var buf []byte 149 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 150 hdr.Data = uintptr(val) 151 hdr.Len = size * count 152 hdr.Cap = size * count 153 154 length, err := cc.CopyOutBytes(addr, buf) // escapes: okay. 155 // Since we bypassed the compiler's escape analysis, indicate that src 156 // must live until the use above. 157 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 158 return length, err 159 } 160 161 // MarshalUnsafeGIDSlice is like GID.MarshalUnsafe, but for a []GID. 162 func MarshalUnsafeGIDSlice(src []GID, dst []byte) []byte { 163 count := len(src) 164 if count == 0 { 165 return dst 166 } 167 size := (*GID)(nil).SizeBytes() 168 169 buf := dst[:size*count] 170 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 171 return dst[size*count:] 172 } 173 174 // UnmarshalUnsafeGIDSlice is like GID.UnmarshalUnsafe, but for a []GID. 175 func UnmarshalUnsafeGIDSlice(dst []GID, src []byte) []byte { 176 count := len(dst) 177 if count == 0 { 178 return src 179 } 180 size := (*GID)(nil).SizeBytes() 181 182 buf := src[:size*count] 183 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 184 return src[size*count:] 185 } 186 187 // SizeBytes implements marshal.Marshallable.SizeBytes. 188 //go:nosplit 189 func (uid *UID) SizeBytes() int { 190 return 4 191 } 192 193 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 194 func (uid *UID) MarshalBytes(dst []byte) []byte { 195 hostarch.ByteOrder.PutUint32(dst[:4], uint32(*uid)) 196 return dst[4:] 197 } 198 199 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 200 func (uid *UID) UnmarshalBytes(src []byte) []byte { 201 *uid = UID(uint32(hostarch.ByteOrder.Uint32(src[:4]))) 202 return src[4:] 203 } 204 205 // Packed implements marshal.Marshallable.Packed. 206 //go:nosplit 207 func (uid *UID) Packed() bool { 208 // Scalar newtypes are always packed. 209 return true 210 } 211 212 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 213 func (uid *UID) MarshalUnsafe(dst []byte) []byte { 214 size := uid.SizeBytes() 215 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(uid), uintptr(size)) 216 return dst[size:] 217 } 218 219 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 220 func (uid *UID) UnmarshalUnsafe(src []byte) []byte { 221 size := uid.SizeBytes() 222 gohacks.Memmove(unsafe.Pointer(uid), unsafe.Pointer(&src[0]), uintptr(size)) 223 return src[size:] 224 } 225 226 // CopyOutN implements marshal.Marshallable.CopyOutN. 227 func (uid *UID) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 228 // Construct a slice backed by dst's underlying memory. 229 var buf []byte 230 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 231 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(uid))) 232 hdr.Len = uid.SizeBytes() 233 hdr.Cap = uid.SizeBytes() 234 235 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 236 // Since we bypassed the compiler's escape analysis, indicate that uid 237 // must live until the use above. 238 runtime.KeepAlive(uid) // escapes: replaced by intrinsic. 239 return length, err 240 } 241 242 // CopyOut implements marshal.Marshallable.CopyOut. 243 func (uid *UID) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 244 return uid.CopyOutN(cc, addr, uid.SizeBytes()) 245 } 246 247 // CopyIn implements marshal.Marshallable.CopyIn. 248 func (uid *UID) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 249 // Construct a slice backed by dst's underlying memory. 250 var buf []byte 251 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 252 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(uid))) 253 hdr.Len = uid.SizeBytes() 254 hdr.Cap = uid.SizeBytes() 255 256 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 257 // Since we bypassed the compiler's escape analysis, indicate that uid 258 // must live until the use above. 259 runtime.KeepAlive(uid) // escapes: replaced by intrinsic. 260 return length, err 261 } 262 263 // WriteTo implements io.WriterTo.WriteTo. 264 func (uid *UID) WriteTo(writer io.Writer) (int64, error) { 265 // Construct a slice backed by dst's underlying memory. 266 var buf []byte 267 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 268 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(uid))) 269 hdr.Len = uid.SizeBytes() 270 hdr.Cap = uid.SizeBytes() 271 272 length, err := writer.Write(buf) 273 // Since we bypassed the compiler's escape analysis, indicate that uid 274 // must live until the use above. 275 runtime.KeepAlive(uid) // escapes: replaced by intrinsic. 276 return int64(length), err 277 } 278