...
Run Format

Source file src/syscall/syscall_netbsd.go

Documentation: syscall

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

View as plain text