github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/sys/unix/syscall_dragonfly.go (about) 1 // Copyright 2009 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 // DragonFly BSD 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 unix 14 15 import "unsafe" 16 17 //sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL 18 19 // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. 20 type SockaddrDatalink struct { 21 Len uint8 22 Family uint8 23 Index uint16 24 Type uint8 25 Nlen uint8 26 Alen uint8 27 Slen uint8 28 Data [12]int8 29 Rcf uint16 30 Route [16]uint16 31 raw RawSockaddrDatalink 32 } 33 34 // Translate "kern.hostname" to []_C_int{0,1,2,3}. 35 func nametomib(name string) (mib []_C_int, err error) { 36 const siz = unsafe.Sizeof(mib[0]) 37 38 // NOTE(rsc): It seems strange to set the buffer to have 39 // size CTL_MAXNAME+2 but use only CTL_MAXNAME 40 // as the size. I don't know why the +2 is here, but the 41 // kernel uses +2 for its own implementation of this function. 42 // I am scared that if we don't include the +2 here, the kernel 43 // will silently write 2 words farther than we specify 44 // and we'll get memory corruption. 45 var buf [CTL_MAXNAME + 2]_C_int 46 n := uintptr(CTL_MAXNAME) * siz 47 48 p := (*byte)(unsafe.Pointer(&buf[0])) 49 bytes, err := ByteSliceFromString(name) 50 if err != nil { 51 return nil, err 52 } 53 54 // Magic sysctl: "setting" 0.3 to a string name 55 // lets you read back the array of integers form. 56 if err = sysctl([]_C_int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil { 57 return nil, err 58 } 59 return buf[0 : n/siz], nil 60 } 61 62 func direntIno(buf []byte) (uint64, bool) { 63 return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno)) 64 } 65 66 func direntReclen(buf []byte) (uint64, bool) { 67 namlen, ok := direntNamlen(buf) 68 if !ok { 69 return 0, false 70 } 71 return (16 + namlen + 1 + 7) &^ 7, true 72 } 73 74 func direntNamlen(buf []byte) (uint64, bool) { 75 return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) 76 } 77 78 //sysnb pipe() (r int, w int, err error) 79 80 func Pipe(p []int) (err error) { 81 if len(p) != 2 { 82 return EINVAL 83 } 84 p[0], p[1], err = pipe() 85 return 86 } 87 88 //sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error) 89 func Pread(fd int, p []byte, offset int64) (n int, err error) { 90 return extpread(fd, p, 0, offset) 91 } 92 93 //sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error) 94 func Pwrite(fd int, p []byte, offset int64) (n int, err error) { 95 return extpwrite(fd, p, 0, offset) 96 } 97 98 func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) { 99 var rsa RawSockaddrAny 100 var len _Socklen = SizeofSockaddrAny 101 nfd, err = accept4(fd, &rsa, &len, flags) 102 if err != nil { 103 return 104 } 105 if len > SizeofSockaddrAny { 106 panic("RawSockaddrAny too small") 107 } 108 sa, err = anyToSockaddr(fd, &rsa) 109 if err != nil { 110 Close(nfd) 111 nfd = 0 112 } 113 return 114 } 115 116 const ImplementsGetwd = true 117 118 //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD 119 120 func Getwd() (string, error) { 121 var buf [PathMax]byte 122 _, err := Getcwd(buf[0:]) 123 if err != nil { 124 return "", err 125 } 126 n := clen(buf[:]) 127 if n < 1 { 128 return "", EINVAL 129 } 130 return string(buf[:n]), nil 131 } 132 133 func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { 134 var _p0 unsafe.Pointer 135 var bufsize uintptr 136 if len(buf) > 0 { 137 _p0 = unsafe.Pointer(&buf[0]) 138 bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) 139 } 140 r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) 141 n = int(r0) 142 if e1 != 0 { 143 err = e1 144 } 145 return 146 } 147 148 func setattrlistTimes(path string, times []Timespec, flags int) error { 149 // used on Darwin for UtimesNano 150 return ENOSYS 151 } 152 153 //sys ioctl(fd int, req uint, arg uintptr) (err error) 154 155 func sysctlUname(mib []_C_int, old *byte, oldlen *uintptr) error { 156 err := sysctl(mib, old, oldlen, nil, 0) 157 if err != nil { 158 // Utsname members on Dragonfly are only 32 bytes and 159 // the syscall returns ENOMEM in case the actual value 160 // is longer. 161 if err == ENOMEM { 162 err = nil 163 } 164 } 165 return err 166 } 167 168 func Uname(uname *Utsname) error { 169 mib := []_C_int{CTL_KERN, KERN_OSTYPE} 170 n := unsafe.Sizeof(uname.Sysname) 171 if err := sysctlUname(mib, &uname.Sysname[0], &n); err != nil { 172 return err 173 } 174 uname.Sysname[unsafe.Sizeof(uname.Sysname)-1] = 0 175 176 mib = []_C_int{CTL_KERN, KERN_HOSTNAME} 177 n = unsafe.Sizeof(uname.Nodename) 178 if err := sysctlUname(mib, &uname.Nodename[0], &n); err != nil { 179 return err 180 } 181 uname.Nodename[unsafe.Sizeof(uname.Nodename)-1] = 0 182 183 mib = []_C_int{CTL_KERN, KERN_OSRELEASE} 184 n = unsafe.Sizeof(uname.Release) 185 if err := sysctlUname(mib, &uname.Release[0], &n); err != nil { 186 return err 187 } 188 uname.Release[unsafe.Sizeof(uname.Release)-1] = 0 189 190 mib = []_C_int{CTL_KERN, KERN_VERSION} 191 n = unsafe.Sizeof(uname.Version) 192 if err := sysctlUname(mib, &uname.Version[0], &n); err != nil { 193 return err 194 } 195 196 // The version might have newlines or tabs in it, convert them to 197 // spaces. 198 for i, b := range uname.Version { 199 if b == '\n' || b == '\t' { 200 if i == len(uname.Version)-1 { 201 uname.Version[i] = 0 202 } else { 203 uname.Version[i] = ' ' 204 } 205 } 206 } 207 208 mib = []_C_int{CTL_HW, HW_MACHINE} 209 n = unsafe.Sizeof(uname.Machine) 210 if err := sysctlUname(mib, &uname.Machine[0], &n); err != nil { 211 return err 212 } 213 uname.Machine[unsafe.Sizeof(uname.Machine)-1] = 0 214 215 return nil 216 } 217 218 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 219 if raceenabled { 220 raceReleaseMerge(unsafe.Pointer(&ioSync)) 221 } 222 return sendfile(outfd, infd, offset, count) 223 } 224 225 /* 226 * Exposed directly 227 */ 228 //sys Access(path string, mode uint32) (err error) 229 //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) 230 //sys Chdir(path string) (err error) 231 //sys Chflags(path string, flags int) (err error) 232 //sys Chmod(path string, mode uint32) (err error) 233 //sys Chown(path string, uid int, gid int) (err error) 234 //sys Chroot(path string) (err error) 235 //sys Close(fd int) (err error) 236 //sys Dup(fd int) (nfd int, err error) 237 //sys Dup2(from int, to int) (err error) 238 //sys Exit(code int) 239 //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) 240 //sys Fchdir(fd int) (err error) 241 //sys Fchflags(fd int, flags int) (err error) 242 //sys Fchmod(fd int, mode uint32) (err error) 243 //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) 244 //sys Fchown(fd int, uid int, gid int) (err error) 245 //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) 246 //sys Flock(fd int, how int) (err error) 247 //sys Fpathconf(fd int, name int) (val int, err error) 248 //sys Fstat(fd int, stat *Stat_t) (err error) 249 //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) 250 //sys Fstatfs(fd int, stat *Statfs_t) (err error) 251 //sys Fsync(fd int) (err error) 252 //sys Ftruncate(fd int, length int64) (err error) 253 //sys Getdents(fd int, buf []byte) (n int, err error) 254 //sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) 255 //sys Getdtablesize() (size int) 256 //sysnb Getegid() (egid int) 257 //sysnb Geteuid() (uid int) 258 //sysnb Getgid() (gid int) 259 //sysnb Getpgid(pid int) (pgid int, err error) 260 //sysnb Getpgrp() (pgrp int) 261 //sysnb Getpid() (pid int) 262 //sysnb Getppid() (ppid int) 263 //sys Getpriority(which int, who int) (prio int, err error) 264 //sysnb Getrlimit(which int, lim *Rlimit) (err error) 265 //sysnb Getrusage(who int, rusage *Rusage) (err error) 266 //sysnb Getsid(pid int) (sid int, err error) 267 //sysnb Gettimeofday(tv *Timeval) (err error) 268 //sysnb Getuid() (uid int) 269 //sys Issetugid() (tainted bool) 270 //sys Kill(pid int, signum syscall.Signal) (err error) 271 //sys Kqueue() (fd int, err error) 272 //sys Lchown(path string, uid int, gid int) (err error) 273 //sys Link(path string, link string) (err error) 274 //sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) 275 //sys Listen(s int, backlog int) (err error) 276 //sys Lstat(path string, stat *Stat_t) (err error) 277 //sys Mkdir(path string, mode uint32) (err error) 278 //sys Mkdirat(dirfd int, path string, mode uint32) (err error) 279 //sys Mkfifo(path string, mode uint32) (err error) 280 //sys Mknod(path string, mode uint32, dev int) (err error) 281 //sys Mknodat(fd int, path string, mode uint32, dev int) (err error) 282 //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) 283 //sys Open(path string, mode int, perm uint32) (fd int, err error) 284 //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) 285 //sys Pathconf(path string, name int) (val int, err error) 286 //sys read(fd int, p []byte) (n int, err error) 287 //sys Readlink(path string, buf []byte) (n int, err error) 288 //sys Rename(from string, to string) (err error) 289 //sys Renameat(fromfd int, from string, tofd int, to string) (err error) 290 //sys Revoke(path string) (err error) 291 //sys Rmdir(path string) (err error) 292 //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK 293 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) 294 //sysnb Setegid(egid int) (err error) 295 //sysnb Seteuid(euid int) (err error) 296 //sysnb Setgid(gid int) (err error) 297 //sys Setlogin(name string) (err error) 298 //sysnb Setpgid(pid int, pgid int) (err error) 299 //sys Setpriority(which int, who int, prio int) (err error) 300 //sysnb Setregid(rgid int, egid int) (err error) 301 //sysnb Setreuid(ruid int, euid int) (err error) 302 //sysnb Setresgid(rgid int, egid int, sgid int) (err error) 303 //sysnb Setresuid(ruid int, euid int, suid int) (err error) 304 //sysnb Setrlimit(which int, lim *Rlimit) (err error) 305 //sysnb Setsid() (pid int, err error) 306 //sysnb Settimeofday(tp *Timeval) (err error) 307 //sysnb Setuid(uid int) (err error) 308 //sys Stat(path string, stat *Stat_t) (err error) 309 //sys Statfs(path string, stat *Statfs_t) (err error) 310 //sys Symlink(path string, link string) (err error) 311 //sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) 312 //sys Sync() (err error) 313 //sys Truncate(path string, length int64) (err error) 314 //sys Umask(newmask int) (oldmask int) 315 //sys Undelete(path string) (err error) 316 //sys Unlink(path string) (err error) 317 //sys Unlinkat(dirfd int, path string, flags int) (err error) 318 //sys Unmount(path string, flags int) (err error) 319 //sys write(fd int, p []byte) (n int, err error) 320 //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) 321 //sys munmap(addr uintptr, length uintptr) (err error) 322 //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ 323 //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE 324 //sys accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) 325 //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) 326 327 /* 328 * Unimplemented 329 * TODO(jsing): Update this list for DragonFly. 330 */ 331 // Profil 332 // Sigaction 333 // Sigprocmask 334 // Getlogin 335 // Sigpending 336 // Sigaltstack 337 // Reboot 338 // Execve 339 // Vfork 340 // Sbrk 341 // Sstk 342 // Ovadvise 343 // Mincore 344 // Setitimer 345 // Swapon 346 // Select 347 // Sigsuspend 348 // Readv 349 // Writev 350 // Nfssvc 351 // Getfh 352 // Quotactl 353 // Mount 354 // Csops 355 // Waitid 356 // Add_profil 357 // Kdebug_trace 358 // Sigreturn 359 // Atsocket 360 // Kqueue_from_portset_np 361 // Kqueue_portset 362 // Getattrlist 363 // Setattrlist 364 // Getdirentriesattr 365 // Searchfs 366 // Delete 367 // Copyfile 368 // Watchevent 369 // Waitevent 370 // Modwatch 371 // Getxattr 372 // Fgetxattr 373 // Setxattr 374 // Fsetxattr 375 // Removexattr 376 // Fremovexattr 377 // Listxattr 378 // Flistxattr 379 // Fsctl 380 // Initgroups 381 // Posix_spawn 382 // Nfsclnt 383 // Fhopen 384 // Minherit 385 // Semsys 386 // Msgsys 387 // Shmsys 388 // Semctl 389 // Semget 390 // Semop 391 // Msgctl 392 // Msgget 393 // Msgsnd 394 // Msgrcv 395 // Shmat 396 // Shmctl 397 // Shmdt 398 // Shmget 399 // Shm_open 400 // Shm_unlink 401 // Sem_open 402 // Sem_close 403 // Sem_unlink 404 // Sem_wait 405 // Sem_trywait 406 // Sem_post 407 // Sem_getvalue 408 // Sem_init 409 // Sem_destroy 410 // Open_extended 411 // Umask_extended 412 // Stat_extended 413 // Lstat_extended 414 // Fstat_extended 415 // Chmod_extended 416 // Fchmod_extended 417 // Access_extended 418 // Settid 419 // Gettid 420 // Setsgroups 421 // Getsgroups 422 // Setwgroups 423 // Getwgroups 424 // Mkfifo_extended 425 // Mkdir_extended 426 // Identitysvc 427 // Shared_region_check_np 428 // Shared_region_map_np 429 // __pthread_mutex_destroy 430 // __pthread_mutex_init 431 // __pthread_mutex_lock 432 // __pthread_mutex_trylock 433 // __pthread_mutex_unlock 434 // __pthread_cond_init 435 // __pthread_cond_destroy 436 // __pthread_cond_broadcast 437 // __pthread_cond_signal 438 // Setsid_with_pid 439 // __pthread_cond_timedwait 440 // Aio_fsync 441 // Aio_return 442 // Aio_suspend 443 // Aio_cancel 444 // Aio_error 445 // Aio_read 446 // Aio_write 447 // Lio_listio 448 // __pthread_cond_wait 449 // Iopolicysys 450 // __pthread_kill 451 // __pthread_sigmask 452 // __sigwait 453 // __disable_threadsignal 454 // __pthread_markcancel 455 // __pthread_canceled 456 // __semwait_signal 457 // Proc_info 458 // Stat64_extended 459 // Lstat64_extended 460 // Fstat64_extended 461 // __pthread_chdir 462 // __pthread_fchdir 463 // Audit 464 // Auditon 465 // Getauid 466 // Setauid 467 // Getaudit 468 // Setaudit 469 // Getaudit_addr 470 // Setaudit_addr 471 // Auditctl 472 // Bsdthread_create 473 // Bsdthread_terminate 474 // Stack_snapshot 475 // Bsdthread_register 476 // Workq_open 477 // Workq_ops 478 // __mac_execve 479 // __mac_syscall 480 // __mac_get_file 481 // __mac_set_file 482 // __mac_get_link 483 // __mac_set_link 484 // __mac_get_proc 485 // __mac_set_proc 486 // __mac_get_fd 487 // __mac_set_fd 488 // __mac_get_pid 489 // __mac_get_lcid 490 // __mac_get_lctx 491 // __mac_set_lctx 492 // Setlcid 493 // Read_nocancel 494 // Write_nocancel 495 // Open_nocancel 496 // Close_nocancel 497 // Wait4_nocancel 498 // Recvmsg_nocancel 499 // Sendmsg_nocancel 500 // Recvfrom_nocancel 501 // Accept_nocancel 502 // Fcntl_nocancel 503 // Select_nocancel 504 // Fsync_nocancel 505 // Connect_nocancel 506 // Sigsuspend_nocancel 507 // Readv_nocancel 508 // Writev_nocancel 509 // Sendto_nocancel 510 // Pread_nocancel 511 // Pwrite_nocancel 512 // Waitid_nocancel 513 // Msgsnd_nocancel 514 // Msgrcv_nocancel 515 // Sem_wait_nocancel 516 // Aio_suspend_nocancel 517 // __sigwait_nocancel 518 // __semwait_signal_nocancel 519 // __mac_mount 520 // __mac_get_mount 521 // __mac_getfsstat