]>
git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/golang.org/x/sys/unix/mksyscall_solaris.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_solaris.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 err.
15 # * If go func name needs to be different than its libc name,
16 # * or the function is not in libc, name could be specified
17 # * at the end, after "=" sign, like
18 # //sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
22 my $cmdline = "mksyscall_solaris.pl " . join(' ', @ARGV);
25 my $tags = ""; # build tags
29 if($ARGV[0] eq "-b32") {
30 $_32bit = "big-endian";
32 } elsif($ARGV[0] eq "-l32") {
33 $_32bit = "little-endian";
36 if($ARGV[0] eq "-tags") {
42 if($ARGV[0] =~ /^-/) {
43 print STDERR
"usage: mksyscall_solaris.pl [-b32 | -l32] [-tags x,y] [file ...]\n";
47 sub parseparamlist
($) {
54 return split(/\s*,\s*/, $list);
59 if($p !~ /^(\S*) (\S*)$/) {
60 print STDERR
"$ARGV:$.: malformed parameter: $p\n";
77 $package = $1 if !$package && /^package (\S+)$/;
78 my $nonblock = /^\/\
/sysnb /;
79 next if !/^\/\
/sys / && !$nonblock;
81 # Line must be of the form
82 # func Open(path string, mode int, perm int) (fd int, err error)
83 # Split into name, in params, out params.
84 if(!/^\/\
/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$/) {
85 print STDERR
"$ARGV:$.: malformed //sys declaration\n";
89 my ($nb, $func, $in, $out, $modname, $sysname) = ($1, $2, $3, $4, $5, $6);
91 # Split argument lists on comma.
92 my @in = parseparamlist
($in);
93 my @out = parseparamlist
($out);
95 # Try in vain to keep people from editing this file.
96 # The theory is that they jump into the middle of the file
97 # without reading the header.
98 $text .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n";
110 # System call pointer variable name.
111 my $sysvarname = "proc$sysname";
113 my $strconvfunc = "BytePtrFromString";
114 my $strconvtype = "*byte";
116 $sysname =~ y/A-Z/a-z/; # All libc functions are lowercase.
118 # Runtime import of function to allow cross-platform builds.
119 $dynimports .= "//go:cgo_import_dynamic libc_${sysname} ${sysname} \"$modname.so\"\n";
120 # Link symbol to proc address variable.
121 $linknames .= "//go:linkname ${sysvarname} libc_${sysname}\n";
122 # Library proc address variable.
123 push @vars, $sysvarname;
125 # Go function header.
126 $out = join(', ', @out);
133 $text .= sprintf "func %s(%s)%s {\n", $func, join(', ', @in), $out;
135 # Check if err return available
137 foreach my $p (@out) {
138 my ($name, $type) = parseparam
($p);
139 if($type eq "error") {
145 # Prepare arguments to Syscall.
148 foreach my $p (@in) {
149 my ($name, $type) = parseparam
($p);
151 push @args, "uintptr(unsafe.Pointer($name))";
152 } elsif($type eq "string" && $errvar ne "") {
153 $text .= "\tvar _p$n $strconvtype\n";
154 $text .= "\t_p$n, $errvar = $strconvfunc($name)\n";
155 $text .= "\tif $errvar != nil {\n\t\treturn\n\t}\n";
156 push @args, "uintptr(unsafe.Pointer(_p$n))";
158 } elsif($type eq "string") {
159 print STDERR
"$ARGV:$.: $func uses string arguments, but has no error return\n";
160 $text .= "\tvar _p$n $strconvtype\n";
161 $text .= "\t_p$n, _ = $strconvfunc($name)\n";
162 push @args, "uintptr(unsafe.Pointer(_p$n))";
164 } elsif($type =~ /^\[\](.*)/) {
165 # Convert slice into pointer, length.
166 # Have to be careful not to take address of &a[0] if len == 0:
167 # pass nil in that case.
168 $text .= "\tvar _p$n *$1\n";
169 $text .= "\tif len($name) > 0 {\n\t\t_p$n = \&$name\[0]\n\t}\n";
170 push @args, "uintptr(unsafe.Pointer(_p$n))", "uintptr(len($name))";
172 } elsif($type eq "int64" && $_32bit ne "") {
173 if($_32bit eq "big-endian") {
174 push @args, "uintptr($name >> 32)", "uintptr($name)";
176 push @args, "uintptr($name)", "uintptr($name >> 32)";
178 } elsif($type eq "bool") {
179 $text .= "\tvar _p$n uint32\n";
180 $text .= "\tif $name {\n\t\t_p$n = 1\n\t} else {\n\t\t_p$n = 0\n\t}\n";
181 push @args, "uintptr(_p$n)";
184 push @args, "uintptr($name)";
189 # Determine which form to use; pad args with zeros.
190 my $asm = "sysvicall6";
192 $asm = "rawSysvicall6";
199 print STDERR
"$ARGV:$.: too many arguments to system call\n";
203 my $args = join(', ', @args);
204 my $call = "$asm(uintptr(unsafe.Pointer(&$sysvarname)), $nargs, $args)";
206 # Assign return values.
209 my @ret = ("_", "_", "_");
212 for(my $i=0; $i<@out; $i++) {
214 my ($name, $type) = parseparam
($p);
221 $reg = sprintf("r%d", $i);
224 if($type eq "bool") {
227 if($type eq "int64" && $_32bit ne "") {
228 # 64-bit number in r1:r0 or r0:r1.
230 print STDERR
"$ARGV:$.: not enough registers for int64 return\n";
232 if($_32bit eq "big-endian") {
233 $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i, $i+1);
235 $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i+1, $i);
237 $ret[$i] = sprintf("r%d", $i);
238 $ret[$i+1] = sprintf("r%d", $i+1);
241 $body .= "\t$name = $type($reg)\n";
244 if ($ret[0] eq "_" && $ret[1] eq "_" && $ret[2] eq "_") {
245 $text .= "\t$call\n";
247 $text .= "\t$ret[0], $ret[1], $ret[2] := $call\n";
252 $text .= "\tif e1 != 0 {\n";
253 $text .= "\t\terr = e1\n";
256 $text .= "\treturn\n";
266 // Code generated by the command above; see README.md. DO NOT EDIT.
278 print "import \"golang.org/x/sys/unix\"\n" if $package ne "unix";
280 my $vardecls = "\t" . join(",\n\t", @vars);
281 $vardecls .= " syscallFunc";