1// Copyright 2014 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
5package syscall
6
7import "unsafe"
8
9func setTimespec(sec, nsec int64) Timespec {
10	return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
11}
12
13func setTimeval(sec, usec int64) Timeval {
14	return Timeval{Sec: int32(sec), Usec: int32(usec)}
15}
16
17//sys	Fstat(fd int, stat *Stat_t) (err error)
18//sys	Fstatfs(fd int, stat *Statfs_t) (err error)
19//sysnb	Gettimeofday(tp *Timeval) (err error)
20//sys	Lstat(path string, stat *Stat_t) (err error)
21//sys	Stat(path string, stat *Stat_t) (err error)
22//sys	Statfs(path string, stat *Statfs_t) (err error)
23//sys   fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
24
25// Marked nosplit because it is called from forkAndExecInChild where
26// stack growth is forbidden.
27//go:nosplit
28func ptrace(request int, pid int, addr uintptr, data uintptr) error {
29	return ENOTSUP
30}
31
32func SetKevent(k *Kevent_t, fd, mode, flags int) {
33	k.Ident = uint32(fd)
34	k.Filter = int16(mode)
35	k.Flags = uint16(flags)
36}
37
38func (iov *Iovec) SetLen(length int) {
39	iov.Len = uint32(length)
40}
41
42func (msghdr *Msghdr) SetControllen(length int) {
43	msghdr.Controllen = uint32(length)
44}
45
46func (cmsg *Cmsghdr) SetLen(length int) {
47	cmsg.Len = uint32(length)
48}
49
50func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
51	var length = uint64(count)
52
53	_, _, e1 := Syscall9(funcPC(libc_sendfile_trampoline), uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(*offset>>32), uintptr(unsafe.Pointer(&length)), 0, 0, 0, 0)
54
55	written = int(length)
56
57	if e1 != 0 {
58		err = e1
59	}
60	return
61}
62
63func libc_sendfile_trampoline()
64
65//go:linkname libc_sendfile libc_sendfile
66//go:cgo_import_dynamic libc_sendfile sendfile "/usr/lib/libSystem.B.dylib"
67
68// Implemented in the runtime package (runtime/sys_darwin_32.go)
69func syscall9(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
70
71func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) // sic
72