Commit 6201a963 authored by Russ Cox's avatar Russ Cox

move src/syscall to src/lib/syscall.

enforce rule: all kernel data structures and constants
	go in syscall module.
move things that should be in syscall out of net.
make net a single package.

R=r
OCL=15985
CL=15994
parent 2662aad7
......@@ -3,7 +3,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
for i in lib9 libbio libmach_amd64 libregexp syscall cmd runtime lib
for i in lib9 libbio libmach_amd64 libregexp cmd runtime lib
do
cd $i
case $i in
......
......@@ -6,7 +6,7 @@
rm -f $GOROOT/pkg/*
for i in os math net time
for i in syscall os math net time
do
cd $i
make nuke
......
......@@ -6,7 +6,7 @@
set -e
for i in os math
for i in syscall os math
do
echo; echo; echo %%%% making lib/$i %%%%; echo
cd $i
......
......@@ -2,46 +2,57 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m net net.go fd_darwin.go ip.go cast_amd64.s net_darwin.go
O=6
GC=$(O)g
CC=$(O)c -w
AS=$(O)a
AR=$(O)ar
NET=$(GOROOT)/pkg/net.a
SOCKET=$(GOROOT)/pkg/socket.a
IP=$(GOROOT)/pkg/ip.$O
PKG=$(GOROOT)/pkg/net.a
NETO=\
net.$O\
install: $(PKG)
SOCKETO=\
cvt.$O\
socket_$(GOOS).$O\
nuke: clean
rm -f $(PKG)
$(NET): $(NETO)
$(O)ar grc $(NET) $(NETO)
clean:
rm -f *.$O *.a
$(NETO): $(IP) $(SOCKET)
%.$O: %.go
$(GC) $*.go
$(SOCKETO): $(IP)
%.$O: %.c
$(CC) $*.c
$(SOCKET): $(SOCKETO)
$(O)ar grc $(SOCKET) $(SOCKETO)
rm $(SOCKETO)
%.$O: %.s
$(AS) $*.s
$(GOROOT)/pkg/%.$O: %.$O
cp $*.$O $(GOROOT)/pkg/$*.$O
rm $*.$O
install: nuke $(IP) $(SOCKET) $(NET)
O1=\
ip.$O\
cast_$(GOARCH).$O\
nuke:
rm -f *.$O *.a $(IP) $(NET)
O2=\
fd_$(GOOS).$O\
net_$(GOOS).$O\
clean:
rm -f *.$O *.a
O3=\
net.$O\
%.$O: %.go
$(GC) $<
$(PKG): a1 a2 a3
a1: $(O1)
$(AR) grc $(PKG) $(O1)
rm -f $(O1)
a2: $(O2)
$(AR) grc $(PKG) $(O2)
rm -f $(O2)
a3: $(O3)
$(AR) grc $(PKG) $(O3)
rm -f $(O3)
$(O1): nuke
$(O2): a1
$(O3): a2
%.$O: %.s
$(AS) $<
// Copyright 2009 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.
// Network file descriptors.
package net
import (
"os";
"syscall";
"net"
)
/* BUG 6g has trouble with this.
export type FD os.FD;
export func NewFD(fd int64) (nfd *FD, err *os.Error) {
ofd := os.NewFD(fd)
return ofd, nil
}
func (fd *FD) Close() *os.Error {
var ofd *os.FD = fd
return ofd.Close()
}
func (fd *FD) Read(p *[]byte) (n int, err *os.Error) {
var ofd *os.FD = fd;
n, err = ofd.Read(p)
return n, err
}
func (fd *FD) Write(p *[]byte) (n int, err *os.Error) {
var ofd *os.FD = fd;
n, err = ofd.Write(p)
return n, err
}
*/
// TODO: Replace with kqueue/kevent.
export type FD struct {
fd int64;
osfd *os.FD;
}
export func NewFD(fd int64) (nfd *FD, err *os.Error) {
nfd = new(FD);
nfd.osfd = os.NewFD(fd);
nfd.fd = fd
return nfd, nil
}
func (fd *FD) Close() *os.Error {
return fd.osfd.Close()
}
func (fd *FD) Read(p *[]byte) (n int, err *os.Error) {
n, err = fd.osfd.Read(p)
return n, err
}
func (fd *FD) Write(p *[]byte) (n int, err *os.Error) {
n, err = fd.osfd.Write(p)
return n, err
}
func (fd *FD) Accept(sa *syscall.Sockaddr) (nfd *FD, err *os.Error) {
s, e := syscall.accept(fd.fd, sa);
if e != 0 {
return nil, os.ErrnoToError(e)
}
nfd, err = NewFD(s)
return nfd, err
}
// Copyright 2009 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.
// Network file descriptors.
package net
import (
"os";
"syscall";
"net"
)
/* BUG 6g has trouble with this.
export type FD os.FD;
export func NewFD(fd int64) (nfd *FD, err *os.Error) {
ofd := os.NewFD(fd)
return ofd, nil
}
func (fd *FD) Close() *os.Error {
var ofd *os.FD = fd
return ofd.Close()
}
func (fd *FD) Read(p *[]byte) (n int, err *os.Error) {
var ofd *os.FD = fd;
n, err = ofd.Read(p)
return n, err
}
func (fd *FD) Write(p *[]byte) (n int, err *os.Error) {
var ofd *os.FD = fd;
n, err = ofd.Write(p)
return n, err
}
*/
// TODO: Replace with epoll.
export type FD struct {
fd int64;
osfd *os.FD;
}
export func NewFD(fd int64) (nfd *FD, err *os.Error) {
nfd = new(FD);
nfd.osfd = os.NewFD(fd);
nfd.fd = fd
return nfd, nil
}
func (fd *FD) Close() *os.Error {
return fd.osfd.Close()
}
func (fd *FD) Read(p *[]byte) (n int, err *os.Error) {
n, err = fd.osfd.Read(p)
return n, err
}
func (fd *FD) Write(p *[]byte) (n int, err *os.Error) {
n, err = fd.osfd.Write(p)
return n, err
}
func (fd *FD) Accept(sa *syscall.Sockaddr) (nfd *FD, err *os.Error) {
s, e := syscall.accept(fd.fd, sa);
if e != 0 {
return nil, os.ErrnoToError(e)
}
nfd, err = NewFD(s)
return nfd, err
}
......@@ -10,7 +10,7 @@
// This library accepts either size of byte array but always
// returns 16-byte addresses.
package ip
package net
export const (
IPv4len = 4;
......
This diff is collapsed.
// Copyright 2009 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 net
import (
"os";
"syscall";
"net"
)
export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv4(p)
if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL
}
sa := new(syscall.SockaddrInet4);
sa.len = syscall.SizeofSockaddrInet4;
sa.family = syscall.AF_INET;
sa.port[0] = byte(port>>8);
sa.port[1] = byte(port);
for i := 0; i < IPv4len; i++ {
sa.addr[i] = p[i]
}
return syscall.SockaddrInet4ToSockaddr(sa), nil
}
export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv6(p)
if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL
}
sa := new(syscall.SockaddrInet6);
sa.len = syscall.SizeofSockaddrInet6;
sa.family = syscall.AF_INET6;
sa.port[0] = byte(port>>8);
sa.port[1] = byte(port);
for i := 0; i < IPv6len; i++ {
sa.addr[i] = p[i]
}
return syscall.SockaddrInet6ToSockaddr(sa), nil
}
export func SockaddrToIP(sa1 *syscall.Sockaddr) (p *[]byte, port int, err *os.Error) {
switch sa1.family {
case syscall.AF_INET:
sa := syscall.SockaddrToSockaddrInet4(sa1);
a := ToIPv6(&sa.addr)
if a == nil {
return nil, 0, os.EINVAL
}
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil
case syscall.AF_INET6:
sa := syscall.SockaddrToSockaddrInet6(sa1);
a := ToIPv6(&sa.addr)
if a == nil {
return nil, 0, os.EINVAL
}
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil
default:
return nil, 0, os.EINVAL
}
return nil, 0, nil // not reached
}
export func ListenBacklog() int64 {
return syscall.SOMAXCONN
}
// Copyright 2009 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 net
import (
"os";
"syscall";
"net"
)
export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv4(p)
if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL
}
sa := new(syscall.SockaddrInet4);
sa.family = syscall.AF_INET;
sa.port[0] = byte(port>>8);
sa.port[1] = byte(port);
for i := 0; i < IPv4len; i++ {
sa.addr[i] = p[i]
}
return syscall.SockaddrInet4ToSockaddr(sa), nil
}
export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv6(p)
if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL
}
sa := new(syscall.SockaddrInet6);
sa.family = syscall.AF_INET6;
sa.port[0] = byte(port>>8);
sa.port[1] = byte(port);
for i := 0; i < IPv6len; i++ {
sa.addr[i] = p[i]
}
return syscall.SockaddrInet6ToSockaddr(sa), nil
}
export func SockaddrToIP(sa1 *syscall.Sockaddr) (p *[]byte, port int, err *os.Error) {
switch sa1.family {
case syscall.AF_INET:
sa := syscall.SockaddrToSockaddrInet4(sa1);
a := ToIPv6(&sa.addr)
if a == nil {
return nil, 0, os.EINVAL
}
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil
case syscall.AF_INET6:
sa := syscall.SockaddrToSockaddrInet6(sa1);
a := ToIPv6(&sa.addr)
if a == nil {
return nil, 0, os.EINVAL
}
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil
default:
return nil, 0, os.EINVAL
}
return nil, 0, nil // not reached
}
export func ListenBacklog() int64 {
// TODO: Read the limit from /proc/sys/net/core/somaxconn,
// to take advantage of kernels that have raised the limit.
return syscall.SOMAXCONN
}
# Copyright 2009 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.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m syscall errstr_darwin.go file_darwin.go socket_darwin.go\
# syscall_amd64_darwin.go time_amd64_darwin.go types_amd64_darwin.go\
# asm_amd64_darwin.s cast_amd64.s syscall.go
O=6
GC=$(O)g
CC=$(O)c -w
AS=$(O)a
AR=$(O)ar
PKG=$(GOROOT)/pkg/syscall.a
install: $(PKG)
nuke: clean
rm -f $(PKG)
clean:
rm -f *.$O *.a
%.$O: %.go
$(GC) $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
errstr_$(GOOS).$O\
syscall_$(GOARCH)_$(GOOS).$O\
types_$(GOARCH)_$(GOOS).$O\
asm_$(GOARCH)_$(GOOS).$O\
cast_$(GOARCH).$O\
syscall.$O\
O2=\
file_$(GOOS).$O\
socket_$(GOOS).$O\
time_$(GOARCH)_$(GOOS).$O\
$(PKG): a1 a2
a1: $(O1)
$(AR) grc $(PKG) $(O1)
rm -f $(O1)
a2: $(O2)
$(AR) grc $(PKG) $(O2)
rm -f $(O2)
$(O1): nuke
$(O2): a1
......@@ -10,7 +10,7 @@
// func Syscall6(trap int64, a1, a2, a3, a4, a5, a6 int64) (r1, r2, err int64);
// Trap # in AX, args in DI SI DX, return in AX DX
TEXT syscall·Syscall(SB),7,$-8
TEXT syscall·Syscall(SB),7,$0
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
......@@ -27,7 +27,7 @@ TEXT syscall·Syscall(SB),7,$-8
MOVQ $0, 56(SP) // errno
RET
TEXT syscall·Syscall6(SB),7,$-8
TEXT syscall·Syscall6(SB),7,$0
MOVQ 16(SP), DI
MOVQ 24(SP), SI
MOVQ 32(SP), DX
......@@ -46,14 +46,3 @@ TEXT syscall·Syscall6(SB),7,$-8
MOVQ DX, 72(SP) // r2
MOVQ $0, 80(SP) // errno
RET
// conversion operators - really just casts
TEXT syscall·BytePtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT syscall·StatPtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
......@@ -48,24 +48,3 @@ TEXT syscall·Syscall6(SB),7,$-8
MOVQ DX, 72(SP) // r2
MOVQ $0, 80(SP) // errno
RET
// conversion operators - really just casts
TEXT syscall·BytePtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT syscall·Int32Ptr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT syscall·Int64Ptr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT syscall·StatPtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
......@@ -2,37 +2,69 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Type-unsafe casts.
// conversion operators - really just casts
TEXT syscall·BytePtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT syscall·Int32Ptr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT socket·SockaddrPtr(SB),7,$0
TEXT syscall·Int64Ptr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT socket·Int32Ptr(SB),7,$0
TEXT syscall·KeventPtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT socket·LingerPtr(SB),7,$0
TEXT syscall·LingerPtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT socket·TimevalPtr(SB),7,$0
TEXT syscall·SockaddrPtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT socket·SockaddrInet4ToSockaddr(SB),7,$0
TEXT syscall·StatPtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT socket·SockaddrToSockaddrInet4(SB),7,$0
TEXT syscall·TimespecPtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT socket·SockaddrInet6ToSockaddr(SB),7,$0
TEXT syscall·TimevalPtr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT socket·SockaddrToSockaddrInet6(SB),7,$0
TEXT syscall·SockaddrToSockaddrInet4(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT syscall·SockaddrToSockaddrInet6(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT syscall·SockaddrInet4ToSockaddr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
TEXT syscall·SockaddrInet6ToSockaddr(SB),7,$-8
MOVQ 8(SP), AX
MOVQ AX, 16(SP)
RET
......@@ -8,106 +8,43 @@ package syscall
import syscall "syscall"
//export Stat
//export stat, fstat, lstat
//export open, creat, close, read, write, pipe
//export unlink
func StatPtr(s *Stat) int64;
type dev_t uint32;
type ino_t uint64;
type mode_t uint16;
type nlink_t uint16;
type uid_t uint32;
type gid_t uint32;
type off_t int64;
type blksize_t int64;
type blkcnt_t int64;
type time_t int64;
type Timespec struct {
tv_sec time_t;
tv_nsec int64;
}
export type Stat struct {
st_dev dev_t; /* ID of device containing file */
st_mode mode_t; /* protection */
st_nlink nlink_t; /* number of hard links */
st_ino ino_t; /* inode number */
st_uid uid_t; /* user ID of owner */
st_gid gid_t; /* group ID of owner */
st_rdev dev_t; /* device ID (if special file) */
st_atime Timespec; /* time of last access */
st_mtime Timespec; /* time of last modification */
st_ctime Timespec; /* time of last status change */
st_birthtimespec Timespec; /* birth time */
st_size off_t; /* total size, in bytes */
st_blocks blkcnt_t; /* number of blocks allocated */
st_blksize blksize_t; /* blocksize for filesystem I/O */
st_flags uint32;
st_gen uint32;
st_qspare[2] int64;
}
export const (
O_RDONLY = 0x0;
O_WRONLY = 0x1;
O_RDWR = 0x2;
O_APPEND = 0x8;
O_ASYNC = 0x40;
O_CREAT = 0x200;
O_NOCTTY = 0x20000;
O_NONBLOCK = 0x4;
O_NDELAY = O_NONBLOCK;
O_SYNC = 0x80;
O_TRUNC = 0x400;
)
const NameBufsize = 512
export func open(name string, mode int64, perm int64) (ret int64, errno int64) {
var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) {
return -1, syscall.ENAMETOOLONG
return -1, ENAMETOOLONG
}
const SYSOPEN = 5;
r1, r2, err := syscall.Syscall(SYSOPEN, BytePtr(&namebuf[0]), mode, perm);
r1, r2, err := Syscall(SYS_OPEN, BytePtr(&namebuf[0]), mode, perm);
return r1, err;
}
export func creat(name string, perm int64) (ret int64, errno int64) {
var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) {
return -1, syscall.ENAMETOOLONG
return -1, ENAMETOOLONG
}
const SYSOPEN = 5;
r1, r2, err := syscall.Syscall(SYSOPEN, BytePtr(&namebuf[0]), O_CREAT|O_WRONLY|O_TRUNC, perm);
r1, r2, err := Syscall(SYS_OPEN, BytePtr(&namebuf[0]), O_CREAT|O_WRONLY|O_TRUNC, perm);
return r1, err;
}
export func close(fd int64) (ret int64, errno int64) {
const SYSCLOSE = 6;
r1, r2, err := syscall.Syscall(SYSCLOSE, fd, 0, 0);
r1, r2, err := Syscall(SYS_CLOSE, fd, 0, 0);
return r1, err;
}
export func read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
const SYSREAD = 3;
r1, r2, err := syscall.Syscall(SYSREAD, fd, BytePtr(buf), nbytes);
r1, r2, err := Syscall(SYS_READ, fd, BytePtr(buf), nbytes);
return r1, err;
}
export func write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
const SYSWRITE = 4;
r1, r2, err := syscall.Syscall(SYSWRITE, fd, BytePtr(buf), nbytes);
r1, r2, err := Syscall(SYS_WRITE, fd, BytePtr(buf), nbytes);
return r1, err;
}
export func pipe(fds *[2]int64) (ret int64, errno int64) {
const SYSPIPE = 42;
r1, r2, err := syscall.Syscall(SYSPIPE, 0, 0, 0);
r1, r2, err := Syscall(SYS_PIPE, 0, 0, 0);
if r1 < 0 {
return r1, err;
}
......@@ -119,31 +56,33 @@ export func pipe(fds *[2]int64) (ret int64, errno int64) {
export func stat(name string, buf *Stat) (ret int64, errno int64) {
var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) {
return -1, syscall.ENAMETOOLONG
return -1, ENAMETOOLONG
}
const SYSSTAT = 338;
r1, r2, err := syscall.Syscall(SYSSTAT, BytePtr(&namebuf[0]), StatPtr(buf), 0);
r1, r2, err := Syscall(SYS_STAT, BytePtr(&namebuf[0]), StatPtr(buf), 0);
return r1, err;
}
export func lstat(name *byte, buf *Stat) (ret int64, errno int64) {
const SYSLSTAT = 340;
r1, r2, err := syscall.Syscall(SYSLSTAT, BytePtr(name), StatPtr(buf), 0);
r1, r2, err := Syscall(SYS_LSTAT, BytePtr(name), StatPtr(buf), 0);
return r1, err;
}
export func fstat(fd int64, buf *Stat) (ret int64, errno int64) {
const SYSFSTAT = 339;
r1, r2, err := syscall.Syscall(SYSFSTAT, fd, StatPtr(buf), 0);
r1, r2, err := Syscall(SYS_FSTAT, fd, StatPtr(buf), 0);
return r1, err;
}
export func unlink(name string) (ret int64, errno int64) {
var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) {
return -1, syscall.ENAMETOOLONG
return -1, ENAMETOOLONG
}
const SYSUNLINK = 10;
r1, r2, err := syscall.Syscall(SYSUNLINK, BytePtr(&namebuf[0]), 0, 0);
r1, r2, err := Syscall(SYS_UNLINK, BytePtr(&namebuf[0]), 0, 0);
return r1, err;
}
export func fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_FCNTL, fd, cmd, arg)
return r1, err
}
......@@ -8,108 +8,44 @@ package syscall
import syscall "syscall"
//export Stat
//export stat, fstat, lstat
//export open, creat, close, read, write, pipe
//export unlink
func StatPtr(s *Stat) int64;
func Int32Ptr(s *int32) int64;
type dev_t uint64;
type ino_t uint64;
type mode_t uint32;
type nlink_t uint64;
type uid_t uint32;
type gid_t uint32;
type off_t int64;
type blksize_t int64;
type blkcnt_t int64;
type time_t int64;
type Timespec struct {
tv_sec time_t;
tv_nsec int64;
}
export type Stat struct {
st_dev dev_t; /* ID of device containing file */
st_ino ino_t; /* inode number */
st_nlink nlink_t; /* number of hard links */
st_mode mode_t; /* protection */
st_uid uid_t; /* user ID of owner */
st_gid gid_t; /* group ID of owner */
pad0 int32;
st_rdev dev_t; /* device ID (if special file) */
st_size off_t; /* total size, in bytes */
st_blksize blksize_t; /* blocksize for filesystem I/O */
st_blocks blkcnt_t; /* number of blocks allocated */
st_atime Timespec; /* time of last access */
st_mtime Timespec; /* time of last modification */
st_ctime Timespec; /* time of last status change */
st_unused4 int64;
st_unused5 int64;
st_unused6 int64;
}
export const (
O_RDONLY = 0x0;
O_WRONLY = 0x1;
O_RDWR = 0x2;
O_APPEND = 0x400;
O_ASYNC = 0x2000;
O_CREAT = 0x40;
O_NOCTTY = 0x100;
O_NONBLOCK = 0x800;
O_NDELAY = O_NONBLOCK;
O_SYNC = 0x1000;
O_TRUNC = 0x200;
)
const NameBufsize = 512
export func open(name string, mode int64, perm int64) (ret int64, errno int64) {
var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) {
return -1, syscall.ENAMETOOLONG
return -1, ENAMETOOLONG
}
const SYSOPEN = 2;
r1, r2, err := syscall.Syscall(SYSOPEN, BytePtr(&namebuf[0]), mode, perm);
r1, r2, err := Syscall(SYS_OPEN, BytePtr(&namebuf[0]), mode, perm);
return r1, err;
}
export func creat(name string, perm int64) (ret int64, errno int64) {
var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) {
return -1, syscall.ENAMETOOLONG
return -1, ENAMETOOLONG
}
const SYSOPEN = 2;
r1, r2, err := syscall.Syscall(SYSOPEN, BytePtr(&namebuf[0]), O_CREAT|O_WRONLY|O_TRUNC, perm);
r1, r2, err := Syscall(SYS_OPEN, BytePtr(&namebuf[0]), O_CREAT|O_WRONLY|O_TRUNC, perm);
return r1, err;
}
export func close(fd int64) (ret int64, errno int64) {
const SYSCLOSE = 3;
r1, r2, err := syscall.Syscall(SYSCLOSE, fd, 0, 0);
r1, r2, err := Syscall(SYS_CLOSE, fd, 0, 0);
return r1, err;
}
export func read(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
const SYSREAD = 0;
r1, r2, err := syscall.Syscall(SYSREAD, fd, BytePtr(buf), nbytes);
r1, r2, err := Syscall(SYS_READ, fd, BytePtr(buf), nbytes);
return r1, err;
}
export func write(fd int64, buf *byte, nbytes int64) (ret int64, errno int64) {
const SYSWRITE = 1;
r1, r2, err := syscall.Syscall(SYSWRITE, fd, BytePtr(buf), nbytes);
r1, r2, err := Syscall(SYS_WRITE, fd, BytePtr(buf), nbytes);
return r1, err;
}
export func pipe(fds *[2]int64) (ret int64, errno int64) {
const SYSPIPE = 22;
var t [2] int32;
r1, r2, err := syscall.Syscall(SYSPIPE, Int32Ptr(&t[0]), 0, 0);
r1, r2, err := Syscall(SYS_PIPE, Int32Ptr(&t[0]), 0, 0);
if r1 < 0 {
return r1, err;
}
......@@ -121,31 +57,28 @@ export func pipe(fds *[2]int64) (ret int64, errno int64) {
export func stat(name string, buf *Stat) (ret int64, errno int64) {
var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) {
return -1, syscall.ENAMETOOLONG
return -1, ENAMETOOLONG
}
const SYSSTAT = 4;
r1, r2, err := syscall.Syscall(SYSSTAT, BytePtr(&namebuf[0]), StatPtr(buf), 0);
r1, r2, err := Syscall(SYS_STAT, BytePtr(&namebuf[0]), StatPtr(buf), 0);
return r1, err;
}
export func lstat(name *byte, buf *Stat) (ret int64, errno int64) {
const SYSLSTAT = 6;
r1, r2, err := syscall.Syscall(SYSLSTAT, BytePtr(name), StatPtr(buf), 0);
r1, r2, err := Syscall(SYS_LSTAT, BytePtr(name), StatPtr(buf), 0);
return r1, err;
}
export func fstat(fd int64, buf *Stat) (ret int64, errno int64) {
const SYSFSTAT = 5;
r1, r2, err := syscall.Syscall(SYSFSTAT, fd, StatPtr(buf), 0);
r1, r2, err := Syscall(SYS_FSTAT, fd, StatPtr(buf), 0);
return r1, err;
}
export func unlink(name string) (ret int64, errno int64) {
var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) {
return -1, syscall.ENAMETOOLONG
return -1, ENAMETOOLONG
}
const SYSUNLINK = 87;
r1, r2, err := syscall.Syscall(SYSUNLINK, BytePtr(&namebuf[0]), 0, 0);
r1, r2, err := Syscall(SYS_UNLINK, BytePtr(&namebuf[0]), 0, 0);
return r1, err;
}
# Copyright 2009 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.
my $command = "mkdarwin " . join(' ', @ARGV);
print <<EOF;
// Generated by mkdarwin; DO NOT EDIT.
// $command
package syscall
export const (
EOF
while(<>){
if(/^([0-9]+)\s+ALL\s+({ \S+\s+(\w+).*})/){
my $num = $1;
my $proto = $2;
my $name = "SYS_$3";
$name =~ y/a-z/A-Z/;
# There are multiple entries for nosys(), so comment them out.
if($name eq "SYS_NOSYS"){
$name = "// $name";
}
print " $name = $num; // $proto\n";
}
}
print <<EOF;
)
EOF
#!/usr/bin/perl
# Copyright 2009 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.
my $command = "mklinux ". join(' ', @ARGV);
print <<EOF;
// Generated by mklinux; DO NOT EDIT.
// $command
package syscall
export const(
EOF
while(<>){
if(/^#define __NR_(\w+)\s+([0-9]+)/){
my $name = "SYS_$1";
my $num = $2;
$name =~ y/a-z/A-Z/;
print " $name = $num;\n";
}
}
print <<EOF;
)
EOF
// Copyright 2009 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.
// Low-level socket interface.
// Only for implementing net package.
// DO NOT USE DIRECTLY.
package syscall
import "syscall"
export func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
export func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
export func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
export func SockaddrInet6ToSockaddr(s *SockaddrInet6) *Sockaddr;
export func socket(domain, proto, typ int64) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_SOCKET, domain, proto, typ);
return r1, e
}
export func connect(fd int64, sa *Sockaddr) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_CONNECT, fd, SockaddrPtr(sa), int64(sa.len));
return r1, e
}
export func bind(fd int64, sa *Sockaddr) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_BIND, fd, SockaddrPtr(sa), int64(sa.len));
return r1, e
}
export func listen(fd, n int64) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_LISTEN, fd, n, 0);
return r1, e
}
export func accept(fd int64, sa *Sockaddr) (ret int64, err int64) {
n := SizeofSockaddr;
r1, r2, e := Syscall(SYS_ACCEPT, fd, SockaddrPtr(sa), Int32Ptr(&n));
return r1, e
}
export func setsockopt(fd, level, opt, valueptr, length int64) (ret int64, err int64) {
if fd < 0 {
return -1, EINVAL
}
r1, r2, e := Syscall6(SYS_SETSOCKOPT, fd, level, opt, valueptr, length, 0);
return r1, e
}
export func setsockopt_int(fd, level, opt int64, value int) int64 {
n := int32(opt);
r1, e := setsockopt(fd, level, opt, Int32Ptr(&n), 4)
return e
}
export func setsockopt_tv(fd, level, opt, nsec int64) int64 {
var tv Timeval;
nsec += 999;
tv.sec = int64(nsec/1000000000);
tv.usec = uint32(nsec%1000000000);
r1, e := setsockopt(fd, level, opt, TimevalPtr(&tv), 4)
return e
}
export func setsockopt_linger(fd, level, opt int64, sec int) int64 {
var l Linger;
if sec != 0 {
l.yes = 1;
l.sec = sec
} else {
l.yes = 0;
l.sec = 0
}
r1, err := setsockopt(fd, level, opt, LingerPtr(&l), 8)
return err
}
/*
export func getsockopt(fd, level, opt, valueptr, lenptr int64) (ret int64, errno int64) {
r1, r2, err := Syscall6(SYS_GETSOCKOPT, fd, level, opt, valueptr, lenptr, 0);
return r1, err;
}
*/
export func kqueue() (ret int64, errno int64) {
r1, r2, err := Syscall(SYS_KQUEUE, 0, 0, 0);
return r1, err
}
export func kevent(kq int64, changes, events *[]Kevent, timeout *Timespec) (ret int64, errno int64) {
var nchange, changeptr, nevent, eventptr int64;
nchange = 0;
changeptr = 0;
nevent = 0;
eventptr = 0;
if changes != nil && len(changes) > 0 {
changeptr = KeventPtr(&changes[0]);
nchange = int64(len(changes))
}
if events != nil && len(events) > 0 {
eventptr = KeventPtr(&events[0]);
nevent = int64(len(events))
}
r1, r2, err := Syscall6(SYS_KEVENT, kq, changeptr, nchange,
eventptr, nevent, TimespecPtr(timeout));
return r1, err
}
// Copyright 2009 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.
// Low-level socket interface.
// Only for implementing net package.
// DO NOT USE DIRECTLY.
package syscall
import "syscall"
export func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
export func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
export func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
export func SockaddrInet6ToSockaddr(s *SockaddrInet6) *Sockaddr;
func Len(s *Sockaddr) int64 {
switch s.family {
case AF_UNIX:
return SizeofSockaddrUnix
case AF_INET:
return SizeofSockaddrInet4
case AF_INET6:
return SizeofSockaddrInet6
}
return 0
}
export func socket(domain, proto, typ int64) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_SOCKET, domain, proto, typ);
return r1, e
}
export func connect(fd int64, sa *Sockaddr) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_CONNECT, fd, SockaddrPtr(sa), Len(sa));
return r1, e
}
export func bind(fd int64, sa *Sockaddr) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_BIND, fd, SockaddrPtr(sa), Len(sa));
return r1, e
}
export func listen(fd, n int64) (ret int64, err int64) {
r1, r2, e := Syscall(SYS_LISTEN, fd, n, 0);
return r1, e
}
export func accept(fd int64, sa *Sockaddr) (ret int64, err int64) {
n := SizeofSockaddr;
r1, r2, e := Syscall(SYS_ACCEPT, fd, SockaddrPtr(sa), Int32Ptr(&n));
return r1, e
}
export func setsockopt(fd, level, opt, valueptr, length int64) (ret int64, err int64) {
if fd < 0 {
return -1, EINVAL
}
r1, r2, e := Syscall6(SYS_SETSOCKOPT, fd, level, opt, valueptr, length, 0);
return r1, e
}
export func setsockopt_int(fd, level, opt int64, value int) int64 {
n := int32(opt);
r1, e := setsockopt(fd, level, opt, Int32Ptr(&n), 4)
return e
}
export func setsockopt_tv(fd, level, opt, nsec int64) int64 {
var tv Timeval;
nsec += 999;
tv.sec = int64(nsec/1000000000);
tv.usec = uint64(nsec%1000000000);
r1, e := setsockopt(fd, level, opt, TimevalPtr(&tv), 4)
return e
}
export func setsockopt_linger(fd, level, opt int64, sec int) int64 {
var l Linger;
if sec != 0 {
l.yes = 1;
l.sec = sec
} else {
l.yes = 0;
l.sec = 0
}
r1, err := setsockopt(fd, level, opt, LingerPtr(&l), 8)
return err
}
/*
export func getsockopt(fd, level, opt, valueptr, lenptr int64) (ret int64, errno int64) {
r1, r2, err := Syscall6(GETSOCKOPT, fd, level, opt, valueptr, lenptr, 0);
return r1, err;
}
*/
// TODO: epoll
......@@ -10,7 +10,10 @@ package syscall
export func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
export func Syscall6(trap int64, a1, a2, a3, a4, a5, a6 int64) (r1, r2, err int64);
export func BytePtr(b *byte) int64;
export func Int32Ptr(p *int32) int64;
export func Int64Ptr(p *int64) int64;
/*
* Used to convert file names to byte arrays for passing to kernel,
......
This diff is collapsed.
// Copyright 2009 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.
// Generated by mklinux; DO NOT EDIT.
// mklinux /usr/include/asm/unistd_64.h
package syscall
export const(
SYS_READ = 0;
SYS_WRITE = 1;
SYS_OPEN = 2;
SYS_CLOSE = 3;
SYS_STAT = 4;
SYS_FSTAT = 5;
SYS_LSTAT = 6;
SYS_POLL = 7;
SYS_LSEEK = 8;
SYS_MMAP = 9;
SYS_MPROTECT = 10;
SYS_MUNMAP = 11;
SYS_BRK = 12;
SYS_RT_SIGACTION = 13;
SYS_RT_SIGPROCMASK = 14;
SYS_RT_SIGRETURN = 15;
SYS_IOCTL = 16;
SYS_PREAD64 = 17;
SYS_PWRITE64 = 18;
SYS_READV = 19;
SYS_WRITEV = 20;
SYS_ACCESS = 21;
SYS_PIPE = 22;
SYS_SELECT = 23;
SYS_SCHED_YIELD = 24;
SYS_MREMAP = 25;
SYS_MSYNC = 26;
SYS_MINCORE = 27;
SYS_MADVISE = 28;
SYS_SHMGET = 29;
SYS_SHMAT = 30;
SYS_SHMCTL = 31;
SYS_DUP = 32;
SYS_DUP2 = 33;
SYS_PAUSE = 34;
SYS_NANOSLEEP = 35;
SYS_GETITIMER = 36;
SYS_ALARM = 37;
SYS_SETITIMER = 38;
SYS_GETPID = 39;
SYS_SENDFILE = 40;
SYS_SOCKET = 41;
SYS_CONNECT = 42;
SYS_ACCEPT = 43;
SYS_SENDTO = 44;
SYS_RECVFROM = 45;
SYS_SENDMSG = 46;
SYS_RECVMSG = 47;
SYS_SHUTDOWN = 48;
SYS_BIND = 49;
SYS_LISTEN = 50;
SYS_GETSOCKNAME = 51;
SYS_GETPEERNAME = 52;
SYS_SOCKETPAIR = 53;
SYS_SETSOCKOPT = 54;
SYS_GETSOCKOPT = 55;
SYS_CLONE = 56;
SYS_FORK = 57;
SYS_VFORK = 58;
SYS_EXECVE = 59;
SYS_EXIT = 60;
SYS_WAIT4 = 61;
SYS_KILL = 62;
SYS_UNAME = 63;
SYS_SEMGET = 64;
SYS_SEMOP = 65;
SYS_SEMCTL = 66;
SYS_SHMDT = 67;
SYS_MSGGET = 68;
SYS_MSGSND = 69;
SYS_MSGRCV = 70;
SYS_MSGCTL = 71;
SYS_FCNTL = 72;
SYS_FLOCK = 73;
SYS_FSYNC = 74;
SYS_FDATASYNC = 75;
SYS_TRUNCATE = 76;
SYS_FTRUNCATE = 77;
SYS_GETDENTS = 78;
SYS_GETCWD = 79;
SYS_CHDIR = 80;
SYS_FCHDIR = 81;
SYS_RENAME = 82;
SYS_MKDIR = 83;
SYS_RMDIR = 84;
SYS_CREAT = 85;
SYS_LINK = 86;
SYS_UNLINK = 87;
SYS_SYMLINK = 88;
SYS_READLINK = 89;
SYS_CHMOD = 90;
SYS_FCHMOD = 91;
SYS_CHOWN = 92;
SYS_FCHOWN = 93;
SYS_LCHOWN = 94;
SYS_UMASK = 95;
SYS_GETTIMEOFDAY = 96;
SYS_GETRLIMIT = 97;
SYS_GETRUSAGE = 98;
SYS_SYSINFO = 99;
SYS_TIMES = 100;
SYS_PTRACE = 101;
SYS_GETUID = 102;
SYS_SYSLOG = 103;
SYS_GETGID = 104;
SYS_SETUID = 105;
SYS_SETGID = 106;
SYS_GETEUID = 107;
SYS_GETEGID = 108;
SYS_SETPGID = 109;
SYS_GETPPID = 110;
SYS_GETPGRP = 111;
SYS_SETSID = 112;
SYS_SETREUID = 113;
SYS_SETREGID = 114;
SYS_GETGROUPS = 115;
SYS_SETGROUPS = 116;
SYS_SETRESUID = 117;
SYS_GETRESUID = 118;
SYS_SETRESGID = 119;
SYS_GETRESGID = 120;
SYS_GETPGID = 121;
SYS_SETFSUID = 122;
SYS_SETFSGID = 123;
SYS_GETSID = 124;
SYS_CAPGET = 125;
SYS_CAPSET = 126;
SYS_RT_SIGPENDING = 127;
SYS_RT_SIGTIMEDWAIT = 128;
SYS_RT_SIGQUEUEINFO = 129;
SYS_RT_SIGSUSPEND = 130;
SYS_SIGALTSTACK = 131;
SYS_UTIME = 132;
SYS_MKNOD = 133;
SYS_USELIB = 134;
SYS_PERSONALITY = 135;
SYS_USTAT = 136;
SYS_STATFS = 137;
SYS_FSTATFS = 138;
SYS_SYSFS = 139;
SYS_GETPRIORITY = 140;
SYS_SETPRIORITY = 141;
SYS_SCHED_SETPARAM = 142;
SYS_SCHED_GETPARAM = 143;
SYS_SCHED_SETSCHEDULER = 144;
SYS_SCHED_GETSCHEDULER = 145;
SYS_SCHED_GET_PRIORITY_MAX = 146;
SYS_SCHED_GET_PRIORITY_MIN = 147;
SYS_SCHED_RR_GET_INTERVAL = 148;
SYS_MLOCK = 149;
SYS_MUNLOCK = 150;
SYS_MLOCKALL = 151;
SYS_MUNLOCKALL = 152;
SYS_VHANGUP = 153;
SYS_MODIFY_LDT = 154;
SYS_PIVOT_ROOT = 155;
SYS__SYSCTL = 156;
SYS_PRCTL = 157;
SYS_ARCH_PRCTL = 158;
SYS_ADJTIMEX = 159;
SYS_SETRLIMIT = 160;
SYS_CHROOT = 161;
SYS_SYNC = 162;
SYS_ACCT = 163;
SYS_SETTIMEOFDAY = 164;
SYS_MOUNT = 165;
SYS_UMOUNT2 = 166;
SYS_SWAPON = 167;
SYS_SWAPOFF = 168;
SYS_REBOOT = 169;
SYS_SETHOSTNAME = 170;
SYS_SETDOMAINNAME = 171;
SYS_IOPL = 172;
SYS_IOPERM = 173;
SYS_CREATE_MODULE = 174;
SYS_INIT_MODULE = 175;
SYS_DELETE_MODULE = 176;
SYS_GET_KERNEL_SYMS = 177;
SYS_QUERY_MODULE = 178;
SYS_QUOTACTL = 179;
SYS_NFSSERVCTL = 180;
SYS_GETPMSG = 181;
SYS_PUTPMSG = 182;
SYS_AFS_SYSCALL = 183;
SYS_TUXCALL = 184;
SYS_SECURITY = 185;
SYS_GETTID = 186;
SYS_READAHEAD = 187;
SYS_SETXATTR = 188;
SYS_LSETXATTR = 189;
SYS_FSETXATTR = 190;
SYS_GETXATTR = 191;
SYS_LGETXATTR = 192;
SYS_FGETXATTR = 193;
SYS_LISTXATTR = 194;
SYS_LLISTXATTR = 195;
SYS_FLISTXATTR = 196;
SYS_REMOVEXATTR = 197;
SYS_LREMOVEXATTR = 198;
SYS_FREMOVEXATTR = 199;
SYS_TKILL = 200;
SYS_TIME = 201;
SYS_FUTEX = 202;
SYS_SCHED_SETAFFINITY = 203;
SYS_SCHED_GETAFFINITY = 204;
SYS_SET_THREAD_AREA = 205;
SYS_IO_SETUP = 206;
SYS_IO_DESTROY = 207;
SYS_IO_GETEVENTS = 208;
SYS_IO_SUBMIT = 209;
SYS_IO_CANCEL = 210;
SYS_GET_THREAD_AREA = 211;
SYS_LOOKUP_DCOOKIE = 212;
SYS_EPOLL_CREATE = 213;
SYS_EPOLL_CTL_OLD = 214;
SYS_EPOLL_WAIT_OLD = 215;
SYS_REMAP_FILE_PAGES = 216;
SYS_GETDENTS64 = 217;
SYS_SET_TID_ADDRESS = 218;
SYS_RESTART_SYSCALL = 219;
SYS_SEMTIMEDOP = 220;
SYS_FADVISE64 = 221;
SYS_TIMER_CREATE = 222;
SYS_TIMER_SETTIME = 223;
SYS_TIMER_GETTIME = 224;
SYS_TIMER_GETOVERRUN = 225;
SYS_TIMER_DELETE = 226;
SYS_CLOCK_SETTIME = 227;
SYS_CLOCK_GETTIME = 228;
SYS_CLOCK_GETRES = 229;
SYS_CLOCK_NANOSLEEP = 230;
SYS_EXIT_GROUP = 231;
SYS_EPOLL_WAIT = 232;
SYS_EPOLL_CTL = 233;
SYS_TGKILL = 234;
SYS_UTIMES = 235;
SYS_VSERVER = 236;
SYS_MBIND = 237;
SYS_SET_MEMPOLICY = 238;
SYS_GET_MEMPOLICY = 239;
SYS_MQ_OPEN = 240;
SYS_MQ_UNLINK = 241;
SYS_MQ_TIMEDSEND = 242;
SYS_MQ_TIMEDRECEIVE = 243;
SYS_MQ_NOTIFY = 244;
SYS_MQ_GETSETATTR = 245;
SYS_KEXEC_LOAD = 246;
SYS_WAITID = 247;
SYS_ADD_KEY = 248;
SYS_REQUEST_KEY = 249;
SYS_KEYCTL = 250;
SYS_IOPRIO_SET = 251;
SYS_IOPRIO_GET = 252;
SYS_INOTIFY_INIT = 253;
SYS_INOTIFY_ADD_WATCH = 254;
SYS_INOTIFY_RM_WATCH = 255;
SYS_MIGRATE_PAGES = 256;
SYS_OPENAT = 257;
SYS_MKDIRAT = 258;
SYS_MKNODAT = 259;
SYS_FCHOWNAT = 260;
SYS_FUTIMESAT = 261;
SYS_NEWFSTATAT = 262;
SYS_UNLINKAT = 263;
SYS_RENAMEAT = 264;
SYS_LINKAT = 265;
SYS_SYMLINKAT = 266;
SYS_READLINKAT = 267;
SYS_FCHMODAT = 268;
SYS_FACCESSAT = 269;
SYS_PSELECT6 = 270;
SYS_PPOLL = 271;
SYS_UNSHARE = 272;
SYS_SET_ROBUST_LIST = 273;
SYS_GET_ROBUST_LIST = 274;
SYS_SPLICE = 275;
SYS_TEE = 276;
SYS_SYNC_FILE_RANGE = 277;
SYS_VMSPLICE = 278;
SYS_MOVE_PAGES = 279;
SYS_UTIMENSAT = 280;
SYS_EPOLL_PWAIT = 281;
SYS_SIGNALFD = 282;
SYS_TIMERFD = 283;
SYS_EVENTFD = 284;
SYS_FALLOCATE = 285;
)
......@@ -7,11 +7,10 @@ package syscall
import syscall "syscall"
export func gettimeofday() (sec, nsec, errno int64) {
const GETTIMEOFDAY = 116;
// The "1" in the call is the timeval pointer, which must be
// non-zero but is otherwise unused. The results
// are returned in r1, r2.
r1, r2, err := syscall.Syscall(GETTIMEOFDAY, 1, 0, 0);
r1, r2, err := Syscall(SYS_GETTIMEOFDAY, 1, 0, 0);
if err != 0 {
return 0, 0, err
}
......
......@@ -6,14 +6,11 @@ package syscall
import syscall "syscall"
func Int64Ptr(s *int64) int64;
export func gettimeofday() (sec, nsec, errno int64) {
const GETTIMEOFDAY = 96
var tv [2]int64; // struct timeval
r1, r2, err := syscall.Syscall(GETTIMEOFDAY, Int64Ptr(&tv[0]), 0, 0);
if err != 0 {
return 0, 0, err
var tv Timeval;
r1, r2, e := Syscall(SYS_GETTIMEOFDAY, TimevalPtr(&tv), 0, 0);
if e != 0 {
return 0, 0, e
}
return tv[0], tv[1]*1000, 0
return int64(tv.sec), int64(tv.usec*1000), 0
}
// Copyright 2009 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.
// Types and defined constants.
// Should be automatically generated, but is not.
package syscall
// Time
export type Timespec struct {
sec int64;
nsec uint64;
}
export func TimespecPtr(t *Timespec) int64;
export type Timeval struct {
sec int64;
usec uint32;
}
export func TimevalPtr(t *Timeval) int64;
// Files
export const (
O_RDONLY = 0x0;
O_WRONLY = 0x1;
O_RDWR = 0x2;
O_APPEND = 0x8;
O_ASYNC = 0x40;
O_CREAT = 0x200;
O_NOCTTY = 0x20000;
O_NONBLOCK = 0x4;
O_NDELAY = O_NONBLOCK;
O_SYNC = 0x80;
O_TRUNC = 0x400;
F_GETFL = 3;
F_SETFL = 4;
)
export type Stat struct {
dev uint32;
mode uint16;
nlink uint16;
ino uint64;
uid uint32;
gid uint32;
rdev uint32;
pad1 uint32;
atime Timespec;
mtime Timespec;
ctime Timespec;
birthtime Timespec;
size uint64;
blocks uint64;
blksize uint32;
flags uint32;
gen uint32;
lspare uint32;
qspare [2]uint64;
}
export func StatPtr(s *Stat) int64;
// Sockets
export const (
AF_UNIX = 1;
AF_INET = 2;
AF_DATAKIT = 9;
AF_INET6 = 30;
SOCK_STREAM = 1;
SOCK_DGRAM = 2;
SOCK_RAW = 3;
SOCK_RDM = 4;
SOCK_SEQPACKET = 5;
SOL_SOCKET = 0xffff;
SO_REUSEADDR = 0x0004;
SO_KEEPALIVE = 0x0008;
SO_DONTROUTE = 0x0010;
SO_BROADCAST = 0x0020;
SO_USELOOPBACK = 0x0040;
SO_LINGER = 0x1080;
SO_REUSEPORT = 0x0200;
SO_SNDBUF = 0x1001;
SO_RCVBUF = 0x1002;
SO_SNDTIMEO = 0x1005;
SO_RCVTIMEO = 0x1006;
SO_NOSIGPIPE = 0x1022;
IPPROTO_TCP = 6;
IPPROTO_UDP = 17;
TCP_NODELAY = 0x01;
SOMAXCONN = 128;
)
export type SockaddrUnix struct {
len byte;
family byte;
path [104]byte
}
export const SizeofSockaddrUnix = 106
export type SockaddrInet4 struct {
len byte;
family byte;
port [2]byte;
addr [4]byte;
zero [8]byte
}
export const SizeofSockaddrInet4 = 16
export type SockaddrInet6 struct {
len byte;
family byte;
port [2]byte;
flowinfo [4]byte;
addr [16]byte;
scopeid [4]byte;
}
export const SizeofSockaddrInet6 = 28
export type Sockaddr struct {
len byte;
family byte;
opaque [126]byte
}
export const SizeofSockaddr = 128
export func SockaddrPtr(s *Sockaddr) int64;
export type Linger struct {
yes int32;
sec int32;
}
export func LingerPtr(l *Linger) int64;
// Events (kqueue, kevent)
export const (
// filters
EVFILT_READ = -1;
EVFILT_WRITE = -2;
EVFILT_AIO = -3;
EVFILT_VNODE = -4;
EVFILT_PROC = -5;
EVFILT_SIGNAL = -6;
EVFILT_TIMER = -7;
EVFILT_MACHPORT = -8;
EVFILT_FS = -9;
EVFILT_SYSCOUNT = 9;
// actions
EV_ADD = 0x0001;
EV_DELETE = 0x0002;
EV_DISABLE = 0x0008;
EV_RECEIPT = 0x0040;
// flags
EV_ONESHOT = 0x0010;
EV_CLEAR = 0x0020;
EV_RECEIPT = 0x40;
EV_SYSFLAGS = 0xF000;
EV_FLAG0 = 0x1000;
EV_FLAG1 = 0x2000;
// returned values
EV_EOF = 0x8000;
EV_ERROR = 0x4000
)
export type Kevent struct {
ident int64;
filter int16;
flags uint16;
fflags uint32;
data int64;
udata int64;
}
export func KeventPtr(e *Kevent) int64;
// Copyright 2009 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.
// Types and defined constants.
// Should be automatically generated, but is not.
package syscall
// Time
export type Timespec struct {
sec int64;
nsec uint64;
}
export func TimespecPtr(t *Timespec) int64;
export type Timeval struct {
sec int64;
usec uint64;
}
export func TimevalPtr(t *Timeval) int64;
// Files
export const (
O_RDONLY = 0x0;
O_WRONLY = 0x1;
O_RDWR = 0x2;
O_APPEND = 0x400;
O_ASYNC = 0x2000;
O_CREAT = 0x40;
O_NOCTTY = 0x100;
O_NONBLOCK = 0x800;
O_NDELAY = O_NONBLOCK;
O_SYNC = 0x1000;
O_TRUNC = 0x200;
)
export type Stat struct {
dev uint64;
ino uint64;
nlink uint64;
mode uint32;
uid uint32;
gid uint32;
_pad0 uint32;
rdev uint64;
size int64;
blksize int64;
blocks int64;
atime Timespec;
mtime Timespec;
ctime Timespec;
_unused [3]int64
}
export func StatPtr(s *Stat) int64;
// Sockets
export const (
AF_UNIX = 1;
AF_INET = 2;
AF_INET6 = 10;
SOCK_STREAM = 1;
SOCK_DGRAM = 2;
SOCK_RAW = 3;
SOCK_RDM = 4;
SOCK_SEQPACKET = 5;
SOL_SOCKET = 1;
SO_DEBUG = 1;
SO_REUSEADDR = 2;
SO_TYPE = 3;
SO_ERROR = 4;
SO_DONTROUTE = 5;
SO_BROADCAST = 6;
SO_SNDBUF = 7;
SO_RCVBUF = 8;
SO_SNDBUFFORCE = 32;
SO_RCVBUFFORCE = 33;
SO_KEEPALIVE = 9;
SO_OOBINLINE = 10;
SO_NO_CHECK = 11;
SO_PRIORITY = 12;
SO_LINGER = 13;
SO_BSDCOMPAT = 14;
SO_PASSCRED = 16;
SO_PEERCRED = 17;
SO_RCVLOWAT = 18;
SO_SNDLOWAT = 19;
SO_RCVTIMEO = 20;
SO_SNDTIMEO = 21;
SO_BINDTODEVICE = 25;
IPPROTO_TCP = 6;
IPPROTO_UDP = 17;
TCP_NODELAY = 0x01;
SOMAXCONN = 128;
)
export type SockaddrUnix struct {
family uint16;
path [108]byte
}
export const SizeofSockaddrUnix = 110
export type SockaddrInet4 struct {
family uint16;
port [2]byte;
addr [4]byte;
zero [8]byte
}
export const SizeofSockaddrInet4 = 16
export type SockaddrInet6 struct {
family uint16;
port [2]byte;
flowinfo [4]byte;
addr [16]byte;
scopeid [4]byte;
}
export const SizeofSockaddrInet6 = 28
export type Sockaddr struct {
family uint16;
opaque [126]byte
}
export const SizeofSockaddr = 128
export func SockaddrPtr(s *Sockaddr) int64;
export type Linger struct {
yes int32;
sec int32;
}
export func LingerPtr(l *Linger) int64;
// Events (epoll)
// TODO
......@@ -8,7 +8,7 @@ export MAKEFLAGS=-j4
bash clean.bash
for i in lib9 libbio libmach_amd64 libregexp cmd runtime syscall lib
for i in lib9 libbio libmach_amd64 libregexp cmd runtime lib
do
echo; echo; echo %%%% making $i %%%%; echo
cd $i
......
# Copyright 2009 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.
CFLAGS=
O=6
CC=$(O)c
AS=$(O)a
GC=$(O)g
PKG=$(GOROOT)/pkg/syscall.a
O1=\
syscall.$O \
errstr_$(GOOS).$O \
O2=\
file_$(GOARCH)_$(GOOS).$O \
time_$(GOARCH)_$(GOOS).$O \
syscall_$(GOARCH)_$(GOOS).$O \
install: nuke $(PKG)
$(PKG): a1 a2
a1: $(O1)
$(O)ar grc $(PKG) $(O1)
rm *.6
a2: $(O2)
$(O)ar grc $(PKG) $(O2)
rm *.6
$(O1): nuke
$(O2): a1
nuke:
rm -f *.$(O) *.a $(PKG)
clean:
rm -f *.$(O) *.a
%.$O: %.c
$(CC) $<
sys_file.$O: sys_file.c sys_types.h $(OS_H)
$(CC) -D$(GOARCH)_$(GOOS) $<
%.$O: %.s
$(AS) $<
%.$O: %.go
$(GC) $<
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