2009-11-14 16:29:09 -07:00
|
|
|
#!/usr/bin/env bash
|
2009-06-01 23:14:57 -06:00
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
# The syscall package provides access to the raw system call
|
|
|
|
# interface of the underlying operating system. Porting Go to
|
|
|
|
# a new architecture/operating system combination requires
|
|
|
|
# some manual effort, though there are tools that automate
|
|
|
|
# much of the process. The auto-generated files have names
|
|
|
|
# beginning with z.
|
|
|
|
#
|
2009-11-01 12:13:27 -07:00
|
|
|
# This script runs or (given -n) prints suggested commands to generate z files
|
2009-06-01 23:14:57 -06:00
|
|
|
# for the current system. Running those commands is not automatic.
|
|
|
|
# This script is documentation more than anything else.
|
|
|
|
#
|
|
|
|
# * asm_${GOOS}_${GOARCH}.s
|
|
|
|
#
|
|
|
|
# This hand-written assembly file implements system call dispatch.
|
|
|
|
# There are three entry points:
|
|
|
|
#
|
|
|
|
# func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
|
|
|
|
# func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
|
|
|
|
# func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
|
|
|
|
#
|
|
|
|
# The first and second are the standard ones; they differ only in
|
|
|
|
# how many arguments can be passed to the kernel.
|
|
|
|
# The third is for low-level use by the ForkExec wrapper;
|
|
|
|
# unlike the first two, it does not call into the scheduler to
|
|
|
|
# let it know that a system call is running.
|
|
|
|
#
|
|
|
|
# * syscall_${GOOS}.go
|
|
|
|
#
|
|
|
|
# This hand-written Go file implements system calls that need
|
|
|
|
# special handling and lists "//sys" comments giving prototypes
|
|
|
|
# for ones that can be auto-generated. Mksyscall reads those
|
|
|
|
# comments to generate the stubs.
|
|
|
|
#
|
|
|
|
# * syscall_${GOOS}_${GOARCH}.go
|
|
|
|
#
|
|
|
|
# Same as syscall_${GOOS}.go except that it contains code specific
|
|
|
|
# to ${GOOS} on one particular architecture.
|
|
|
|
#
|
|
|
|
# * types_${GOOS}.c
|
|
|
|
#
|
|
|
|
# This hand-written C file includes standard C headers and then
|
|
|
|
# creates typedef or enum names beginning with a dollar sign
|
|
|
|
# (use of $ in variable names is a gcc extension). The hardest
|
|
|
|
# part about preparing this file is figuring out which headers to
|
|
|
|
# include and which symbols need to be #defined to get the
|
|
|
|
# actual data structures that pass through to the kernel system calls.
|
|
|
|
# Some C libraries present alternate versions for binary compatibility
|
|
|
|
# and translate them on the way in and out of system calls, but
|
|
|
|
# there is almost always a #define that can get the real ones.
|
|
|
|
# See types_darwin.c and types_linux.c for examples.
|
|
|
|
#
|
|
|
|
# * zerror_${GOOS}_${GOARCH}.go
|
|
|
|
#
|
|
|
|
# This machine-generated file defines the system's error numbers,
|
2009-08-13 14:22:37 -06:00
|
|
|
# error strings, and signal numbers. The generator is "mkerrors.sh".
|
|
|
|
# Usually no arguments are needed, but mkerrors.sh will pass its
|
2009-06-01 23:14:57 -06:00
|
|
|
# arguments on to godefs.
|
|
|
|
#
|
|
|
|
# * zsyscall_${GOOS}_${GOARCH}.go
|
|
|
|
#
|
2011-03-21 14:02:10 -06:00
|
|
|
# Generated by mksyscall.pl; see syscall_${GOOS}.go above.
|
2009-06-01 23:14:57 -06:00
|
|
|
#
|
|
|
|
# * zsysnum_${GOOS}_${GOARCH}.go
|
|
|
|
#
|
|
|
|
# Generated by mksysnum_${GOOS}.
|
|
|
|
#
|
|
|
|
# * ztypes_${GOOS}_${GOARCH}.go
|
|
|
|
#
|
|
|
|
# Generated by godefs; see types_${GOOS}.c above.
|
|
|
|
|
|
|
|
GOOSARCH="${GOOS}_${GOARCH}"
|
|
|
|
|
|
|
|
# defaults
|
2011-03-21 14:02:10 -06:00
|
|
|
mksyscall="./mksyscall.pl"
|
2010-03-17 21:07:14 -06:00
|
|
|
mkerrors="./mkerrors.sh"
|
2011-07-06 18:40:45 -06:00
|
|
|
zerrors="zerrors_$GOOSARCH.go"
|
2011-11-17 05:13:49 -07:00
|
|
|
mksysctl=""
|
|
|
|
zsysctl="zsysctl_$GOOSARCH.go"
|
2014-03-10 23:36:14 -06:00
|
|
|
mksysnum=
|
|
|
|
mktypes=
|
2009-11-01 12:13:27 -07:00
|
|
|
run="sh"
|
|
|
|
|
|
|
|
case "$1" in
|
2011-04-06 15:52:02 -06:00
|
|
|
-syscalls)
|
|
|
|
for i in zsyscall*go
|
|
|
|
do
|
2012-07-29 15:59:14 -06:00
|
|
|
sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
|
|
|
|
rm _$i
|
2011-04-06 15:52:02 -06:00
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
;;
|
2009-11-01 12:13:27 -07:00
|
|
|
-n)
|
|
|
|
run="cat"
|
|
|
|
shift
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "$#" in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo 'usage: mkall.sh [-n]' 1>&2
|
|
|
|
exit 2
|
|
|
|
esac
|
2009-06-01 23:14:57 -06:00
|
|
|
|
2014-08-12 17:49:31 -06:00
|
|
|
GOOSARCH_in=syscall_$GOOSARCH.go
|
2009-06-01 23:14:57 -06:00
|
|
|
case "$GOOSARCH" in
|
|
|
|
_* | *_ | _)
|
|
|
|
echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
2011-12-16 03:51:25 -07:00
|
|
|
darwin_386)
|
2011-11-10 17:08:28 -07:00
|
|
|
mkerrors="$mkerrors -m32"
|
2011-03-21 14:02:10 -06:00
|
|
|
mksyscall="./mksyscall.pl -l32"
|
2011-12-16 03:51:25 -07:00
|
|
|
mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2009-11-18 00:58:51 -07:00
|
|
|
;;
|
2011-12-16 03:51:25 -07:00
|
|
|
darwin_amd64)
|
2011-11-10 17:08:28 -07:00
|
|
|
mkerrors="$mkerrors -m64"
|
2011-12-16 03:51:25 -07:00
|
|
|
mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2009-11-14 16:29:09 -07:00
|
|
|
;;
|
2013-08-31 10:32:07 -06:00
|
|
|
dragonfly_386)
|
|
|
|
mkerrors="$mkerrors -m32"
|
|
|
|
mksyscall="./mksyscall.pl -l32 -dragonfly"
|
|
|
|
mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
|
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
|
|
|
;;
|
2013-08-23 09:51:25 -06:00
|
|
|
dragonfly_amd64)
|
|
|
|
mkerrors="$mkerrors -m64"
|
|
|
|
mksyscall="./mksyscall.pl -dragonfly"
|
|
|
|
mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
|
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
|
|
|
;;
|
2011-12-16 03:51:25 -07:00
|
|
|
freebsd_386)
|
2011-11-10 17:08:28 -07:00
|
|
|
mkerrors="$mkerrors -m32"
|
2011-03-21 14:02:10 -06:00
|
|
|
mksyscall="./mksyscall.pl -l32"
|
2014-03-03 17:26:01 -07:00
|
|
|
mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2009-06-01 23:14:57 -06:00
|
|
|
;;
|
2011-12-16 03:51:25 -07:00
|
|
|
freebsd_amd64)
|
2011-11-10 17:08:28 -07:00
|
|
|
mkerrors="$mkerrors -m64"
|
2014-03-03 17:26:01 -07:00
|
|
|
mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
|
2012-10-12 02:26:42 -06:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
|
|
|
;;
|
|
|
|
freebsd_arm)
|
|
|
|
mkerrors="$mkerrors"
|
|
|
|
mksyscall="./mksyscall.pl -l32 -arm"
|
2014-03-03 17:26:01 -07:00
|
|
|
mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
|
2014-02-06 18:23:53 -07:00
|
|
|
# Let the type of C char be singed for making the bare syscall
|
|
|
|
# API consistent across over platforms.
|
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
|
2009-06-01 23:14:57 -06:00
|
|
|
;;
|
2009-06-04 14:33:40 -06:00
|
|
|
linux_386)
|
2011-11-10 17:08:28 -07:00
|
|
|
mkerrors="$mkerrors -m32"
|
2011-03-21 14:02:10 -06:00
|
|
|
mksyscall="./mksyscall.pl -l32"
|
|
|
|
mksysnum="./mksysnum_linux.pl /usr/include/asm/unistd_32.h"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2009-06-04 14:33:40 -06:00
|
|
|
;;
|
2009-06-01 23:14:57 -06:00
|
|
|
linux_amd64)
|
2012-12-11 10:03:18 -07:00
|
|
|
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)
|
|
|
|
if [ "$unistd_h" = "" ]; then
|
|
|
|
echo >&2 cannot find unistd_64.h
|
|
|
|
exit 1
|
|
|
|
fi
|
2011-11-10 17:08:28 -07:00
|
|
|
mkerrors="$mkerrors -m64"
|
2012-12-11 10:03:18 -07:00
|
|
|
mksysnum="./mksysnum_linux.pl $unistd_h"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2009-06-01 23:14:57 -06:00
|
|
|
;;
|
2009-10-01 07:55:01 -06:00
|
|
|
linux_arm)
|
2010-08-23 04:25:14 -06:00
|
|
|
mkerrors="$mkerrors"
|
syscall: fix mkall.sh, mksyscall_linux.pl, and regen for Linux/ARM
CL 3075041 says ARM is not little-endian, but my test suggests otherwise.
My test program is:
package main
import ("fmt"; "syscall"; "os")
func main() {
err := syscall.Fallocate(1, 1/*FALLOC_FL_KEEP_SIZE*/, 0, int64(40960));
fmt.Fprintln(os.Stderr, err)
}
Without this CL, ./test > testfile will show: file too large; and strace shows:
fallocate(1, 01, 0, 175921860444160) = -1 EFBIG (File too large)
With this CL, ./test > testfile will show: <nil>; and strace shows:
fallocate(1, 01, 0, 40960) = 0
Quoting rsc:
"[It turns out that] ARM syscall ABI requires 64-bit arguments to use an
(even, odd) register pair, not an (odd, even) pair. Switching to "big-endian"
worked because it ended up using the high 32-bits (always zero in the tests
we had) as the padding word, because the 64-bit argument was the last one,
and because we fill in zeros for the rest of the system call arguments, up to
six. So it happened to work."
I updated mksyscall_linux.pl to accommodate the register pair ABI requirement,
and removed all hand-tweaked syscall routines in favor of the auto-generated
ones. These including: Ftruncate, Truncate, Pread and Pwrite.
Some recent Linux/ARM distributions do not bundle kernel asm headers,
so instead we always get latest asm/unistd.h from git.kernel.org (just like
what we do for FreeBSD).
R=ken, r, rsc, r, dave, iant
CC=golang-dev
https://golang.org/cl/5726051
2012-03-05 12:12:11 -07:00
|
|
|
mksyscall="./mksyscall.pl -l32 -arm"
|
2013-08-21 16:59:48 -06:00
|
|
|
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"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2009-10-01 07:55:01 -06:00
|
|
|
;;
|
2014-12-05 17:13:20 -07:00
|
|
|
linux_ppc64)
|
|
|
|
GOOSARCH_in=syscall_linux_ppc64x.go
|
2014-08-12 17:49:31 -06:00
|
|
|
unistd_h=/usr/include/asm/unistd.h
|
|
|
|
mkerrors="$mkerrors -m64"
|
|
|
|
mksysnum="./mksysnum_linux.pl $unistd_h"
|
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
|
|
|
;;
|
2014-12-05 17:13:20 -07:00
|
|
|
linux_ppc64le)
|
|
|
|
GOOSARCH_in=syscall_linux_ppc64x.go
|
2014-08-12 17:49:31 -06:00
|
|
|
unistd_h=/usr/include/powerpc64le-linux-gnu/asm/unistd.h
|
|
|
|
mkerrors="$mkerrors -m64"
|
|
|
|
mksysnum="./mksysnum_linux.pl $unistd_h"
|
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
|
|
|
;;
|
all: merge NaCl branch (part 1)
See golang.org/s/go13nacl for design overview.
This CL is the mostly mechanical changes from rsc's Go 1.2 based NaCl branch, specifically 39cb35750369 to 500771b477cf from https://code.google.com/r/rsc-go13nacl. This CL does not include working NaCl support, there are probably two or three more large merges to come.
CL 15750044 is not included as it involves more invasive changes to the linker which will need to be merged separately.
The exact change lists included are
15050047: syscall: support for Native Client
15360044: syscall: unzip implementation for Native Client
15370044: syscall: Native Client SRPC implementation
15400047: cmd/dist, cmd/go, go/build, test: support for Native Client
15410048: runtime: support for Native Client
15410049: syscall: file descriptor table for Native Client
15410050: syscall: in-memory file system for Native Client
15440048: all: update +build lines for Native Client port
15540045: cmd/6g, cmd/8g, cmd/gc: support for Native Client
15570045: os: support for Native Client
15680044: crypto/..., hash/crc32, reflect, sync/atomic: support for amd64p32
15690044: net: support for Native Client
15690048: runtime: support for fake time like on Go Playground
15690051: build: disable various tests on Native Client
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/68150047
2014-02-25 07:47:42 -07:00
|
|
|
nacl_386)
|
|
|
|
mkerrors=""
|
|
|
|
mksyscall="./mksyscall.pl -l32 -nacl"
|
|
|
|
mksysnum=""
|
|
|
|
mktypes=""
|
|
|
|
;;
|
|
|
|
nacl_amd64p32)
|
|
|
|
mkerrors=""
|
|
|
|
mksyscall="./mksyscall.pl -nacl"
|
|
|
|
mksysnum=""
|
|
|
|
mktypes=""
|
|
|
|
;;
|
2011-12-19 09:57:58 -07:00
|
|
|
netbsd_386)
|
|
|
|
mkerrors="$mkerrors -m32"
|
|
|
|
mksyscall="./mksyscall.pl -l32 -netbsd"
|
|
|
|
mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2011-12-19 09:57:58 -07:00
|
|
|
;;
|
|
|
|
netbsd_amd64)
|
|
|
|
mkerrors="$mkerrors -m64"
|
|
|
|
mksyscall="./mksyscall.pl -netbsd"
|
|
|
|
mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2011-12-19 09:57:58 -07:00
|
|
|
;;
|
2011-08-29 08:04:28 -06:00
|
|
|
openbsd_386)
|
2011-11-10 17:08:28 -07:00
|
|
|
mkerrors="$mkerrors -m32"
|
2011-08-29 08:04:28 -06:00
|
|
|
mksyscall="./mksyscall.pl -l32 -openbsd"
|
2011-11-17 05:13:49 -07:00
|
|
|
mksysctl="./mksysctl_openbsd.pl"
|
|
|
|
zsysctl="zsysctl_openbsd.go"
|
2015-02-15 08:28:39 -07:00
|
|
|
mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2011-08-29 08:04:28 -06:00
|
|
|
;;
|
2011-08-22 21:24:32 -06:00
|
|
|
openbsd_amd64)
|
2011-11-10 17:08:28 -07:00
|
|
|
mkerrors="$mkerrors -m64"
|
2011-08-22 21:24:32 -06:00
|
|
|
mksyscall="./mksyscall.pl -openbsd"
|
2011-11-17 05:13:49 -07:00
|
|
|
mksysctl="./mksysctl_openbsd.pl"
|
|
|
|
zsysctl="zsysctl_openbsd.go"
|
2015-02-15 08:28:39 -07:00
|
|
|
mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
|
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
|
|
|
;;
|
|
|
|
openbsd_arm)
|
|
|
|
mkerrors="$mkerrors"
|
|
|
|
mksyscall="./mksyscall.pl -l32 -openbsd -arm"
|
|
|
|
mksysctl="./mksysctl_openbsd.pl"
|
|
|
|
zsysctl="zsysctl_openbsd.go"
|
|
|
|
mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
|
2012-02-02 20:22:40 -07:00
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
2011-08-22 21:24:32 -06:00
|
|
|
;;
|
2011-12-16 03:51:25 -07:00
|
|
|
plan9_386)
|
|
|
|
mkerrors=
|
|
|
|
mksyscall="./mksyscall.pl -l32 -plan9"
|
|
|
|
mksysnum="./mksysnum_plan9.sh /n/sources/plan9/sys/src/libc/9syscall/sys.h"
|
|
|
|
mktypes="XXX"
|
|
|
|
;;
|
syscall: add support for GOOS=solaris
These are only the new files, autogenerated files are in a
different CL to keep the size down.
LGTM=dave, minux.ma, jsing
R=golang-codereviews, dave, jsing, gobot, minux.ma, rsc, iant, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/36000043
2014-02-25 03:12:10 -07:00
|
|
|
solaris_amd64)
|
|
|
|
mksyscall="./mksyscall_solaris.pl"
|
|
|
|
mkerrors="$mkerrors -m64"
|
|
|
|
mksysnum=
|
|
|
|
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
|
|
|
;;
|
2014-03-10 23:36:14 -06:00
|
|
|
windows_*)
|
2014-12-21 22:54:07 -07:00
|
|
|
echo 'run "go generate syscall_windows.go" instead' 1>&2
|
|
|
|
exit 1
|
2011-12-16 03:51:25 -07:00
|
|
|
;;
|
2009-06-01 23:14:57 -06:00
|
|
|
*)
|
|
|
|
echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-11-01 12:13:27 -07:00
|
|
|
(
|
2011-07-06 18:40:45 -06:00
|
|
|
if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
|
2014-12-21 22:54:07 -07:00
|
|
|
syscall_goos="syscall_$GOOS.go"
|
|
|
|
case "$GOOS" in
|
|
|
|
darwin | dragonfly | freebsd | netbsd | openbsd)
|
|
|
|
syscall_goos="syscall_bsd.go $syscall_goos"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ -n "$mksyscall" ]; then echo "$mksyscall $syscall_goos syscall_$GOOSARCH.go |gofmt >zsyscall_$GOOSARCH.go"; fi
|
2011-11-17 05:13:49 -07:00
|
|
|
if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
|
2010-03-17 00:10:07 -06:00
|
|
|
if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
|
2011-11-10 17:08:28 -07:00
|
|
|
if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go |gofmt >ztypes_$GOOSARCH.go"; fi
|
2009-11-01 12:13:27 -07:00
|
|
|
) | $run
|