github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/pkg/syscall/syscall_dragonfly.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 // FreeBSD 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 Rcf uint16 27 Route [16]uint16 28 raw RawSockaddrDatalink 29 } 30 31 // Translate "kern.hostname" to []_C_int{0,1,2,3}. 32 func nametomib(name string) (mib []_C_int, err error) { 33 const siz = unsafe.Sizeof(mib[0]) 34 35 // NOTE(rsc): It seems strange to set the buffer to have 36 // size CTL_MAXNAME+2 but use only CTL_MAXNAME 37 // as the size. I don't know why the +2 is here, but the 38 // kernel uses +2 for its own implementation of this function. 39 // I am scared that if we don't include the +2 here, the kernel 40 // will silently write 2 words farther than we specify 41 // and we'll get memory corruption. 42 var buf [CTL_MAXNAME + 2]_C_int 43 n := uintptr(CTL_MAXNAME) * siz 44 45 p := (*byte)(unsafe.Pointer(&buf[0])) 46 bytes, err := ByteSliceFromString(name) 47 if err != nil { 48 return nil, err 49 } 50 51 // Magic sysctl: "setting" 0.3 to a string name 52 // lets you read back the array of integers form. 53 if err = sysctl([]_C_int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil { 54 return nil, err 55 } 56 return buf[0 : n/siz], nil 57 } 58 59 // ParseDirent parses up to max directory entries in buf, 60 // appending the names to names. It returns the number 61 // bytes consumed from buf, the number of entries added 62 // to names, and the new names slice. 63 func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) { 64 origlen := len(buf) 65 for max != 0 && len(buf) > 0 { 66 dirent := (*Dirent)(unsafe.Pointer(&buf[0])) 67 reclen := int(16+dirent.Namlen+1+7) & ^7 68 buf = buf[reclen:] 69 if dirent.Fileno == 0 { // File absent in directory. 70 continue 71 } 72 bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0])) 73 var name = string(bytes[0:dirent.Namlen]) 74 if name == "." || name == ".." { // Useless names 75 continue 76 } 77 max-- 78 count++ 79 names = append(names, name) 80 } 81 return origlen - len(buf), count, names 82 } 83 84 //sysnb pipe() (r int, w int, err error) 85 86 func Pipe(p []int) (err error) { 87 if len(p) != 2 { 88 return EINVAL 89 } 90 p[0], p[1], err = pipe() 91 return 92 } 93 94 //sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error) 95 func Pread(fd int, p []byte, offset int64) (n int, err error) { 96 return extpread(fd, p, 0, offset) 97 } 98 99 //sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error) 100 func Pwrite(fd int, p []byte, offset int64) (n int, err error) { 101 return extpwrite(fd, p, 0, offset) 102 } 103 104 /* 105 * Exposed directly 106 */ 107 //sys Access(path string, mode uint32) (err error) 108 //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) 109 //sys Chdir(path string) (err error) 110 //sys Chflags(path string, flags int) (err error) 111 //sys Chmod(path string, mode uint32) (err error) 112 //sys Chown(path string, uid int, gid int) (err error) 113 //sys Chroot(path string) (err error) 114 //sys Close(fd int) (err error) 115 //sysnb Dup(fd int) (nfd int, err error) 116 //sysnb Dup2(from int, to int) (err error) 117 //sys Exit(code int) 118 //sys Fchdir(fd int) (err error) 119 //sys Fchflags(fd int, flags int) (err error) 120 //sys Fchmod(fd int, mode uint32) (err error) 121 //sys Fchown(fd int, uid int, gid int) (err error) 122 //sys Flock(fd int, how int) (err error) 123 //sys Fpathconf(fd int, name int) (val int, err error) 124 //sys Fstat(fd int, stat *Stat_t) (err error) 125 //sys Fstatfs(fd int, stat *Statfs_t) (err error) 126 //sys Fsync(fd int) (err error) 127 //sys Ftruncate(fd int, length int64) (err error) 128 //sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) 129 //sys Getdtablesize() (size int) 130 //sysnb Getegid() (egid int) 131 //sysnb Geteuid() (uid int) 132 //sys Getfsstat(buf []Statfs_t, flags int) (n int, err error) 133 //sysnb Getgid() (gid int) 134 //sysnb Getpgid(pid int) (pgid int, err error) 135 //sysnb Getpgrp() (pgrp int) 136 //sysnb Getpid() (pid int) 137 //sysnb Getppid() (ppid int) 138 //sys Getpriority(which int, who int) (prio int, err error) 139 //sysnb Getrlimit(which int, lim *Rlimit) (err error) 140 //sysnb Getrusage(who int, rusage *Rusage) (err error) 141 //sysnb Getsid(pid int) (sid int, err error) 142 //sysnb Gettimeofday(tv *Timeval) (err error) 143 //sysnb Getuid() (uid int) 144 //sys Issetugid() (tainted bool) 145 //sys Kill(pid int, signum Signal) (err error) 146 //sys Kqueue() (fd int, err error) 147 //sys Lchown(path string, uid int, gid int) (err error) 148 //sys Link(path string, link string) (err error) 149 //sys Listen(s int, backlog int) (err error) 150 //sys Lstat(path string, stat *Stat_t) (err error) 151 //sys Mkdir(path string, mode uint32) (err error) 152 //sys Mkfifo(path string, mode uint32) (err error) 153 //sys Mknod(path string, mode uint32, dev int) (err error) 154 //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) 155 //sys Open(path string, mode int, perm uint32) (fd int, err error) 156 //sys Pathconf(path string, name int) (val int, err error) 157 //sys read(fd int, p []byte) (n int, err error) 158 //sys Readlink(path string, buf []byte) (n int, err error) 159 //sys Rename(from string, to string) (err error) 160 //sys Revoke(path string) (err error) 161 //sys Rmdir(path string) (err error) 162 //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK 163 //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error) 164 //sysnb Setegid(egid int) (err error) 165 //sysnb Seteuid(euid int) (err error) 166 //sysnb Setgid(gid int) (err error) 167 //sys Setlogin(name string) (err error) 168 //sysnb Setpgid(pid int, pgid int) (err error) 169 //sys Setpriority(which int, who int, prio int) (err error) 170 //sysnb Setregid(rgid int, egid int) (err error) 171 //sysnb Setreuid(ruid int, euid int) (err error) 172 //sysnb Setrlimit(which int, lim *Rlimit) (err error) 173 //sysnb Setsid() (pid int, err error) 174 //sysnb Settimeofday(tp *Timeval) (err error) 175 //sysnb Setuid(uid int) (err error) 176 //sys Stat(path string, stat *Stat_t) (err error) 177 //sys Statfs(path string, stat *Statfs_t) (err error) 178 //sys Symlink(path string, link string) (err error) 179 //sys Sync() (err error) 180 //sys Truncate(path string, length int64) (err error) 181 //sys Umask(newmask int) (oldmask int) 182 //sys Undelete(path string) (err error) 183 //sys Unlink(path string) (err error) 184 //sys Unmount(path string, flags int) (err error) 185 //sys write(fd int, p []byte) (n int, err error) 186 //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) 187 //sys munmap(addr uintptr, length uintptr) (err error) 188 //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ 189 //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE 190 191 /* 192 * Unimplemented 193 * TODO(jsing): Update this list for DragonFly. 194 */ 195 // Profil 196 // Sigaction 197 // Sigprocmask 198 // Getlogin 199 // Sigpending 200 // Sigaltstack 201 // Ioctl 202 // Reboot 203 // Execve 204 // Vfork 205 // Sbrk 206 // Sstk 207 // Ovadvise 208 // Mincore 209 // Setitimer 210 // Swapon 211 // Select 212 // Sigsuspend 213 // Readv 214 // Writev 215 // Nfssvc 216 // Getfh 217 // Quotactl 218 // Mount 219 // Csops 220 // Waitid 221 // Add_profil 222 // Kdebug_trace 223 // Sigreturn 224 // Mmap 225 // Mlock 226 // Munlock 227 // Atsocket 228 // Kqueue_from_portset_np 229 // Kqueue_portset 230 // Getattrlist 231 // Setattrlist 232 // Getdirentriesattr 233 // Searchfs 234 // Delete 235 // Copyfile 236 // Poll 237 // Watchevent 238 // Waitevent 239 // Modwatch 240 // Getxattr 241 // Fgetxattr 242 // Setxattr 243 // Fsetxattr 244 // Removexattr 245 // Fremovexattr 246 // Listxattr 247 // Flistxattr 248 // Fsctl 249 // Initgroups 250 // Posix_spawn 251 // Nfsclnt 252 // Fhopen 253 // Minherit 254 // Semsys 255 // Msgsys 256 // Shmsys 257 // Semctl 258 // Semget 259 // Semop 260 // Msgctl 261 // Msgget 262 // Msgsnd 263 // Msgrcv 264 // Shmat 265 // Shmctl 266 // Shmdt 267 // Shmget 268 // Shm_open 269 // Shm_unlink 270 // Sem_open 271 // Sem_close 272 // Sem_unlink 273 // Sem_wait 274 // Sem_trywait 275 // Sem_post 276 // Sem_getvalue 277 // Sem_init 278 // Sem_destroy 279 // Open_extended 280 // Umask_extended 281 // Stat_extended 282 // Lstat_extended 283 // Fstat_extended 284 // Chmod_extended 285 // Fchmod_extended 286 // Access_extended 287 // Settid 288 // Gettid 289 // Setsgroups 290 // Getsgroups 291 // Setwgroups 292 // Getwgroups 293 // Mkfifo_extended 294 // Mkdir_extended 295 // Identitysvc 296 // Shared_region_check_np 297 // Shared_region_map_np 298 // __pthread_mutex_destroy 299 // __pthread_mutex_init 300 // __pthread_mutex_lock 301 // __pthread_mutex_trylock 302 // __pthread_mutex_unlock 303 // __pthread_cond_init 304 // __pthread_cond_destroy 305 // __pthread_cond_broadcast 306 // __pthread_cond_signal 307 // Setsid_with_pid 308 // __pthread_cond_timedwait 309 // Aio_fsync 310 // Aio_return 311 // Aio_suspend 312 // Aio_cancel 313 // Aio_error 314 // Aio_read 315 // Aio_write 316 // Lio_listio 317 // __pthread_cond_wait 318 // Iopolicysys 319 // Mlockall 320 // Munlockall 321 // __pthread_kill 322 // __pthread_sigmask 323 // __sigwait 324 // __disable_threadsignal 325 // __pthread_markcancel 326 // __pthread_canceled 327 // __semwait_signal 328 // Proc_info 329 // Stat64_extended 330 // Lstat64_extended 331 // Fstat64_extended 332 // __pthread_chdir 333 // __pthread_fchdir 334 // Audit 335 // Auditon 336 // Getauid 337 // Setauid 338 // Getaudit 339 // Setaudit 340 // Getaudit_addr 341 // Setaudit_addr 342 // Auditctl 343 // Bsdthread_create 344 // Bsdthread_terminate 345 // Stack_snapshot 346 // Bsdthread_register 347 // Workq_open 348 // Workq_ops 349 // __mac_execve 350 // __mac_syscall 351 // __mac_get_file 352 // __mac_set_file 353 // __mac_get_link 354 // __mac_set_link 355 // __mac_get_proc 356 // __mac_set_proc 357 // __mac_get_fd 358 // __mac_set_fd 359 // __mac_get_pid 360 // __mac_get_lcid 361 // __mac_get_lctx 362 // __mac_set_lctx 363 // Setlcid 364 // Read_nocancel 365 // Write_nocancel 366 // Open_nocancel 367 // Close_nocancel 368 // Wait4_nocancel 369 // Recvmsg_nocancel 370 // Sendmsg_nocancel 371 // Recvfrom_nocancel 372 // Accept_nocancel 373 // Msync_nocancel 374 // Fcntl_nocancel 375 // Select_nocancel 376 // Fsync_nocancel 377 // Connect_nocancel 378 // Sigsuspend_nocancel 379 // Readv_nocancel 380 // Writev_nocancel 381 // Sendto_nocancel 382 // Pread_nocancel 383 // Pwrite_nocancel 384 // Waitid_nocancel 385 // Poll_nocancel 386 // Msgsnd_nocancel 387 // Msgrcv_nocancel 388 // Sem_wait_nocancel 389 // Aio_suspend_nocancel 390 // __sigwait_nocancel 391 // __semwait_signal_nocancel 392 // __mac_mount 393 // __mac_get_mount 394 // __mac_getfsstat