diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
commit | 3e45412327a2654a77944249962b3652e6142299 (patch) | |
tree | bc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/pkg/syscall/mksyscall.sh | |
parent | c533680039762cacbc37db8dc7eed074c3e497be (diff) | |
download | golang-upstream/2011.01.12.tar.gz |
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/pkg/syscall/mksyscall.sh')
-rwxr-xr-x | src/pkg/syscall/mksyscall.sh | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/pkg/syscall/mksyscall.sh b/src/pkg/syscall/mksyscall.sh index 215882552..79d19d0d0 100755 --- a/src/pkg/syscall/mksyscall.sh +++ b/src/pkg/syscall/mksyscall.sh @@ -16,6 +16,7 @@ $cmdline = "mksyscall.sh " . join(' ', @ARGV); $errors = 0; $_32bit = ""; +$nacl = 0; if($ARGV[0] eq "-b32") { $_32bit = "big-endian"; @@ -24,6 +25,10 @@ if($ARGV[0] eq "-b32") { $_32bit = "little-endian"; shift; } +if($ARGV[0] eq "-nacl") { + $nacl = 1; + shift; +} if($ARGV[0] =~ /^-/) { print STDERR "usage: mksyscall.sh [-b32 | -l32] [file ...]\n"; @@ -72,8 +77,14 @@ while(<>) { my @in = parseparamlist($in); my @out = parseparamlist($out); + # Try in vain to keep people from editing this file. + # The theory is that they jump into the middle of the file + # without reading the header. + $text .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"; + # Go function header. - $text .= sprintf "func %s(%s) (%s) {\n", $func, join(', ', @in), join(', ', @out); + my $out_decl = @out ? sprintf(" (%s)", join(', ', @out)) : ""; + $text .= sprintf "func %s(%s)%s {\n", $func, join(', ', @in), $out_decl; # Prepare arguments to Syscall. my @args = (); @@ -88,15 +99,21 @@ while(<>) { # Convert slice into pointer, length. # Have to be careful not to take address of &a[0] if len == 0: # pass nil in that case. - $text .= "\tvar _p$n *$1;\n"; - $text .= "\tif len($name) > 0 { _p$n = \&${name}[0]; }\n"; - push @args, "uintptr(unsafe.Pointer(_p$n))", "uintptr(len($name))"; + $text .= "\tvar _p$n unsafe.Pointer\n"; + $text .= "\tif len($name) > 0 {\n\t\t_p$n = unsafe.Pointer(\&${name}[0])\n\t}"; + if($nacl) { + # NaCl rejects zero length write with nil pointer, + # so use non-nil pointer. + $text .= " else {\n\t\t_p$n = unsafe.Pointer(&_zero[0])\n\t}"; + } + $text .= "\n"; + push @args, "uintptr(_p$n)", "uintptr(len($name))"; $n++; } elsif($type eq "int64" && $_32bit ne "") { if($_32bit eq "big-endian") { - push @args, "uintptr($name >> 32)", "uintptr($name)"; + push @args, "uintptr($name>>32)", "uintptr($name)"; } else { - push @args, "uintptr($name)", "uintptr($name >> 32)"; + push @args, "uintptr($name)", "uintptr($name>>32)"; } } else { push @args, "uintptr($name)"; @@ -159,19 +176,22 @@ while(<>) { $ret[$i] = sprintf("r%d", $i); $ret[$i+1] = sprintf("r%d", $i+1); } - $body .= "\t$name = $type($reg);\n"; + $body .= "\t$name = $type($reg)\n"; } if ($ret[0] eq "_" && $ret[1] eq "_" && $ret[2] eq "_") { - $text .= "\t$call;\n"; + $text .= "\t$call\n"; } else { - $text .= "\t$ret[0], $ret[1], $ret[2] := $call;\n"; + $text .= "\t$ret[0], $ret[1], $ret[2] := $call\n"; } $text .= $body; - $text .= "\treturn;\n"; + $text .= "\treturn\n"; $text .= "}\n\n"; } +chomp $text; +chomp $text; + if($errors) { exit 1; } @@ -185,6 +205,5 @@ package syscall import "unsafe" $text - EOF exit 0; |