github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/go/src/syscall/syscall_netbsd.go (about)

     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  //sysnb pipe() (fd1 int, fd2 int, err error)
   106  func Pipe(p []int) (err error) {
   107  	if len(p) != 2 {
   108  		return EINVAL
   109  	}
   110  	p[0], p[1], err = pipe()
   111  	return
   112  }
   113  
   114  //sys getdents(fd int, buf []byte) (n int, err error)
   115  func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
   116  	return getdents(fd, buf)
   117  }
   118  
   119  // TODO
   120  func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
   121  	return -1, ENOSYS
   122  }
   123  
   124  func setattrlistTimes(path string, times []Timespec) error {
   125  	// used on Darwin for UtimesNano
   126  	return ENOSYS
   127  }
   128  
   129  /*
   130   * Exposed directly
   131   */
   132  //sys	Access(path string, mode uint32) (err error)
   133  //sys	Adjtime(delta *Timeval, olddelta *Timeval) (err error)
   134  //sys	Chdir(path string) (err error)
   135  //sys	Chflags(path string, flags int) (err error)
   136  //sys	Chmod(path string, mode uint32) (err error)
   137  //sys	Chown(path string, uid int, gid int) (err error)
   138  //sys	Chroot(path string) (err error)
   139  //sys	Close(fd int) (err error)
   140  //sys	Dup(fd int) (nfd int, err error)
   141  //sys	Dup2(from int, to int) (err error)
   142  //sys	Fchdir(fd int) (err error)
   143  //sys	Fchflags(fd int, flags int) (err error)
   144  //sys	Fchmod(fd int, mode uint32) (err error)
   145  //sys	Fchown(fd int, uid int, gid int) (err error)
   146  //sys	Flock(fd int, how int) (err error)
   147  //sys	Fpathconf(fd int, name int) (val int, err error)
   148  //sys	Fstat(fd int, stat *Stat_t) (err error)
   149  //sys	Fsync(fd int) (err error)
   150  //sys	Ftruncate(fd int, length int64) (err error)
   151  //sysnb	Getegid() (egid int)
   152  //sysnb	Geteuid() (uid int)
   153  //sysnb	Getgid() (gid int)
   154  //sysnb	Getpgid(pid int) (pgid int, err error)
   155  //sysnb	Getpgrp() (pgrp int)
   156  //sysnb	Getpid() (pid int)
   157  //sysnb	Getppid() (ppid int)
   158  //sys	Getpriority(which int, who int) (prio int, err error)
   159  //sysnb	Getrlimit(which int, lim *Rlimit) (err error)
   160  //sysnb	Getrusage(who int, rusage *Rusage) (err error)
   161  //sysnb	Getsid(pid int) (sid int, err error)
   162  //sysnb	Gettimeofday(tv *Timeval) (err error)
   163  //sysnb	Getuid() (uid int)
   164  //sys	Issetugid() (tainted bool)
   165  //sys	Kill(pid int, signum Signal) (err error)
   166  //sys	Kqueue() (fd int, err error)
   167  //sys	Lchown(path string, uid int, gid int) (err error)
   168  //sys	Link(path string, link string) (err error)
   169  //sys	Listen(s int, backlog int) (err error)
   170  //sys	Lstat(path string, stat *Stat_t) (err error)
   171  //sys	Mkdir(path string, mode uint32) (err error)
   172  //sys	Mkfifo(path string, mode uint32) (err error)
   173  //sys	Mknod(path string, mode uint32, dev int) (err error)
   174  //sys	Nanosleep(time *Timespec, leftover *Timespec) (err error)
   175  //sys	Open(path string, mode int, perm uint32) (fd int, err error)
   176  //sys	Pathconf(path string, name int) (val int, err error)
   177  //sys	Pread(fd int, p []byte, offset int64) (n int, err error)
   178  //sys	Pwrite(fd int, p []byte, offset int64) (n int, err error)
   179  //sys	read(fd int, p []byte) (n int, err error)
   180  //sys	Readlink(path string, buf []byte) (n int, err error)
   181  //sys	Rename(from string, to string) (err error)
   182  //sys	Revoke(path string) (err error)
   183  //sys	Rmdir(path string) (err error)
   184  //sys	Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
   185  //sys	Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
   186  //sysnb	Setegid(egid int) (err error)
   187  //sysnb	Seteuid(euid int) (err error)
   188  //sysnb	Setgid(gid int) (err error)
   189  //sysnb	Setpgid(pid int, pgid int) (err error)
   190  //sys	Setpriority(which int, who int, prio int) (err error)
   191  //sysnb	Setregid(rgid int, egid int) (err error)
   192  //sysnb	Setreuid(ruid int, euid int) (err error)
   193  //sysnb	Setrlimit(which int, lim *Rlimit) (err error)
   194  //sysnb	Setsid() (pid int, err error)
   195  //sysnb	Settimeofday(tp *Timeval) (err error)
   196  //sysnb	Setuid(uid int) (err error)
   197  //sys	Stat(path string, stat *Stat_t) (err error)
   198  //sys	Symlink(path string, link string) (err error)
   199  //sys	Sync() (err error)
   200  //sys	Truncate(path string, length int64) (err error)
   201  //sys	Umask(newmask int) (oldmask int)
   202  //sys	Unlink(path string) (err error)
   203  //sys	Unmount(path string, flags int) (err error)
   204  //sys	write(fd int, p []byte) (n int, err error)
   205  //sys	mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
   206  //sys	munmap(addr uintptr, length uintptr) (err error)
   207  //sys	readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
   208  //sys	writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
   209  //sys	utimensat(dirfd int, path string, times *[2]Timespec, flag int) (err error)
   210  
   211  /*
   212   * Unimplemented
   213   */
   214  // ____semctl13
   215  // __clone
   216  // __fhopen40
   217  // __fhstat40
   218  // __fhstatvfs140
   219  // __fstat30
   220  // __getcwd
   221  // __getfh30
   222  // __getlogin
   223  // __lstat30
   224  // __mount50
   225  // __msgctl13
   226  // __msync13
   227  // __ntp_gettime30
   228  // __posix_chown
   229  // __posix_fadvise50
   230  // __posix_fchown
   231  // __posix_lchown
   232  // __posix_rename
   233  // __setlogin
   234  // __shmctl13
   235  // __sigaction_sigtramp
   236  // __sigaltstack14
   237  // __sigpending14
   238  // __sigprocmask14
   239  // __sigsuspend14
   240  // __sigtimedwait
   241  // __stat30
   242  // __syscall
   243  // __vfork14
   244  // _ksem_close
   245  // _ksem_destroy
   246  // _ksem_getvalue
   247  // _ksem_init
   248  // _ksem_open
   249  // _ksem_post
   250  // _ksem_trywait
   251  // _ksem_unlink
   252  // _ksem_wait
   253  // _lwp_continue
   254  // _lwp_create
   255  // _lwp_ctl
   256  // _lwp_detach
   257  // _lwp_exit
   258  // _lwp_getname
   259  // _lwp_getprivate
   260  // _lwp_kill
   261  // _lwp_park
   262  // _lwp_self
   263  // _lwp_setname
   264  // _lwp_setprivate
   265  // _lwp_suspend
   266  // _lwp_unpark
   267  // _lwp_unpark_all
   268  // _lwp_wait
   269  // _lwp_wakeup
   270  // _pset_bind
   271  // _sched_getaffinity
   272  // _sched_getparam
   273  // _sched_setaffinity
   274  // _sched_setparam
   275  // acct
   276  // aio_cancel
   277  // aio_error
   278  // aio_fsync
   279  // aio_read
   280  // aio_return
   281  // aio_suspend
   282  // aio_write
   283  // break
   284  // clock_getres
   285  // clock_gettime
   286  // clock_settime
   287  // compat_09_ogetdomainname
   288  // compat_09_osetdomainname
   289  // compat_09_ouname
   290  // compat_10_omsgsys
   291  // compat_10_osemsys
   292  // compat_10_oshmsys
   293  // compat_12_fstat12
   294  // compat_12_getdirentries
   295  // compat_12_lstat12
   296  // compat_12_msync
   297  // compat_12_oreboot
   298  // compat_12_oswapon
   299  // compat_12_stat12
   300  // compat_13_sigaction13
   301  // compat_13_sigaltstack13
   302  // compat_13_sigpending13
   303  // compat_13_sigprocmask13
   304  // compat_13_sigreturn13
   305  // compat_13_sigsuspend13
   306  // compat_14___semctl
   307  // compat_14_msgctl
   308  // compat_14_shmctl
   309  // compat_16___sigaction14
   310  // compat_16___sigreturn14
   311  // compat_20_fhstatfs
   312  // compat_20_fstatfs
   313  // compat_20_getfsstat
   314  // compat_20_statfs
   315  // compat_30___fhstat30
   316  // compat_30___fstat13
   317  // compat_30___lstat13
   318  // compat_30___stat13
   319  // compat_30_fhopen
   320  // compat_30_fhstat
   321  // compat_30_fhstatvfs1
   322  // compat_30_getdents
   323  // compat_30_getfh
   324  // compat_30_ntp_gettime
   325  // compat_30_socket
   326  // compat_40_mount
   327  // compat_43_fstat43
   328  // compat_43_lstat43
   329  // compat_43_oaccept
   330  // compat_43_ocreat
   331  // compat_43_oftruncate
   332  // compat_43_ogetdirentries
   333  // compat_43_ogetdtablesize
   334  // compat_43_ogethostid
   335  // compat_43_ogethostname
   336  // compat_43_ogetkerninfo
   337  // compat_43_ogetpagesize
   338  // compat_43_ogetpeername
   339  // compat_43_ogetrlimit
   340  // compat_43_ogetsockname
   341  // compat_43_okillpg
   342  // compat_43_olseek
   343  // compat_43_ommap
   344  // compat_43_oquota
   345  // compat_43_orecv
   346  // compat_43_orecvfrom
   347  // compat_43_orecvmsg
   348  // compat_43_osend
   349  // compat_43_osendmsg
   350  // compat_43_osethostid
   351  // compat_43_osethostname
   352  // compat_43_osetrlimit
   353  // compat_43_osigblock
   354  // compat_43_osigsetmask
   355  // compat_43_osigstack
   356  // compat_43_osigvec
   357  // compat_43_otruncate
   358  // compat_43_owait
   359  // compat_43_stat43
   360  // execve
   361  // extattr_delete_fd
   362  // extattr_delete_file
   363  // extattr_delete_link
   364  // extattr_get_fd
   365  // extattr_get_file
   366  // extattr_get_link
   367  // extattr_list_fd
   368  // extattr_list_file
   369  // extattr_list_link
   370  // extattr_set_fd
   371  // extattr_set_file
   372  // extattr_set_link
   373  // extattrctl
   374  // fchroot
   375  // fdatasync
   376  // fgetxattr
   377  // fktrace
   378  // flistxattr
   379  // fork
   380  // fremovexattr
   381  // fsetxattr
   382  // fstatvfs1
   383  // fsync_range
   384  // getcontext
   385  // getitimer
   386  // getvfsstat
   387  // getxattr
   388  // ioctl
   389  // ktrace
   390  // lchflags
   391  // lchmod
   392  // lfs_bmapv
   393  // lfs_markv
   394  // lfs_segclean
   395  // lfs_segwait
   396  // lgetxattr
   397  // lio_listio
   398  // listxattr
   399  // llistxattr
   400  // lremovexattr
   401  // lseek
   402  // lsetxattr
   403  // lutimes
   404  // madvise
   405  // mincore
   406  // minherit
   407  // mlock
   408  // mlockall
   409  // modctl
   410  // mprotect
   411  // mq_close
   412  // mq_getattr
   413  // mq_notify
   414  // mq_open
   415  // mq_receive
   416  // mq_send
   417  // mq_setattr
   418  // mq_timedreceive
   419  // mq_timedsend
   420  // mq_unlink
   421  // mremap
   422  // msgget
   423  // msgrcv
   424  // msgsnd
   425  // munlock
   426  // munlockall
   427  // nfssvc
   428  // ntp_adjtime
   429  // pmc_control
   430  // pmc_get_info
   431  // poll
   432  // pollts
   433  // preadv
   434  // profil
   435  // pselect
   436  // pset_assign
   437  // pset_create
   438  // pset_destroy
   439  // ptrace
   440  // pwritev
   441  // quotactl
   442  // rasctl
   443  // readv
   444  // reboot
   445  // removexattr
   446  // sa_enable
   447  // sa_preempt
   448  // sa_register
   449  // sa_setconcurrency
   450  // sa_stacks
   451  // sa_yield
   452  // sbrk
   453  // sched_yield
   454  // semconfig
   455  // semget
   456  // semop
   457  // setcontext
   458  // setitimer
   459  // setxattr
   460  // shmat
   461  // shmdt
   462  // shmget
   463  // sstk
   464  // statvfs1
   465  // swapctl
   466  // sysarch
   467  // syscall
   468  // timer_create
   469  // timer_delete
   470  // timer_getoverrun
   471  // timer_gettime
   472  // timer_settime
   473  // undelete
   474  // utrace
   475  // uuidgen
   476  // vadvise
   477  // vfork
   478  // writev