]>
git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/fsouza/go-dockerclient/external/golang.org/x/sys/unix/mksyscall.pl
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.
6 # This program reads a file containing function prototypes
7 # (like syscall_darwin.go) and generates system call bodies.
8 # The prototypes are marked by lines beginning with "//sys"
9 # and read like func declarations if //sys is replaced by func, but:
10 # * The parameter lists must give a name for each argument.
11 # This includes return parameters.
12 # * The parameter lists must give a type for each argument:
13 # the (x, y, z int) shorthand is not allowed.
14 # * If the return parameter is an error number, it must be named errno.
16 # A line beginning with //sysnb is like //sys, except that the
17 # goroutine will not be suspended during the execution of the system
18 # call. This must only be used for system calls which can never
19 # block, as otherwise the system call could cause all goroutines to
24 my $cmdline = "mksyscall.pl " . join(' ', @ARGV);
31 my $arm = 0; # 64-bit value should use (even, odd)-pair
33 if($ARGV[0] eq "-b32") {
34 $_32bit = "big-endian";
36 } elsif($ARGV[0] eq "-l32") {
37 $_32bit = "little-endian";
40 if($ARGV[0] eq "-plan9") {
44 if($ARGV[0] eq "-openbsd") {
48 if($ARGV[0] eq "-netbsd") {
52 if($ARGV[0] eq "-dragonfly") {
56 if($ARGV[0] eq "-arm") {
61 if($ARGV[0] =~ /^-/) {
62 print STDERR
"usage: mksyscall.pl [-b32 | -l32] [file ...]\n";
66 if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") {
67 print STDERR
"GOARCH or GOOS not defined in environment\n";
71 sub parseparamlist
($) {
78 return split(/\s*,\s*/, $list);
83 if($p !~ /^(\S*) (\S*)$/) {
84 print STDERR
"$ARGV:$.: malformed parameter: $p\n";
97 my $nonblock = /^\/\
/sysnb /;
98 next if !/^\/\
/sys / && !$nonblock;
100 # Line must be of the form
101 # func Open(path string, mode int, perm int) (fd int, errno error)
102 # Split into name, in params, out params.
103 if(!/^\/\
/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*((?i)SYS_[A-Z0-9_]+))?$/) {
104 print STDERR
"$ARGV:$.: malformed //sys declaration\n";
108 my ($func, $in, $out, $sysname) = ($2, $3, $4, $5);
110 # Split argument lists on comma.
111 my @in = parseparamlist
($in);
112 my @out = parseparamlist
($out);
114 # Try in vain to keep people from editing this file.
115 # The theory is that they jump into the middle of the file
116 # without reading the header.
117 $text .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n";
119 # Go function header.
120 my $out_decl = @out ? sprintf(" (%s)", join(', ', @out)) : "";
121 $text .= sprintf "func %s(%s)%s {\n", $func, join(', ', @in), $out_decl;
123 # Check if err return available
125 foreach my $p (@out) {
126 my ($name, $type) = parseparam
($p);
127 if($type eq "error") {
133 # Prepare arguments to Syscall.
137 foreach my $p (@in) {
138 my ($name, $type) = parseparam
($p);
140 push @args, "uintptr(unsafe.Pointer($name))";
141 } elsif($type eq "string" && $errvar ne "") {
142 $text .= "\tvar _p$n *byte\n";
143 $text .= "\t_p$n, $errvar = BytePtrFromString($name)\n";
144 $text .= "\tif $errvar != nil {\n\t\treturn\n\t}\n";
145 push @args, "uintptr(unsafe.Pointer(_p$n))";
146 push @uses, "use(unsafe.Pointer(_p$n))";
148 } elsif($type eq "string") {
149 print STDERR
"$ARGV:$.: $func uses string arguments, but has no error return\n";
150 $text .= "\tvar _p$n *byte\n";
151 $text .= "\t_p$n, _ = BytePtrFromString($name)\n";
152 push @args, "uintptr(unsafe.Pointer(_p$n))";
153 push @uses, "use(unsafe.Pointer(_p$n))";
155 } elsif($type =~ /^\[\](.*)/) {
156 # Convert slice into pointer, length.
157 # Have to be careful not to take address of &a[0] if len == 0:
158 # pass dummy pointer in that case.
159 # Used to pass nil, but some OSes or simulators reject write(fd, nil, 0).
160 $text .= "\tvar _p$n unsafe.Pointer\n";
161 $text .= "\tif len($name) > 0 {\n\t\t_p$n = unsafe.Pointer(\&${name}[0])\n\t}";
162 $text .= " else {\n\t\t_p$n = unsafe.Pointer(&_zero)\n\t}";
164 push @args, "uintptr(_p$n)", "uintptr(len($name))";
166 } elsif($type eq "int64" && ($openbsd || $netbsd)) {
168 if($_32bit eq "big-endian") {
169 push @args, "uintptr($name>>32)", "uintptr($name)";
170 } elsif($_32bit eq "little-endian") {
171 push @args, "uintptr($name)", "uintptr($name>>32)";
173 push @args, "uintptr($name)";
175 } elsif($type eq "int64" && $dragonfly) {
176 if ($func !~ /^extp(read|write)/i) {
179 if($_32bit eq "big-endian") {
180 push @args, "uintptr($name>>32)", "uintptr($name)";
181 } elsif($_32bit eq "little-endian") {
182 push @args, "uintptr($name)", "uintptr($name>>32)";
184 push @args, "uintptr($name)";
186 } elsif($type eq "int64" && $_32bit ne "") {
187 if(@args % 2 && $arm) {
188 # arm abi specifies 64-bit argument uses
192 if($_32bit eq "big-endian") {
193 push @args, "uintptr($name>>32)", "uintptr($name)";
195 push @args, "uintptr($name)", "uintptr($name>>32)";
198 push @args, "uintptr($name)";
202 # Determine which form to use; pad args with zeros.
211 } elsif(@args <= 6) {
216 } elsif(@args <= 9) {
222 print STDERR
"$ARGV:$.: too many arguments to system call\n";
225 # System call number.
227 $sysname = "SYS_$func";
228 $sysname =~ s/([a-z])([A-Z])/${1}_$2/g; # turn FooBar into Foo_Bar
229 $sysname =~ y/a-z/A-Z/;
233 my $args = join(', ', @args);
234 my $call = "$asm($sysname, $args)";
236 # Assign return values.
238 my @ret = ("_", "_", "_");
240 for(my $i=0; $i<@out; $i++) {
242 my ($name, $type) = parseparam
($p);
244 if($name eq "err" && !$plan9) {
248 } elsif($name eq "err" && $plan9) {
253 $reg = sprintf("r%d", $i);
256 if($type eq "bool") {
259 if($type eq "int64" && $_32bit ne "") {
260 # 64-bit number in r1:r0 or r0:r1.
262 print STDERR
"$ARGV:$.: not enough registers for int64 return\n";
264 if($_32bit eq "big-endian") {
265 $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i, $i+1);
267 $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i+1, $i);
269 $ret[$i] = sprintf("r%d", $i);
270 $ret[$i+1] = sprintf("r%d", $i+1);
272 if($reg ne "e1" || $plan9) {
273 $body .= "\t$name = $type($reg)\n";
276 if ($ret[0] eq "_" && $ret[1] eq "_" && $ret[2] eq "_") {
277 $text .= "\t$call\n";
279 $text .= "\t$ret[0], $ret[1], $ret[2] := $call\n";
281 foreach my $use (@uses) {
286 if ($plan9 && $ret[2] eq "e1") {
287 $text .= "\tif int32(r0) == -1 {\n";
288 $text .= "\t\terr = e1\n";
290 } elsif ($do_errno) {
291 $text .= "\tif e1 != 0 {\n";
292 $text .= "\t\terr = errnoErr(e1)\n";
295 $text .= "\treturn\n";
308 // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
310 // +build $ENV{'GOARCH'},$ENV{'GOOS'}