github.com/ccccaoqing/test@v0.0.0-20220510085219-3985d23445c0/src/syscall/mkall.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2009 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 # The syscall package provides access to the raw system call 7 # interface of the underlying operating system. Porting Go to 8 # a new architecture/operating system combination requires 9 # some manual effort, though there are tools that automate 10 # much of the process. The auto-generated files have names 11 # beginning with z. 12 # 13 # This script runs or (given -n) prints suggested commands to generate z files 14 # for the current system. Running those commands is not automatic. 15 # This script is documentation more than anything else. 16 # 17 # * asm_${GOOS}_${GOARCH}.s 18 # 19 # This hand-written assembly file implements system call dispatch. 20 # There are three entry points: 21 # 22 # func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr); 23 # func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr); 24 # func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr); 25 # 26 # The first and second are the standard ones; they differ only in 27 # how many arguments can be passed to the kernel. 28 # The third is for low-level use by the ForkExec wrapper; 29 # unlike the first two, it does not call into the scheduler to 30 # let it know that a system call is running. 31 # 32 # * syscall_${GOOS}.go 33 # 34 # This hand-written Go file implements system calls that need 35 # special handling and lists "//sys" comments giving prototypes 36 # for ones that can be auto-generated. Mksyscall reads those 37 # comments to generate the stubs. 38 # 39 # * syscall_${GOOS}_${GOARCH}.go 40 # 41 # Same as syscall_${GOOS}.go except that it contains code specific 42 # to ${GOOS} on one particular architecture. 43 # 44 # * types_${GOOS}.c 45 # 46 # This hand-written C file includes standard C headers and then 47 # creates typedef or enum names beginning with a dollar sign 48 # (use of $ in variable names is a gcc extension). The hardest 49 # part about preparing this file is figuring out which headers to 50 # include and which symbols need to be #defined to get the 51 # actual data structures that pass through to the kernel system calls. 52 # Some C libraries present alternate versions for binary compatibility 53 # and translate them on the way in and out of system calls, but 54 # there is almost always a #define that can get the real ones. 55 # See types_darwin.c and types_linux.c for examples. 56 # 57 # * zerror_${GOOS}_${GOARCH}.go 58 # 59 # This machine-generated file defines the system's error numbers, 60 # error strings, and signal numbers. The generator is "mkerrors.sh". 61 # Usually no arguments are needed, but mkerrors.sh will pass its 62 # arguments on to godefs. 63 # 64 # * zsyscall_${GOOS}_${GOARCH}.go 65 # 66 # Generated by mksyscall.pl; see syscall_${GOOS}.go above. 67 # 68 # * zsysnum_${GOOS}_${GOARCH}.go 69 # 70 # Generated by mksysnum_${GOOS}. 71 # 72 # * ztypes_${GOOS}_${GOARCH}.go 73 # 74 # Generated by godefs; see types_${GOOS}.c above. 75 76 GOOSARCH="${GOOS}_${GOARCH}" 77 78 # defaults 79 mksyscall="./mksyscall.pl" 80 mkerrors="./mkerrors.sh" 81 zerrors="zerrors_$GOOSARCH.go" 82 mksysctl="" 83 zsysctl="zsysctl_$GOOSARCH.go" 84 mksysnum= 85 mktypes= 86 run="sh" 87 88 case "$1" in 89 -syscalls) 90 for i in zsyscall*go 91 do 92 sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i 93 rm _$i 94 done 95 exit 0 96 ;; 97 -n) 98 run="cat" 99 shift 100 esac 101 102 case "$#" in 103 0) 104 ;; 105 *) 106 echo 'usage: mkall.sh [-n]' 1>&2 107 exit 2 108 esac 109 110 case "$GOOSARCH" in 111 _* | *_ | _) 112 echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2 113 exit 1 114 ;; 115 darwin_386) 116 mkerrors="$mkerrors -m32" 117 mksyscall="./mksyscall.pl -l32" 118 mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h" 119 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 120 ;; 121 darwin_amd64) 122 mkerrors="$mkerrors -m64" 123 mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h" 124 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 125 ;; 126 dragonfly_386) 127 mkerrors="$mkerrors -m32" 128 mksyscall="./mksyscall.pl -l32 -dragonfly" 129 mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl" 130 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 131 ;; 132 dragonfly_amd64) 133 mkerrors="$mkerrors -m64" 134 mksyscall="./mksyscall.pl -dragonfly" 135 mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl" 136 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 137 ;; 138 freebsd_386) 139 mkerrors="$mkerrors -m32" 140 mksyscall="./mksyscall.pl -l32" 141 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl" 142 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 143 ;; 144 freebsd_amd64) 145 mkerrors="$mkerrors -m64" 146 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl" 147 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 148 ;; 149 freebsd_arm) 150 mkerrors="$mkerrors" 151 mksyscall="./mksyscall.pl -l32 -arm" 152 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl" 153 # Let the type of C char be singed for making the bare syscall 154 # API consistent across over platforms. 155 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char" 156 ;; 157 linux_386) 158 mkerrors="$mkerrors -m32" 159 mksyscall="./mksyscall.pl -l32" 160 mksysnum="./mksysnum_linux.pl /usr/include/asm/unistd_32.h" 161 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 162 ;; 163 linux_amd64) 164 unistd_h=$(ls -1 /usr/include/asm/unistd_64.h /usr/include/x86_64-linux-gnu/asm/unistd_64.h 2>/dev/null | head -1) 165 if [ "$unistd_h" = "" ]; then 166 echo >&2 cannot find unistd_64.h 167 exit 1 168 fi 169 mkerrors="$mkerrors -m64" 170 mksysnum="./mksysnum_linux.pl $unistd_h" 171 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 172 ;; 173 linux_arm) 174 mkerrors="$mkerrors" 175 mksyscall="./mksyscall.pl -l32 -arm" 176 mksysnum="curl -s 'http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/arch/arm/include/uapi/asm/unistd.h' | ./mksysnum_linux.pl" 177 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 178 ;; 179 nacl_386) 180 mkerrors="" 181 mksyscall="./mksyscall.pl -l32 -nacl" 182 mksysnum="" 183 mktypes="" 184 ;; 185 nacl_amd64p32) 186 mkerrors="" 187 mksyscall="./mksyscall.pl -nacl" 188 mksysnum="" 189 mktypes="" 190 ;; 191 netbsd_386) 192 mkerrors="$mkerrors -m32" 193 mksyscall="./mksyscall.pl -l32 -netbsd" 194 mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl" 195 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 196 ;; 197 netbsd_amd64) 198 mkerrors="$mkerrors -m64" 199 mksyscall="./mksyscall.pl -netbsd" 200 mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl" 201 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 202 ;; 203 openbsd_386) 204 mkerrors="$mkerrors -m32" 205 mksyscall="./mksyscall.pl -l32 -openbsd" 206 mksysctl="./mksysctl_openbsd.pl" 207 zsysctl="zsysctl_openbsd.go" 208 mksysnum="curl -s 'http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl" 209 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 210 ;; 211 openbsd_amd64) 212 mkerrors="$mkerrors -m64" 213 mksyscall="./mksyscall.pl -openbsd" 214 mksysctl="./mksysctl_openbsd.pl" 215 zsysctl="zsysctl_openbsd.go" 216 mksysnum="curl -s 'http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl" 217 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 218 ;; 219 plan9_386) 220 mkerrors= 221 mksyscall="./mksyscall.pl -l32 -plan9" 222 mksysnum="./mksysnum_plan9.sh /n/sources/plan9/sys/src/libc/9syscall/sys.h" 223 mktypes="XXX" 224 ;; 225 solaris_amd64) 226 mksyscall="./mksyscall_solaris.pl" 227 mkerrors="$mkerrors -m64" 228 mksysnum= 229 mktypes="GOARCH=$GOARCH go tool cgo -godefs" 230 ;; 231 windows_*) 232 mksyscall= 233 mkerrors= 234 zerrors= 235 ;; 236 *) 237 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2 238 exit 1 239 ;; 240 esac 241 242 ( 243 if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi 244 case "$GOOS" in 245 windows) 246 echo "GOOS= GOARCH= go build mksyscall_windows.go" 247 echo "./mksyscall_windows syscall_windows.go security_windows.go |gofmt >zsyscall_windows.go" 248 echo "rm -f ./mksyscall_windows" 249 ;; 250 *) 251 syscall_goos="syscall_$GOOS.go" 252 case "$GOOS" in 253 darwin | dragonfly | freebsd | netbsd | openbsd) 254 syscall_goos="syscall_bsd.go $syscall_goos" 255 ;; 256 esac 257 if [ -n "$mksyscall" ]; then echo "$mksyscall $syscall_goos syscall_$GOOSARCH.go |gofmt >zsyscall_$GOOSARCH.go"; fi 258 ;; 259 esac 260 if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi 261 if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi 262 if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go |gofmt >ztypes_$GOOSARCH.go"; fi 263 ) | $run