github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/sys/unix/syscall_openbsd.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 // OpenBSD 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 ( 16 "sort" 17 "syscall" 18 "unsafe" 19 ) 20 21 //sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL 22 23 // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets. 24 type SockaddrDatalink struct { 25 Len uint8 26 Family uint8 27 Index uint16 28 Type uint8 29 Nlen uint8 30 Alen uint8 31 Slen uint8 32 Data [24]int8 33 raw RawSockaddrDatalink 34 } 35 36 func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 37 38 func nametomib(name string) (mib []_C_int, err error) { 39 i := sort.Search(len(sysctlMib), func(i int) bool { 40 return sysctlMib[i].ctlname >= name 41 }) 42 if i < len(sysctlMib) && sysctlMib[i].ctlname == name { 43 return sysctlMib[i].ctloid, nil 44 } 45 return nil, EINVAL 46 } 47 48 func direntIno(buf []byte) (uint64, bool) { 49 return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno)) 50 } 51 52 func direntReclen(buf []byte) (uint64, bool) { 53 return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen)) 54 } 55 56 func direntNamlen(buf []byte) (uint64, bool) { 57 return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) 58 } 59 60 func SysctlClockinfo(name string) (*Clockinfo, error) { 61 mib, err := sysctlmib(name) 62 if err != nil { 63 return nil, err 64 } 65 66 n := uintptr(SizeofClockinfo) 67 var ci Clockinfo 68 if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil { 69 return nil, err 70 } 71 if n != SizeofClockinfo { 72 return nil, EIO 73 } 74 return &ci, nil 75 } 76 77 func SysctlUvmexp(name string) (*Uvmexp, error) { 78 mib, err := sysctlmib(name) 79 if err != nil { 80 return nil, err 81 } 82 83 n := uintptr(SizeofUvmexp) 84 var u Uvmexp 85 if err := sysctl(mib, (*byte)(unsafe.Pointer(&u)), &n, nil, 0); err != nil { 86 return nil, err 87 } 88 if n != SizeofUvmexp { 89 return nil, EIO 90 } 91 return &u, nil 92 } 93 94 //sysnb pipe(p *[2]_C_int) (err error) 95 func Pipe(p []int) (err error) { 96 if len(p) != 2 { 97 return EINVAL 98 } 99 var pp [2]_C_int 100 err = pipe(&pp) 101 p[0] = int(pp[0]) 102 p[1] = int(pp[1]) 103 return 104 } 105 106 //sys Getdents(fd int, buf []byte) (n int, err error) 107 func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { 108 n, err = Getdents(fd, buf) 109 if err != nil || basep == nil { 110 return 111 } 112 113 var off int64 114 off, err = Seek(fd, 0, 1 /* SEEK_CUR */) 115 if err != nil { 116 *basep = ^uintptr(0) 117 return 118 } 119 *basep = uintptr(off) 120 if unsafe.Sizeof(*basep) == 8 { 121 return 122 } 123 if off>>32 != 0 { 124 // We can't stuff the offset back into a uintptr, so any 125 // future calls would be suspect. Generate an error. 126 // EIO was allowed by getdirentries. 127 err = EIO 128 } 129 return 130 } 131 132 const ImplementsGetwd = true 133 134 //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD 135 136 func Getwd() (string, error) { 137 var buf [PathMax]byte 138 _, err := Getcwd(buf[0:]) 139 if err != nil { 140 return "", err 141 } 142 n := clen(buf[:]) 143 if n < 1 { 144 return "", EINVAL 145 } 146 return string(buf[:n]), nil 147 } 148 149 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 150 if raceenabled { 151 raceReleaseMerge(unsafe.Pointer(&ioSync)) 152 } 153 return sendfile(outfd, infd, offset, count) 154 } 155 156 // TODO 157 func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 158 return -1, ENOSYS 159 } 160 161 func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { 162 var _p0 unsafe.Pointer 163 var bufsize uintptr 164 if len(buf) > 0 { 165 _p0 = unsafe.Pointer(&buf[0]) 166 bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) 167 } 168 r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) 169 n = int(r0) 170 if e1 != 0 { 171 err = e1 172 } 173 return 174 } 175 176 func setattrlistTimes(path string, times []Timespec, flags int) error { 177 // used on Darwin for UtimesNano 178 return ENOSYS 179 } 180 181 //sys ioctl(fd int, req uint, arg uintptr) (err error) 182 183 //sys ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error) 184 185 func Ppoll(fds []PollFd, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { 186 if len(fds) == 0 { 187 return ppoll(nil, 0, timeout, sigmask) 188 } 189 return ppoll(&fds[0], len(fds), timeout, sigmask) 190 } 191 192 func Uname(uname *Utsname) error { 193 mib := []_C_int{CTL_KERN, KERN_OSTYPE} 194 n := unsafe.Sizeof(uname.Sysname) 195 if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil { 196 return err 197 } 198 199 mib = []_C_int{CTL_KERN, KERN_HOSTNAME} 200 n = unsafe.Sizeof(uname.Nodename) 201 if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil { 202 return err 203 } 204 205 mib = []_C_int{CTL_KERN, KERN_OSRELEASE} 206 n = unsafe.Sizeof(uname.Release) 207 if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil { 208 return err 209 } 210 211 mib = []_C_int{CTL_KERN, KERN_VERSION} 212 n = unsafe.Sizeof(uname.Version) 213 if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil { 214 return err 215 } 216 217 // The version might have newlines or tabs in it, convert them to 218 // spaces. 219 for i, b := range uname.Version { 220 if b == '\n' || b == '\t' { 221 if i == len(uname.Version)-1 { 222 uname.Version[i] = 0 223 } else { 224 uname.Version[i] = ' ' 225 } 226 } 227 } 228 229 mib = []_C_int{CTL_HW, HW_MACHINE} 230 n = unsafe.Sizeof(uname.Machine) 231 if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil { 232 return err 233 } 234 235 return nil 236 } 237 238 /* 239 * Exposed directly 240 */ 241 //sys Access(path string, mode uint32) (err error) 242 //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error) 243 //sys Chdir(path string) (err error) 244 //sys Chflags(path string, flags int) (err error) 245 //sys Chmod(path string, mode uint32) (err error) 246 //sys Chown(path string, uid int, gid int) (err error) 247 //sys Chroot(path string) (err error) 248 //sys Close(fd int) (err error) 249 //sys Dup(fd int) (nfd int, err error) 250 //sys Dup2(from int, to int) (err error) 251 //sys Exit(code int) 252 //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) 253 //sys Fchdir(fd int) (err error) 254 //sys Fchflags(fd int, flags int) (err error) 255 //sys Fchmod(fd int, mode uint32) (err error) 256 //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) 257 //sys Fchown(fd int, uid int, gid int) (err error) 258 //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) 259 //sys Flock(fd int, how int) (err error) 260 //sys Fpathconf(fd int, name int) (val int, err error) 261 //sys Fstat(fd int, stat *Stat_t) (err error) 262 //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) 263 //sys Fstatfs(fd int, stat *Statfs_t) (err error) 264 //sys Fsync(fd int) (err error) 265 //sys Ftruncate(fd int, length int64) (err error) 266 //sysnb Getegid() (egid int) 267 //sysnb Geteuid() (uid int) 268 //sysnb Getgid() (gid int) 269 //sysnb Getpgid(pid int) (pgid int, err error) 270 //sysnb Getpgrp() (pgrp int) 271 //sysnb Getpid() (pid int) 272 //sysnb Getppid() (ppid int) 273 //sys Getpriority(which int, who int) (prio int, err error) 274 //sysnb Getrlimit(which int, lim *Rlimit) (err error) 275 //sysnb Getrtable() (rtable int, err error) 276 //sysnb Getrusage(who int, rusage *Rusage) (err error) 277 //sysnb Getsid(pid int) (sid int, err error) 278 //sysnb Gettimeofday(tv *Timeval) (err error) 279 //sysnb Getuid() (uid int) 280 //sys Issetugid() (tainted bool) 281 //sys Kill(pid int, signum syscall.Signal) (err error) 282 //sys Kqueue() (fd int, err error) 283 //sys Lchown(path string, uid int, gid int) (err error) 284 //sys Link(path string, link string) (err error) 285 //sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error) 286 //sys Listen(s int, backlog int) (err error) 287 //sys Lstat(path string, stat *Stat_t) (err error) 288 //sys Mkdir(path string, mode uint32) (err error) 289 //sys Mkdirat(dirfd int, path string, mode uint32) (err error) 290 //sys Mkfifo(path string, mode uint32) (err error) 291 //sys Mkfifoat(dirfd int, path string, mode uint32) (err error) 292 //sys Mknod(path string, mode uint32, dev int) (err error) 293 //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error) 294 //sys Nanosleep(time *Timespec, leftover *Timespec) (err error) 295 //sys Open(path string, mode int, perm uint32) (fd int, err error) 296 //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) 297 //sys Pathconf(path string, name int) (val int, err error) 298 //sys Pread(fd int, p []byte, offset int64) (n int, err error) 299 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) 300 //sys read(fd int, p []byte) (n int, err error) 301 //sys Readlink(path string, buf []byte) (n int, err error) 302 //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error) 303 //sys Rename(from string, to string) (err error) 304 //sys Renameat(fromfd int, from string, tofd int, to string) (err error) 305 //sys Revoke(path string) (err error) 306 //sys Rmdir(path string) (err error) 307 //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK 308 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) 309 //sysnb Setegid(egid int) (err error) 310 //sysnb Seteuid(euid int) (err error) 311 //sysnb Setgid(gid int) (err error) 312 //sys Setlogin(name string) (err error) 313 //sysnb Setpgid(pid int, pgid int) (err error) 314 //sys Setpriority(which int, who int, prio int) (err error) 315 //sysnb Setregid(rgid int, egid int) (err error) 316 //sysnb Setreuid(ruid int, euid int) (err error) 317 //sysnb Setresgid(rgid int, egid int, sgid int) (err error) 318 //sysnb Setresuid(ruid int, euid int, suid int) (err error) 319 //sysnb Setrlimit(which int, lim *Rlimit) (err error) 320 //sysnb Setrtable(rtable int) (err error) 321 //sysnb Setsid() (pid int, err error) 322 //sysnb Settimeofday(tp *Timeval) (err error) 323 //sysnb Setuid(uid int) (err error) 324 //sys Stat(path string, stat *Stat_t) (err error) 325 //sys Statfs(path string, stat *Statfs_t) (err error) 326 //sys Symlink(path string, link string) (err error) 327 //sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error) 328 //sys Sync() (err error) 329 //sys Truncate(path string, length int64) (err error) 330 //sys Umask(newmask int) (oldmask int) 331 //sys Unlink(path string) (err error) 332 //sys Unlinkat(dirfd int, path string, flags int) (err error) 333 //sys Unmount(path string, flags int) (err error) 334 //sys write(fd int, p []byte) (n int, err error) 335 //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) 336 //sys munmap(addr uintptr, length uintptr) (err error) 337 //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ 338 //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE 339 //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) 340 341 /* 342 * Unimplemented 343 */ 344 // __getcwd 345 // __semctl 346 // __syscall 347 // __sysctl 348 // adjfreq 349 // break 350 // clock_getres 351 // clock_gettime 352 // clock_settime 353 // closefrom 354 // execve 355 // fcntl 356 // fhopen 357 // fhstat 358 // fhstatfs 359 // fork 360 // futimens 361 // getfh 362 // getgid 363 // getitimer 364 // getlogin 365 // getresgid 366 // getresuid 367 // getthrid 368 // ktrace 369 // lfs_bmapv 370 // lfs_markv 371 // lfs_segclean 372 // lfs_segwait 373 // mincore 374 // minherit 375 // mount 376 // mquery 377 // msgctl 378 // msgget 379 // msgrcv 380 // msgsnd 381 // nfssvc 382 // nnpfspioctl 383 // preadv 384 // profil 385 // pwritev 386 // quotactl 387 // readv 388 // reboot 389 // renameat 390 // rfork 391 // sched_yield 392 // semget 393 // semop 394 // setgroups 395 // setitimer 396 // setsockopt 397 // shmat 398 // shmctl 399 // shmdt 400 // shmget 401 // sigaction 402 // sigaltstack 403 // sigpending 404 // sigprocmask 405 // sigreturn 406 // sigsuspend 407 // sysarch 408 // syscall 409 // threxit 410 // thrsigdivert 411 // thrsleep 412 // thrwakeup 413 // vfork 414 // writev