Source file src/syscall/syscall_netbsd.go

     1  // Copyright 2009,2010 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // NetBSD system calls.
     6  // This file is compiled as ordinary Go code,
     7  // but it is also input to mksyscall,
     8  // which parses the //sys lines and generates system call stubs.
     9  // Note that sometimes we use a lowercase //sys name and wrap
    10  // it in our own nicer implementation, either here or in
    11  // syscall_bsd.go or syscall_unix.go.
    12  
    13  package syscall
    14  
    15  import "unsafe"
    16  
    17  const _SYS_DUP3 = SYS_DUP3
    18  
    19  type SockaddrDatalink struct {
    20  	Len    uint8
    21  	Family uint8
    22  	Index  uint16
    23  	Type   uint8
    24  	Nlen   uint8
    25  	Alen   uint8
    26  	Slen   uint8
    27  	Data   [12]int8
    28  	raw    RawSockaddrDatalink
    29  }
    30  
    31  func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
    32  
    33  func sysctlNodes(mib []_C_int) (nodes []Sysctlnode, err error) {
    34  	var olen uintptr
    35  
    36  	// Get a list of all sysctl nodes below the given MIB by performing
    37  	// a sysctl for the given MIB with CTL_QUERY appended.
    38  	mib = append(mib, CTL_QUERY)
    39  	qnode := Sysctlnode{Flags: SYSCTL_VERS_1}
    40  	qp := (*byte)(unsafe.Pointer(&qnode))
    41  	sz := unsafe.Sizeof(qnode)
    42  	if err = sysctl(mib, nil, &olen, qp, sz); err != nil {
    43  		return nil, err
    44  	}
    45  
    46  	// Now that we know the size, get the actual nodes.
    47  	nodes = make([]Sysctlnode, olen/sz)
    48  	np := (*byte)(unsafe.Pointer(&nodes[0]))
    49  	if err = sysctl(mib, np, &olen, qp, sz); err != nil {
    50  		return nil, err
    51  	}
    52  
    53  	return nodes, nil
    54  }
    55  
    56  func nametomib(name string) (mib []_C_int, err error) {
    57  	// Split name into components.
    58  	var parts []string
    59  	last := 0
    60  	for i := 0; i < len(name); i++ {
    61  		if name[i] == '.' {
    62  			parts = append(parts, name[last:i])
    63  			last = i + 1
    64  		}
    65  	}
    66  	parts = append(parts, name[last:])
    67  
    68  	// Discover the nodes and construct the MIB OID.
    69  	for partno, part := range parts {
    70  		nodes, err := sysctlNodes(mib)
    71  		if err != nil {
    72  			return nil, err
    73  		}
    74  		for _, node := range nodes {
    75  			n := make([]byte, 0)
    76  			for i := range node.Name {
    77  				if node.Name[i] != 0 {
    78  					n = append(n, byte(node.Name[i]))
    79  				}
    80  			}
    81  			if string(n) == part {
    82  				mib = append(mib, _C_int(node.Num))
    83  				break
    84  			}
    85  		}
    86  		if len(mib) != partno+1 {
    87  			return nil, EINVAL
    88  		}
    89  	}
    90  
    91  	return mib, nil
    92  }
    93  
    94  func direntIno(buf []byte) (uint64, bool) {
    95  	return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
    96  }
    97  
    98  func direntReclen(buf []byte) (uint64, bool) {
    99  	return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
   100  }
   101  
   102  func direntNamlen(buf []byte) (uint64, bool) {
   103  	return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
   104  }
   105  
   106  func Pipe(p []int) (err error) {
   107  	return Pipe2(p, 0)
   108  }
   109  
   110  //sysnb pipe2(p *[2]_C_int, flags int) (err error)
   111  func Pipe2(p []int, flags int) error {
   112  	if len(p) != 2 {
   113  		return EINVAL
   114  	}
   115  	var pp [2]_C_int
   116  	err := pipe2(&pp, flags)
   117  	if err == nil {
   118  		p[0] = int(pp[0])
   119  		p[1] = int(pp[1])
   120  	}
   121  	return err
   122  }
   123  
   124  //sys paccept(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, sigmask *sigset, flags int) (nfd int, err error)
   125  func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
   126  	var rsa RawSockaddrAny
   127  	var len _Socklen = SizeofSockaddrAny
   128  	nfd, err = paccept(fd, &rsa, &len, nil, flags)
   129  	if err != nil {
   130  		return
   131  	}
   132  	if len > SizeofSockaddrAny {
   133  		panic("RawSockaddrAny too small")
   134  	}
   135  	sa, err = anyToSockaddr(&rsa)
   136  	if err != nil {
   137  		Close(nfd)
   138  		nfd = 0
   139  	}
   140  	return
   141  }
   142  
   143  //sys getdents(fd int, buf []byte) (n int, err error)
   144  func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
   145  	return getdents(fd, buf)
   146  }
   147  
   148  // TODO, see golang.org/issue/5847
   149  func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
   150  	return -1, ENOSYS
   151  }
   152  
   153  /*
   154   * Exposed directly
   155   */
   156  //sys	Access(path string, mode uint32) (err error)
   157  //sys	Adjtime(delta *Timeval, olddelta *Timeval) (err error)
   158  //sys	Chdir(path string) (err error)
   159  //sys	Chflags(path string, flags int) (err error)
   160  //sys	Chmod(path string, mode uint32) (err error)
   161  //sys	Chown(path string, uid int, gid int) (err error)
   162  //sys	Chroot(path string) (err error)
   163  //sys	Close(fd int) (err error)
   164  //sys	Dup(fd int) (nfd int, err error)
   165  //sys	Dup2(from int, to int) (err error)
   166  //sys	Fchdir(fd int) (err error)
   167  //sys	Fchflags(fd int, flags int) (err error)
   168  //sys	Fchmod(fd int, mode uint32) (err error)
   169  //sys	Fchown(fd int, uid int, gid int) (err error)
   170  //sys	Flock(fd int, how int) (err error)
   171  //sys	Fpathconf(fd int, name int) (val int, err error)
   172  //sys	Fstat(fd int, stat *Stat_t) (err error)
   173  //sys	Fsync(fd int) (err error)
   174  //sys	Ftruncate(fd int, length int64) (err error)
   175  //sysnb	Getegid() (egid int)
   176  //sysnb	Geteuid() (uid int)
   177  //sysnb	Getgid() (gid int)
   178  //sysnb	Getpgid(pid int) (pgid int, err error)
   179  //sysnb	Getpgrp() (pgrp int)
   180  //sysnb	Getpid() (pid int)
   181  //sysnb	Getppid() (ppid int)
   182  //sys	Getpriority(which int, who int) (prio int, err error)
   183  //sysnb	Getrlimit(which int, lim *Rlimit) (err error)
   184  //sysnb	Getrusage(who int, rusage *Rusage) (err error)
   185  //sysnb	Getsid(pid int) (sid int, err error)
   186  //sysnb	Gettimeofday(tv *Timeval) (err error)
   187  //sysnb	Getuid() (uid int)
   188  //sys	Issetugid() (tainted bool)
   189  //sys	Kill(pid int, signum Signal) (err error)
   190  //sys	Kqueue() (fd int, err error)
   191  //sys	Lchown(path string, uid int, gid int) (err error)
   192  //sys	Link(path string, link string) (err error)
   193  //sys	Listen(s int, backlog int) (err error)
   194  //sys	Lstat(path string, stat *Stat_t) (err error)
   195  //sys	Mkdir(path string, mode uint32) (err error)
   196  //sys	Mkfifo(path string, mode uint32) (err error)
   197  //sys	Mknod(path string, mode uint32, dev int) (err error)
   198  //sys	Nanosleep(time *Timespec, leftover *Timespec) (err error)
   199  //sys	Open(path string, mode int, perm uint32) (fd int, err error)
   200  //sys	Pathconf(path string, name int) (val int, err error)
   201  //sys	Pread(fd int, p []byte, offset int64) (n int, err error)
   202  //sys	Pwrite(fd int, p []byte, offset int64) (n int, err error)
   203  //sys	read(fd int, p []byte) (n int, err error)
   204  //sys	Readlink(path string, buf []byte) (n int, err error)
   205  //sys	Rename(from string, to string) (err error)
   206  //sys	Revoke(path string) (err error)
   207  //sys	Rmdir(path string) (err error)
   208  //sys	Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
   209  //sys	Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
   210  //sysnb	Setegid(egid int) (err error)
   211  //sysnb	Seteuid(euid int) (err error)
   212  //sysnb	Setgid(gid int) (err error)
   213  //sysnb	Setpgid(pid int, pgid int) (err error)
   214  //sys	Setpriority(which int, who int, prio int) (err error)
   215  //sysnb	Setregid(rgid int, egid int) (err error)
   216  //sysnb	Setreuid(ruid int, euid int) (err error)
   217  //sysnb	Setrlimit(which int, lim *Rlimit) (err error)
   218  //sysnb	Setsid() (pid int, err error)
   219  //sysnb	Settimeofday(tp *Timeval) (err error)
   220  //sysnb	Setuid(uid int) (err error)
   221  //sys	Stat(path string, stat *Stat_t) (err error)
   222  //sys	Symlink(path string, link string) (err error)
   223  //sys	Sync() (err error)
   224  //sys	Truncate(path string, length int64) (err error)
   225  //sys	Umask(newmask int) (oldmask int)
   226  //sys	Unlink(path string) (err error)
   227  //sys	Unmount(path string, flags int) (err error)
   228  //sys	write(fd int, p []byte) (n int, err error)
   229  //sys	mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
   230  //sys	munmap(addr uintptr, length uintptr) (err error)
   231  //sys	readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
   232  //sys	writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
   233  //sys	utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error)
   234  //sys	getcwd(buf []byte) (n int, err error) = SYS___GETCWD
   235  //sys	sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
   236  

View as plain text