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.
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.
21 // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
22 type SockaddrDatalink struct {
31 raw RawSockaddrDatalink
34 func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
36 func sysctlNodes(mib []_C_int) (nodes []Sysctlnode, err error) {
39 // Get a list of all sysctl nodes below the given MIB by performing
40 // a sysctl for the given MIB with CTL_QUERY appended.
41 mib = append(mib, CTL_QUERY)
42 qnode := Sysctlnode{Flags: SYSCTL_VERS_1}
43 qp := (*byte)(unsafe.Pointer(&qnode))
44 sz := unsafe.Sizeof(qnode)
45 if err = sysctl(mib, nil, &olen, qp, sz); err != nil {
49 // Now that we know the size, get the actual nodes.
50 nodes = make([]Sysctlnode, olen/sz)
51 np := (*byte)(unsafe.Pointer(&nodes[0]))
52 if err = sysctl(mib, np, &olen, qp, sz); err != nil {
59 func nametomib(name string) (mib []_C_int, err error) {
60 // Split name into components.
63 for i := 0; i < len(name); i++ {
65 parts = append(parts, name[last:i])
69 parts = append(parts, name[last:])
71 // Discover the nodes and construct the MIB OID.
72 for partno, part := range parts {
73 nodes, err := sysctlNodes(mib)
77 for _, node := range nodes {
79 for i := range node.Name {
80 if node.Name[i] != 0 {
81 n = append(n, byte(node.Name[i]))
84 if string(n) == part {
85 mib = append(mib, _C_int(node.Num))
89 if len(mib) != partno+1 {
97 func SysctlClockinfo(name string) (*Clockinfo, error) {
98 mib, err := sysctlmib(name)
103 n := uintptr(SizeofClockinfo)
105 if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil {
108 if n != SizeofClockinfo {
114 //sysnb pipe() (fd1 int, fd2 int, err error)
115 func Pipe(p []int) (err error) {
119 p[0], p[1], err = pipe()
123 //sys getdents(fd int, buf []byte) (n int, err error)
124 func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
125 return getdents(fd, buf)
128 const ImplementsGetwd = true
130 //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD
132 func Getwd() (string, error) {
133 var buf [PathMax]byte
134 _, err := Getcwd(buf[0:])
142 return string(buf[:n]), nil
146 func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
150 func setattrlistTimes(path string, times []Timespec, flags int) error {
151 // used on Darwin for UtimesNano
155 //sys ioctl(fd int, req uint, arg uintptr) (err error)
157 // ioctl itself should not be exposed directly, but additional get/set
158 // functions for specific types are permissible.
160 // IoctlSetInt performs an ioctl operation which sets an integer value
161 // on fd, using the specified request number.
162 func IoctlSetInt(fd int, req uint, value int) error {
163 return ioctl(fd, req, uintptr(value))
166 func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
167 return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
170 func ioctlSetTermios(fd int, req uint, value *Termios) error {
171 return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
174 // IoctlGetInt performs an ioctl operation which gets an integer value
175 // from fd, using the specified request number.
176 func IoctlGetInt(fd int, req uint) (int, error) {
178 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
182 func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
184 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
188 func IoctlGetTermios(fd int, req uint) (*Termios, error) {
190 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
194 func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) {
196 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
197 runtime.KeepAlive(value)
201 func Uname(uname *Utsname) error {
202 mib := []_C_int{CTL_KERN, KERN_OSTYPE}
203 n := unsafe.Sizeof(uname.Sysname)
204 if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil {
208 mib = []_C_int{CTL_KERN, KERN_HOSTNAME}
209 n = unsafe.Sizeof(uname.Nodename)
210 if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil {
214 mib = []_C_int{CTL_KERN, KERN_OSRELEASE}
215 n = unsafe.Sizeof(uname.Release)
216 if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil {
220 mib = []_C_int{CTL_KERN, KERN_VERSION}
221 n = unsafe.Sizeof(uname.Version)
222 if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil {
226 // The version might have newlines or tabs in it, convert them to
228 for i, b := range uname.Version {
229 if b == '\n' || b == '\t' {
230 if i == len(uname.Version)-1 {
233 uname.Version[i] = ' '
238 mib = []_C_int{CTL_HW, HW_MACHINE}
239 n = unsafe.Sizeof(uname.Machine)
240 if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil {
247 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
249 raceReleaseMerge(unsafe.Pointer(&ioSync))
251 return sendfile(outfd, infd, offset, count)
257 //sys Access(path string, mode uint32) (err error)
258 //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
259 //sys Chdir(path string) (err error)
260 //sys Chflags(path string, flags int) (err error)
261 //sys Chmod(path string, mode uint32) (err error)
262 //sys Chown(path string, uid int, gid int) (err error)
263 //sys Chroot(path string) (err error)
264 //sys Close(fd int) (err error)
265 //sys Dup(fd int) (nfd int, err error)
266 //sys Dup2(from int, to int) (err error)
268 //sys ExtattrGetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error)
269 //sys ExtattrSetFd(fd int, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error)
270 //sys ExtattrDeleteFd(fd int, attrnamespace int, attrname string) (err error)
271 //sys ExtattrListFd(fd int, attrnamespace int, data uintptr, nbytes int) (ret int, err error)
272 //sys ExtattrGetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error)
273 //sys ExtattrSetFile(file string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error)
274 //sys ExtattrDeleteFile(file string, attrnamespace int, attrname string) (err error)
275 //sys ExtattrListFile(file string, attrnamespace int, data uintptr, nbytes int) (ret int, err error)
276 //sys ExtattrGetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error)
277 //sys ExtattrSetLink(link string, attrnamespace int, attrname string, data uintptr, nbytes int) (ret int, err error)
278 //sys ExtattrDeleteLink(link string, attrnamespace int, attrname string) (err error)
279 //sys ExtattrListLink(link string, attrnamespace int, data uintptr, nbytes int) (ret int, err error)
280 //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
281 //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_POSIX_FADVISE
282 //sys Fchdir(fd int) (err error)
283 //sys Fchflags(fd int, flags int) (err error)
284 //sys Fchmod(fd int, mode uint32) (err error)
285 //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
286 //sys Fchown(fd int, uid int, gid int) (err error)
287 //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
288 //sys Flock(fd int, how int) (err error)
289 //sys Fpathconf(fd int, name int) (val int, err error)
290 //sys Fstat(fd int, stat *Stat_t) (err error)
291 //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
292 //sys Fsync(fd int) (err error)
293 //sys Ftruncate(fd int, length int64) (err error)
294 //sysnb Getegid() (egid int)
295 //sysnb Geteuid() (uid int)
296 //sysnb Getgid() (gid int)
297 //sysnb Getpgid(pid int) (pgid int, err error)
298 //sysnb Getpgrp() (pgrp int)
299 //sysnb Getpid() (pid int)
300 //sysnb Getppid() (ppid int)
301 //sys Getpriority(which int, who int) (prio int, err error)
302 //sysnb Getrlimit(which int, lim *Rlimit) (err error)
303 //sysnb Getrusage(who int, rusage *Rusage) (err error)
304 //sysnb Getsid(pid int) (sid int, err error)
305 //sysnb Gettimeofday(tv *Timeval) (err error)
306 //sysnb Getuid() (uid int)
307 //sys Issetugid() (tainted bool)
308 //sys Kill(pid int, signum syscall.Signal) (err error)
309 //sys Kqueue() (fd int, err error)
310 //sys Lchown(path string, uid int, gid int) (err error)
311 //sys Link(path string, link string) (err error)
312 //sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error)
313 //sys Listen(s int, backlog int) (err error)
314 //sys Lstat(path string, stat *Stat_t) (err error)
315 //sys Mkdir(path string, mode uint32) (err error)
316 //sys Mkdirat(dirfd int, path string, mode uint32) (err error)
317 //sys Mkfifo(path string, mode uint32) (err error)
318 //sys Mkfifoat(dirfd int, path string, mode uint32) (err error)
319 //sys Mknod(path string, mode uint32, dev int) (err error)
320 //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
321 //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
322 //sys Open(path string, mode int, perm uint32) (fd int, err error)
323 //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error)
324 //sys Pathconf(path string, name int) (val int, err error)
325 //sys Pread(fd int, p []byte, offset int64) (n int, err error)
326 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
327 //sys read(fd int, p []byte) (n int, err error)
328 //sys Readlink(path string, buf []byte) (n int, err error)
329 //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error)
330 //sys Rename(from string, to string) (err error)
331 //sys Renameat(fromfd int, from string, tofd int, to string) (err error)
332 //sys Revoke(path string) (err error)
333 //sys Rmdir(path string) (err error)
334 //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
335 //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
336 //sysnb Setegid(egid int) (err error)
337 //sysnb Seteuid(euid int) (err error)
338 //sysnb Setgid(gid int) (err error)
339 //sysnb Setpgid(pid int, pgid int) (err error)
340 //sys Setpriority(which int, who int, prio int) (err error)
341 //sysnb Setregid(rgid int, egid int) (err error)
342 //sysnb Setreuid(ruid int, euid int) (err error)
343 //sysnb Setrlimit(which int, lim *Rlimit) (err error)
344 //sysnb Setsid() (pid int, err error)
345 //sysnb Settimeofday(tp *Timeval) (err error)
346 //sysnb Setuid(uid int) (err error)
347 //sys Stat(path string, stat *Stat_t) (err error)
348 //sys Symlink(path string, link string) (err error)
349 //sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error)
350 //sys Sync() (err error)
351 //sys Truncate(path string, length int64) (err error)
352 //sys Umask(newmask int) (oldmask int)
353 //sys Unlink(path string) (err error)
354 //sys Unlinkat(dirfd int, path string, flags int) (err error)
355 //sys Unmount(path string, flags int) (err error)
356 //sys write(fd int, p []byte) (n int, err error)
357 //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
358 //sys munmap(addr uintptr, length uintptr) (err error)
359 //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
360 //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
361 //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
386 // __sigaction_sigtramp
422 // _sched_getaffinity
424 // _sched_setaffinity
438 // compat_09_ogetdomainname
439 // compat_09_osetdomainname
445 // compat_12_getdirentries
451 // compat_13_sigaction13
452 // compat_13_sigaltstack13
453 // compat_13_sigpending13
454 // compat_13_sigprocmask13
455 // compat_13_sigreturn13
456 // compat_13_sigsuspend13
457 // compat_14___semctl
460 // compat_16___sigaction14
461 // compat_16___sigreturn14
462 // compat_20_fhstatfs
464 // compat_20_getfsstat
466 // compat_30___fhstat30
467 // compat_30___fstat13
468 // compat_30___lstat13
469 // compat_30___stat13
472 // compat_30_fhstatvfs1
473 // compat_30_getdents
475 // compat_30_ntp_gettime
482 // compat_43_oftruncate
483 // compat_43_ogetdirentries
484 // compat_43_ogetdtablesize
485 // compat_43_ogethostid
486 // compat_43_ogethostname
487 // compat_43_ogetkerninfo
488 // compat_43_ogetpagesize
489 // compat_43_ogetpeername
490 // compat_43_ogetrlimit
491 // compat_43_ogetsockname
497 // compat_43_orecvfrom
498 // compat_43_orecvmsg
500 // compat_43_osendmsg
501 // compat_43_osethostid
502 // compat_43_osethostname
503 // compat_43_osetrlimit
504 // compat_43_osigblock
505 // compat_43_osigsetmask
506 // compat_43_osigstack
508 // compat_43_otruncate
513 // extattr_delete_file
514 // extattr_delete_link