Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 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 | package syscall |
| 6 | |
Shenghou Ma | 72faa4b | 2013-07-12 04:34:54 +0800 | [diff] [blame] | 7 | import "unsafe" |
| 8 | |
Robert Griesemer | d65a5cc | 2009-12-15 15:40:16 -0800 | [diff] [blame] | 9 | func Getpagesize() int { return 4096 } |
David Symonds | e02d3e8 | 2009-06-03 03:25:34 -0700 | [diff] [blame] | 10 | |
Robert Griesemer | d65a5cc | 2009-12-15 15:40:16 -0800 | [diff] [blame] | 11 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 12 | |
| 13 | func NsecToTimespec(nsec int64) (ts Timespec) { |
Robert Griesemer | d65a5cc | 2009-12-15 15:40:16 -0800 | [diff] [blame] | 14 | ts.Sec = nsec / 1e9 |
| 15 | ts.Nsec = nsec % 1e9 |
| 16 | return |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 17 | } |
| 18 | |
Robert Griesemer | d65a5cc | 2009-12-15 15:40:16 -0800 | [diff] [blame] | 19 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 20 | |
| 21 | func NsecToTimeval(nsec int64) (tv Timeval) { |
Robert Griesemer | d65a5cc | 2009-12-15 15:40:16 -0800 | [diff] [blame] | 22 | nsec += 999 // round up to microsecond |
| 23 | tv.Usec = int32(nsec % 1e9 / 1e3) |
| 24 | tv.Sec = int64(nsec / 1e9) |
| 25 | return |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 26 | } |
Russ Cox | 73c10dd | 2009-06-02 23:22:12 -0700 | [diff] [blame] | 27 | |
Russ Cox | c017a82 | 2011-11-13 22:44:52 -0500 | [diff] [blame] | 28 | //sysnb gettimeofday(tp *Timeval) (sec int64, usec int32, err error) |
| 29 | func Gettimeofday(tv *Timeval) (err error) { |
Russ Cox | 73c10dd | 2009-06-02 23:22:12 -0700 | [diff] [blame] | 30 | // The tv passed to gettimeofday must be non-nil |
| 31 | // but is otherwise unused. The answers come back |
| 32 | // in the two registers. |
Robert Griesemer | d65a5cc | 2009-12-15 15:40:16 -0800 | [diff] [blame] | 33 | sec, usec, err := gettimeofday(tv) |
| 34 | tv.Sec = sec |
| 35 | tv.Usec = usec |
| 36 | return err |
Russ Cox | 73c10dd | 2009-06-02 23:22:12 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 39 | func SetKevent(k *Kevent_t, fd, mode, flags int) { |
Robert Griesemer | d65a5cc | 2009-12-15 15:40:16 -0800 | [diff] [blame] | 40 | k.Ident = uint64(fd) |
| 41 | k.Filter = int16(mode) |
| 42 | k.Flags = uint16(flags) |
Russ Cox | 3a0df4c | 2009-06-04 11:16:03 -0700 | [diff] [blame] | 43 | } |
Mikio Hara | 5d6f118 | 2011-06-20 18:40:20 -0400 | [diff] [blame] | 44 | |
| 45 | func (iov *Iovec) SetLen(length int) { |
| 46 | iov.Len = uint64(length) |
| 47 | } |
| 48 | |
| 49 | func (msghdr *Msghdr) SetControllen(length int) { |
| 50 | msghdr.Controllen = uint32(length) |
| 51 | } |
| 52 | |
| 53 | func (cmsg *Cmsghdr) SetLen(length int) { |
| 54 | cmsg.Len = uint32(length) |
| 55 | } |
Shenghou Ma | 72faa4b | 2013-07-12 04:34:54 +0800 | [diff] [blame] | 56 | |
| 57 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { |
| 58 | var length = uint64(count) |
| 59 | |
| 60 | _, _, e1 := Syscall6(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(unsafe.Pointer(&length)), 0, 0) |
| 61 | |
| 62 | written = int(length) |
| 63 | |
| 64 | if e1 != 0 { |
| 65 | err = e1 |
| 66 | } |
| 67 | return |
| 68 | } |
| 69 | |
Mikio Hara | b100216 | 2015-03-03 12:15:53 +0900 | [diff] [blame] | 70 | func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) |