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