github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/strace/syscalls.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 import "fmt" 18 19 // FormatSpecifier values describe how an individual syscall argument should be 20 // formatted. 21 type FormatSpecifier int 22 23 // Valid FormatSpecifiers. 24 // 25 // Unless otherwise specified, values are formatted before syscall execution 26 // and not updated after syscall execution (the same value is output). 27 const ( 28 // Hex is just a hexadecimal number. 29 Hex FormatSpecifier = iota 30 31 // Oct is just an octal number. 32 Oct 33 34 // ReadBuffer is a buffer for a read-style call. The syscall return 35 // value is used for the length. 36 // 37 // Formatted after syscall execution. 38 ReadBuffer 39 40 // WriteBuffer is a buffer for a write-style call. The following arg is 41 // used for the length. 42 // 43 // Contents omitted after syscall execution. 44 WriteBuffer 45 46 // ReadIOVec is a pointer to a struct iovec for a writev-style call. 47 // The following arg is used for the length. The return value is used 48 // for the total length. 49 // 50 // Complete contents only formatted after syscall execution. 51 ReadIOVec 52 53 // WriteIOVec is a pointer to a struct iovec for a writev-style call. 54 // The following arg is used for the length. 55 // 56 // Complete contents only formatted before syscall execution, omitted 57 // after. 58 WriteIOVec 59 60 // IOVec is a generic pointer to a struct iovec. Contents are not dumped. 61 IOVec 62 63 // SendMsgHdr is a pointer to a struct msghdr for a sendmsg-style call. 64 // Contents formatted only before syscall execution, omitted after. 65 SendMsgHdr 66 67 // RecvMsgHdr is a pointer to a struct msghdr for a recvmsg-style call. 68 // Contents formatted only after syscall execution. 69 RecvMsgHdr 70 71 // Path is a pointer to a char* path. 72 Path 73 74 // PostPath is a pointer to a char* path, formatted after syscall 75 // execution. 76 PostPath 77 78 // ExecveStringVector is a NULL-terminated array of strings. Enforces 79 // the maximum execve array length. 80 ExecveStringVector 81 82 // PipeFDs is an array of two FDs, formatted after syscall execution. 83 PipeFDs 84 85 // Uname is a pointer to a struct uname, formatted after syscall execution. 86 Uname 87 88 // Stat is a pointer to a struct stat, formatted after syscall execution. 89 Stat 90 91 // SockAddr is a pointer to a struct sockaddr. The following arg is 92 // used for length. 93 SockAddr 94 95 // PostSockAddr is a pointer to a struct sockaddr, formatted after 96 // syscall execution. The following arg is a pointer to the socklen_t 97 // length. 98 PostSockAddr 99 100 // SockLen is a pointer to a socklen_t, formatted before and after 101 // syscall execution. 102 SockLen 103 104 // SockFamily is a socket protocol family value. 105 SockFamily 106 107 // SockType is a socket type and flags value. 108 SockType 109 110 // SockProtocol is a socket protocol value. Argument n-2 is the socket 111 // protocol family. 112 SockProtocol 113 114 // SockFlags are socket flags. 115 SockFlags 116 117 // Timespec is a pointer to a struct timespec. 118 Timespec 119 120 // PostTimespec is a pointer to a struct timespec, formatted after 121 // syscall execution. 122 PostTimespec 123 124 // UTimeTimespec is a pointer to a struct timespec. Formatting includes 125 // UTIME_NOW and UTIME_OMIT. 126 UTimeTimespec 127 128 // ItimerVal is a pointer to a struct itimerval. 129 ItimerVal 130 131 // PostItimerVal is a pointer to a struct itimerval, formatted after 132 // syscall execution. 133 PostItimerVal 134 135 // ItimerSpec is a pointer to a struct itimerspec. 136 ItimerSpec 137 138 // PostItimerSpec is a pointer to a struct itimerspec, formatted after 139 // syscall execution. 140 PostItimerSpec 141 142 // Timeval is a pointer to a struct timeval, formatted before and after 143 // syscall execution. 144 Timeval 145 146 // Utimbuf is a pointer to a struct utimbuf. 147 Utimbuf 148 149 // Rusage is a struct rusage, formatted after syscall execution. 150 Rusage 151 152 // CloneFlags are clone(2) flags. 153 CloneFlags 154 155 // OpenFlags are open(2) flags. 156 OpenFlags 157 158 // Mode is a mode_t. 159 Mode 160 161 // FutexOp is the futex(2) operation. 162 FutexOp 163 164 // PtraceRequest is the ptrace(2) request. 165 PtraceRequest 166 167 // ItimerType is an itimer type (ITIMER_REAL, etc). 168 ItimerType 169 ) 170 171 // defaultFormat is the syscall argument format to use if the actual format is 172 // not known. It formats all six arguments as hex. 173 var defaultFormat = []FormatSpecifier{Hex, Hex, Hex, Hex, Hex, Hex} 174 175 func defaultSyscallInfo(sysno int) *SyscallInfo { 176 return &SyscallInfo{name: fmt.Sprintf("%d", sysno), format: defaultFormat} 177 } 178 179 // SyscallInfo captures the name and printing format of a syscall. 180 type SyscallInfo struct { 181 // name is the name of the syscall. 182 name string 183 184 // format contains the format specifiers for each argument. 185 // 186 // Syscall calls can have up to six arguments. Arguments without a 187 // corresponding entry in format will not be printed. 188 format []FormatSpecifier 189 } 190 191 // makeSyscallInfo returns a SyscallInfo for a syscall. 192 func makeSyscallInfo(name string, f ...FormatSpecifier) SyscallInfo { 193 return SyscallInfo{name: name, format: f} 194 } 195 196 // SyscallMap maps syscalls into names and printing formats. 197 type SyscallMap map[uintptr]SyscallInfo