1// Copyright 2018 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// +build arm64,freebsd
6
7package unix
8
9import (
10	"syscall"
11	"unsafe"
12)
13
14func Getpagesize() int { return 4096 }
15
16func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
17
18func NsecToTimespec(nsec int64) (ts Timespec) {
19	ts.Sec = nsec / 1e9
20	ts.Nsec = nsec % 1e9
21	return
22}
23
24func NsecToTimeval(nsec int64) (tv Timeval) {
25	nsec += 999 // round up to microsecond
26	tv.Usec = nsec % 1e9 / 1e3
27	tv.Sec = int64(nsec / 1e9)
28	return
29}
30
31func SetKevent(k *Kevent_t, fd, mode, flags int) {
32	k.Ident = uint64(fd)
33	k.Filter = int16(mode)
34	k.Flags = uint16(flags)
35}
36
37func (iov *Iovec) SetLen(length int) {
38	iov.Len = uint64(length)
39}
40
41func (msghdr *Msghdr) SetControllen(length int) {
42	msghdr.Controllen = uint32(length)
43}
44
45func (cmsg *Cmsghdr) SetLen(length int) {
46	cmsg.Len = uint32(length)
47}
48
49func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
50	var writtenOut uint64 = 0
51	_, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0, 0)
52
53	written = int(writtenOut)
54
55	if e1 != 0 {
56		err = e1
57	}
58	return
59}
60
61func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
62