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.
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.
17 // SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
18 type SockaddrDatalink struct {
29 raw RawSockaddrDatalink
32 // Translate "kern.hostname" to []_C_int{0,1,2,3}.
33 func nametomib(name string) (mib []_C_int, err error) {
34 const siz = unsafe.Sizeof(mib[0])
36 // NOTE(rsc): It seems strange to set the buffer to have
37 // size CTL_MAXNAME+2 but use only CTL_MAXNAME
38 // as the size. I don't know why the +2 is here, but the
39 // kernel uses +2 for its own implementation of this function.
40 // I am scared that if we don't include the +2 here, the kernel
41 // will silently write 2 words farther than we specify
42 // and we'll get memory corruption.
43 var buf [CTL_MAXNAME + 2]_C_int
44 n := uintptr(CTL_MAXNAME) * siz
46 p := (*byte)(unsafe.Pointer(&buf[0]))
47 bytes, err := ByteSliceFromString(name)
52 // Magic sysctl: "setting" 0.3 to a string name
53 // lets you read back the array of integers form.
54 if err = sysctl([]_C_int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil {
57 return buf[0 : n/siz], nil
60 //sysnb pipe() (r int, w int, err error)
62 func Pipe(p []int) (err error) {
66 p[0], p[1], err = pipe()
70 //sys extpread(fd int, p []byte, flags int, offset int64) (n int, err error)
71 func Pread(fd int, p []byte, offset int64) (n int, err error) {
72 return extpread(fd, p, 0, offset)
75 //sys extpwrite(fd int, p []byte, flags int, offset int64) (n int, err error)
76 func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
77 return extpwrite(fd, p, 0, offset)
80 func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
81 var rsa RawSockaddrAny
82 var len _Socklen = SizeofSockaddrAny
83 nfd, err = accept4(fd, &rsa, &len, flags)
87 if len > SizeofSockaddrAny {
88 panic("RawSockaddrAny too small")
90 sa, err = anyToSockaddr(fd, &rsa)
98 const ImplementsGetwd = true
100 //sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD
102 func Getwd() (string, error) {
103 var buf [PathMax]byte
104 _, err := Getcwd(buf[0:])
112 return string(buf[:n]), nil
115 func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
116 var _p0 unsafe.Pointer
119 _p0 = unsafe.Pointer(&buf[0])
120 bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
122 r0, _, e1 := Syscall(SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
130 func setattrlistTimes(path string, times []Timespec, flags int) error {
131 // used on Darwin for UtimesNano
135 //sys ioctl(fd int, req uint, arg uintptr) (err error)
137 // ioctl itself should not be exposed directly, but additional get/set
138 // functions for specific types are permissible.
140 // IoctlSetInt performs an ioctl operation which sets an integer value
141 // on fd, using the specified request number.
142 func IoctlSetInt(fd int, req uint, value int) error {
143 return ioctl(fd, req, uintptr(value))
146 func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
147 return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
150 func ioctlSetTermios(fd int, req uint, value *Termios) error {
151 return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
154 // IoctlGetInt performs an ioctl operation which gets an integer value
155 // from fd, using the specified request number.
156 func IoctlGetInt(fd int, req uint) (int, error) {
158 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
162 func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
164 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
168 func IoctlGetTermios(fd int, req uint) (*Termios, error) {
170 err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
174 func sysctlUname(mib []_C_int, old *byte, oldlen *uintptr) error {
175 err := sysctl(mib, old, oldlen, nil, 0)
177 // Utsname members on Dragonfly are only 32 bytes and
178 // the syscall returns ENOMEM in case the actual value
187 func Uname(uname *Utsname) error {
188 mib := []_C_int{CTL_KERN, KERN_OSTYPE}
189 n := unsafe.Sizeof(uname.Sysname)
190 if err := sysctlUname(mib, &uname.Sysname[0], &n); err != nil {
193 uname.Sysname[unsafe.Sizeof(uname.Sysname)-1] = 0
195 mib = []_C_int{CTL_KERN, KERN_HOSTNAME}
196 n = unsafe.Sizeof(uname.Nodename)
197 if err := sysctlUname(mib, &uname.Nodename[0], &n); err != nil {
200 uname.Nodename[unsafe.Sizeof(uname.Nodename)-1] = 0
202 mib = []_C_int{CTL_KERN, KERN_OSRELEASE}
203 n = unsafe.Sizeof(uname.Release)
204 if err := sysctlUname(mib, &uname.Release[0], &n); err != nil {
207 uname.Release[unsafe.Sizeof(uname.Release)-1] = 0
209 mib = []_C_int{CTL_KERN, KERN_VERSION}
210 n = unsafe.Sizeof(uname.Version)
211 if err := sysctlUname(mib, &uname.Version[0], &n); err != nil {
215 // The version might have newlines or tabs in it, convert them to
217 for i, b := range uname.Version {
218 if b == '\n' || b == '\t' {
219 if i == len(uname.Version)-1 {
222 uname.Version[i] = ' '
227 mib = []_C_int{CTL_HW, HW_MACHINE}
228 n = unsafe.Sizeof(uname.Machine)
229 if err := sysctlUname(mib, &uname.Machine[0], &n); err != nil {
232 uname.Machine[unsafe.Sizeof(uname.Machine)-1] = 0
237 func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
239 raceReleaseMerge(unsafe.Pointer(&ioSync))
241 return sendfile(outfd, infd, offset, count)
247 //sys Access(path string, mode uint32) (err error)
248 //sys Adjtime(delta *Timeval, olddelta *Timeval) (err error)
249 //sys Chdir(path string) (err error)
250 //sys Chflags(path string, flags int) (err error)
251 //sys Chmod(path string, mode uint32) (err error)
252 //sys Chown(path string, uid int, gid int) (err error)
253 //sys Chroot(path string) (err error)
254 //sys Close(fd int) (err error)
255 //sys Dup(fd int) (nfd int, err error)
256 //sys Dup2(from int, to int) (err error)
258 //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
259 //sys Fchdir(fd int) (err error)
260 //sys Fchflags(fd int, flags int) (err error)
261 //sys Fchmod(fd int, mode uint32) (err error)
262 //sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
263 //sys Fchown(fd int, uid int, gid int) (err error)
264 //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
265 //sys Flock(fd int, how int) (err error)
266 //sys Fpathconf(fd int, name int) (val int, err error)
267 //sys Fstat(fd int, stat *Stat_t) (err error)
268 //sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
269 //sys Fstatfs(fd int, stat *Statfs_t) (err error)
270 //sys Fsync(fd int) (err error)
271 //sys Ftruncate(fd int, length int64) (err error)
272 //sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
273 //sys Getdtablesize() (size int)
274 //sysnb Getegid() (egid int)
275 //sysnb Geteuid() (uid int)
276 //sysnb Getgid() (gid int)
277 //sysnb Getpgid(pid int) (pgid int, err error)
278 //sysnb Getpgrp() (pgrp int)
279 //sysnb Getpid() (pid int)
280 //sysnb Getppid() (ppid int)
281 //sys Getpriority(which int, who int) (prio int, err error)
282 //sysnb Getrlimit(which int, lim *Rlimit) (err error)
283 //sysnb Getrusage(who int, rusage *Rusage) (err error)
284 //sysnb Getsid(pid int) (sid int, err error)
285 //sysnb Gettimeofday(tv *Timeval) (err error)
286 //sysnb Getuid() (uid int)
287 //sys Issetugid() (tainted bool)
288 //sys Kill(pid int, signum syscall.Signal) (err error)
289 //sys Kqueue() (fd int, err error)
290 //sys Lchown(path string, uid int, gid int) (err error)
291 //sys Link(path string, link string) (err error)
292 //sys Linkat(pathfd int, path string, linkfd int, link string, flags int) (err error)
293 //sys Listen(s int, backlog int) (err error)
294 //sys Lstat(path string, stat *Stat_t) (err error)
295 //sys Mkdir(path string, mode uint32) (err error)
296 //sys Mkdirat(dirfd int, path string, mode uint32) (err error)
297 //sys Mkfifo(path string, mode uint32) (err error)
298 //sys Mknod(path string, mode uint32, dev int) (err error)
299 //sys Mknodat(fd int, path string, mode uint32, dev int) (err error)
300 //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
301 //sys Open(path string, mode int, perm uint32) (fd int, err error)
302 //sys Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error)
303 //sys Pathconf(path string, name int) (val int, err error)
304 //sys read(fd int, p []byte) (n int, err error)
305 //sys Readlink(path string, buf []byte) (n int, err error)
306 //sys Rename(from string, to string) (err error)
307 //sys Renameat(fromfd int, from string, tofd int, to string) (err error)
308 //sys Revoke(path string) (err error)
309 //sys Rmdir(path string) (err error)
310 //sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_LSEEK
311 //sys Select(n int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (err error)
312 //sysnb Setegid(egid int) (err error)
313 //sysnb Seteuid(euid int) (err error)
314 //sysnb Setgid(gid int) (err error)
315 //sys Setlogin(name string) (err error)
316 //sysnb Setpgid(pid int, pgid int) (err error)
317 //sys Setpriority(which int, who int, prio int) (err error)
318 //sysnb Setregid(rgid int, egid int) (err error)
319 //sysnb Setreuid(ruid int, euid int) (err error)
320 //sysnb Setresgid(rgid int, egid int, sgid int) (err error)
321 //sysnb Setresuid(ruid int, euid int, suid int) (err error)
322 //sysnb Setrlimit(which int, lim *Rlimit) (err error)
323 //sysnb Setsid() (pid int, err error)
324 //sysnb Settimeofday(tp *Timeval) (err error)
325 //sysnb Setuid(uid int) (err error)
326 //sys Stat(path string, stat *Stat_t) (err error)
327 //sys Statfs(path string, stat *Statfs_t) (err error)
328 //sys Symlink(path string, link string) (err error)
329 //sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error)
330 //sys Sync() (err error)
331 //sys Truncate(path string, length int64) (err error)
332 //sys Umask(newmask int) (oldmask int)
333 //sys Undelete(path string) (err error)
334 //sys Unlink(path string) (err error)
335 //sys Unlinkat(dirfd int, path string, flags int) (err error)
336 //sys Unmount(path string, flags int) (err error)
337 //sys write(fd int, p []byte) (n int, err error)
338 //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error)
339 //sys munmap(addr uintptr, length uintptr) (err error)
340 //sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_READ
341 //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE
342 //sys accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error)
343 //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
347 * TODO(jsing): Update this list for DragonFly.
378 // Kqueue_from_portset_np
445 // Shared_region_check_np
446 // Shared_region_map_np
447 // __pthread_mutex_destroy
448 // __pthread_mutex_init
449 // __pthread_mutex_lock
450 // __pthread_mutex_trylock
451 // __pthread_mutex_unlock
452 // __pthread_cond_init
453 // __pthread_cond_destroy
454 // __pthread_cond_broadcast
455 // __pthread_cond_signal
457 // __pthread_cond_timedwait
466 // __pthread_cond_wait
471 // __disable_threadsignal
472 // __pthread_markcancel
473 // __pthread_canceled
491 // Bsdthread_terminate
493 // Bsdthread_register
524 // Sigsuspend_nocancel
534 // Aio_suspend_nocancel
535 // __sigwait_nocancel
536 // __semwait_signal_nocancel