gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/strace/arch.go (about) 1 // Copyright 2018 Google LLC. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package strace 16 17 // SyscallArgument is an argument supplied to a syscall implementation. The 18 // methods used to access the arguments are named after the ***C type name*** and 19 // they convert to the closest Go type available. For example, Int() refers to a 20 // 32-bit signed integer argument represented in Go as an int32. 21 // 22 // Using the accessor methods guarantees that the conversion between types is 23 // correct, taking into account size and signedness (i.e., zero-extension vs 24 // signed-extension). 25 type SyscallArgument struct { 26 // Prefer to use accessor methods instead of 'Value' directly. 27 Value uintptr 28 } 29 30 // SyscallArguments represents the set of arguments passed to a syscall. 31 type SyscallArguments [6]SyscallArgument 32 33 // Pointer returns the usermem.Addr representation of a pointer argument. 34 func (a SyscallArgument) Pointer() Addr { 35 return Addr(a.Value) 36 } 37 38 // Int returns the int32 representation of a 32-bit signed integer argument. 39 func (a SyscallArgument) Int() int32 { 40 return int32(a.Value) 41 } 42 43 // Uint returns the uint32 representation of a 32-bit unsigned integer argument. 44 func (a SyscallArgument) Uint() uint32 { 45 return uint32(a.Value) 46 } 47 48 // Int64 returns the int64 representation of a 64-bit signed integer argument. 49 func (a SyscallArgument) Int64() int64 { 50 return int64(a.Value) 51 } 52 53 // Uint64 returns the uint64 representation of a 64-bit unsigned integer argument. 54 func (a SyscallArgument) Uint64() uint64 { 55 return uint64(a.Value) 56 } 57 58 // SizeT returns the uint representation of a size_t argument. 59 func (a SyscallArgument) SizeT() uint { 60 return uint(a.Value) 61 } 62 63 // ModeT returns the int representation of a mode_t argument. 64 func (a SyscallArgument) ModeT() uint { 65 return uint(uint16(a.Value)) 66 } 67 68 // From gvisor: 69 const ( 70 // ExecMaxTotalSize is the maximum length of all argv and envv entries. 71 // 72 // N.B. The behavior here is different than Linux. Linux provides a limit on 73 // individual arguments of 32 pages, and an aggregate limit of at least 32 pages 74 // but otherwise bounded by min(stack size / 4, 8 MB * 3 / 4). We don't implement 75 // any behavior based on the stack size, and instead provide a fixed hard-limit of 76 // 2 MB (which should work well given that 8 MB stack limits are common). 77 ExecMaxTotalSize = 2 * 1024 * 1024 78 79 // ExecMaxElemSize is the maximum length of a single argv or envv entry. 80 ExecMaxElemSize = 32 * 4096 81 )