• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

.gitignoreD23-Nov-202316 32

README.mdD23-Nov-20238.1 KiB174130

affinity_linux.goD23-Nov-20233.2 KiB12571

asm_darwin_386.sD23-Nov-2023675 3011

asm_darwin_amd64.sD23-Nov-2023678 3011

asm_darwin_arm.sD23-Nov-2023686 3111

asm_darwin_arm64.sD23-Nov-2023691 3111

asm_dragonfly_amd64.sD23-Nov-2023681 3011

asm_freebsd_386.sD23-Nov-2023676 3011

asm_freebsd_amd64.sD23-Nov-2023679 3011

asm_freebsd_arm.sD23-Nov-2023666 3011

asm_linux_386.sD23-Nov-20231.4 KiB6640

asm_linux_amd64.sD23-Nov-20231.2 KiB5837

asm_linux_arm.sD23-Nov-20231.1 KiB5736

asm_linux_arm64.sD23-Nov-20231.1 KiB5335

asm_linux_mips64x.sD23-Nov-20231.1 KiB5735

asm_linux_mipsx.sD23-Nov-20231.1 KiB5532

asm_linux_ppc64x.sD23-Nov-20231.1 KiB5735

asm_linux_s390x.sD23-Nov-20231.1 KiB5735

asm_netbsd_386.sD23-Nov-2023675 3011

asm_netbsd_amd64.sD23-Nov-2023678 3011

asm_netbsd_arm.sD23-Nov-2023665 3011

asm_openbsd_386.sD23-Nov-2023676 3011

asm_openbsd_amd64.sD23-Nov-2023679 3011

asm_openbsd_arm.sD23-Nov-2023666 3011

asm_solaris_amd64.sD23-Nov-2023426 185

bluetooth_linux.goD23-Nov-2023655 3624

cap_freebsd.goD23-Nov-20235 KiB196148

constants.goD23-Nov-2023285 146

dev_darwin.goD23-Nov-2023747 2510

dev_dragonfly.goD23-Nov-20231 KiB3110

dev_freebsd.goD23-Nov-20231,013 3110

dev_linux.goD23-Nov-20231.5 KiB4318

dev_netbsd.goD23-Nov-2023913 3015

dev_openbsd.goD23-Nov-2023918 3015

dirent.goD23-Nov-2023620 185

endian_big.goD23-Nov-2023236 102

endian_little.goD23-Nov-2023266 102

env_unix.goD23-Nov-2023612 3217

errors_freebsd_386.goD23-Nov-20239.2 KiB228219

errors_freebsd_amd64.goD23-Nov-20239.2 KiB228219

errors_freebsd_arm.goD23-Nov-20238.8 KiB227219

fcntl.goD23-Nov-2023936 2914

fcntl_linux_32bit.goD23-Nov-2023388 144

gccgo.goD23-Nov-20231.9 KiB6240

gccgo_c.cD23-Nov-20231 KiB3924

gccgo_linux_amd64.goD23-Nov-2023429 2110

mkall.shD23-Nov-20236.1 KiB189162

mkerrors.shD23-Nov-202314.7 KiB605531

mkpost.goD23-Nov-20233.1 KiB9953

mksyscall.plD23-Nov-20238.4 KiB342270

mksyscall_solaris.plD23-Nov-20236.9 KiB290218

mksysctl_openbsd.plD23-Nov-20235.2 KiB265220

mksysnum_darwin.plD23-Nov-2023751 4024

mksysnum_dragonfly.plD23-Nov-20231 KiB5131

mksysnum_freebsd.plD23-Nov-20231 KiB5131

mksysnum_netbsd.plD23-Nov-20231.2 KiB5938

mksysnum_openbsd.plD23-Nov-20231 KiB5131

openbsd_pledge.goD23-Nov-2023891 3927

pagesize_unix.goD23-Nov-2023363 165

race.goD23-Nov-2023607 3118

race0.goD23-Nov-2023505 2613

sockcmsg_linux.goD23-Nov-20231 KiB3721

sockcmsg_unix.goD23-Nov-20232.9 KiB10571

str.goD23-Nov-2023611 2718

syscall.goD23-Nov-20232 KiB5518

syscall_bsd.goD23-Nov-202315.6 KiB625463

syscall_darwin.goD23-Nov-202318.4 KiB681249

syscall_darwin_386.goD23-Nov-20231.7 KiB6942

syscall_darwin_amd64.goD23-Nov-20231.6 KiB6942

syscall_darwin_arm.goD23-Nov-20231.7 KiB6742

syscall_darwin_arm64.goD23-Nov-20231.6 KiB6942

syscall_dragonfly.goD23-Nov-202313.3 KiB524163

syscall_dragonfly_amd64.goD23-Nov-20231.2 KiB5335

syscall_freebsd.goD23-Nov-202319.7 KiB757318

syscall_freebsd_386.goD23-Nov-20231.2 KiB5335

syscall_freebsd_amd64.goD23-Nov-20231.2 KiB5335

syscall_freebsd_arm.goD23-Nov-20231.2 KiB5335

syscall_linux.goD23-Nov-202341.5 KiB1,475850

syscall_linux_386.goD23-Nov-202310.5 KiB386271

syscall_linux_amd64.goD23-Nov-20235.5 KiB16372

syscall_linux_amd64_gc.goD23-Nov-2023297 143

syscall_linux_arm.goD23-Nov-20237.7 KiB260156

syscall_linux_arm64.goD23-Nov-20236.2 KiB213126

syscall_linux_gc.goD23-Nov-2023495 153

syscall_linux_gc_386.goD23-Nov-2023582 175

syscall_linux_gccgo_386.goD23-Nov-2023979 3120

syscall_linux_gccgo_arm.goD23-Nov-2023589 2112

syscall_linux_mips64x.goD23-Nov-20236.4 KiB215122

syscall_linux_mipsx.goD23-Nov-20237.1 KiB235131

syscall_linux_ppc64x.goD23-Nov-20235.1 KiB13244

syscall_linux_s390x.goD23-Nov-20239.9 KiB325231

syscall_linux_sparc64.goD23-Nov-20235.1 KiB14761

syscall_netbsd.goD23-Nov-202313.6 KiB569156

syscall_netbsd_386.goD23-Nov-2023735 3421

syscall_netbsd_amd64.goD23-Nov-2023730 3421

syscall_netbsd_arm.goD23-Nov-2023735 3421

syscall_openbsd.goD23-Nov-20239.9 KiB369134

syscall_openbsd_386.goD23-Nov-2023735 3421

syscall_openbsd_amd64.goD23-Nov-2023905 3822

syscall_openbsd_arm.goD23-Nov-2023735 3421

syscall_solaris.goD23-Nov-202320.6 KiB727459

syscall_solaris_amd64.goD23-Nov-2023509 2413

syscall_unix.goD23-Nov-20239.6 KiB395308

syscall_unix_gc.goD23-Nov-2023606 166

timestruct.goD23-Nov-20232.5 KiB8344

types_darwin.goD23-Nov-20235.5 KiB278120

types_dragonfly.goD23-Nov-20235.5 KiB281130

types_freebsd.goD23-Nov-20238.5 KiB403152

types_netbsd.goD23-Nov-20235.5 KiB282123

types_openbsd.goD23-Nov-20235.5 KiB283130

types_solaris.goD23-Nov-20235.7 KiB284128

zerrors_darwin_386.goD23-Nov-202372.8 KiB1,7841,765

zerrors_darwin_amd64.goD23-Nov-202372.8 KiB1,7841,765

zerrors_darwin_arm.goD23-Nov-202372.8 KiB1,7841,765

zerrors_darwin_arm64.goD23-Nov-202372.8 KiB1,7841,765

zerrors_dragonfly_amd64.goD23-Nov-202364.3 KiB1,5871,568

zerrors_freebsd_386.goD23-Nov-202368.7 KiB1,7651,746

zerrors_freebsd_amd64.goD23-Nov-202368.8 KiB1,7661,747

zerrors_freebsd_arm.goD23-Nov-202369 KiB1,7741,755

zerrors_linux_386.goD23-Nov-2023113.4 KiB2,6032,584

zerrors_linux_amd64.goD23-Nov-2023113.4 KiB2,6032,584

zerrors_linux_arm.goD23-Nov-2023113.6 KiB2,6092,590

zerrors_linux_arm64.goD23-Nov-2023113 KiB2,5942,575

zerrors_linux_mips.goD23-Nov-2023113.9 KiB2,6112,592

zerrors_linux_mips64.goD23-Nov-2023113.9 KiB2,6112,592

zerrors_linux_mips64le.goD23-Nov-2023113.9 KiB2,6112,592

zerrors_linux_mipsle.goD23-Nov-2023113.9 KiB2,6112,592

zerrors_linux_ppc64.goD23-Nov-2023116.3 KiB2,6642,645

zerrors_linux_ppc64le.goD23-Nov-2023116.3 KiB2,6642,645

zerrors_linux_s390x.goD23-Nov-2023116.1 KiB2,6632,644

zerrors_linux_sparc64.goD23-Nov-202383.9 KiB2,1432,124

zerrors_netbsd_386.goD23-Nov-202370.6 KiB1,7291,710

zerrors_netbsd_amd64.goD23-Nov-202370.2 KiB1,7191,700

zerrors_netbsd_arm.goD23-Nov-202369.7 KiB1,7081,689

zerrors_openbsd_386.goD23-Nov-202365.5 KiB1,6011,582

zerrors_openbsd_amd64.goD23-Nov-202369.9 KiB1,7071,688

zerrors_openbsd_arm.goD23-Nov-202365.5 KiB1,6031,584

zerrors_solaris_amd64.goD23-Nov-202356.7 KiB1,4981,479

zptrace386_linux.goD23-Nov-20231.8 KiB8162

zptracearm_linux.goD23-Nov-20231.2 KiB4223

zptracemips_linux.goD23-Nov-20231.4 KiB5132

zptracemipsle_linux.goD23-Nov-20231.4 KiB5132

zsyscall_darwin_386.goD23-Nov-202340 KiB1,7131,306

zsyscall_darwin_amd64.goD23-Nov-202339.8 KiB1,7131,306

zsyscall_darwin_arm.goD23-Nov-202340 KiB1,7131,306

zsyscall_darwin_arm64.goD23-Nov-202339.8 KiB1,7131,306

zsyscall_dragonfly_amd64.goD23-Nov-202335 KiB1,5091,132

zsyscall_freebsd_386.goD23-Nov-202346 KiB1,9381,483

zsyscall_freebsd_amd64.goD23-Nov-202345.8 KiB1,9381,483

zsyscall_freebsd_arm.goD23-Nov-202346 KiB1,9381,483

zsyscall_linux_386.goD23-Nov-202347.7 KiB2,0111,547

zsyscall_linux_amd64.goD23-Nov-202352.1 KiB2,1781,669

zsyscall_linux_arm.goD23-Nov-202350.8 KiB2,1131,622

zsyscall_linux_arm64.goD23-Nov-202348.5 KiB2,0201,550

zsyscall_linux_mips.goD23-Nov-202352.4 KiB2,1791,670

zsyscall_linux_mips64.goD23-Nov-202351.7 KiB2,1621,659

zsyscall_linux_mips64le.goD23-Nov-202351.8 KiB2,1621,659

zsyscall_linux_mipsle.goD23-Nov-202352.4 KiB2,1791,670

zsyscall_linux_ppc64.goD23-Nov-202353.2 KiB2,2251,704

zsyscall_linux_ppc64le.goD23-Nov-202353.3 KiB2,2251,704

zsyscall_linux_s390x.goD23-Nov-202347 KiB1,9951,537

zsyscall_linux_sparc64.goD23-Nov-202352.1 KiB2,1731,667

zsyscall_netbsd_386.goD23-Nov-202333.5 KiB1,4401,081

zsyscall_netbsd_amd64.goD23-Nov-202333.3 KiB1,4401,081

zsyscall_netbsd_arm.goD23-Nov-202333.5 KiB1,4401,081

zsyscall_openbsd_386.goD23-Nov-202335 KiB1,5091,132

zsyscall_openbsd_amd64.goD23-Nov-202334.8 KiB1,5091,132

zsyscall_openbsd_arm.goD23-Nov-202335 KiB1,5091,132

zsyscall_solaris_amd64.goD23-Nov-202345.5 KiB1,6981,304

zsysctl_openbsd_386.goD23-Nov-202311.7 KiB271265

zsysctl_openbsd_amd64.goD23-Nov-202311.1 KiB258250

zsysctl_openbsd_arm.goD23-Nov-202311.7 KiB271265

zsysnum_darwin_386.goD23-Nov-202317.7 KiB437430

zsysnum_darwin_amd64.goD23-Nov-202317.7 KiB437430

zsysnum_darwin_arm.goD23-Nov-202317.7 KiB437430

zsysnum_darwin_arm64.goD23-Nov-202317.7 KiB437430

zsysnum_dragonfly_amd64.goD23-Nov-202323.6 KiB316307

zsysnum_freebsd_386.goD23-Nov-202325 KiB354346

zsysnum_freebsd_amd64.goD23-Nov-202325 KiB354346

zsysnum_freebsd_arm.goD23-Nov-202325 KiB354346

zsysnum_linux_386.goD23-Nov-202312.7 KiB391384

zsysnum_linux_amd64.goD23-Nov-202311.1 KiB343336

zsysnum_linux_arm.goD23-Nov-202311.8 KiB363356

zsysnum_linux_arm64.goD23-Nov-20239.3 KiB287280

zsysnum_linux_mips.goD23-Nov-202312.7 KiB376369

zsysnum_linux_mips64.goD23-Nov-202311.3 KiB336329

zsysnum_linux_mips64le.goD23-Nov-202311.3 KiB336329

zsysnum_linux_mipsle.goD23-Nov-202312.7 KiB376369

zsysnum_linux_ppc64.goD23-Nov-202312.2 KiB374367

zsysnum_linux_ppc64le.goD23-Nov-202312.2 KiB374367

zsysnum_linux_s390x.goD23-Nov-202311 KiB336329

zsysnum_linux_sparc64.goD23-Nov-202311.4 KiB349342

zsysnum_netbsd_386.goD23-Nov-202325.6 KiB275268

zsysnum_netbsd_amd64.goD23-Nov-202325.6 KiB275268

zsysnum_netbsd_arm.goD23-Nov-202325.6 KiB275268

zsysnum_openbsd_386.goD23-Nov-202314 KiB208201

zsysnum_openbsd_amd64.goD23-Nov-202314.8 KiB218211

zsysnum_openbsd_arm.goD23-Nov-202314.5 KiB214207

ztypes_darwin_386.goD23-Nov-20237.2 KiB490426

ztypes_darwin_amd64.goD23-Nov-20237.3 KiB500436

ztypes_darwin_arm.goD23-Nov-20237.2 KiB491426

ztypes_darwin_arm64.goD23-Nov-20237.3 KiB500436

ztypes_dragonfly_amd64.goD23-Nov-20237.1 KiB487427

ztypes_freebsd_386.goD23-Nov-20238.6 KiB554487

ztypes_freebsd_amd64.goD23-Nov-20238.7 KiB557490

ztypes_freebsd_arm.goD23-Nov-20238.7 KiB557490

ztypes_linux_386.goD23-Nov-202346 KiB1,8471,706

ztypes_linux_amd64.goD23-Nov-202346.3 KiB1,8671,726

ztypes_linux_arm.goD23-Nov-202345.8 KiB1,8361,695

ztypes_linux_arm64.goD23-Nov-202346 KiB1,8461,705

ztypes_linux_mips.goD23-Nov-202345.9 KiB1,8411,700

ztypes_linux_mips64.goD23-Nov-202346 KiB1,8481,707

ztypes_linux_mips64le.goD23-Nov-202346 KiB1,8481,707

ztypes_linux_mipsle.goD23-Nov-202345.9 KiB1,8411,700

ztypes_linux_ppc64.goD23-Nov-202346.2 KiB1,8561,715

ztypes_linux_ppc64le.goD23-Nov-202346.2 KiB1,8561,715

ztypes_linux_s390x.goD23-Nov-202346.6 KiB1,8731,729

ztypes_linux_sparc64.goD23-Nov-202312 KiB691614

ztypes_netbsd_386.goD23-Nov-20236.6 KiB449387

ztypes_netbsd_amd64.goD23-Nov-20236.8 KiB456394

ztypes_netbsd_arm.goD23-Nov-20236.8 KiB454392

ztypes_openbsd_386.goD23-Nov-20237.2 KiB485424

ztypes_openbsd_amd64.goD23-Nov-20237.1 KiB485424

ztypes_openbsd_arm.goD23-Nov-20237.1 KiB478417

ztypes_solaris_amd64.goD23-Nov-20236.6 KiB460399

README.md

1# Building `sys/unix`
2
3The sys/unix package provides access to the raw system call interface of the
4underlying operating system. See: https://godoc.org/golang.org/x/sys/unix
5
6Porting Go to a new architecture/OS combination or adding syscalls, types, or
7constants to an existing architecture/OS pair requires some manual effort;
8however, there are tools that automate much of the process.
9
10## Build Systems
11
12There are currently two ways we generate the necessary files. We are currently
13migrating the build system to use containers so the builds are reproducible.
14This is being done on an OS-by-OS basis. Please update this documentation as
15components of the build system change.
16
17### Old Build System (currently for `GOOS != "Linux" || GOARCH == "sparc64"`)
18
19The old build system generates the Go files based on the C header files
20present on your system. This means that files
21for a given GOOS/GOARCH pair must be generated on a system with that OS and
22architecture. This also means that the generated code can differ from system
23to system, based on differences in the header files.
24
25To avoid this, if you are using the old build system, only generate the Go
26files on an installation with unmodified header files. It is also important to
27keep track of which version of the OS the files were generated from (ex.
28Darwin 14 vs Darwin 15). This makes it easier to track the progress of changes
29and have each OS upgrade correspond to a single change.
30
31To build the files for your current OS and architecture, make sure GOOS and
32GOARCH are set correctly and run `mkall.sh`. This will generate the files for
33your specific system. Running `mkall.sh -n` shows the commands that will be run.
34
35Requirements: bash, perl, go
36
37### New Build System (currently for `GOOS == "Linux" && GOARCH != "sparc64"`)
38
39The new build system uses a Docker container to generate the go files directly
40from source checkouts of the kernel and various system libraries. This means
41that on any platform that supports Docker, all the files using the new build
42system can be generated at once, and generated files will not change based on
43what the person running the scripts has installed on their computer.
44
45The OS specific files for the new build system are located in the `${GOOS}`
46directory, and the build is coordinated by the `${GOOS}/mkall.go` program. When
47the kernel or system library updates, modify the Dockerfile at
48`${GOOS}/Dockerfile` to checkout the new release of the source.
49
50To build all the files under the new build system, you must be on an amd64/Linux
51system and have your GOOS and GOARCH set accordingly. Running `mkall.sh` will
52then generate all of the files for all of the GOOS/GOARCH pairs in the new build
53system. Running `mkall.sh -n` shows the commands that will be run.
54
55Requirements: bash, perl, go, docker
56
57## Component files
58
59This section describes the various files used in the code generation process.
60It also contains instructions on how to modify these files to add a new
61architecture/OS or to add additional syscalls, types, or constants. Note that
62if you are using the new build system, the scripts cannot be called normally.
63They must be called from within the docker container.
64
65### asm files
66
67The hand-written assembly file at `asm_${GOOS}_${GOARCH}.s` implements system
68call dispatch. There are three entry points:
69```
70  func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
71  func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
72  func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
73```
74The first and second are the standard ones; they differ only in how many
75arguments can be passed to the kernel. The third is for low-level use by the
76ForkExec wrapper. Unlike the first two, it does not call into the scheduler to
77let it know that a system call is running.
78
79When porting Go to an new architecture/OS, this file must be implemented for
80each GOOS/GOARCH pair.
81
82### mksysnum
83
84Mksysnum is a script located at `${GOOS}/mksysnum.pl` (or `mksysnum_${GOOS}.pl`
85for the old system). This script takes in a list of header files containing the
86syscall number declarations and parses them to produce the corresponding list of
87Go numeric constants. See `zsysnum_${GOOS}_${GOARCH}.go` for the generated
88constants.
89
90Adding new syscall numbers is mostly done by running the build on a sufficiently
91new installation of the target OS (or updating the source checkouts for the
92new build system). However, depending on the OS, you make need to update the
93parsing in mksysnum.
94
95### mksyscall.pl
96
97The `syscall.go`, `syscall_${GOOS}.go`, `syscall_${GOOS}_${GOARCH}.go` are
98hand-written Go files which implement system calls (for unix, the specific OS,
99or the specific OS/Architecture pair respectively) that need special handling
100and list `//sys` comments giving prototypes for ones that can be generated.
101
102The mksyscall.pl script takes the `//sys` and `//sysnb` comments and converts
103them into syscalls. This requires the name of the prototype in the comment to
104match a syscall number in the `zsysnum_${GOOS}_${GOARCH}.go` file. The function
105prototype can be exported (capitalized) or not.
106
107Adding a new syscall often just requires adding a new `//sys` function prototype
108with the desired arguments and a capitalized name so it is exported. However, if
109you want the interface to the syscall to be different, often one will make an
110unexported `//sys` prototype, an then write a custom wrapper in
111`syscall_${GOOS}.go`.
112
113### types files
114
115For each OS, there is a hand-written Go file at `${GOOS}/types.go` (or
116`types_${GOOS}.go` on the old system). This file includes standard C headers and
117creates Go type aliases to the corresponding C types. The file is then fed
118through godef to get the Go compatible definitions. Finally, the generated code
119is fed though mkpost.go to format the code correctly and remove any hidden or
120private identifiers. This cleaned-up code is written to
121`ztypes_${GOOS}_${GOARCH}.go`.
122
123The hardest part about preparing this file is figuring out which headers to
124include and which symbols need to be `#define`d to get the actual data
125structures that pass through to the kernel system calls. Some C libraries
126preset alternate versions for binary compatibility and translate them on the
127way in and out of system calls, but there is almost always a `#define` that can
128get the real ones.
129See `types_darwin.go` and `linux/types.go` for examples.
130
131To add a new type, add in the necessary include statement at the top of the
132file (if it is not already there) and add in a type alias line. Note that if
133your type is significantly different on different architectures, you may need
134some `#if/#elif` macros in your include statements.
135
136### mkerrors.sh
137
138This script is used to generate the system's various constants. This doesn't
139just include the error numbers and error strings, but also the signal numbers
140an a wide variety of miscellaneous constants. The constants come from the list
141of include files in the `includes_${uname}` variable. A regex then picks out
142the desired `#define` statements, and generates the corresponding Go constants.
143The error numbers and strings are generated from `#include <errno.h>`, and the
144signal numbers and strings are generated from `#include <signal.h>`. All of
145these constants are written to `zerrors_${GOOS}_${GOARCH}.go` via a C program,
146`_errors.c`, which prints out all the constants.
147
148To add a constant, add the header that includes it to the appropriate variable.
149Then, edit the regex (if necessary) to match the desired constant. Avoid making
150the regex too broad to avoid matching unintended constants.
151
152
153## Generated files
154
155### `zerror_${GOOS}_${GOARCH}.go`
156
157A file containing all of the system's generated error numbers, error strings,
158signal numbers, and constants. Generated by `mkerrors.sh` (see above).
159
160### `zsyscall_${GOOS}_${GOARCH}.go`
161
162A file containing all the generated syscalls for a specific GOOS and GOARCH.
163Generated by `mksyscall.pl` (see above).
164
165### `zsysnum_${GOOS}_${GOARCH}.go`
166
167A list of numeric constants for all the syscall number of the specific GOOS
168and GOARCH. Generated by mksysnum (see above).
169
170### `ztypes_${GOOS}_${GOARCH}.go`
171
172A file containing Go types for passing into (or returning from) syscalls.
173Generated by godefs and the types file (see above).
174