Commit 55e2a233 authored by Rob Pike's avatar Rob Pike

go.sys/unix: delete nacl

It's a peculiar environment that probably doesn't belong here.
We can bring it back easily if we need it.

LGTM=dave, rsc
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/128110043
parent 8768103c
// Copyright 2013 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.
#include "textflag.h"
#include "../runtime/syscall_nacl.h" // TODO: how to refer to this?
//
// System call support for 386, Native Client
//
#define NACL_SYSCALL(code) \
MOVL $(0x10000 + ((code)<<5)), AX; CALL AX
#define NACL_SYSJMP(code) \
MOVL $(0x10000 + ((code)<<5)), AX; JMP AX
TEXT unix·Syscall(SB),NOSPLIT,$12-28
CALL runtime·entersyscall(SB)
MOVL trap+0(FP), AX
MOVL a1+4(FP), BX
MOVL BX, 0(SP)
MOVL a2+8(FP), BX
MOVL BX, 4(SP)
MOVL a3+12(FP), BX
MOVL BX, 8(SP)
SHLL $5, AX
ADDL $0x10000, AX
CALL AX
CMPL AX, $0
JGE ok
MOVL $-1, r1+16(FP)
MOVL $-1, r2+20(FP)
NEGL AX
MOVL AX, err+24(FP)
CALL runtime·exitsyscall(SB)
RET
ok:
MOVL AX, r1+16(FP)
MOVL DX, r2+20(FP)
MOVL $0, err+24(FP)
CALL runtime·exitsyscall(SB)
RET
// Copyright 2013 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.
#include "textflag.h"
#include "../runtime/syscall_nacl.h" // TODO: how to refer to this?
//
// System call support for amd64, Native Client
//
#define NACL_SYSCALL(code) \
MOVL $(0x10000 + ((code)<<5)), AX; CALL AX
#define NACL_SYSJMP(code) \
MOVL $(0x10000 + ((code)<<5)), AX; JMP AX
TEXT unix·Syscall(SB),NOSPLIT,$0-28
CALL runtime·entersyscall(SB)
MOVL trap+0(FP), AX
MOVL a1+4(FP), DI
MOVL a2+8(FP), SI
MOVL a3+12(FP), DX
// more args would use CX, R8, R9
SHLL $5, AX
ADDL $0x10000, AX
CALL AX
CMPL AX, $0
JGE ok
MOVL $-1, r1+16(FP)
MOVL $-1, r2+20(FP)
NEGL AX
MOVL AX, err+24(FP)
CALL runtime·exitsyscall(SB)
RET
ok:
MOVL AX, r1+16(FP)
MOVL DX, r2+20(FP)
MOVL $0, err+24(FP)
CALL runtime·exitsyscall(SB)
RET
// Copyright 2014 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.
#include "textflag.h"
#include "../runtime/syscall_nacl.h" // TODO: how to refer to this?
//
// System call support for ARM, Native Client
//
#define NACL_SYSCALL(code) \
MOVW $(0x10000 + ((code)<<5)), R8; BL (R8)
#define NACL_SYSJMP(code) \
MOVW $(0x10000 + ((code)<<5)), R8; B (R8)
TEXT unix·Syscall(SB),NOSPLIT,$0-28
BL runtime·entersyscall(SB)
MOVW trap+0(FP), R8
MOVW a1+4(FP), R0
MOVW a2+8(FP), R1
MOVW a3+12(FP), R2
// more args would use R3, and then stack.
MOVW $0x10000, R7
ADD R8<<5, R7
BL (R7)
CMP $0, R0
BGE ok
MOVW $-1, R1
MOVW R1, r1+16(FP)
MOVW R1, r2+20(FP)
RSB $0, R0
MOVW R0, err+24(FP)
BL runtime·exitsyscall(SB)
RET
ok:
MOVW R0, r1+16(FP)
MOVW R1, r2+20(FP)
MOVW $0, R2
MOVW R2, err+24(FP)
BL runtime·exitsyscall(SB)
RET
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
// Unix environment variables.
......
// Copyright 2013 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.
// File descriptor support for Native Client.
// We want to provide access to a broader range of (simulated) files than
// Native Client allows, so we maintain our own file descriptor table exposed
// to higher-level packages.
package unix
import (
"sync"
)
// files is the table indexed by a file descriptor.
var files struct {
sync.RWMutex
tab []*file
}
// A file is an open file, something with a file descriptor.
// A particular *file may appear in files multiple times, due to use of Dup or Dup2.
type file struct {
fdref int // uses in files.tab
impl fileImpl // underlying implementation
}
// A fileImpl is the implementation of something that can be a file.
type fileImpl interface {
// Standard operations.
// These can be called concurrently from multiple goroutines.
stat(*Stat_t) error
read([]byte) (int, error)
write([]byte) (int, error)
seek(int64, int) (int64, error)
pread([]byte, int64) (int, error)
pwrite([]byte, int64) (int, error)
// Close is called when the last reference to a *file is removed
// from the file descriptor table. It may be called concurrently
// with active operations such as blocked read or write calls.
close() error
}
// newFD adds impl to the file descriptor table,
// returning the new file descriptor.
// Like Unix, it uses the lowest available descriptor.
func newFD(impl fileImpl) int {
files.Lock()
defer files.Unlock()
f := &file{impl: impl, fdref: 1}
for fd, oldf := range files.tab {
if oldf == nil {
files.tab[fd] = f
return fd
}
}
fd := len(files.tab)
files.tab = append(files.tab, f)
return fd
}
// Install Native Client stdin, stdout, stderr.
func init() {
newFD(&naclFile{naclFD: 0})
newFD(&naclFile{naclFD: 1})
newFD(&naclFile{naclFD: 2})
}
// fdToFile retrieves the *file corresponding to a file descriptor.
func fdToFile(fd int) (*file, error) {
files.Lock()
defer files.Unlock()
if fd < 0 || fd >= len(files.tab) || files.tab[fd] == nil {
return nil, EBADF
}
return files.tab[fd], nil
}
func Close(fd int) error {
files.Lock()
if fd < 0 || fd >= len(files.tab) || files.tab[fd] == nil {
files.Unlock()
return EBADF
}
f := files.tab[fd]
files.tab[fd] = nil
f.fdref--
fdref := f.fdref
files.Unlock()
if fdref > 0 {
return nil
}
return f.impl.close()
}
func CloseOnExec(fd int) {
// nothing to do - no exec
}
func Dup(fd int) (int, error) {
files.Lock()
defer files.Unlock()
if fd < 0 || fd >= len(files.tab) || files.tab[fd] == nil {
return -1, EBADF
}
f := files.tab[fd]
f.fdref++
for newfd, oldf := range files.tab {
if oldf == nil {
files.tab[newfd] = f
return newfd, nil
}
}
newfd := len(files.tab)
files.tab = append(files.tab, f)
return newfd, nil
}
func Dup2(fd, newfd int) error {
files.Lock()
defer files.Unlock()
if fd < 0 || fd >= len(files.tab) || files.tab[fd] == nil || newfd < 0 || newfd >= len(files.tab)+100 {
files.Unlock()
return EBADF
}
f := files.tab[fd]
f.fdref++
for cap(files.tab) <= newfd {
files.tab = append(files.tab[:cap(files.tab)], nil)
}
oldf := files.tab[newfd]
var oldfdref int
if oldf != nil {
oldf.fdref--
oldfdref = oldf.fdref
}
files.tab[newfd] = f
files.Unlock()
if oldf != nil {
if oldfdref == 0 {
oldf.impl.close()
}
}
return nil
}
func Fstat(fd int, st *Stat_t) error {
f, err := fdToFile(fd)
if err != nil {
return err
}
return f.impl.stat(st)
}
func Read(fd int, b []byte) (int, error) {
f, err := fdToFile(fd)
if err != nil {
return 0, err
}
return f.impl.read(b)
}
var zerobuf [0]byte
func Write(fd int, b []byte) (int, error) {
if b == nil {
// avoid nil in syscalls; nacl doesn't like that.
b = zerobuf[:]
}
f, err := fdToFile(fd)
if err != nil {
return 0, err
}
return f.impl.write(b)
}
func Pread(fd int, b []byte, offset int64) (int, error) {
f, err := fdToFile(fd)
if err != nil {
return 0, err
}
return f.impl.pread(b, offset)
}
func Pwrite(fd int, b []byte, offset int64) (int, error) {
f, err := fdToFile(fd)
if err != nil {
return 0, err
}
return f.impl.pwrite(b, offset)
}
func Seek(fd int, offset int64, whence int) (int64, error) {
f, err := fdToFile(fd)
if err != nil {
return 0, err
}
return f.impl.seek(offset, whence)
}
// defaulFileImpl implements fileImpl.
// It can be embedded to complete a partial fileImpl implementation.
type defaultFileImpl struct{}
func (*defaultFileImpl) close() error { return nil }
func (*defaultFileImpl) stat(*Stat_t) error { return ENOSYS }
func (*defaultFileImpl) read([]byte) (int, error) { return 0, ENOSYS }
func (*defaultFileImpl) write([]byte) (int, error) { return 0, ENOSYS }
func (*defaultFileImpl) seek(int64, int) (int64, error) { return 0, ENOSYS }
func (*defaultFileImpl) pread([]byte, int64) (int, error) { return 0, ENOSYS }
func (*defaultFileImpl) pwrite([]byte, int64) (int, error) { return 0, ENOSYS }
// naclFile is the fileImpl implementation for a Native Client file descriptor.
type naclFile struct {
defaultFileImpl
naclFD int
}
func (f *naclFile) stat(st *Stat_t) error {
return naclFstat(f.naclFD, st)
}
func (f *naclFile) read(b []byte) (int, error) {
n, err := naclRead(f.naclFD, b)
if err != nil {
n = 0
}
return n, err
}
// implemented in package runtime, to add time header on playground
func naclWrite(fd int, b []byte) int
func (f *naclFile) write(b []byte) (int, error) {
n := naclWrite(f.naclFD, b)
if n < 0 {
return 0, Errno(-n)
}
return n, nil
}
func (f *naclFile) seek(off int64, whence int) (int64, error) {
old := off
err := naclSeek(f.naclFD, &off, whence)
if err != nil {
return old, err
}
return off, nil
}
func (f *naclFile) prw(b []byte, offset int64, rw func([]byte) (int, error)) (int, error) {
// NaCl has no pread; simulate with seek and hope for no races.
old, err := f.seek(0, 1)
if err != nil {
return 0, err
}
if _, err := f.seek(offset, 0); err != nil {
return 0, err
}
n, err := rw(b)
f.seek(old, 0)
return n, err
}
func (f *naclFile) pread(b []byte, offset int64) (int, error) {
return f.prw(b, offset, f.read)
}
func (f *naclFile) pwrite(b []byte, offset int64) (int, error) {
return f.prw(b, offset, f.write)
}
func (f *naclFile) close() error {
err := naclClose(f.naclFD)
f.naclFD = -1
return err
}
// A pipeFile is an in-memory implementation of a pipe.
// The byteq implementation is in net_nacl.go.
type pipeFile struct {
defaultFileImpl
rd *byteq
wr *byteq
}
func (f *pipeFile) close() error {
if f.rd != nil {
f.rd.close()
}
if f.wr != nil {
f.wr.close()
}
return nil
}
func (f *pipeFile) read(b []byte) (int, error) {
if f.rd == nil {
return 0, EINVAL
}
n, err := f.rd.read(b, 0)
if err == EAGAIN {
err = nil
}
return n, err
}
func (f *pipeFile) write(b []byte) (int, error) {
if f.wr == nil {
return 0, EINVAL
}
n, err := f.wr.write(b, 0)
if err == EAGAIN {
err = EPIPE
}
return n, err
}
func Pipe(fd []int) error {
q := newByteq()
fd[0] = newFD(&pipeFile{rd: q})
fd[1] = newFD(&pipeFile{wr: q})
return nil
}
This diff is collapsed.
......@@ -176,18 +176,6 @@ linux_arm)
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"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
nacl_386)
mkerrors=""
mksyscall="./mksyscall.pl -l32 -nacl"
mksysnum=""
mktypes=""
;;
nacl_amd64p32)
mkerrors=""
mksyscall="./mksyscall.pl -nacl"
mksysnum=""
mktypes=""
;;
netbsd_386)
mkerrors="$mkerrors -m32"
mksyscall="./mksyscall.pl -l32 -netbsd"
......
......@@ -28,7 +28,6 @@ my $plan9 = 0;
my $openbsd = 0;
my $netbsd = 0;
my $dragonfly = 0;
my $nacl = 0;
my $arm = 0; # 64-bit value should use (even, odd)-pair
if($ARGV[0] eq "-b32") {
......@@ -54,10 +53,6 @@ if($ARGV[0] eq "-dragonfly") {
$dragonfly = 1;
shift;
}
if($ARGV[0] eq "-nacl") {
$nacl = 1;
shift;
}
if($ARGV[0] eq "-arm") {
$arm = 1;
shift;
......@@ -224,9 +219,6 @@ while(<>) {
$sysname = "SYS_$func";
$sysname =~ s/([a-z])([A-Z])/${1}_$2/g; # turn FooBar into Foo_Bar
$sysname =~ y/a-z/A-Z/;
if($nacl) {
$sysname =~ y/A-Z/a-z/;
}
}
# Actual call.
......
This diff is collapsed.
This diff is collapsed.
// Copyright 2013 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.
package unix
import (
"sync"
"unsafe"
)
//sys naclClose(fd int) (err error) = sys_close
//sys Exit(code int) (err error)
//sys naclFstat(fd int, stat *Stat_t) (err error) = sys_fstat
//sys naclRead(fd int, b []byte) (n int, err error) = sys_read
//sys naclSeek(fd int, off *int64, whence int) (err error) = sys_lseek
const direntSize = 8 + 8 + 2 + 256
// native_client/src/trusted/service_runtime/include/sys/dirent.h
type Dirent struct {
Ino int64
Off int64
Reclen uint16
Name [256]byte
}
func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) {
origlen := len(buf)
count = 0
for max != 0 && len(buf) > 0 {
dirent := (*Dirent)(unsafe.Pointer(&buf[0]))
buf = buf[dirent.Reclen:]
if dirent.Ino == 0 { // File absent in directory.
continue
}
bytes := (*[512 + PathMax]byte)(unsafe.Pointer(&dirent.Name[0]))
var name = string(bytes[0:clen(bytes[:])])
if name == "." || name == ".." { // Useless names
continue
}
max--
count++
names = append(names, name)
}
return origlen - len(buf), count, names
}
func clen(n []byte) int {
for i := 0; i < len(n); i++ {
if n[i] == 0 {
return i
}
}
return len(n)
}
const PathMax = 256
// An Errno is an unsigned number describing an error condition.
// It implements the error interface. The zero Errno is by convention
// a non-error, so code to convert from Errno to error should use:
// err = nil
// if errno != 0 {
// err = errno
// }
type Errno uintptr
func (e Errno) Error() string {
if 0 <= int(e) && int(e) < len(errorstr) {
s := errorstr[e]
if s != "" {
return s
}
}
return "errno " + itoa(int(e))
}
func (e Errno) Temporary() bool {
return e == EINTR || e == EMFILE || e.Timeout()
}
func (e Errno) Timeout() bool {
return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
}
// A Signal is a number describing a process signal.
// It implements the os.Signal interface.
type Signal int
const (
_ Signal = iota
SIGCHLD
SIGINT
SIGKILL
SIGTRAP
SIGQUIT
)
func (s Signal) Signal() {}
func (s Signal) String() string {
if 0 <= s && int(s) < len(signals) {
str := signals[s]
if str != "" {
return str
}
}
return "signal " + itoa(int(s))
}
var signals = [...]string{}
// File system
const (
Stdin = 0
Stdout = 1
Stderr = 2
)
// native_client/src/trusted/service_runtime/include/sys/fcntl.h
const (
O_RDONLY = 0
O_WRONLY = 1
O_RDWR = 2
O_ACCMODE = 3
O_CREAT = 0100
O_CREATE = O_CREAT // for ken
O_TRUNC = 01000
O_APPEND = 02000
O_EXCL = 0200
O_NONBLOCK = 04000
O_NDELAY = O_NONBLOCK
O_SYNC = 010000
O_FSYNC = O_SYNC
O_ASYNC = 020000
O_CLOEXEC = 0
FD_CLOEXEC = 1
)
// native_client/src/trusted/service_runtime/include/sys/fcntl.h
const (
F_DUPFD = 0
F_GETFD = 1
F_SETFD = 2
F_GETFL = 3
F_SETFL = 4
F_GETOWN = 5
F_SETOWN = 6
F_GETLK = 7
F_SETLK = 8
F_SETLKW = 9
F_RGETLK = 10
F_RSETLK = 11
F_CNVT = 12
F_RSETLKW = 13
F_RDLCK = 1
F_WRLCK = 2
F_UNLCK = 3
F_UNLKSYS = 4
)
// native_client/src/trusted/service_runtime/include/bits/stat.h
const (
S_IFMT = 0000370000
S_IFSHM_SYSV = 0000300000
S_IFSEMA = 0000270000
S_IFCOND = 0000260000
S_IFMUTEX = 0000250000
S_IFSHM = 0000240000
S_IFBOUNDSOCK = 0000230000
S_IFSOCKADDR = 0000220000
S_IFDSOCK = 0000210000
S_IFSOCK = 0000140000
S_IFLNK = 0000120000
S_IFREG = 0000100000
S_IFBLK = 0000060000
S_IFDIR = 0000040000
S_IFCHR = 0000020000
S_IFIFO = 0000010000
S_UNSUP = 0000370000
S_ISUID = 0004000
S_ISGID = 0002000
S_ISVTX = 0001000
S_IREAD = 0400
S_IWRITE = 0200
S_IEXEC = 0100
S_IRWXU = 0700
S_IRUSR = 0400
S_IWUSR = 0200
S_IXUSR = 0100
S_IRWXG = 070
S_IRGRP = 040
S_IWGRP = 020
S_IXGRP = 010
S_IRWXO = 07
S_IROTH = 04
S_IWOTH = 02
S_IXOTH = 01
)
// native_client/src/trusted/service_runtime/include/sys/stat.h
// native_client/src/trusted/service_runtime/include/machine/_types.h
type Stat_t struct {
Dev int64
Ino uint64
Mode uint32
Nlink uint32
Uid uint32
Gid uint32
Rdev int64
Size int64
Blksize int32
Blocks int32
Atime int64
AtimeNsec int64
Mtime int64
MtimeNsec int64
Ctime int64
CtimeNsec int64
}
// Processes
// Not supported on NaCl - just enough for package os.
var ForkLock sync.RWMutex
type WaitStatus uint32
func (w WaitStatus) Exited() bool { return false }
func (w WaitStatus) ExitStatus() int { return 0 }
func (w WaitStatus) Signaled() bool { return false }
func (w WaitStatus) Signal() Signal { return 0 }
func (w WaitStatus) CoreDump() bool { return false }
func (w WaitStatus) Stopped() bool { return false }
func (w WaitStatus) Continued() bool { return false }
func (w WaitStatus) StopSignal() Signal { return 0 }
func (w WaitStatus) TrapCause() int { return 0 }
// XXX made up
type Rusage struct {
Utime Timeval
Stime Timeval
}
// XXX made up
type ProcAttr struct {
Dir string
Env []string
Files []uintptr
Sys *SysProcAttr
}
type SysProcAttr struct {
}
// System
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) { return 0, 0, ENOSYS }
func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) { return 0, 0, ENOSYS }
func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
return 0, 0, ENOSYS
}
func Sysctl(key string) (string, error) {
if key == "kern.hostname" {
return "naclbox", nil
}
return "", ENOSYS
}
// Unimplemented Unix midden heap.
const ImplementsGetwd = false
func Getwd() (wd string, err error) { return "", ENOSYS }
func Getegid() int { return 1 }
func Geteuid() int { return 1 }
func Getgid() int { return 1 }
func Getgroups() ([]int, error) { return []int{1}, nil }
func Getpagesize() int { return 65536 }
func Getppid() int { return 2 }
func Getpid() int { return 3 }
func Getuid() int { return 1 }
func Kill(pid int, signum Signal) error { return ENOSYS }
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
return 0, ENOSYS
}
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
return 0, 0, ENOSYS
}
func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
return 0, ENOSYS
}
func RouteRIB(facility, param int) ([]byte, error) { return nil, ENOSYS }
func ParseRoutingMessage(b []byte) ([]RoutingMessage, error) { return nil, ENOSYS }
func ParseRoutingSockaddr(msg RoutingMessage) ([]Sockaddr, error) { return nil, ENOSYS }
func SysctlUint32(name string) (value uint32, err error) { return 0, ENOSYS }
// Copyright 2013 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.
package unix
type Timespec struct {
Sec int64
Nsec int32
}
type Timeval struct {
Sec int64
Usec int32
}
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9)
return
}
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3)
tv.Sec = int64(nsec / 1e9)
return
}
// Copyright 2013 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.
package unix
type Timespec struct {
Sec int64
Nsec int32
}
type Timeval struct {
Sec int64
Usec int32
}
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9)
return
}
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3)
tv.Sec = int64(nsec / 1e9)
return
}
// Copyright 2014 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.
package unix
type Timespec struct {
Sec int64
Nsec int32
}
type Timeval struct {
Sec int64
Usec int32
}
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9)
return
}
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3)
tv.Sec = int64(nsec / 1e9)
return
}
This diff is collapsed.
// Copyright 2013 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.
#include "textflag.h"
TEXT ·startTimer(SB),NOSPLIT,$0
JMP time·startTimer(SB)
TEXT ·stopTimer(SB),NOSPLIT,$0
JMP time·stopTimer(SB)
// Copyright 2013 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.
#include "textflag.h"
TEXT ·startTimer(SB),NOSPLIT,$0
JMP time·startTimer(SB)
TEXT ·stopTimer(SB),NOSPLIT,$0
JMP time·stopTimer(SB)
// Copyright 2014 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.
#include "textflag.h"
TEXT ·startTimer(SB),NOSPLIT,$0
B time·startTimer(SB)
TEXT ·stopTimer(SB),NOSPLIT,$0
B time·stopTimer(SB)
This diff is collapsed.
// mkunix.pl -l32 -nacl syscall_nacl.go syscall_nacl_386.go
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
package unix
import "unsafe"
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclClose(fd int) (err error) {
_, _, e1 := Syscall(sys_close, uintptr(fd), 0, 0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Exit(code int) (err error) {
_, _, e1 := Syscall(sys_exit, uintptr(code), 0, 0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclFstat(fd int, stat *Stat_t) (err error) {
_, _, e1 := Syscall(sys_fstat, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclRead(fd int, b []byte) (n int, err error) {
var _p0 unsafe.Pointer
if len(b) > 0 {
_p0 = unsafe.Pointer(&b[0])
} else {
_p0 = unsafe.Pointer(&_zero)
}
r0, _, e1 := Syscall(sys_read, uintptr(fd), uintptr(_p0), uintptr(len(b)))
n = int(r0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclSeek(fd int, off *int64, whence int) (err error) {
_, _, e1 := Syscall(sys_lseek, uintptr(fd), uintptr(unsafe.Pointer(off)), uintptr(whence))
if e1 != 0 {
err = e1
}
return
}
// mkunix.pl -nacl syscall_nacl.go syscall_nacl_amd64p32.go
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
package unix
import "unsafe"
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclClose(fd int) (err error) {
_, _, e1 := Syscall(sys_close, uintptr(fd), 0, 0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Exit(code int) (err error) {
_, _, e1 := Syscall(sys_exit, uintptr(code), 0, 0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclFstat(fd int, stat *Stat_t) (err error) {
_, _, e1 := Syscall(sys_fstat, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclRead(fd int, b []byte) (n int, err error) {
var _p0 unsafe.Pointer
if len(b) > 0 {
_p0 = unsafe.Pointer(&b[0])
} else {
_p0 = unsafe.Pointer(&_zero)
}
r0, _, e1 := Syscall(sys_read, uintptr(fd), uintptr(_p0), uintptr(len(b)))
n = int(r0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclSeek(fd int, off *int64, whence int) (err error) {
_, _, e1 := Syscall(sys_lseek, uintptr(fd), uintptr(unsafe.Pointer(off)), uintptr(whence))
if e1 != 0 {
err = e1
}
return
}
// mkunix.pl -l32 -nacl -arm syscall_nacl.go syscall_nacl_arm.go
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
package unix
import "unsafe"
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclClose(fd int) (err error) {
_, _, e1 := Syscall(sys_close, uintptr(fd), 0, 0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Exit(code int) (err error) {
_, _, e1 := Syscall(sys_exit, uintptr(code), 0, 0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclFstat(fd int, stat *Stat_t) (err error) {
_, _, e1 := Syscall(sys_fstat, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclRead(fd int, b []byte) (n int, err error) {
var _p0 unsafe.Pointer
if len(b) > 0 {
_p0 = unsafe.Pointer(&b[0])
} else {
_p0 = unsafe.Pointer(&_zero)
}
r0, _, e1 := Syscall(sys_read, uintptr(fd), uintptr(_p0), uintptr(len(b)))
n = int(r0)
if e1 != 0 {
err = e1
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func naclSeek(fd int, off *int64, whence int) (err error) {
_, _, e1 := Syscall(sys_lseek, uintptr(fd), uintptr(unsafe.Pointer(off)), uintptr(whence))
if e1 != 0 {
err = e1
}
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment